Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support updating only dirty CompressedArrayTexture layers #27972

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/api/en/textures/CompressedArrayTexture.html
Expand Up @@ -61,6 +61,20 @@ <h3>[property:number wrapR]</h3>
<h3>[property:Object image]</h3>
<p>Overridden with a object containing width, height, and depth.</p>

<h3>[property:Boolean layerNeedsUpdate]</h3>
<p>
Specifies that a specific layer of the texture needs to be updated. Unlike
[page:Texture.needsUpdate needsUpdate] which sends the entire compressed
texture array to the GPU, marking specific layers will only transmit
subsets of all mipmaps associated with a specific depth in the array.
</p>

<h3>[property:Array dirtyLayers]</h3>
<p>
A list of all dirty layers in the texture. See
[Page:CompressedTextureArray.layerNeedsUpdate layerNeedsUpdate].
</p>

<h3>[property:Boolean isCompressedArrayTexture]</h3>
<p>Read-only flag to check if a given object is of type [name].</p>

Expand Down
17 changes: 16 additions & 1 deletion src/renderers/webgl/WebGLTextures.js
Expand Up @@ -820,7 +820,22 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

if ( dataReady ) {

state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data, 0, 0 );
if ( texture.dirtyLayers.length > 0 ) {

for ( const layerIndex of texture.dirtyLayers ) {

const layerSize = mipmap.width * mipmap.height;
state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, layerIndex, mipmap.width, mipmap.height, 1, glFormat, mipmap.data.slice( layerSize * layerIndex, layerSize * ( layerIndex + 1 ) ), 0, 0 );

}

texture.dirtyLayers = [];

} else {

state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data, 0, 0 );

}

}

Expand Down
8 changes: 8 additions & 0 deletions src/textures/CompressedArrayTexture.js
Expand Up @@ -10,6 +10,14 @@ class CompressedArrayTexture extends CompressedTexture {
this.isCompressedArrayTexture = true;
this.image.depth = depth;
this.wrapR = ClampToEdgeWrapping;
this.dirtyLayers = [];

}

set layerNeedsUpdate( layerIndex ) {
HunterLarco marked this conversation as resolved.
Show resolved Hide resolved

this.needsUpdate = true;
this.dirtyLayers.push( layerIndex );

HunterLarco marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down