Skip to content

Commit 128c054

Browse files
authored
WebGLBackend:Hhonor layerUpdates for array textures. (#31582)
* webgl-fallback: honor layerUpdates for array textures * fix linting --------- Co-authored-by: user <merowinger>
1 parent bc1c2bb commit 128c054

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/renderers/webgl-fallback/utils/WebGLTextureUtils.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, FloatType, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare, NoColorSpace, LinearTransfer, SRGBTransfer } from '../../../constants.js';
22
import { ColorManagement } from '../../../math/ColorManagement.js';
3+
import { getByteLength } from '../../../extras/TextureUtils.js';
34

45
let initialized = false, wrappingToGL, filterToGL, compareToGL;
56

@@ -564,7 +565,27 @@ class WebGLTextureUtils {
564565

565566
const image = options.image;
566567

567-
gl.texSubImage3D( gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data );
568+
if ( texture.layerUpdates.size > 0 ) {
569+
570+
const layerByteLength = getByteLength( image.width, image.height, texture.format, texture.type );
571+
572+
for ( const layerIndex of texture.layerUpdates ) {
573+
574+
const layerData = image.data.subarray(
575+
layerIndex * layerByteLength / image.data.BYTES_PER_ELEMENT,
576+
( layerIndex + 1 ) * layerByteLength / image.data.BYTES_PER_ELEMENT
577+
);
578+
gl.texSubImage3D( gl.TEXTURE_2D_ARRAY, 0, 0, 0, layerIndex, image.width, image.height, 1, glFormat, glType, layerData );
579+
580+
}
581+
582+
texture.clearLayerUpdates();
583+
584+
} else {
585+
586+
gl.texSubImage3D( gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data );
587+
588+
}
568589

569590
} else if ( texture.isData3DTexture ) {
570591

0 commit comments

Comments
 (0)