@@ -1518,14 +1518,14 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
15181518 glCompressedTexImage2D : ( target , level , internalFormat , width , height , border , imageSize , data ) = > {
15191519#if MAX_WEBGL_VERSION >= 2
15201520 if ( { { { isCurrentContextWebGL2( ) } } } ) {
1521- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1522- // those always when possible.
15231521 if ( GLctx . currentPixelUnpackBufferBinding || ! imageSize ) {
15241522 GLctx . compressedTexImage2D ( target , level , internalFormat , width , height , border , imageSize , data ) ;
1525- } else {
1526- GLctx . compressedTexImage2D( target , level, internalFormat, width, height, border, HEAPU8 , data, imageSize) ;
1523+ return ;
15271524 }
1525+ #if WEBGL_USE_GARBAGE_FREE_APIS
1526+ GLctx . compressedTexImage2D ( target , level , internalFormat , width , height , border , HEAPU8 , data , imageSize ) ;
15281527 return ;
1528+ #endif
15291529 }
15301530#endif
15311531 GLctx . compressedTexImage2D ( target , level , internalFormat , width , height , border , data ? { { { makeHEAPView ( 'U8' , 'data' , 'data+imageSize' ) } } } : null ) ;
@@ -1535,14 +1535,14 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
15351535 glCompressedTexSubImage2D : ( target , level , xoffset , yoffset , width , height , format , imageSize , data ) = > {
15361536#if MAX_WEBGL_VERSION >= 2
15371537 if ( { { { isCurrentContextWebGL2( ) } } } ) {
1538- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1539- // those always when possible.
15401538 if ( GLctx . currentPixelUnpackBufferBinding || ! imageSize ) {
15411539 GLctx . compressedTexSubImage2D ( target , level , xoffset , yoffset , width , height , format , imageSize , data ) ;
1542- } else {
1543- GLctx . compressedTexSubImage2D( target , level, xoffset, yoffset, width, height, format, HEAPU8 , data, imageSize) ;
1540+ return ;
15441541 }
1542+ #if WEBGL_USE_GARBAGE_FREE_APIS
1543+ GLctx . compressedTexSubImage2D ( target , level , xoffset , yoffset , width , height , format , HEAPU8 , data , imageSize ) ;
15451544 return ;
1545+ #endif
15461546 }
15471547#endif
15481548 GLctx . compressedTexSubImage2D ( target , level , xoffset , yoffset , width , height , format , data ? { { { makeHEAPView ( 'U8' , 'data' , 'data+imageSize' ) } } } : null ) ;
@@ -1637,18 +1637,18 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16371637 }
16381638#endif
16391639 if ( { { { isCurrentContextWebGL2( ) } } } ) {
1640- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1641- // those always when possible.
16421640 if ( GLctx . currentPixelUnpackBufferBinding ) {
16431641 GLctx . texImage2D ( target , level , internalFormat , width , height , border , format , type , pixels ) ;
16441642 return ;
16451643 }
1644+ #if WEBGL_USE_GARBAGE_FREE_APIS
16461645 if ( pixels ) {
16471646 var heap = heapObjectForWebGLType ( type ) ;
16481647 var index = toTypedArrayIndex ( pixels , heap ) ;
16491648 GLctx . texImage2D ( target , level , internalFormat , width , height , border , format , type , heap , index ) ;
16501649 return ;
16511650 }
1651+ #endif
16521652 }
16531653#endif
16541654 var pixelData = pixels ? emscriptenWebGLGetTexPixelData ( type , format , width , height , pixels , internalFormat ) : null ;
@@ -1672,15 +1672,17 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16721672 }
16731673#endif
16741674 if ( { { { isCurrentContextWebGL2( ) } } } ) {
1675- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1676- // those always when possible.
16771675 if ( GLctx . currentPixelUnpackBufferBinding ) {
16781676 GLctx . texSubImage2D( target , level, xoffset, yoffset, width, height, format, type, pixels) ;
1679- } else if ( pixels ) {
1677+ return ;
1678+ }
1679+ #if WEBGL_USE_GARBAGE_FREE_APIS
1680+ if ( pixels ) {
16801681 var heap = heapObjectForWebGLType ( type ) ;
16811682 GLctx . texSubImage2D ( target , level , xoffset , yoffset , width , height , format , type , heap , toTypedArrayIndex ( pixels , heap ) ) ;
16821683 return ;
16831684 }
1685+ #endif
16841686 }
16851687#endif
16861688 var pixelData = pixels ? emscriptenWebGLGetTexPixelData ( type , format , width , height , pixels , 0 ) : null ;
@@ -1695,16 +1697,16 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16951697 glReadPixels : ( x , y , width , height , format , type , pixels ) => {
16961698#if MAX_WEBGL_VERSION >= 2
16971699 if ( { { { isCurrentContextWebGL2( ) } } } ) {
1698- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1699- // those always when possible.
17001700 if ( GLctx . currentPixelPackBufferBinding ) {
17011701 GLctx . readPixels ( x , y , width , height , format , type , pixels ) ;
1702- } else {
1703- var heap = heapObjectForWebGLType ( type ) ;
1704- var target = toTypedArrayIndex ( pixels , heap ) ;
1705- GLctx . readPixels ( x , y , width , height , format , type , heap , target ) ;
1702+ return ;
17061703 }
1704+ #if WEBGL_USE_GARBAGE_FREE_APIS
1705+ var heap = heapObjectForWebGLType ( type ) ;
1706+ var target = toTypedArrayIndex ( pixels , heap ) ;
1707+ GLctx . readPixels ( x , y , width , height , format , type , heap , target ) ;
17071708 return ;
1709+ #endif
17081710 }
17091711#endif
17101712 var pixelData = emscriptenWebGLGetTexPixelData ( type , format , width , height , pixels , format ) ;
@@ -1841,14 +1843,12 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
18411843 }
18421844#endif
18431845
1844- #if MAX_WEBGL_VERSION >= 2
1846+ #if WEBGL_USE_GARBAGE_FREE_APIS
18451847 if ( { { { isCurrentContextWebGL2 ( ) } } } ) {
1846- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1847- // those always when possible. If size is zero, WebGL would interpret
1848- // uploading the whole input arraybuffer (starting from given offset),
1849- // which would not make sense in WebAssembly, so avoid uploading if size
1850- // is zero. However we must still call bufferData to establish a backing
1851- // storage of zero bytes.
1848+ // If size is zero, WebGL would interpret uploading the whole input
1849+ // arraybuffer (starting from given offset), which would not make sense in
1850+ // WebAssembly, so avoid uploading if size is zero. However we must still
1851+ // call bufferData to establish a backing storage of zero bytes.
18521852 if ( data && size ) {
18531853 GLctx . bufferData ( target , HEAPU8 , usage , data , size ) ;
18541854 } else {
@@ -1865,10 +1865,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
18651865 } ,
18661866
18671867 glBufferSubData : ( target , offset , size , data ) = > {
1868- #if MAX_WEBGL_VERSION >= 2
1868+ #if WEBGL_USE_GARBAGE_FREE_APIS
18691869 if ( { { { isCurrentContextWebGL2( ) } } } ) {
1870- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1871- // those always when possible.
18721870 size && GLctx . bufferSubData ( target , offset , HEAPU8 , data , size ) ;
18731871 return ;
18741872 }
@@ -2431,8 +2429,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
24312429 count && GLctx . uniform1iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count ) ;
24322430#else
24332431
2434- #if MAX_WEBGL_VERSION >= 2
2435- if ( { { { isCurrentContextWebGL2( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2432+ #if WEBGL_USE_GARBAGE_FREE_APIS
2433+ if ( { { { isCurrentContextWebGL2( ) } } } ) {
24362434 count && GLctx . uniform1iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count) ;
24372435 return ;
24382436 }
@@ -2472,8 +2470,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
24722470 count && GLctx . uniform2iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 2 ) ;
24732471#else
24742472
2475- #if MAX_WEBGL_VERSION >= 2
2476- if ( { { { isCurrentContextWebGL2( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2473+ #if WEBGL_USE_GARBAGE_FREE_APIS
2474+ if ( { { { isCurrentContextWebGL2( ) } } } ) {
24772475 count && GLctx . uniform2iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 2 ) ;
24782476 return ;
24792477 }
@@ -2514,8 +2512,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
25142512 count && GLctx . uniform3iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 3 ) ;
25152513#else
25162514
2517- #if MAX_WEBGL_VERSION >= 2
2518- if ( { { { isCurrentContextWebGL2( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2515+ #if WEBGL_USE_GARBAGE_FREE_APIS
2516+ if ( { { { isCurrentContextWebGL2( ) } } } ) {
25192517 count && GLctx . uniform3iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 3 ) ;
25202518 return ;
25212519 }
@@ -2557,9 +2555,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
25572555 count && GLctx . uniform4iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 4 ) ;
25582556#else
25592557
2560- #if MAX_WEBGL_VERSION >= 2
2561- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2562- // those always when possible.
2558+ #if WEBGL_USE_GARBAGE_FREE_APIS
25632559 if ( { { { isCurrentContextWebGL2( ) } } } ) {
25642560 count && GLctx . uniform4iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 4 ) ;
25652561 return ;
@@ -2603,8 +2599,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
26032599 count && GLctx . uniform1fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count ) ;
26042600#else
26052601
2606- #if MAX_WEBGL_VERSION >= 2
2607- if ( { { { isCurrentContextWebGL2( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2602+ #if WEBGL_USE_GARBAGE_FREE_APIS
2603+ if ( { { { isCurrentContextWebGL2( ) } } } ) {
26082604 count && GLctx . uniform1fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count ) ;
26092605 return ;
26102606 }
@@ -2644,9 +2640,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
26442640 count && GLctx . uniform2fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 2 ) ;
26452641#else
26462642
2647- #if MAX_WEBGL_VERSION >= 2
2648- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2649- // those always when possible.
2643+ #if WEBGL_USE_GARBAGE_FREE_APIS
26502644 if ( { { { isCurrentContextWebGL2( ) } } } ) {
26512645 count && GLctx . uniform2fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 2 ) ;
26522646 return ;
@@ -2671,7 +2665,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
26712665 } ,
26722666
26732667 glUniform3fv__deps : [ '$webglGetUniformLocation'
2674- #if GL_POOL_TEMP_BUFFERS && MIN_WEBGL_VERSION == 1
2668+ #if GL_POOL_TEMP_BUFFERS && ! ( MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS )
26752669 , '$miniTempWebGLFloatBuffers'
26762670#endif
26772671 ] ,
@@ -2681,16 +2675,14 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
26812675 assert ( ( value % 4 ) == 0 , 'Pointer to float data passed to glUniform3fv must be aligned to four bytes!' + value ) ;
26822676#endif
26832677
2684- #if MIN_WEBGL_VERSION >= 2
2678+ #if MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
26852679#if GL_ASSERTIONS
26862680 assert ( GL . currentContext . version >= 2 ) ;
26872681#endif
26882682 count && GLctx . uniform3fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 3 ) ;
26892683#else
26902684
2691- #if MAX_WEBGL_VERSION >= 2
2692- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2693- // those always when possible.
2685+ #if WEBGL_USE_GARBAGE_FREE_APIS
26942686 if ( { { { isCurrentContextWebGL2( ) } } } ) {
26952687 count && GLctx . uniform3fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 3 ) ;
26962688 return ;
@@ -2733,9 +2725,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
27332725 count && GLctx . uniform4fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 4 ) ;
27342726#else
27352727
2736- #if MAX_WEBGL_VERSION >= 2
2737- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2738- // those always when possible.
2728+ #if WEBGL_USE_GARBAGE_FREE_APIS
27392729 if ( { { { isCurrentContextWebGL2( ) } } } ) {
27402730 count && GLctx . uniform4fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 4 ) ;
27412731 return ;
@@ -2783,9 +2773,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
27832773 count && GLctx . uniformMatrix2fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 4 ) ;
27842774#else
27852775
2786- #if MAX_WEBGL_VERSION >= 2
2787- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2788- // those always when possible.
2776+ #if WEBGL_USE_GARBAGE_FREE_APIS
27892777 if ( { { { isCurrentContextWebGL2( ) } } } ) {
27902778 count && GLctx . uniformMatrix2fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 4 ) ;
27912779 return ;
@@ -2829,9 +2817,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
28292817 count && GLctx . uniformMatrix3fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 9 ) ;
28302818#else
28312819
2832- #if MAX_WEBGL_VERSION >= 2
2833- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2834- // those always when possible.
2820+ #if WEBGL_USE_GARBAGE_FREE_APIS
28352821 if ( { { { isCurrentContextWebGL2( ) } } } ) {
28362822 count && GLctx . uniformMatrix3fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 9 ) ;
28372823 return ;
@@ -2863,7 +2849,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
28632849 } ,
28642850
28652851 glUniformMatrix4fv__deps : [ '$webglGetUniformLocation'
2866- #if GL_POOL_TEMP_BUFFERS && MIN_WEBGL_VERSION == 1
2852+ #if GL_POOL_TEMP_BUFFERS && ! ( MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS )
28672853 , '$miniTempWebGLFloatBuffers'
28682854#endif
28692855 ] ,
@@ -2873,16 +2859,14 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
28732859 assert ( ( value & 3 ) == 0 , 'Pointer to float data passed to glUniformMatrix4fv must be aligned to four bytes!' ) ;
28742860#endif
28752861
2876- #if MIN_WEBGL_VERSION >= 2
2862+ #if MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
28772863#if GL_ASSERTIONS
28782864 assert ( GL . currentContext . version >= 2 ) ;
28792865#endif
28802866 count && GLctx . uniformMatrix4fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 16 ) ;
28812867#else
28822868
2883- #if MAX_WEBGL_VERSION >= 2
2884- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2885- // those always when possible.
2869+ #if WEBGL_USE_GARBAGE_FREE_APIS
28862870 if ( { { { isCurrentContextWebGL2( ) } } } ) {
28872871 count && GLctx . uniformMatrix4fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 16 ) ;
28882872 return ;
@@ -2921,7 +2905,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
29212905 var view = { { { makeHEAPView ( 'F32' , 'value' , 'value+count*64' ) } } } ;
29222906 }
29232907 GLctx . uniformMatrix4fv ( webglGetUniformLocation ( location ) , ! ! transpose , view ) ;
2924- #endif // MIN_WEBGL_VERSION >= 2
2908+ #endif // MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
29252909 } ,
29262910
29272911 glBindBuffer : ( target , buffer ) = > {
@@ -4157,11 +4141,12 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
41574141 }
41584142
41594143 if ( ! ( mapping . access & 0x10 ) ) { /* GL_MAP_FLUSH_EXPLICIT_BIT */
4160- if ( { { { isCurrentContextWebGL2( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
4144+ #if WEBGL_USE_GARBAGE_FREE_APIS
4145+ if ( { { { isCurrentContextWebGL2( ) } } } ) {
41614146 GLctx . bufferSubData ( target , mapping . offset , HEAPU8 , mapping . mem , mapping . length ) ;
4162- } else {
4163- GLctx . bufferSubData ( target , mapping . offset , HEAPU8 . subarray ( mapping . mem , mapping . mem + mapping . length ) ) ;
4164- }
4147+ } else
4148+ #endif
4149+ GLctx . bufferSubData ( target , mapping . offset , HEAPU8 . subarray ( mapping . mem , mapping . mem + mapping . length ) ) ;
41654150 }
41664151 _free ( mapping . mem ) ;
41674152 mapping . mem = 0 ;
0 commit comments