diff --git a/src/library_webgl.js b/src/library_webgl.js index f052e2c95098..4fa7c4bd6268 100644 --- a/src/library_webgl.js +++ b/src/library_webgl.js @@ -309,6 +309,34 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}}; return ret; }, + // The code path for creating textures, buffers, framebuffers and other + // objects the same (and not in fast path), so we merge the functions + // together. + // 'createFunction' refers to the WebGL context function name to do the actual + // creation, 'objectTable' points to the GL object table where to populate the + // created objects, and 'functionName' carries the name of the caller for + // debug information. + genObject: (n, buffers, createFunction, objectTable +#if GL_ASSERTIONS + , functionName +#endif + ) => { + for (var i = 0; i < n; i++) { + var buffer = GLctx[createFunction](); + var id = buffer && GL.getNewId(objectTable); + if (buffer) { + buffer.name = id; + objectTable[id] = buffer; + } else { + GL.recordError(0x502 /* GL_INVALID_OPERATION */); +#if GL_ASSERTIONS + err(`GL_INVALID_OPERATION in ${functionName}: GLctx.${createFunction} returned null - most likely GL context is lost!`); +#endif + } + {{{ makeSetValue('buffers', 'i*4', 'id', 'i32') }}}; + } + }, + #if FULL_ES2 || LEGACY_GL_EMULATION // When user GL code wants to render from client-side memory, we need to // upload the vertex data to a temp VBO for rendering. Maintain a set of @@ -1770,46 +1798,16 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}}; return GLctx.isTexture(texture); }, - // The code path for creating textures, buffers, framebuffers and other - // objects is so identical to each other (and not in fast path), that merge - // the functions together to only have one generated copy of this. - // 'createFunction' refers to the WebGL context function name to do the actual - // creation, 'objectTable' points to the GL object table where to populate the - // created objects, and 'functionName' carries the name of the caller for - // debug information. - $__glGenObject: (n, buffers, createFunction, objectTable -#if GL_ASSERTIONS - , functionName -#endif - ) => { - for (var i = 0; i < n; i++) { - var buffer = GLctx[createFunction](); - var id = buffer && GL.getNewId(objectTable); - if (buffer) { - buffer.name = id; - objectTable[id] = buffer; - } else { - GL.recordError(0x502 /* GL_INVALID_OPERATION */); -#if GL_ASSERTIONS - err(`GL_INVALID_OPERATION in ${functionName}: GLctx.${createFunction} returned null - most likely GL context is lost!`); -#endif - } - {{{ makeSetValue('buffers', 'i*4', 'id', 'i32') }}}; - } - }, - - glGenBuffers__deps: ['$__glGenObject'], glGenBuffers: (n, buffers) => { - __glGenObject(n, buffers, 'createBuffer', GL.buffers + GL.genObject(n, buffers, 'createBuffer', GL.buffers #if GL_ASSERTIONS , 'glGenBuffers' #endif ); }, - glGenTextures__deps: ['$__glGenObject'], glGenTextures: (n, textures) => { - __glGenObject(n, textures, 'createTexture', GL.textures + GL.genObject(n, textures, 'createTexture', GL.textures #if GL_ASSERTIONS , 'glGenTextures' #endif @@ -2055,9 +2053,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}}; return GLctx.isBuffer(b); }, - glGenRenderbuffers__deps: ['$__glGenObject'], glGenRenderbuffers: (n, renderbuffers) => { - __glGenObject(n, renderbuffers, 'createRenderbuffer', GL.renderbuffers + GL.genObject(n, renderbuffers, 'createRenderbuffer', GL.renderbuffers #if GL_ASSERTIONS , 'glGenRenderbuffers' #endif @@ -3627,9 +3624,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}}; }, - glGenFramebuffers__deps: ['$__glGenObject'], glGenFramebuffers: (n, ids) => { - __glGenObject(n, ids, 'createFramebuffer', GL.framebuffers + GL.genObject(n, ids, 'createFramebuffer', GL.framebuffers #if GL_ASSERTIONS , 'glGenFramebuffers' #endif @@ -3678,11 +3674,9 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}}; return GLctx.isFramebuffer(fb); }, - glGenVertexArrays__deps: ['$__glGenObject' #if LEGACY_GL_EMULATION - , '$emulGlGenVertexArrays' + glGenVertexArrays__deps: ['$emulGlGenVertexArrays'], #endif - ], glGenVertexArrays: (n, arrays) => { #if LEGACY_GL_EMULATION emulGlGenVertexArrays(n, arrays); @@ -3690,7 +3684,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}}; #if GL_ASSERTIONS assert(GLctx.createVertexArray, 'Must have WebGL2 or OES_vertex_array_object to use vao'); #endif - __glGenObject(n, arrays, 'createVertexArray', GL.vaos + GL.genObject(n, arrays, 'createVertexArray', GL.vaos #if GL_ASSERTIONS , 'glGenVertexArrays' #endif diff --git a/src/library_webgl2.js b/src/library_webgl2.js index 49104f82dd67..269b18717a22 100644 --- a/src/library_webgl2.js +++ b/src/library_webgl2.js @@ -172,9 +172,8 @@ var LibraryWebGL2 = { }, // Queries - glGenQueries__deps: ['$__glGenObject'], glGenQueries: (n, ids) => { - __glGenObject(n, ids, 'createQuery', GL.queries + GL.genObject(n, ids, 'createQuery', GL.queries #if GL_ASSERTIONS , 'glGenQueries' #endif @@ -246,9 +245,8 @@ var LibraryWebGL2 = { }, // Sampler objects - glGenSamplers__deps: ['$__glGenObject'], glGenSamplers: (n, samplers) => { - __glGenObject(n, samplers, 'createSampler', GL.samplers + GL.genObject(n, samplers, 'createSampler', GL.samplers #if GL_ASSERTIONS , 'glGenSamplers' #endif @@ -340,9 +338,8 @@ var LibraryWebGL2 = { }, // Transform Feedback - glGenTransformFeedbacks__deps: ['$__glGenObject'], glGenTransformFeedbacks: (n, ids) => { - __glGenObject(n, ids, 'createTransformFeedback', GL.transformFeedbacks + GL.genObject(n, ids, 'createTransformFeedback', GL.transformFeedbacks #if GL_ASSERTIONS , 'glGenTransformFeedbacks' #endif diff --git a/test/code_size/hello_webgl2_wasm2js.json b/test/code_size/hello_webgl2_wasm2js.json index 2aeba687ca63..e110956066b7 100644 --- a/test/code_size/hello_webgl2_wasm2js.json +++ b/test/code_size/hello_webgl2_wasm2js.json @@ -2,9 +2,9 @@ "a.html": 567, "a.html.gz": 379, "a.js": 17795, - "a.js.gz": 7978, + "a.js.gz": 7979, "a.mem": 3123, "a.mem.gz": 2693, "total": 21485, - "total_gz": 11050 + "total_gz": 11051 } diff --git a/test/code_size/hello_webgl_wasm2js.json b/test/code_size/hello_webgl_wasm2js.json index 726c4ce0fe92..6b0dba343893 100644 --- a/test/code_size/hello_webgl_wasm2js.json +++ b/test/code_size/hello_webgl_wasm2js.json @@ -2,9 +2,9 @@ "a.html": 567, "a.html.gz": 379, "a.js": 17267, - "a.js.gz": 7813, + "a.js.gz": 7812, "a.mem": 3123, "a.mem.gz": 2693, "total": 20957, - "total_gz": 10885 + "total_gz": 10884 } diff --git a/test/other/metadce/test_metadce_hello_O0.gzsize b/test/other/metadce/test_metadce_hello_O0.gzsize index 3f69d1fa06d1..7947190fcc75 100644 --- a/test/other/metadce/test_metadce_hello_O0.gzsize +++ b/test/other/metadce/test_metadce_hello_O0.gzsize @@ -1 +1 @@ -8355 +8348 diff --git a/test/other/metadce/test_metadce_hello_O0.jssize b/test/other/metadce/test_metadce_hello_O0.jssize index 454310f5c5f7..41301b045f2b 100644 --- a/test/other/metadce/test_metadce_hello_O0.jssize +++ b/test/other/metadce/test_metadce_hello_O0.jssize @@ -1 +1 @@ -22908 +22894 diff --git a/test/other/metadce/test_metadce_minimal_O0.gzsize b/test/other/metadce/test_metadce_minimal_O0.gzsize index 0ddc2b4bb3f9..115ab5c6fb44 100644 --- a/test/other/metadce/test_metadce_minimal_O0.gzsize +++ b/test/other/metadce/test_metadce_minimal_O0.gzsize @@ -1 +1 @@ -7176 +7169 diff --git a/test/other/metadce/test_metadce_minimal_O0.jssize b/test/other/metadce/test_metadce_minimal_O0.jssize index f200c4ece6d1..ff2d16c42f62 100644 --- a/test/other/metadce/test_metadce_minimal_O0.jssize +++ b/test/other/metadce/test_metadce_minimal_O0.jssize @@ -1 +1 @@ -19532 +19518 diff --git a/test/other/test_unoptimized_code_size.js.size b/test/other/test_unoptimized_code_size.js.size index 196ff54aff67..a051d67f18d6 100644 --- a/test/other/test_unoptimized_code_size.js.size +++ b/test/other/test_unoptimized_code_size.js.size @@ -1 +1 @@ -58114 +58095