1313 if ( MIN_WEBGL_VERSION >= 2 ) return 'true' ;
1414 if ( MAX_WEBGL_VERSION <= 1 ) return 'false' ;
1515 return 'GL.currentContext.version >= 2' ;
16- }
16+ } ;
17+
1718 null ;
1819} } }
1920
@@ -1517,14 +1518,14 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
15171518 glCompressedTexImage2D : ( target , level , internalFormat , width , height , border , imageSize , data ) = > {
15181519#if MAX_WEBGL_VERSION >= 2
15191520 if ( { { { isCurrentContextWebGL2( ) } } } ) {
1520- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1521- // those always when possible.
15221521 if ( GLctx . currentPixelUnpackBufferBinding || ! imageSize ) {
15231522 GLctx . compressedTexImage2D ( target , level , internalFormat , width , height , border , imageSize , data ) ;
1524- } else {
1525- GLctx . compressedTexImage2D( target , level, internalFormat, width, height, border, HEAPU8 , data, imageSize) ;
1523+ return ;
15261524 }
1525+ #if USE_GARBAGE_FREE_APIS
1526+ GLctx . compressedTexImage2D ( target , level , internalFormat , width , height , border , HEAPU8 , data , imageSize ) ;
15271527 return ;
1528+ #endif
15281529 }
15291530#endif
15301531 GLctx . compressedTexImage2D ( target , level , internalFormat , width , height , border , data ? { { { makeHEAPView ( 'U8' , 'data' , 'data+imageSize' ) } } } : null ) ;
@@ -1534,14 +1535,14 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
15341535 glCompressedTexSubImage2D : ( target , level , xoffset , yoffset , width , height , format , imageSize , data ) = > {
15351536#if MAX_WEBGL_VERSION >= 2
15361537 if ( { { { isCurrentContextWebGL2( ) } } } ) {
1537- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1538- // those always when possible.
15391538 if ( GLctx . currentPixelUnpackBufferBinding || ! imageSize ) {
15401539 GLctx . compressedTexSubImage2D ( target , level , xoffset , yoffset , width , height , format , imageSize , data ) ;
1541- } else {
1542- GLctx . compressedTexSubImage2D( target , level, xoffset, yoffset, width, height, format, HEAPU8 , data, imageSize) ;
1540+ return ;
15431541 }
1542+ #if USE_GARBAGE_FREE_APIS
1543+ GLctx . compressedTexSubImage2D ( target , level , xoffset , yoffset , width , height , format , HEAPU8 , data , imageSize ) ;
15441544 return ;
1545+ #endif
15451546 }
15461547#endif
15471548 GLctx . compressedTexSubImage2D ( target , level , xoffset , yoffset , width , height , format , data ? { { { makeHEAPView ( 'U8' , 'data' , 'data+imageSize' ) } } } : null ) ;
@@ -1636,20 +1637,21 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16361637 }
16371638#endif
16381639 if ( { { { isCurrentContextWebGL2( ) } } } ) {
1639- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1640- // those always when possible.
16411640 if ( GLctx . currentPixelUnpackBufferBinding ) {
16421641 GLctx . texImage2D ( target , level , internalFormat , width , height , border , format , type , pixels ) ;
1643- } else if ( pixels ) {
1642+ return ;
1643+ }
1644+ #if USE_GARBAGE_FREE_APIS
1645+ if ( pixels ) {
16441646 var heap = heapObjectForWebGLType ( type ) ;
16451647 GLctx . texImage2D ( target , level , internalFormat , width , height , border , format , type , heap , toTypedArrayIndex ( pixels , heap ) ) ;
1646- } else {
1647- GLctx . texImage2D( target , level, internalFormat, width, height, border, format, type, null) ;
1648+ return ;
16481649 }
1649- return ;
1650+ #endif
16501651 }
16511652#endif
1652- 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 ) ;
16531655 } ,
16541656
16551657 glTexSubImage2D__deps : [ '$emscriptenWebGLGetTexPixelData'
@@ -1669,21 +1671,20 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16691671 }
16701672#endif
16711673 if ( { { { isCurrentContextWebGL2( ) } } } ) {
1672- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1673- // those always when possible.
16741674 if ( GLctx . currentPixelUnpackBufferBinding ) {
16751675 GLctx . texSubImage2D( target , level, xoffset, yoffset, width, height, format, type, pixels) ;
1676- } else if ( pixels ) {
1676+ return ;
1677+ }
1678+ #if USE_GARBAGE_FREE_APIS
1679+ if ( pixels ) {
16771680 var heap = heapObjectForWebGLType ( type ) ;
16781681 GLctx . texSubImage2D ( target , level , xoffset , yoffset , width , height , format , type , heap , toTypedArrayIndex ( pixels , heap ) ) ;
1679- } else {
1680- GLctx . texSubImage2D( target , level, xoffset, yoffset, width, height, format, type, null) ;
1682+ return ;
16811683 }
1682- return ;
1684+ #endif
16831685 }
16841686#endif
1685- var pixelData = null ;
1686- if ( pixels ) pixelData = emscriptenWebGLGetTexPixelData ( type , format , width , height , pixels , 0 ) ;
1687+ var pixelData = pixels ? emscriptenWebGLGetTexPixelData ( type , format , width , height , pixels , 0 ) : null ;
16871688 GLctx . texSubImage2D ( target , level , xoffset , yoffset , width , height , format , type , pixelData ) ;
16881689 } ,
16891690
@@ -1695,16 +1696,16 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16951696 glReadPixels : ( x , y , width , height , format , type , pixels ) => {
16961697#if MAX_WEBGL_VERSION >= 2
16971698 if ( { { { isCurrentContextWebGL2( ) } } } ) {
1698- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1699- // those always when possible.
17001699 if ( GLctx . currentPixelPackBufferBinding ) {
17011700 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 ) ;
1701+ return ;
17061702 }
1703+ #if 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 ) ;
17071707 return ;
1708+ #endif
17081709 }
17091710#endif
17101711 var pixelData = emscriptenWebGLGetTexPixelData ( type , format , width , height , pixels , format ) ;
@@ -1841,36 +1842,30 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
18411842 }
18421843#endif
18431844
1844- #if MAX_WEBGL_VERSION >= 2
1845+ #if USE_GARBAGE_FREE_APIS
18451846 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.
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.
18521851 if ( data && size ) {
18531852 GLctx . bufferData ( target , HEAPU8 , usage , data , size ) ;
18541853 } else {
18551854 GLctx . bufferData ( target , size , usage ) ;
18561855 }
1857- } else {
1858- #endif
1859- // N.b. here first form specifies a heap subarray, second form an integer
1860- // size, so the ?: code here is polymorphic. It is advised to avoid
1861- // randomly mixing both uses in calling code, to avoid any potential JS
1862- // engine JIT issues.
1863- GLctx . bufferData ( target , data ? HEAPU8 . subarray ( data , data + size ) : size , usage ) ;
1864- #if MAX_WEBGL_VERSION >= 2
1856+ return ;
18651857 }
18661858#endif
1859+ // N.b. here first form specifies a heap subarray, second form an integer
1860+ // size, so the ?: code here is polymorphic. It is advised to avoid
1861+ // randomly mixing both uses in calling code, to avoid any potential JS
1862+ // engine JIT issues.
1863+ GLctx . bufferData ( target , data ? HEAPU8 . subarray ( data , data + size ) : size , usage ) ;
18671864 } ,
18681865
18691866 glBufferSubData : ( target , offset , size , data ) = > {
1870- #if MAX_WEBGL_VERSION >= 2
1867+ #if USE_GARBAGE_FREE_APIS
18711868 if ( { { { isCurrentContextWebGL2( ) } } } ) {
1872- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
1873- // those always when possible.
18741869 size && GLctx . bufferSubData ( target , offset , HEAPU8 , data , size ) ;
18751870 return ;
18761871 }
@@ -2433,8 +2428,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
24332428 count && GLctx . uniform1iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count ) ;
24342429#else
24352430
2436- #if MAX_WEBGL_VERSION >= 2
2437- if ( { { { isCurrentContextWebGL2( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2431+ #if USE_GARBAGE_FREE_APIS
2432+ if ( { { { isCurrentContextWebGL2( ) } } } ) {
24382433 count && GLctx . uniform1iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count) ;
24392434 return ;
24402435 }
@@ -2474,8 +2469,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
24742469 count && GLctx . uniform2iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 2 ) ;
24752470#else
24762471
2477- #if MAX_WEBGL_VERSION >= 2
2478- if ( { { { isCurrentContextWebGL2( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2472+ #if USE_GARBAGE_FREE_APIS
2473+ if ( { { { isCurrentContextWebGL2( ) } } } ) {
24792474 count && GLctx . uniform2iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 2 ) ;
24802475 return ;
24812476 }
@@ -2516,8 +2511,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
25162511 count && GLctx . uniform3iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 3 ) ;
25172512#else
25182513
2519- #if MAX_WEBGL_VERSION >= 2
2520- if ( { { { isCurrentContextWebGL2( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2514+ #if USE_GARBAGE_FREE_APIS
2515+ if ( { { { isCurrentContextWebGL2( ) } } } ) {
25212516 count && GLctx . uniform3iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 3 ) ;
25222517 return ;
25232518 }
@@ -2559,9 +2554,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
25592554 count && GLctx . uniform4iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 4 ) ;
25602555#else
25612556
2562- #if MAX_WEBGL_VERSION >= 2
2563- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2564- // those always when possible.
2557+ #if USE_GARBAGE_FREE_APIS
25652558 if ( { { { isCurrentContextWebGL2( ) } } } ) {
25662559 count && GLctx . uniform4iv ( webglGetUniformLocation ( location ) , HEAP32 , { { { getHeapOffset ( 'value' , 'i32' ) } } } , count * 4 ) ;
25672560 return ;
@@ -2605,8 +2598,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
26052598 count && GLctx . uniform1fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count ) ;
26062599#else
26072600
2608- #if MAX_WEBGL_VERSION >= 2
2609- if ( { { { isCurrentContextWebGL2( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2601+ #if USE_GARBAGE_FREE_APIS
2602+ if ( { { { isCurrentContextWebGL2( ) } } } ) {
26102603 count && GLctx . uniform1fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count ) ;
26112604 return ;
26122605 }
@@ -2646,9 +2639,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
26462639 count && GLctx . uniform2fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 2 ) ;
26472640#else
26482641
2649- #if MAX_WEBGL_VERSION >= 2
2650- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2651- // those always when possible.
2642+ #if USE_GARBAGE_FREE_APIS
26522643 if ( { { { isCurrentContextWebGL2( ) } } } ) {
26532644 count && GLctx . uniform2fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 2 ) ;
26542645 return ;
@@ -2690,9 +2681,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
26902681 count && GLctx . uniform3fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 3 ) ;
26912682#else
26922683
2693- #if MAX_WEBGL_VERSION >= 2
2694- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2695- // those always when possible.
2684+ #if USE_GARBAGE_FREE_APIS
26962685 if ( { { { isCurrentContextWebGL2( ) } } } ) {
26972686 count && GLctx . uniform3fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 3 ) ;
26982687 return ;
@@ -2735,9 +2724,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
27352724 count && GLctx . uniform4fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 4 ) ;
27362725#else
27372726
2738- #if MAX_WEBGL_VERSION >= 2
2739- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2740- // those always when possible.
2727+ #if USE_GARBAGE_FREE_APIS
27412728 if ( { { { isCurrentContextWebGL2( ) } } } ) {
27422729 count && GLctx . uniform4fv ( webglGetUniformLocation ( location ) , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 4 ) ;
27432730 return ;
@@ -2785,9 +2772,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
27852772 count && GLctx . uniformMatrix2fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 4 ) ;
27862773#else
27872774
2788- #if MAX_WEBGL_VERSION >= 2
2789- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2790- // those always when possible.
2775+ #if USE_GARBAGE_FREE_APIS
27912776 if ( { { { isCurrentContextWebGL2( ) } } } ) {
27922777 count && GLctx . uniformMatrix2fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 4 ) ;
27932778 return ;
@@ -2831,9 +2816,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
28312816 count && GLctx . uniformMatrix3fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 9 ) ;
28322817#else
28332818
2834- #if MAX_WEBGL_VERSION >= 2
2835- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2836- // those always when possible.
2819+ #if USE_GARBAGE_FREE_APIS
28372820 if ( { { { isCurrentContextWebGL2( ) } } } ) {
28382821 count && GLctx . uniformMatrix3fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 9 ) ;
28392822 return ;
@@ -2882,9 +2865,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
28822865 count && GLctx . uniformMatrix4fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 16 ) ;
28832866#else
28842867
2885- #if MAX_WEBGL_VERSION >= 2
2886- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use
2887- // those always when possible.
2868+ #if USE_GARBAGE_FREE_APIS
28882869 if ( { { { isCurrentContextWebGL2( ) } } } ) {
28892870 count && GLctx . uniformMatrix4fv ( webglGetUniformLocation ( location ) , ! ! transpose , HEAPF32 , { { { getHeapOffset ( 'value' , 'float' ) } } } , count * 16 ) ;
28902871 return ;
@@ -4158,12 +4139,14 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
41584139 return 0 ;
41594140 }
41604141
4161- if ( ! ( mapping . access & 0x10 ) ) /* GL_MAP_FLUSH_EXPLICIT_BIT */
4162- if ( { { { isCurrentContextWebGL2( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
4142+ if ( ! ( mapping . access & 0x10 ) ) { /* GL_MAP_FLUSH_EXPLICIT_BIT */
4143+ #if USE_GARBAGE_FREE_APIS
4144+ if ( { { { isCurrentContextWebGL2( ) } } } ) {
41634145 GLctx . bufferSubData ( target , mapping . offset , HEAPU8 , mapping . mem , mapping . length ) ;
4164- } else {
4165- GLctx . bufferSubData( target , mapping. offset , HEAPU8 . subarray ( mapping . mem, mapping. mem + mapping . length ) ) ;
4166- }
4146+ } else
4147+ #endif
4148+ GLctx . bufferSubData ( target , mapping . offset , HEAPU8 . subarray ( mapping . mem , mapping . mem + mapping . length ) ) ;
4149+ }
41674150 _free ( mapping . mem ) ;
41684151 mapping . mem = 0 ;
41694152 return 1 ;
0 commit comments