Skip to content

Commit 9d77f78

Browse files
committed
Consistently use normal object access notation for GLctx
We were already using the normal notation in most cases anyway: ``` $ git grep "GLctx\[" | wc -l 74 $ git grep "GLctx\." | wc -l 505 ``` IIUC we have tests that verify this doesn't break with --closure=1.
1 parent 07af96a commit 9d77f78

5 files changed

Lines changed: 120 additions & 73 deletions

File tree

embuilder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
'libemmalloc-verbose',
5757
'libemmalloc-memvalidate-verbose',
5858
'libGL',
59+
'libGL-emu-webgl2',
5960
'libhtml5',
6061
'libsockets',
6162
'libstubs',

src/library_webgl.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,14 +1435,14 @@ var LibraryGL = {
14351435
#if MAX_WEBGL_VERSION >= 2
14361436
if ({{{ isCurrentContextWebGL2() }}}) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
14371437
if (GLctx.currentPixelUnpackBufferBinding || !imageSize) {
1438-
GLctx['compressedTexImage2D'](target, level, internalFormat, width, height, border, imageSize, data);
1438+
GLctx.compressedTexImage2D(target, level, internalFormat, width, height, border, imageSize, data);
14391439
} else {
1440-
GLctx['compressedTexImage2D'](target, level, internalFormat, width, height, border, HEAPU8, data, imageSize);
1440+
GLctx.compressedTexImage2D(target, level, internalFormat, width, height, border, HEAPU8, data, imageSize);
14411441
}
14421442
return;
14431443
}
14441444
#endif
1445-
GLctx['compressedTexImage2D'](target, level, internalFormat, width, height, border, data ? {{{ makeHEAPView('U8', 'data', 'data+imageSize') }}} : null);
1445+
GLctx.compressedTexImage2D(target, level, internalFormat, width, height, border, data ? {{{ makeHEAPView('U8', 'data', 'data+imageSize') }}} : null);
14461446
},
14471447

14481448

@@ -1451,14 +1451,14 @@ var LibraryGL = {
14511451
#if MAX_WEBGL_VERSION >= 2
14521452
if ({{{ isCurrentContextWebGL2() }}}) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
14531453
if (GLctx.currentPixelUnpackBufferBinding || !imageSize) {
1454-
GLctx['compressedTexSubImage2D'](target, level, xoffset, yoffset, width, height, format, imageSize, data);
1454+
GLctx.compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data);
14551455
} else {
1456-
GLctx['compressedTexSubImage2D'](target, level, xoffset, yoffset, width, height, format, HEAPU8, data, imageSize);
1456+
GLctx.compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, HEAPU8, data, imageSize);
14571457
}
14581458
return;
14591459
}
14601460
#endif
1461-
GLctx['compressedTexSubImage2D'](target, level, xoffset, yoffset, width, height, format, data ? {{{ makeHEAPView('U8', 'data', 'data+imageSize') }}} : null);
1461+
GLctx.compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, data ? {{{ makeHEAPView('U8', 'data', 'data+imageSize') }}} : null);
14621462
},
14631463

14641464
$computeUnpackAlignedImageSize: function(width, height, sizePerPixel, alignment) {
@@ -1941,7 +1941,7 @@ var LibraryGL = {
19411941
}
19421942
#if MAX_WEBGL_VERSION >= 2
19431943
else {
1944-
param = GLctx['getQueryParameter'](query, pname);
1944+
param = GLctx.getQueryParameter(query, pname);
19451945
}
19461946
#endif
19471947
var ret;
@@ -3642,7 +3642,7 @@ var LibraryGL = {
36423642
_emulGlGenVertexArrays(n, arrays);
36433643
#else
36443644
#if GL_ASSERTIONS
3645-
assert(GLctx['createVertexArray'], 'Must have WebGL2 or OES_vertex_array_object to use vao');
3645+
assert(GLctx.createVertexArray, 'Must have WebGL2 or OES_vertex_array_object to use vao');
36463646
#endif
36473647
__glGenObject(n, arrays, 'createVertexArray', GL.vaos
36483648
#if GL_ASSERTIONS
@@ -3661,11 +3661,11 @@ var LibraryGL = {
36613661
_emulGlDeleteVertexArrays(n, vaos);
36623662
#else
36633663
#if GL_ASSERTIONS
3664-
assert(GLctx['deleteVertexArray'], 'Must have WebGL2 or OES_vertex_array_object to use vao');
3664+
assert(GLctx.deleteVertexArray, 'Must have WebGL2 or OES_vertex_array_object to use vao');
36653665
#endif
36663666
for (var i = 0; i < n; i++) {
36673667
var id = {{{ makeGetValue('vaos', 'i*4', 'i32') }}};
3668-
GLctx['deleteVertexArray'](GL.vaos[id]);
3668+
GLctx.deleteVertexArray(GL.vaos[id]);
36693669
GL.vaos[id] = null;
36703670
}
36713671
#endif
@@ -3680,9 +3680,9 @@ var LibraryGL = {
36803680
_emulGlBindVertexArray(vao);
36813681
#else
36823682
#if GL_ASSERTIONS
3683-
assert(GLctx['bindVertexArray'], 'Must have WebGL2 or OES_vertex_array_object to use vao');
3683+
assert(GLctx.bindVertexArray, 'Must have WebGL2 or OES_vertex_array_object to use vao');
36843684
#endif
3685-
GLctx['bindVertexArray'](GL.vaos[vao]);
3685+
GLctx.bindVertexArray(GL.vaos[vao]);
36863686
#endif
36873687
#if FULL_ES2 || LEGACY_GL_EMULATION
36883688
var ibo = GLctx.getParameter(0x8895 /*ELEMENT_ARRAY_BUFFER_BINDING*/);
@@ -3699,12 +3699,12 @@ var LibraryGL = {
36993699
return _emulGlIsVertexArray(array);
37003700
#else
37013701
#if GL_ASSERTIONS
3702-
assert(GLctx['isVertexArray'], 'Must have WebGL2 or OES_vertex_array_object to use vao');
3702+
assert(GLctx.isVertexArray, 'Must have WebGL2 or OES_vertex_array_object to use vao');
37033703
#endif
37043704

37053705
var vao = GL.vaos[array];
37063706
if (!vao) return 0;
3707-
return GLctx['isVertexArray'](vao);
3707+
return GLctx.isVertexArray(vao);
37083708
#endif
37093709
},
37103710

@@ -3860,25 +3860,25 @@ var LibraryGL = {
38603860
glVertexAttribDivisor__sig: 'vii',
38613861
glVertexAttribDivisor: function(index, divisor) {
38623862
#if GL_ASSERTIONS
3863-
assert(GLctx['vertexAttribDivisor'], 'Must have ANGLE_instanced_arrays extension or WebGL 2 to use WebGL instancing');
3863+
assert(GLctx.vertexAttribDivisor, 'Must have ANGLE_instanced_arrays extension or WebGL 2 to use WebGL instancing');
38643864
#endif
3865-
GLctx['vertexAttribDivisor'](index, divisor);
3865+
GLctx.vertexAttribDivisor(index, divisor);
38663866
},
38673867

38683868
glDrawArraysInstanced__sig: 'viiii',
38693869
glDrawArraysInstanced: function(mode, first, count, primcount) {
38703870
#if GL_ASSERTIONS
3871-
assert(GLctx['drawArraysInstanced'], 'Must have ANGLE_instanced_arrays extension or WebGL 2 to use WebGL instancing');
3871+
assert(GLctx.drawArraysInstanced, 'Must have ANGLE_instanced_arrays extension or WebGL 2 to use WebGL instancing');
38723872
#endif
3873-
GLctx['drawArraysInstanced'](mode, first, count, primcount);
3873+
GLctx.drawArraysInstanced(mode, first, count, primcount);
38743874
},
38753875

38763876
glDrawElementsInstanced__sig: 'viiipi',
38773877
glDrawElementsInstanced: function(mode, count, type, indices, primcount) {
38783878
#if GL_ASSERTIONS
3879-
assert(GLctx['drawElementsInstanced'], 'Must have ANGLE_instanced_arrays extension or WebGL 2 to use WebGL instancing');
3879+
assert(GLctx.drawElementsInstanced, 'Must have ANGLE_instanced_arrays extension or WebGL 2 to use WebGL instancing');
38803880
#endif
3881-
GLctx['drawElementsInstanced'](mode, count, type, indices, primcount);
3881+
GLctx.drawElementsInstanced(mode, count, type, indices, primcount);
38823882
},
38833883

38843884
// OpenGL Desktop/ES 2.0 instancing extensions compatibility
@@ -3901,7 +3901,7 @@ var LibraryGL = {
39013901
glDrawBuffers__sig: 'vip',
39023902
glDrawBuffers: function(n, bufs) {
39033903
#if GL_ASSERTIONS
3904-
assert(GLctx['drawBuffers'], 'Must have WebGL2 or WEBGL_draw_buffers extension to use drawBuffers');
3904+
assert(GLctx.drawBuffers, 'Must have WebGL2 or WEBGL_draw_buffers extension to use drawBuffers');
39053905
#endif
39063906
#if GL_ASSERTIONS
39073907
assert(n < tempFixedLengthArray.length, 'Invalid count of numBuffers=' + n + ' passed to glDrawBuffers (that many draw buffer points do not exist in GL)');
@@ -3912,7 +3912,7 @@ var LibraryGL = {
39123912
bufArray[i] = {{{ makeGetValue('bufs', 'i*4', 'i32') }}};
39133913
}
39143914

3915-
GLctx['drawBuffers'](bufArray);
3915+
GLctx.drawBuffers(bufArray);
39163916
},
39173917

39183918
// OpenGL ES 2.0 draw buffer extensions compatibility
@@ -4197,8 +4197,8 @@ function createGLPassthroughFunctions(lib, funcs) {
41974197
const num = data[0];
41984198
const names = data[1];
41994199
const args = range(num).map((i) => 'x' + i ).join(', ');
4200-
const plainStub = '(function(' + args + ') { GLctx[\'NAME\'](' + args + ') })';
4201-
const returnStub = '(function(' + args + ') { return GLctx[\'NAME\'](' + args + ') })';
4200+
const plainStub = '(function(' + args + ') { GLctx.NAME(' + args + ') })';
4201+
const returnStub = '(function(' + args + ') { return GLctx.NAME(' + args + ') })';
42024202
const sigEnd = range(num).map(() => 'i').join('');
42034203
names.split(' ').forEach((name) => {
42044204
let stub = plainStub;

0 commit comments

Comments
 (0)