diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 36a79146db0fc8..4e5e2fa56536d3 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -2129,7 +2129,9 @@ function WebGLRenderer( parameters = {} ) { } - const { width, height, data } = srcTexture.image; + const width = sourceBox.max.x - sourceBox.min.x + 1; + const height = sourceBox.max.y - sourceBox.min.y + 1; + const depth = sourceBox.max.z - sourceBox.min.z + 1; const glFormat = utils.convert( dstTexture.format ); const glType = utils.convert( dstTexture.type ); let glTarget; @@ -2161,25 +2163,32 @@ function WebGLRenderer( parameters = {} ) { const unpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS ); const unpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES ); - _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, width ); - _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, height ); + const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ 0 ] : srcTexture.image; + + _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width ); + _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height ); _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, sourceBox.min.x ); _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, sourceBox.min.y ); _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, sourceBox.min.z ); - _gl.texSubImage3D( - glTarget, - level, - position.x, - position.y, - position.z, - sourceBox.max.x - sourceBox.min.x + 1, - sourceBox.max.y - sourceBox.min.y + 1, - sourceBox.max.z - sourceBox.min.z + 1, - glFormat, - glType, - data - ); + if ( srcTexture.isDataTexture || srcTexture.isDataTexture3D ) { + + _gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image.data ); + + } else { + + if ( srcTexture.isCompressedTexture ) { + + console.warn( 'THREE.WebGLRenderer.copyTextureToTexture3D: untested support for compressed srcTexture.' ); + _gl.compressedTexSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, image.data ); + + } else { + + _gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image ); + + } + + } _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, unpackRowLen ); _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, unpackImageHeight );