@@ -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,20 +1637,21 @@ 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 ) ;
1644- } else if ( pixels ) {
1642+ return ;
1643+ }
1644+ #if WEBGL_USE_GARBAGE_FREE_APIS
1645+ if ( pixels ) {
16451646 var heap = heapObjectForWebGLType ( type ) ;
16461647 GLctx . texImage2D ( target , level , internalFormat , width , height , border , format , type , heap , toTypedArrayIndex ( pixels , heap ) ) ;
1647- } else {
1648- GLctx . texImage2D( target , level, internalFormat, width, height, border, format, type, null) ;
1648+ return ;
16491649 }
1650- return ;
1650+ #endif
16511651 }
16521652#endif
1653- GLctx . texImage2D ( target , level, internalFormat, width, height, border, format, type, pixels ? emscriptenWebGLGetTexPixelData ( type, format, width, height, pixels, internalFormat ) : null ) ;
1653+ var pixelData = pixels ? emscriptenWebGLGetTexPixelData ( type , format , width , height , pixels , internalFormat ) : null ;
1654+ GLctx . texImage2D ( target , level , internalFormat , width , height , border , format , type , pixelData ) ;
16541655 } ,
16551656
16561657 glTexSubImage2D__deps : [ '$emscriptenWebGLGetTexPixelData'
@@ -1670,15 +1671,17 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16701671 }
16711672#endif
16721673 if ( { { { isCurrentContextWebGL2( ) } } } ) {
1673- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1674- // those always when possible.
16751674 if ( GLctx . currentPixelUnpackBufferBinding ) {
16761675 GLctx . texSubImage2D( target , level, xoffset, yoffset, width, height, format, type, pixels) ;
1677- } else if ( pixels ) {
1676+ return ;
1677+ }
1678+ #if WEBGL_USE_GARBAGE_FREE_APIS
1679+ if ( pixels ) {
16781680 var heap = heapObjectForWebGLType ( type ) ;
16791681 GLctx . texSubImage2D ( target , level , xoffset , yoffset , width , height , format , type , heap , toTypedArrayIndex ( pixels , heap ) ) ;
16801682 return ;
16811683 }
1684+ #endif
16821685 }
16831686#endif
16841687 var pixelData = pixels ? emscriptenWebGLGetTexPixelData ( type , format , width , height , pixels , 0 ) : null ;
@@ -1693,16 +1696,16 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16931696 glReadPixels : ( x , y , width , height , format , type , pixels ) => {
16941697#if MAX_WEBGL_VERSION >= 2
16951698 if ( { { { isCurrentContextWebGL2( ) } } } ) {
1696- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1697- // those always when possible.
16981699 if ( GLctx . currentPixelPackBufferBinding ) {
16991700 GLctx . readPixels ( x , y , width , height , format , type , pixels ) ;
1700- } else {
1701- var heap = heapObjectForWebGLType ( type ) ;
1702- var target = toTypedArrayIndex ( pixels , heap ) ;
1703- GLctx . readPixels ( x , y , width , height , format , type , heap , target ) ;
1701+ return ;
17041702 }
1703+ #if WEBGL_USE_GARBAGE_FREE_APIS
1704+ var heap = heapObjectForWebGLType ( type ) ;
1705+ var target = toTypedArrayIndex ( pixels , heap ) ;
1706+ GLctx . readPixels ( x , y , width , height , format , type , heap , target ) ;
17051707 return ;
1708+ #endif
17061709 }
17071710#endif
17081711 var pixelData = emscriptenWebGLGetTexPixelData ( type , format , width , height , pixels , format ) ;
@@ -1839,14 +1842,12 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
18391842 }
18401843#endif
18411844
1842- #if MAX_WEBGL_VERSION >= 2
1845+ #if WEBGL_USE_GARBAGE_FREE_APIS
18431846 if ( { { { isCurrentContextWebGL2 ( ) } } } ) {
1844- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1845- // those always when possible. If size is zero, WebGL would interpret
1846- // uploading the whole input arraybuffer (starting from given offset),
1847- // which would not make sense in WebAssembly, so avoid uploading if size
1848- // is zero. However we must still call bufferData to establish a backing
1849- // storage of zero bytes.
1847+ // If size is zero, WebGL would interpret uploading the whole input
1848+ // arraybuffer (starting from given offset), which would not make sense in
1849+ // WebAssembly, so avoid uploading if size is zero. However we must still
1850+ // call bufferData to establish a backing storage of zero bytes.
18501851 if ( data && size ) {
18511852 GLctx . bufferData ( target , HEAPU8 , usage , data , size ) ;
18521853 } else {
@@ -1863,10 +1864,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
18631864 } ,
18641865
18651866 glBufferSubData : ( target , offset , size , data ) = > {
1866- #if MAX_WEBGL_VERSION >= 2
1867+ #if WEBGL_USE_GARBAGE_FREE_APIS
18671868 if ( { { { isCurrentContextWebGL2( ) } } } ) {
1868- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1869- // those always when possible.
18701869 size && GLctx . bufferSubData ( target , offset , HEAPU8 , data , size ) ;
18711870 return ;
18721871 }
@@ -2429,8 +2428,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
24292428 count && GLctx . uniform1iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count ) ;
24302429#else
24312430
2432- #if MAX_WEBGL_VERSION >= 2
2433- if ( { { { isCurrentContextWebGL2( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2431+ #if WEBGL_USE_GARBAGE_FREE_APIS
2432+ if ( { { { isCurrentContextWebGL2( ) } } } ) {
24342433 count && GLctx . uniform1iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count) ;
24352434 return ;
24362435 }
@@ -2470,8 +2469,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
24702469 count && GLctx . uniform2iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 2 ) ;
24712470#else
24722471
2473- #if MAX_WEBGL_VERSION >= 2
2474- if ( { { { isCurrentContextWebGL2( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2472+ #if WEBGL_USE_GARBAGE_FREE_APIS
2473+ if ( { { { isCurrentContextWebGL2( ) } } } ) {
24752474 count && GLctx . uniform2iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 2 ) ;
24762475 return ;
24772476 }
@@ -2512,8 +2511,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
25122511 count && GLctx . uniform3iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 3 ) ;
25132512#else
25142513
2515- #if MAX_WEBGL_VERSION >= 2
2516- if ( { { { isCurrentContextWebGL2( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2514+ #if WEBGL_USE_GARBAGE_FREE_APIS
2515+ if ( { { { isCurrentContextWebGL2( ) } } } ) {
25172516 count && GLctx . uniform3iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 3 ) ;
25182517 return ;
25192518 }
@@ -2555,9 +2554,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
25552554 count && GLctx . uniform4iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 4 ) ;
25562555#else
25572556
2558- #if MAX_WEBGL_VERSION >= 2
2559- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2560- // those always when possible.
2557+ #if WEBGL_USE_GARBAGE_FREE_APIS
25612558 if ( { { { isCurrentContextWebGL2( ) } } } ) {
25622559 count && GLctx . uniform4iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 4 ) ;
25632560 return ;
@@ -2601,8 +2598,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
26012598 count && GLctx . uniform1fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count ) ;
26022599#else
26032600
2604- #if MAX_WEBGL_VERSION >= 2
2605- if ( { { { isCurrentContextWebGL2( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2601+ #if WEBGL_USE_GARBAGE_FREE_APIS
2602+ if ( { { { isCurrentContextWebGL2( ) } } } ) {
26062603 count && GLctx . uniform1fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count ) ;
26072604 return ;
26082605 }
@@ -2642,9 +2639,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
26422639 count && GLctx . uniform2fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 2 ) ;
26432640#else
26442641
2645- #if MAX_WEBGL_VERSION >= 2
2646- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2647- // those always when possible.
2642+ #if WEBGL_USE_GARBAGE_FREE_APIS
26482643 if ( { { { isCurrentContextWebGL2( ) } } } ) {
26492644 count && GLctx . uniform2fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 2 ) ;
26502645 return ;
@@ -2669,7 +2664,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
26692664 } ,
26702665
26712666 glUniform3fv__deps : [ '$webglGetUniformLocation'
2672- #if GL_POOL_TEMP_BUFFERS && MIN_WEBGL_VERSION == 1
2667+ #if GL_POOL_TEMP_BUFFERS && ! ( MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS )
26732668 , '$miniTempWebGLFloatBuffers'
26742669#endif
26752670 ] ,
@@ -2679,16 +2674,14 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
26792674 assert ( ( value % 4 ) == 0 , 'Pointer to float data passed to glUniform3fv must be aligned to four bytes!' + value ) ;
26802675#endif
26812676
2682- #if MIN_WEBGL_VERSION >= 2
2677+ #if MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
26832678#if GL_ASSERTIONS
26842679 assert ( GL . currentContext . version >= 2 ) ;
26852680#endif
26862681 count && GLctx . uniform3fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 3 ) ;
26872682#else
26882683
2689- #if MAX_WEBGL_VERSION >= 2
2690- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2691- // those always when possible.
2684+ #if WEBGL_USE_GARBAGE_FREE_APIS
26922685 if ( { { { isCurrentContextWebGL2( ) } } } ) {
26932686 count && GLctx . uniform3fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 3 ) ;
26942687 return ;
@@ -2731,9 +2724,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
27312724 count && GLctx . uniform4fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 4 ) ;
27322725#else
27332726
2734- #if MAX_WEBGL_VERSION >= 2
2735- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2736- // those always when possible.
2727+ #if WEBGL_USE_GARBAGE_FREE_APIS
27372728 if ( { { { isCurrentContextWebGL2( ) } } } ) {
27382729 count && GLctx . uniform4fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 4 ) ;
27392730 return ;
@@ -2781,9 +2772,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
27812772 count && GLctx . uniformMatrix2fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 4 ) ;
27822773#else
27832774
2784- #if MAX_WEBGL_VERSION >= 2
2785- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2786- // those always when possible.
2775+ #if WEBGL_USE_GARBAGE_FREE_APIS
27872776 if ( { { { isCurrentContextWebGL2( ) } } } ) {
27882777 count && GLctx . uniformMatrix2fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 4 ) ;
27892778 return ;
@@ -2827,9 +2816,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
28272816 count && GLctx . uniformMatrix3fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 9 ) ;
28282817#else
28292818
2830- #if MAX_WEBGL_VERSION >= 2
2831- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2832- // those always when possible.
2819+ #if WEBGL_USE_GARBAGE_FREE_APIS
28332820 if ( { { { isCurrentContextWebGL2( ) } } } ) {
28342821 count && GLctx . uniformMatrix3fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 9 ) ;
28352822 return ;
@@ -2861,7 +2848,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
28612848 } ,
28622849
28632850 glUniformMatrix4fv__deps : [ '$webglGetUniformLocation'
2864- #if GL_POOL_TEMP_BUFFERS && MIN_WEBGL_VERSION == 1
2851+ #if GL_POOL_TEMP_BUFFERS && ! ( MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS )
28652852 , '$miniTempWebGLFloatBuffers'
28662853#endif
28672854 ] ,
@@ -2871,16 +2858,14 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
28712858 assert ( ( value & 3 ) == 0 , 'Pointer to float data passed to glUniformMatrix4fv must be aligned to four bytes!' ) ;
28722859#endif
28732860
2874- #if MIN_WEBGL_VERSION >= 2
2861+ #if MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
28752862#if GL_ASSERTIONS
28762863 assert ( GL . currentContext . version >= 2 ) ;
28772864#endif
28782865 count && GLctx . uniformMatrix4fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 16 ) ;
28792866#else
28802867
2881- #if MAX_WEBGL_VERSION >= 2
2882- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2883- // those always when possible.
2868+ #if WEBGL_USE_GARBAGE_FREE_APIS
28842869 if ( { { { isCurrentContextWebGL2( ) } } } ) {
28852870 count && GLctx . uniformMatrix4fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 16 ) ;
28862871 return ;
@@ -2919,7 +2904,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
29192904 var view = { { { makeHEAPView ( 'F32' , 'value' , 'value+count*64' ) } } } ;
29202905 }
29212906 GLctx . uniformMatrix4fv ( webglGetUniformLocation ( location ) , ! ! transpose , view ) ;
2922- #endif // MIN_WEBGL_VERSION >= 2
2907+ #endif // MIN_WEBGL_VERSION >= 2 && WEBGL_USE_GARBAGE_FREE_APIS
29232908 } ,
29242909
29252910 glBindBuffer : ( target , buffer ) = > {
@@ -4155,11 +4140,12 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
41554140 }
41564141
41574142 if ( ! ( mapping . access & 0x10 ) ) { /* GL_MAP_FLUSH_EXPLICIT_BIT */
4158- if ( { { { isCurrentContextWebGL2( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
4143+ #if WEBGL_USE_GARBAGE_FREE_APIS
4144+ if ( { { { isCurrentContextWebGL2( ) } } } ) {
41594145 GLctx . bufferSubData ( target , mapping . offset , HEAPU8 , mapping . mem , mapping . length ) ;
4160- } else {
4161- GLctx . bufferSubData ( target , mapping . offset , HEAPU8 . subarray ( mapping . mem , mapping . mem + mapping . length ) ) ;
4162- }
4146+ } else
4147+ #endif
4148+ GLctx . bufferSubData ( target , mapping . offset , HEAPU8 . subarray ( mapping . mem , mapping . mem + mapping . length ) ) ;
41634149 }
41644150 _free ( mapping . mem ) ;
41654151 mapping . mem = 0 ;
0 commit comments