Skip to content

Commit 93a1072

Browse files
committed
Trigger PR update
1 parent e3b7eba commit 93a1072

File tree

3 files changed

+74
-26
lines changed

3 files changed

+74
-26
lines changed

Diff for: src/renderers/common/Renderer.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -2460,14 +2460,15 @@ class Renderer {
24602460
* @param {Texture} dstTexture - The destination texture.
24612461
* @param {Box2|Box3} [srcRegion=null] - A bounding box which describes the source region. Can be two or three-dimensional.
24622462
* @param {Vector2|Vector3} [dstPosition=null] - A vector that represents the origin of the destination region. Can be two or three-dimensional.
2463-
* @param {number} level - The mipmap level to copy.
2463+
* @param {number} [srcLevel=0] - The mipmap level to copy.
2464+
* @param {number} [dstLevel=null] - The destination mip level to copy to.
24642465
*/
2465-
copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
2466+
copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = null ) {
24662467

24672468
this._textures.updateTexture( srcTexture );
24682469
this._textures.updateTexture( dstTexture );
24692470

2470-
this.backend.copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition, level );
2471+
this.backend.copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition, srcLevel, dstLevel );
24712472

24722473
}
24732474

Diff for: src/renderers/webgl-fallback/WebGLBackend.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1886,13 +1886,14 @@ class WebGLBackend extends Backend {
18861886
*
18871887
* @param {Texture} srcTexture - The source texture.
18881888
* @param {Texture} dstTexture - The destination texture.
1889-
* @param {?Vector4} [srcRegion=null] - The region of the source texture to copy.
1889+
* @param {?(Box3|Box2)} [srcRegion=null] - The region of the source texture to copy.
18901890
* @param {?(Vector2|Vector3)} [dstPosition=null] - The destination position of the copy.
1891-
* @param {number} [level=0] - The mip level to copy.
1891+
* @param {number} [srcLevel=0] - The mip level to copy.
1892+
* @param {number} [dstLevel=null] - The destination mip level to copy to.
18921893
*/
1893-
copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
1894+
copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = null ) {
18941895

1895-
this.textureUtils.copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition, level );
1896+
this.textureUtils.copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition, srcLevel, dstLevel );
18961897

18971898
}
18981899

Diff for: src/renderers/webgl-fallback/utils/WebGLTextureUtils.js

+65-19
Original file line numberDiff line numberDiff line change
@@ -692,75 +692,98 @@ class WebGLTextureUtils {
692692

693693
}
694694

695+
695696
/**
696697
* Copies data of the given source texture to the given destination texture.
697698
*
698699
* @param {Texture} srcTexture - The source texture.
699700
* @param {Texture} dstTexture - The destination texture.
700-
* @param {?Vector4} [srcRegion=null] - The region of the source texture to copy.
701+
* @param {?(Box3|Box2)} [srcRegion=null] - The region of the source texture to copy.
701702
* @param {?(Vector2|Vector3)} [dstPosition=null] - The destination position of the copy.
702-
* @param {number} [level=0] - The mip level to copy.
703+
* @param {number} [srcLevel=0] - The source mip level to copy from.
704+
* @param {number} [dstLevel=null] - The destination mip level to copy to.
703705
*/
704-
copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
706+
copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = null ) {
705707

706708
const { gl, backend } = this;
707709
const { state } = this.backend;
708710

709711
const { textureGPU: dstTextureGPU, glTextureType, glType, glFormat } = backend.get( dstTexture );
710712

711-
let width, height, minX, minY;
712-
let dstX, dstY;
713+
state.bindTexture( glTextureType, dstTextureGPU );
713714

715+
// gather the necessary dimensions to copy
716+
let width, height, depth, minX, minY, minZ;
717+
let dstX, dstY, dstZ;
718+
const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ dstLevel ] : srcTexture.image;
714719
if ( srcRegion !== null ) {
715720

716721
width = srcRegion.max.x - srcRegion.min.x;
717722
height = srcRegion.max.y - srcRegion.min.y;
723+
depth = srcRegion.isBox3 ? srcRegion.max.z - srcRegion.min.z : 1;
718724
minX = srcRegion.min.x;
719725
minY = srcRegion.min.y;
726+
minZ = srcRegion.isBox3 ? srcRegion.min.z : 0;
720727

721728
} else {
722729

723-
width = srcTexture.image.width;
724-
height = srcTexture.image.height;
730+
const levelScale = Math.pow( 2, - srcLevel );
731+
width = Math.floor( image.width * levelScale );
732+
height = Math.floor( image.height * levelScale );
733+
if ( srcTexture.isDataArrayTexture ) {
734+
735+
depth = image.depth;
736+
737+
} else if ( srcTexture.isData3DTexture ) {
738+
739+
depth = Math.floor( image.depth * levelScale );
740+
741+
} else {
742+
743+
depth = 1;
744+
745+
}
746+
725747
minX = 0;
726748
minY = 0;
749+
minZ = 0;
727750

728751
}
729752

730753
if ( dstPosition !== null ) {
731754

732755
dstX = dstPosition.x;
733756
dstY = dstPosition.y;
757+
dstZ = dstPosition.z;
734758

735759
} else {
736760

737761
dstX = 0;
738762
dstY = 0;
763+
dstZ = 0;
739764

740765
}
741766

742-
state.bindTexture( glTextureType, dstTextureGPU );
743767

744-
// As another texture upload may have changed pixelStorei
745-
// parameters, make sure they are correct for the dstTexture
746-
gl.pixelStorei( gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
747768
gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
748769
gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
749770
gl.pixelStorei( gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
750771

772+
// used for copying data from cpu
751773
const currentUnpackRowLen = gl.getParameter( gl.UNPACK_ROW_LENGTH );
752774
const currentUnpackImageHeight = gl.getParameter( gl.UNPACK_IMAGE_HEIGHT );
753775
const currentUnpackSkipPixels = gl.getParameter( gl.UNPACK_SKIP_PIXELS );
754776
const currentUnpackSkipRows = gl.getParameter( gl.UNPACK_SKIP_ROWS );
755777
const currentUnpackSkipImages = gl.getParameter( gl.UNPACK_SKIP_IMAGES );
756778

757-
const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image;
758-
759779
gl.pixelStorei( gl.UNPACK_ROW_LENGTH, image.width );
760780
gl.pixelStorei( gl.UNPACK_IMAGE_HEIGHT, image.height );
761781
gl.pixelStorei( gl.UNPACK_SKIP_PIXELS, minX );
762782
gl.pixelStorei( gl.UNPACK_SKIP_ROWS, minY );
783+
gl.pixelStorei( gl.UNPACK_SKIP_IMAGES, minZ );
763784

785+
// set up the src texture
786+
const isDst3D = dstTexture.isDataArrayTexture || dstTexture.isData3DTexture;
764787
if ( srcTexture.isRenderTargetTexture || srcTexture.isDepthTexture ) {
765788

766789
const srcTextureData = backend.get( srcTexture );
@@ -786,34 +809,57 @@ class WebGLTextureUtils {
786809

787810
} else {
788811

789-
if ( srcTexture.isDataTexture ) {
812+
if ( isDst3D ) {
790813

791-
gl.texSubImage2D( gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image.data );
814+
// copy data into the 3d texture
815+
if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) {
816+
817+
gl.texSubImage3D( glTextureType, dstLevel, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image.data );
818+
819+
} else if ( dstTexture.isCompressedArrayTexture ) {
820+
821+
gl.compressedTexSubImage3D( glTextureType, dstLevel, dstX, dstY, dstZ, width, height, depth, glFormat, image.data );
822+
823+
} else {
824+
825+
gl.texSubImage3D( glTextureType, dstLevel, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image );
826+
827+
}
792828

793829
} else {
794830

795-
if ( srcTexture.isCompressedTexture ) {
831+
// copy data into the 2d texture
832+
if ( srcTexture.isDataTexture ) {
833+
834+
gl.texSubImage2D( glTextureType, dstLevel, dstX, dstY, width, height, glFormat, glType, image.data );
835+
836+
} else if ( srcTexture.isCompressedTexture ) {
796837

797-
gl.compressedTexSubImage2D( gl.TEXTURE_2D, level, dstX, dstY, image.width, image.height, glFormat, image.data );
838+
gl.compressedTexSubImage2D( glTextureType, dstLevel, dstX, dstY, image.width, image.height, glFormat, image.data );
798839

799840
} else {
800841

801-
gl.texSubImage2D( gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image );
842+
gl.texSubImage2D( glTextureType, dstLevel, dstX, dstY, width, height, glFormat, glType, image );
802843

803844
}
804845

805846
}
806847

807848
}
808849

850+
// reset values
809851
gl.pixelStorei( gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
810852
gl.pixelStorei( gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );
811853
gl.pixelStorei( gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
812854
gl.pixelStorei( gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
813855
gl.pixelStorei( gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );
814856

815857
// Generate mipmaps only when copying level 0
816-
if ( level === 0 && dstTexture.generateMipmaps ) gl.generateMipmap( gl.TEXTURE_2D );
858+
if ( dstLevel === 0 && dstTexture.generateMipmaps ) {
859+
860+
gl.generateMipmap( glTextureType );
861+
862+
}
817863

818864
state.unbindTexture();
819865

0 commit comments

Comments
 (0)