Skip to content

Commit a7cc089

Browse files
committed
copyTextureToTexture3D when \!srcTexture.isDataTexture
1 parent 840872b commit a7cc089

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

examples/webgl2_materials_texture2darray.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@
110110
glslVersion: THREE.GLSL3
111111
} );
112112

113+
new THREE.TextureLoader().load( 'textures/uv_grid_opengl.jpg', function(tex) {
114+
const position = new THREE.Vector3(0,0,0);
115+
const box = new THREE.Box3( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 255, 255, 0 ) );
116+
// tex.image.data = tex.image; // workaround to mascarade a THREE.Texture as a THREE.DataTexture
117+
renderer.copyTextureToTexture3D( box, position, tex, texture );
118+
} );
119+
113120
const geometry = new THREE.PlaneGeometry( planeWidth, planeHeight );
114121

115122
mesh = new THREE.Mesh( geometry, material );

src/renderers/WebGLRenderer.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,7 +2107,9 @@ function WebGLRenderer( parameters ) {
21072107

21082108
}
21092109

2110-
const { width, height, data } = srcTexture.image;
2110+
const width = sourceBox.max.x - sourceBox.min.x + 1;
2111+
const height = sourceBox.max.y - sourceBox.min.y + 1;
2112+
const depth = sourceBox.max.z - sourceBox.min.z + 1;
21112113
const glFormat = utils.convert( dstTexture.format );
21122114
const glType = utils.convert( dstTexture.type );
21132115
let glTarget;
@@ -2139,25 +2141,32 @@ function WebGLRenderer( parameters ) {
21392141
const unpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
21402142
const unpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES );
21412143

2142-
_gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, width );
2143-
_gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, height );
2144+
const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ 0 ] : srcTexture.image;
2145+
2146+
_gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
2147+
_gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
21442148
_gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, sourceBox.min.x );
21452149
_gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, sourceBox.min.y );
21462150
_gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, sourceBox.min.z );
21472151

2148-
_gl.texSubImage3D(
2149-
glTarget,
2150-
level,
2151-
position.x,
2152-
position.y,
2153-
position.z,
2154-
sourceBox.max.x - sourceBox.min.x + 1,
2155-
sourceBox.max.y - sourceBox.min.y + 1,
2156-
sourceBox.max.z - sourceBox.min.z + 1,
2157-
glFormat,
2158-
glType,
2159-
data
2160-
);
2152+
if ( srcTexture.isDataTexture || srcTexture.isDataTexture3D ) {
2153+
2154+
_gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image.data );
2155+
2156+
} else {
2157+
2158+
if ( srcTexture.isCompressedTexture ) {
2159+
2160+
console.warn( 'THREE.WebGLRenderer.copyTextureToTexture3D: untested support for compressed srcTexture.');
2161+
_gl.compressedTexSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, image.data );
2162+
2163+
} else {
2164+
2165+
_gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image );
2166+
2167+
}
2168+
2169+
}
21612170

21622171
_gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, unpackRowLen );
21632172
_gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, unpackImageHeight );

0 commit comments

Comments
 (0)