@@ -82,7 +82,12 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
8282 return HEAPU16 ;
8383 } ,
8484
85- $heapAccessShiftForWebGLHeap : ( heap ) => 31 - Math . clz32 ( heap . BYTES_PER_ELEMENT ) ,
85+ $toTypedArrayIndex : ( pointer , heap ) =>
86+ #if MEMORY64
87+ pointer / heap . BYTES_PER_ELEMENT ,
88+ #else
89+ pointer >>> ( 31 - Math . clz32 ( heap . BYTES_PER_ELEMENT ) ) ,
90+ #endif
8691
8792#if MIN_WEBGL_VERSION == 1
8893 $webgl_enable_ANGLE_instanced_arrays: ( ctx ) => {
@@ -1595,22 +1600,20 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
15951600 return colorChannels [ format - 0x1902 ] || 1 ;
15961601 } ,
15971602
1598- $emscriptenWebGLGetTexPixelData__deps : [ '$computeUnpackAlignedImageSize' , '$colorChannelsInGlTextureFormat' , '$heapObjectForWebGLType' , '$heapAccessShiftForWebGLHeap ' ] ,
1603+ $emscriptenWebGLGetTexPixelData__deps : [ '$computeUnpackAlignedImageSize' , '$colorChannelsInGlTextureFormat' , '$heapObjectForWebGLType' , '$toTypedArrayIndex ' ] ,
15991604 $emscriptenWebGLGetTexPixelData : ( type , format , width , height , pixels , internalFormat ) = > {
16001605 var heap = heapObjectForWebGLType ( type ) ;
1601- var shift = heapAccessShiftForWebGLHeap ( heap ) ;
1602- var byteSize = 1 << shift ;
1603- var sizePerPixel = colorChannelsInGlTextureFormat ( format ) * byteSize ;
1606+ var sizePerPixel = colorChannelsInGlTextureFormat ( format ) * heap . BYTES_PER_ELEMENT ;
16041607 var bytes = computeUnpackAlignedImageSize ( width , height , sizePerPixel , GL . unpackAlignment ) ;
16051608#if GL_ASSERTIONS
1606- assert ( ( pixels >> shift ) << shift == pixels , 'Pointer to texture data passed to texture get function must be aligned to the byte size of the pixel type!' ) ;
1609+ assert ( pixels % heap . BYTES_PER_ELEMENT == 0 , 'Pointer to texture data passed to texture get function must be aligned to the byte size of the pixel type!' ) ;
16071610#endif
1608- return heap . subarray ( pixels >> shift , pixels + bytes >> shift ) ;
1611+ return heap . subarray ( toTypedArrayIndex ( pixels , heap ) , toTypedArrayIndex ( pixels + bytes , heap ) ) ;
16091612 } ,
16101613
16111614 glTexImage2D__deps : [ '$emscriptenWebGLGetTexPixelData '
16121615#if MAX_WEBGL_VERSION >= 2
1613- , '$heapObjectForWebGLType ', '$heapAccessShiftForWebGLHeap '
1616+ , '$heapObjectForWebGLType ', '$toTypedArrayIndex '
16141617#endif
16151618 ] ,
16161619 glTexImage2D : ( target , level , internalFormat , width , height , border , format , type , pixels ) => {
@@ -1641,7 +1644,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16411644 GLctx . texImage2D( target , level, internalFormat, width, height, border, format, type, pixels) ;
16421645 } else if ( pixels ) {
16431646 var heap = heapObjectForWebGLType ( type ) ;
1644- GLctx . texImage2D ( target , level , internalFormat , width , height , border , format , type , heap , pixels >> heapAccessShiftForWebGLHeap ( heap ) ) ;
1647+ GLctx . texImage2D ( target , level , internalFormat , width , height , border , format , type , heap , toTypedArrayIndex ( pixels , heap ) ) ;
16451648 } else {
16461649 GLctx . texImage2D( target , level, internalFormat, width, height, border, format, type, null) ;
16471650 }
@@ -1653,7 +1656,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16531656
16541657 glTexSubImage2D__deps : [ '$emscriptenWebGLGetTexPixelData'
16551658#if MAX_WEBGL_VERSION >= 2
1656- , '$heapObjectForWebGLType' , '$heapAccessShiftForWebGLHeap '
1659+ , '$heapObjectForWebGLType' , '$toTypedArrayIndex '
16571660#endif
16581661 ] ,
16591662 glTexSubImage2D : ( target , level , xoffset , yoffset , width , height , format , type , pixels ) = > {
@@ -1674,7 +1677,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16741677 GLctx . texSubImage2D( target , level, xoffset, yoffset, width, height, format, type, pixels) ;
16751678 } else if ( pixels ) {
16761679 var heap = heapObjectForWebGLType ( type ) ;
1677- GLctx . texSubImage2D ( target , level , xoffset , yoffset , width , height , format , type , heap , pixels >> heapAccessShiftForWebGLHeap ( heap ) ) ;
1680+ GLctx . texSubImage2D ( target , level , xoffset , yoffset , width , height , format , type , heap , toTypedArrayIndex ( pixels , heap ) ) ;
16781681 } else {
16791682 GLctx . texSubImage2D( target , level, xoffset, yoffset, width, height, format, type, null) ;
16801683 }
@@ -1688,7 +1691,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16881691
16891692 glReadPixels__deps : [ '$emscriptenWebGLGetTexPixelData '
16901693#if MAX_WEBGL_VERSION >= 2
1691- , '$heapObjectForWebGLType ', '$heapAccessShiftForWebGLHeap '
1694+ , '$heapObjectForWebGLType ', '$toTypedArrayIndex '
16921695#endif
16931696 ] ,
16941697 glReadPixels : ( x , y , width , height , format , type , pixels ) => {
@@ -1700,7 +1703,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
17001703 GLctx . readPixels ( x, y, width, height, format, type, pixels) ;
17011704 } else {
17021705 var heap = heapObjectForWebGLType ( type ) ;
1703- GLctx . readPixels ( x , y , width , height , format , type , heap , pixels >> heapAccessShiftForWebGLHeap ( heap ) ) ;
1706+ GLctx . readPixels ( x , y , width , height , format , type , heap , toTypedArrayIndex ( pixels , heap ) ) ;
17041707 }
17051708 return ;
17061709 }
0 commit comments