Skip to content

Commit

Permalink
WebGLRenderer.copyTextureToTexture3D() support Texture and Compressed…
Browse files Browse the repository at this point in the history
…Texture (#21942)

* copyTextureToTexture3D when \!srcTexture.isDataTexture

* revert example changes
  • Loading branch information
mbredif authored Jun 10, 2021
1 parent 95df9f8 commit 4b22bc5
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 4b22bc5

Please sign in to comment.