@@ -309,6 +309,34 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
309309 return ret ;
310310 } ,
311311
312+ // The code path for creating textures, buffers, framebuffers and other
313+ // objects the same (and not in fast path), so we merge the functions
314+ // together.
315+ // 'createFunction' refers to the WebGL context function name to do the actual
316+ // creation, 'objectTable' points to the GL object table where to populate the
317+ // created objects, and 'functionName' carries the name of the caller for
318+ // debug information.
319+ genObject : ( n , buffers , createFunction , objectTable
320+ #if GL_ASSERTIONS
321+ , functionName
322+ #endif
323+ ) => {
324+ for ( var i = 0 ; i < n ; i ++ ) {
325+ var buffer = GLctx [ createFunction ] ( ) ;
326+ var id = buffer && GL . getNewId ( objectTable ) ;
327+ if ( buffer ) {
328+ buffer . name = id ;
329+ objectTable [ id ] = buffer ;
330+ } else {
331+ GL . recordError ( 0x502 /* GL_INVALID_OPERATION */ ) ;
332+ #if GL_ASSERTIONS
333+ err ( `GL_INVALID_OPERATION in ${ functionName } : GLctx.${ createFunction } returned null - most likely GL context is lost!` ) ;
334+ #endif
335+ }
336+ { { { makeSetValue ( 'buffers' , 'i*4' , 'id' , 'i32' ) } } } ;
337+ }
338+ } ,
339+
312340#if FULL_ES2 || LEGACY_GL_EMULATION
313341 // When user GL code wants to render from client-side memory, we need to
314342 // 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 }}};
17701798 return GLctx . isTexture ( texture ) ;
17711799 } ,
17721800
1773- // The code path for creating textures, buffers, framebuffers and other
1774- // objects is so identical to each other (and not in fast path), that merge
1775- // the functions together to only have one generated copy of this.
1776- // 'createFunction' refers to the WebGL context function name to do the actual
1777- // creation, 'objectTable' points to the GL object table where to populate the
1778- // created objects, and 'functionName' carries the name of the caller for
1779- // debug information.
1780- $__glGenObject : ( n , buffers , createFunction , objectTable
1781- #if GL_ASSERTIONS
1782- , functionName
1783- #endif
1784- ) = > {
1785- for ( var i = 0 ; i < n ; i ++ ) {
1786- var buffer = GLctx [ createFunction ] ( ) ;
1787- var id = buffer && GL . getNewId ( objectTable ) ;
1788- if ( buffer ) {
1789- buffer . name = id ;
1790- objectTable [ id ] = buffer ;
1791- } else {
1792- GL . recordError ( 0x502 /* GL_INVALID_OPERATION */ ) ;
1793- #if GL_ASSERTIONS
1794- err ( `GL_INVALID_OPERATION in ${ functionName } : GLctx.${ createFunction } returned null - most likely GL context is lost!` ) ;
1795- #endif
1796- }
1797- { { { makeSetValue ( 'buffers' , 'i*4' , 'id' , 'i32' ) } } } ;
1798- }
1799- } ,
1800-
1801- glGenBuffers__deps : [ '$__glGenObject' ] ,
18021801 glGenBuffers : ( n , buffers ) => {
1803- __glGenObject ( n , buffers , 'createBuffer' , GL . buffers
1802+ GL . genObject ( n , buffers , 'createBuffer' , GL . buffers
18041803#if GL_ASSERTIONS
18051804 , 'glGenBuffers'
18061805#endif
18071806 ) ;
18081807 } ,
18091808
1810- glGenTextures__deps : [ '$__glGenObject' ] ,
18111809 glGenTextures : ( n , textures ) = > {
1812- __glGenObject ( n , textures , 'createTexture' , GL . textures
1810+ GL . genObject ( n , textures , 'createTexture' , GL . textures
18131811#if GL_ASSERTIONS
18141812 , 'glGenTextures'
18151813#endif
@@ -2055,9 +2053,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
20552053 return GLctx . isBuffer ( b ) ;
20562054 } ,
20572055
2058- glGenRenderbuffers__deps : [ '$__glGenObject' ] ,
20592056 glGenRenderbuffers : ( n , renderbuffers ) => {
2060- __glGenObject ( n , renderbuffers , 'createRenderbuffer' , GL . renderbuffers
2057+ GL . genObject ( n , renderbuffers , 'createRenderbuffer' , GL . renderbuffers
20612058#if GL_ASSERTIONS
20622059 , 'glGenRenderbuffers'
20632060#endif
@@ -3627,9 +3624,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
36273624
36283625 } ,
36293626
3630- glGenFramebuffers__deps : [ '$__glGenObject' ] ,
36313627 glGenFramebuffers : ( n , ids ) => {
3632- __glGenObject ( n , ids , 'createFramebuffer' , GL . framebuffers
3628+ GL . genObject ( n , ids , 'createFramebuffer' , GL . framebuffers
36333629#if GL_ASSERTIONS
36343630 , 'glGenFramebuffers'
36353631#endif
@@ -3678,19 +3674,17 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
36783674 return GLctx . isFramebuffer ( fb ) ;
36793675 } ,
36803676
3681- glGenVertexArrays__deps : [ '$__glGenObject'
36823677#if LEGACY_GL_EMULATION
3683- , '$emulGlGenVertexArrays'
3678+ glGenVertexArrays__deps : [ '$emulGlGenVertexArrays' ] ,
36843679#endif
3685- ] ,
36863680 glGenVertexArrays : ( n , arrays ) => {
36873681#if LEGACY_GL_EMULATION
36883682 emulGlGenVertexArrays ( n , arrays ) ;
36893683#else
36903684#if GL_ASSERTIONS
36913685 assert ( GLctx . createVertexArray , 'Must have WebGL2 or OES_vertex_array_object to use vao' ) ;
36923686#endif
3693- __glGenObject ( n , arrays , 'createVertexArray' , GL . vaos
3687+ GL . genObject ( n , arrays , 'createVertexArray' , GL . vaos
36943688#if GL_ASSERTIONS
36953689 , 'glGenVertexArrays'
36963690#endif
0 commit comments