diff --git a/examples/jsm/misc/VolumeSlice.js b/examples/jsm/misc/VolumeSlice.js index ff3a07da024f20..1a4dbd35f6cedd 100644 --- a/examples/jsm/misc/VolumeSlice.js +++ b/examples/jsm/misc/VolumeSlice.js @@ -93,6 +93,30 @@ class VolumeSlice { */ this.ctxBuffer; + /** + * Width of slice in the original coordinate system, corresponds to the width of the buffer canvas. + * + * @type {number} + * @default 0 + */ + this.iLength = 0; + + /** + * Height of slice in the original coordinate system, corresponds to the height of the buffer canvas. + * + * @type {number} + * @default 0 + */ + this.jLength = 0; + + /** + * Function that allow the slice to access right data. + * + * @type {?Function} + * @see {@link Volume#extractPerpendicularPlane} + */ + this.sliceAccess = null; + this.updateGeometry(); @@ -120,30 +144,6 @@ class VolumeSlice { this.geometryNeedsUpdate = true; this.repaint(); - /** - * Width of slice in the original coordinate system, corresponds to the width of the buffer canvas. - * - * @type {number} - * @default 0 - */ - this.iLength = 0; - - /** - * Height of slice in the original coordinate system, corresponds to the height of the buffer canvas. - * - * @type {number} - * @default 0 - */ - this.jLength = 0; - - /** - * Function that allow the slice to access right data. - * - * @type {?Function} - * @see {@link Volume#extractPerpendicularPlane} - */ - this.sliceAccess = null; - } /** diff --git a/src/renderers/common/Backend.js b/src/renderers/common/Backend.js index 5032d90433149b..7e2ec3b7540d12 100644 --- a/src/renderers/common/Backend.js +++ b/src/renderers/common/Backend.js @@ -352,7 +352,7 @@ class Backend { * @param {number} y - The y coordinate of the copy origin. * @param {number} width - The width of the copy. * @param {number} height - The height of the copy. - * @param {number} faceIndex - The face index. + * @param {number} faceIndex - The cube face, depth slice or array layer index. * @return {Promise} A Promise that resolves with a typed array when the copy operation has finished. */ async copyTextureToBuffer( /*texture, x, y, width, height, faceIndex*/ ) {} diff --git a/src/renderers/common/Renderer.js b/src/renderers/common/Renderer.js index 937f15389a32be..51252b35786636 100644 --- a/src/renderers/common/Renderer.js +++ b/src/renderers/common/Renderer.js @@ -3214,7 +3214,7 @@ class Renderer { * @param {number} width - The width of the copy region. * @param {number} height - The height of the copy region. * @param {number} [textureIndex=0] - The texture index of a MRT render target. - * @param {number} [faceIndex=0] - The active cube face index. + * @param {number} [faceIndex=0] - The cube face, depth slice or array layer index. * @return {Promise} A Promise that resolves when the read has been finished. The resolve provides the read data as a typed array. */ async readRenderTargetPixelsAsync( renderTarget, x, y, width, height, textureIndex = 0, faceIndex = 0 ) { diff --git a/src/renderers/webgl-fallback/WebGLBackend.js b/src/renderers/webgl-fallback/WebGLBackend.js index 70136de35b6a41..5bcdf79f587b4c 100644 --- a/src/renderers/webgl-fallback/WebGLBackend.js +++ b/src/renderers/webgl-fallback/WebGLBackend.js @@ -1438,7 +1438,7 @@ class WebGLBackend extends Backend { * @param {number} y - The y coordinate of the copy origin. * @param {number} width - The width of the copy. * @param {number} height - The height of the copy. - * @param {number} faceIndex - The face index. + * @param {number} faceIndex - The cube face, depth slice or array layer index. * @return {Promise} A Promise that resolves with a typed array when the copy operation has finished. */ async copyTextureToBuffer( texture, x, y, width, height, faceIndex ) { diff --git a/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js b/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js index 401dd7dc0a4c20..4387a3f2486550 100644 --- a/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +++ b/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js @@ -1233,7 +1233,7 @@ class WebGLTextureUtils { * @param {number} y - The y coordinate of the copy origin. * @param {number} width - The width of the copy. * @param {number} height - The height of the copy. - * @param {number} faceIndex - The face index. + * @param {number} faceIndex - The cube face, depth slice or array layer index. * @return {Promise} A Promise that resolves with a typed array when the copy operation has finished. */ async copyTextureToBuffer( texture, x, y, width, height, faceIndex ) { @@ -1246,9 +1246,17 @@ class WebGLTextureUtils { backend.state.bindFramebuffer( gl.READ_FRAMEBUFFER, fb ); - const target = texture.isCubeTexture ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex : gl.TEXTURE_2D; + if ( texture.isData3DTexture || texture.isDataArrayTexture || texture.isArrayTexture ) { - gl.framebufferTexture2D( gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, target, textureGPU, 0 ); + gl.framebufferTextureLayer( gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, textureGPU, 0, faceIndex ); + + } else { + + const target = texture.isCubeTexture ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex : gl.TEXTURE_2D; + + gl.framebufferTexture2D( gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, target, textureGPU, 0 ); + + } const typedArrayType = this._getTypedArrayType( glType ); const bytesPerTexel = this._getBytesPerTexel( glType, glFormat ); diff --git a/src/renderers/webgpu/WebGPUBackend.js b/src/renderers/webgpu/WebGPUBackend.js index 3a3c6f0fe1f99d..47024304077842 100644 --- a/src/renderers/webgpu/WebGPUBackend.js +++ b/src/renderers/webgpu/WebGPUBackend.js @@ -2274,7 +2274,7 @@ class WebGPUBackend extends Backend { * @param {number} y - The y coordinate of the copy origin. * @param {number} width - The width of the copy. * @param {number} height - The height of the copy. - * @param {number} faceIndex - The face index. + * @param {number} faceIndex - The cube face, depth slice or array layer index. * @return {Promise} A Promise that resolves with a typed array when the copy operation has finished. */ async copyTextureToBuffer( texture, x, y, width, height, faceIndex ) { diff --git a/src/renderers/webgpu/utils/WebGPUTextureUtils.js b/src/renderers/webgpu/utils/WebGPUTextureUtils.js index 4b02f3a2669316..ef037242008bd1 100644 --- a/src/renderers/webgpu/utils/WebGPUTextureUtils.js +++ b/src/renderers/webgpu/utils/WebGPUTextureUtils.js @@ -766,7 +766,7 @@ class WebGPUTextureUtils { * @param {number} y - The y coordinate of the copy origin. * @param {number} width - The width of the copy. * @param {number} height - The height of the copy. - * @param {number} faceIndex - The face index. + * @param {number} faceIndex - The cube face, depth slice or array layer index. * @return {Promise} A Promise that resolves with a typed array when the copy operation has finished. */ async copyTextureToBuffer( texture, x, y, width, height, faceIndex ) { diff --git a/src/renderers/webgpu/utils/WebGPUUtils.js b/src/renderers/webgpu/utils/WebGPUUtils.js index 9fbc2af1ad975d..550969944fa9c4 100644 --- a/src/renderers/webgpu/utils/WebGPUUtils.js +++ b/src/renderers/webgpu/utils/WebGPUUtils.js @@ -111,10 +111,21 @@ class WebGPUUtils { } else if ( texture.isDepthTexture && ! texture.renderTarget ) { - const renderer = this.backend.renderer; - const renderTarget = renderer.getRenderTarget(); + const textureData = this.backend.get( texture ); - samples = renderTarget ? renderTarget.samples : renderer.currentSamples; + if ( textureData.texture !== undefined ) { + + // use the effective sample count of the allocated texture + + samples = textureData.texture.sampleCount; + + } else { + + // otherwise use the current samples of the renderer + + samples = this.backend.renderer.currentSamples; + + } } else if ( texture.renderTarget ) {