@@ -82,7 +82,12 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
82
82
return HEAPU16 ;
83
83
} ,
84
84
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
86
91
87
92
#if MIN_WEBGL_VERSION == 1
88
93
$webgl_enable_ANGLE_instanced_arrays: ( ctx ) => {
@@ -1595,22 +1600,20 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
1595
1600
return colorChannels [ format - 0x1902 ] || 1 ;
1596
1601
} ,
1597
1602
1598
- $emscriptenWebGLGetTexPixelData__deps : [ '$computeUnpackAlignedImageSize' , '$colorChannelsInGlTextureFormat' , '$heapObjectForWebGLType' , '$heapAccessShiftForWebGLHeap ' ] ,
1603
+ $emscriptenWebGLGetTexPixelData__deps : [ '$computeUnpackAlignedImageSize' , '$colorChannelsInGlTextureFormat' , '$heapObjectForWebGLType' , '$toTypedArrayIndex ' ] ,
1599
1604
$emscriptenWebGLGetTexPixelData : ( type , format , width , height , pixels , internalFormat ) = > {
1600
1605
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 ;
1604
1607
var bytes = computeUnpackAlignedImageSize ( width , height , sizePerPixel , GL . unpackAlignment ) ;
1605
1608
#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!' ) ;
1607
1610
#endif
1608
- return heap . subarray ( pixels >> shift , pixels + bytes >> shift ) ;
1611
+ return heap . subarray ( toTypedArrayIndex ( pixels , heap ) , toTypedArrayIndex ( pixels + bytes , heap ) ) ;
1609
1612
} ,
1610
1613
1611
1614
glTexImage2D__deps : [ '$emscriptenWebGLGetTexPixelData '
1612
1615
#if MAX_WEBGL_VERSION >= 2
1613
- , '$heapObjectForWebGLType ', '$heapAccessShiftForWebGLHeap '
1616
+ , '$heapObjectForWebGLType ', '$toTypedArrayIndex '
1614
1617
#endif
1615
1618
] ,
1616
1619
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 }}};
1641
1644
GLctx . texImage2D( target , level, internalFormat, width, height, border, format, type, pixels) ;
1642
1645
} else if ( pixels ) {
1643
1646
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 ) ) ;
1645
1648
} else {
1646
1649
GLctx . texImage2D( target , level, internalFormat, width, height, border, format, type, null) ;
1647
1650
}
@@ -1653,7 +1656,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
1653
1656
1654
1657
glTexSubImage2D__deps : [ '$emscriptenWebGLGetTexPixelData'
1655
1658
#if MAX_WEBGL_VERSION >= 2
1656
- , '$heapObjectForWebGLType' , '$heapAccessShiftForWebGLHeap '
1659
+ , '$heapObjectForWebGLType' , '$toTypedArrayIndex '
1657
1660
#endif
1658
1661
] ,
1659
1662
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 }}};
1674
1677
GLctx . texSubImage2D( target , level, xoffset, yoffset, width, height, format, type, pixels) ;
1675
1678
} else if ( pixels ) {
1676
1679
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 ) ) ;
1678
1681
} else {
1679
1682
GLctx . texSubImage2D( target , level, xoffset, yoffset, width, height, format, type, null) ;
1680
1683
}
@@ -1688,7 +1691,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
1688
1691
1689
1692
glReadPixels__deps : [ '$emscriptenWebGLGetTexPixelData '
1690
1693
#if MAX_WEBGL_VERSION >= 2
1691
- , '$heapObjectForWebGLType ', '$heapAccessShiftForWebGLHeap '
1694
+ , '$heapObjectForWebGLType ', '$toTypedArrayIndex '
1692
1695
#endif
1693
1696
] ,
1694
1697
glReadPixels : ( x , y , width , height , format , type , pixels ) => {
@@ -1700,7 +1703,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
1700
1703
GLctx . readPixels ( x, y, width, height, format, type, pixels) ;
1701
1704
} else {
1702
1705
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 ) ) ;
1704
1707
}
1705
1708
return ;
1706
1709
}
0 commit comments