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 4 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
20 changes: 18 additions & 2 deletions docs/api/en/textures/CompressedArrayTexture.html
Expand Up @@ -61,14 +61,30 @@ <h3>[property:number wrapR]</h3>
<h3>[property:Object image]</h3>
<p>Overridden with a object containing width, height, and depth.</p>

<h3>[property:Set dirtyLayers]</h3>
<p>
A set of all dirty layers in the texture. See
[Page:CompressedTextureArray.addDirtyLayer addDirtyLayer].
</p>

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

<h2>Methods</h2>

<h3>[method:addDirtyLayer addDirtyLayer]( layerIndex )</h3>
<p>
Describes that a specific layer of the texture needs to be updated.
Normally when [page:Texture.needsUpdate needsUpdate] is set to true, the
entire compressed texture array is sent to the GPU. Marking specific
layers will only transmit subsets of all mipmaps associated with a
specific depth in the array which is often much more performant.
</p>

<h3>[method:clearDirtyLayers clearDirtyLayers]()</h3>
<p>
See the base [page:CompressedTexture CompressedTexture] class for common
methods.
Resets the dirty layers registry. See
[Page:CompressedTextureArray.addDirtyLayer addDirtyLayer].
</p>

<h2>Source</h2>
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.size > 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.clearDirtyLayers();

} else {

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

}

}

Expand Down
14 changes: 14 additions & 0 deletions src/textures/CompressedArrayTexture.js
Expand Up @@ -11,6 +11,20 @@ class CompressedArrayTexture extends CompressedTexture {
this.image.depth = depth;
this.wrapR = ClampToEdgeWrapping;

this.dirtyLayers = new Set();

}

addDirtyLayer( layerIndex ) {

this.dirtyLayers.add( layerIndex );

}

clearDirtyLayers() {

this.dirtyLayers.clear();

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

}
Expand Down