From 105488bfb328aa9b063f08639198ec827f4af051 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Sat, 4 May 2024 23:43:15 +0900 Subject: [PATCH 01/16] align WebGLRenderer.copyTextureToTexture with copyTextureToTexture3D --- src/renderers/WebGLRenderer.js | 41 +++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 6fe5a52fa19f08..b0d81f6b887520 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -2371,10 +2371,20 @@ class WebGLRenderer { }; - this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0 ) { + this.copyTextureToTexture = function ( sourceBox, position, srcTexture, dstTexture, level = 0 ) { - const width = srcTexture.image.width; - const height = srcTexture.image.height; + if ( sourceBox.isBox2 !== true ) { + + console.warn( 'WebGLRenderer: copyTextureToTexture function signature has changed.' ); + position = arguments[ 0 ]; + srcTexture = arguments[ 1 ]; + dstTexture = arguments[ 2 ]; + level = arguments[ 3 ]; + + } + + const width = sourceBox.max.x - sourceBox.min.x; + const height = sourceBox.max.y - sourceBox.min.y; const glFormat = utils.convert( dstTexture.format ); const glType = utils.convert( dstTexture.type ); @@ -2386,24 +2396,43 @@ class WebGLRenderer { _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha ); _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment ); + const unpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH ); + const unpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT ); + const unpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS ); + const unpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS ); + const unpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES ); + + const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : 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 ); + if ( srcTexture.isDataTexture ) { - _gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data ); + _gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, width, height, glFormat, glType, image.data ); } else { if ( srcTexture.isCompressedTexture ) { - _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data ); + _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, image.width, image.height, glFormat, image.data ); } else { - _gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, srcTexture.image ); + _gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, image ); } } + _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, unpackRowLen ); + _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, unpackImageHeight ); + _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, unpackSkipPixels ); + _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, unpackSkipRows ); + _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, unpackSkipImages ); + // Generate mipmaps only when copying level 0 if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( _gl.TEXTURE_2D ); From 38c2f1d48ff1c6644a201b20d0f966f2f4007571 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Sun, 5 May 2024 00:20:32 +0900 Subject: [PATCH 02/16] Make the function backwards compatible --- src/renderers/WebGLRenderer.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index b0d81f6b887520..5e6e5777298c36 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -2376,11 +2376,17 @@ class WebGLRenderer { if ( sourceBox.isBox2 !== true ) { console.warn( 'WebGLRenderer: copyTextureToTexture function signature has changed.' ); + position = arguments[ 0 ]; srcTexture = arguments[ 1 ]; dstTexture = arguments[ 2 ]; level = arguments[ 3 ]; + const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image; + sourceBox = new Box2(); + sourceBox.min.set( 0, 0 ); + sourceBox.max.set( image.width, image.height ); + } const width = sourceBox.max.x - sourceBox.min.x; From 8e3deaf5451834f3e8d39b5bf8c50f2b6252b5bd Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Sun, 5 May 2024 00:20:40 +0900 Subject: [PATCH 03/16] Add import statement --- src/renderers/WebGLRenderer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 5e6e5777298c36..6a8efe7754474e 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -56,6 +56,7 @@ import { WebGLMaterials } from './webgl/WebGLMaterials.js'; import { WebGLUniformsGroups } from './webgl/WebGLUniformsGroups.js'; import { createCanvasElement } from '../utils.js'; import { ColorManagement } from '../math/ColorManagement.js'; +import { Box2 } from '../math/Box2.js'; class WebGLRenderer { From 55a12e2e9ffa62c424328dc192b6575c2b91f1be Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Sun, 5 May 2024 00:26:20 +0900 Subject: [PATCH 04/16] Fix example --- examples/webgl_materials_texture_partialupdate.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/webgl_materials_texture_partialupdate.html b/examples/webgl_materials_texture_partialupdate.html index 504b9c4be575a7..5c7be1c1b27ea2 100644 --- a/examples/webgl_materials_texture_partialupdate.html +++ b/examples/webgl_materials_texture_partialupdate.html @@ -31,6 +31,7 @@ let last = 0; const position = new THREE.Vector2(); const color = new THREE.Color(); + const box = new THREE.Box2(); init(); @@ -103,7 +104,10 @@ // perform copy from src to dest texture to a random position - renderer.copyTextureToTexture( position, dataTexture, diffuseMap ); + box.min.set( 0, 0 ); + box.max.set( dataTexture.image.width, dataTexture.image.height ); + + renderer.copyTextureToTexture( box, position, dataTexture, diffuseMap ); } From 9f62ed6b264ae9b6db3b1a00ef6660dfe513f829 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 6 May 2024 22:57:54 +0900 Subject: [PATCH 05/16] rename local state variables --- src/renderers/WebGLRenderer.js | 40 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 6a8efe7754474e..caa321144c255e 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -2403,11 +2403,11 @@ class WebGLRenderer { _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha ); _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment ); - const unpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH ); - const unpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT ); - const unpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS ); - const unpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS ); - const unpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES ); + const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH ); + const currentUnpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT ); + const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS ); + const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS ); + const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES ); const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image; @@ -2434,11 +2434,11 @@ class WebGLRenderer { } - _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, unpackRowLen ); - _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, unpackImageHeight ); - _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, unpackSkipPixels ); - _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, unpackSkipRows ); - _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, unpackSkipImages ); + _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen ); + _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight ); + _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels ); + _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows ); + _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages ); // Generate mipmaps only when copying level 0 if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( _gl.TEXTURE_2D ); @@ -2477,11 +2477,11 @@ class WebGLRenderer { _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha ); _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment ); - const unpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH ); - const unpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT ); - const unpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS ); - const unpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS ); - const unpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES ); + const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH ); + const currentUnpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT ); + const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS ); + const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS ); + const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES ); const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image; @@ -2509,11 +2509,11 @@ class WebGLRenderer { } - _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, unpackRowLen ); - _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, unpackImageHeight ); - _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, unpackSkipPixels ); - _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, unpackSkipRows ); - _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, unpackSkipImages ); + _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen ); + _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight ); + _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels ); + _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows ); + _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages ); // Generate mipmaps only when copying level 0 if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( glTarget ); From 67c1f1b876b0796caba49da5b597ddc57df1c12a Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 6 May 2024 22:58:42 +0900 Subject: [PATCH 06/16] Add deprecation comment --- src/renderers/WebGLRenderer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index caa321144c255e..8aa52d8c00234c 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -2376,6 +2376,7 @@ class WebGLRenderer { if ( sourceBox.isBox2 !== true ) { + // @deprecated, r165 console.warn( 'WebGLRenderer: copyTextureToTexture function signature has changed.' ); position = arguments[ 0 ]; From 2944a86e2e403095e415ef933a44f9127748b9f6 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 6 May 2024 23:00:30 +0900 Subject: [PATCH 07/16] Update docs --- docs/api/en/renderers/WebGLRenderer.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/api/en/renderers/WebGLRenderer.html b/docs/api/en/renderers/WebGLRenderer.html index c80c7eeafcb4bd..a687f5d13fcb6f 100644 --- a/docs/api/en/renderers/WebGLRenderer.html +++ b/docs/api/en/renderers/WebGLRenderer.html @@ -376,11 +376,12 @@

- [method:undefined copyTextureToTexture]( [param:Vector2 position], [param:Texture srcTexture], [param:Texture dstTexture], [param:Number level] ) + [method:undefined copyTextureToTexture]( [param:Box2 sourceBox], [param:Vector2 position], [param:Texture srcTexture], [param:Texture dstTexture], [param:Number level] )

- Copies all pixels of a texture to an existing texture starting from the - given position. Enables access to + Copies the pixels of a texture in the bounds '[page:Box2 sourceBox]' in + the destination texture starting from the given position. Enables access + to [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texSubImage2D WebGLRenderingContext.texSubImage2D].

From f5c77613b4cc3489ac31c0bc3c492eaf0833f0bf Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Tue, 7 May 2024 00:08:15 +0900 Subject: [PATCH 08/16] Update API signatures --- docs/api/en/renderers/WebGLRenderer.html | 4 +- src/renderers/WebGLRenderer.js | 76 +++++++++++++++++------- 2 files changed, 55 insertions(+), 25 deletions(-) diff --git a/docs/api/en/renderers/WebGLRenderer.html b/docs/api/en/renderers/WebGLRenderer.html index a687f5d13fcb6f..424782ebe84b87 100644 --- a/docs/api/en/renderers/WebGLRenderer.html +++ b/docs/api/en/renderers/WebGLRenderer.html @@ -376,7 +376,7 @@

- [method:undefined copyTextureToTexture]( [param:Box2 sourceBox], [param:Vector2 position], [param:Texture srcTexture], [param:Texture dstTexture], [param:Number level] ) + [method:undefined copyTextureToTexture]( [param:Vector2 position], [param:Texture srcTexture], [param:Texture dstTexture], [param:Number level], [param:Box2 sourceBox] )

Copies the pixels of a texture in the bounds '[page:Box2 sourceBox]' in @@ -386,7 +386,7 @@

- [method:undefined copyTextureToTexture3D]( [param:Box3 sourceBox], [param:Vector3 position], [param:Texture srcTexture], [param:Texture dstTexture], [param:Number level] ) + [method:undefined copyTextureToTexture3D]( [param:Vector3 position], [param:Texture srcTexture], [param:Texture dstTexture], [param:Number level], [param:Box3 sourceBox] )

Copies the pixels of a texture in the bounds '[page:Box3 sourceBox]' in diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 8aa52d8c00234c..5238201436c8af 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -2372,27 +2372,25 @@ class WebGLRenderer { }; - this.copyTextureToTexture = function ( sourceBox, position, srcTexture, dstTexture, level = 0 ) { + this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0, sourceBox = null ) { - if ( sourceBox.isBox2 !== true ) { + let width, height, minX, minY; + if ( sourceBox ) { - // @deprecated, r165 - console.warn( 'WebGLRenderer: copyTextureToTexture function signature has changed.' ); + width = sourceBox.max.x - sourceBox.min.x; + height = sourceBox.max.y - sourceBox.min.y; + minX = sourceBox.min.x; + minY = sourceBox.min.y; - position = arguments[ 0 ]; - srcTexture = arguments[ 1 ]; - dstTexture = arguments[ 2 ]; - level = arguments[ 3 ]; + } else { - const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image; - sourceBox = new Box2(); - sourceBox.min.set( 0, 0 ); - sourceBox.max.set( image.width, image.height ); + width = srcTexture.image.width; + height = srcTexture.image.height; + minX = 0; + minY = 0; } - const width = sourceBox.max.x - sourceBox.min.x; - const height = sourceBox.max.y - sourceBox.min.y; const glFormat = utils.convert( dstTexture.format ); const glType = utils.convert( dstTexture.type ); @@ -2414,8 +2412,8 @@ class WebGLRenderer { _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_PIXELS, minX ); + _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY ); if ( srcTexture.isDataTexture ) { @@ -2448,11 +2446,43 @@ class WebGLRenderer { }; - this.copyTextureToTexture3D = function ( sourceBox, position, srcTexture, dstTexture, level = 0 ) { + this.copyTextureToTexture3D = function ( position, srcTexture, dstTexture, level = 0, sourceBox = null ) { + + if ( position.isBox3 === true ) { + + // @deprecated, r165 + console.warn( 'WebGLRenderer: copyTextureToTexture3D function signature has changed.' ); + + sourceBox = arguments[ 0 ]; + position = arguments[ 1 ]; + srcTexture = arguments[ 2 ]; + dstTexture = arguments[ 3 ]; + level = arguments[ 4 ] || 0; + + } + + let width, height, depth, minX, minY, minZ; + if ( sourceBox ) { + + width = sourceBox.max.x - sourceBox.min.x; + height = sourceBox.max.y - sourceBox.min.y; + depth = sourceBox.max.z - sourceBox.min.z; + minX = sourceBox.min.x; + minY = sourceBox.min.y; + minZ = sourceBox.min.z; + + } else { + + const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image; + width = image.width; + height = image.height; + depth = image.depth; + minX = 0; + minY = 0; + minZ = 0; + + } - const width = sourceBox.max.x - sourceBox.min.x; - const height = sourceBox.max.y - sourceBox.min.y; - const depth = sourceBox.max.z - sourceBox.min.z; const glFormat = utils.convert( dstTexture.format ); const glType = utils.convert( dstTexture.type ); let glTarget; @@ -2488,9 +2518,9 @@ class WebGLRenderer { _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.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX ); + _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY ); + _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, minZ ); if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) { From 7398afd322a3da34714e6ba0df86b6456a301acc Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Tue, 7 May 2024 00:09:02 +0900 Subject: [PATCH 09/16] Simplify --- src/renderers/WebGLRenderer.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 5238201436c8af..f02be9a7e7d6e8 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -2375,7 +2375,7 @@ class WebGLRenderer { this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0, sourceBox = null ) { let width, height, minX, minY; - if ( sourceBox ) { + if ( sourceBox !== null ) { width = sourceBox.max.x - sourceBox.min.x; height = sourceBox.max.y - sourceBox.min.y; @@ -2462,7 +2462,8 @@ class WebGLRenderer { } let width, height, depth, minX, minY, minZ; - if ( sourceBox ) { + const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image; + if ( sourceBox !== null ) { width = sourceBox.max.x - sourceBox.min.x; height = sourceBox.max.y - sourceBox.min.y; @@ -2473,7 +2474,6 @@ class WebGLRenderer { } else { - const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image; width = image.width; height = image.height; depth = image.depth; @@ -2514,8 +2514,6 @@ class WebGLRenderer { const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS ); const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES ); - const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image; - _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width ); _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height ); _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX ); From dc0a9185333f1d8686ee6b0d360482b1b23527e5 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Tue, 7 May 2024 00:09:12 +0900 Subject: [PATCH 10/16] Update examples --- examples/webgl2_materials_texture3d_partialupdate.html | 2 +- examples/webgl_materials_texture_partialupdate.html | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/webgl2_materials_texture3d_partialupdate.html b/examples/webgl2_materials_texture3d_partialupdate.html index f1a041b223c77d..5f313408bc10fb 100644 --- a/examples/webgl2_materials_texture3d_partialupdate.html +++ b/examples/webgl2_materials_texture3d_partialupdate.html @@ -343,7 +343,7 @@ const scaleFactor = ( Math.random() + 0.5 ) * 0.5; const source = generateCloudTexture( perElementPaddedSize, scaleFactor ); - renderer.copyTextureToTexture3D( box, position, source, cloudTexture ); + renderer.copyTextureToTexture3D( position, source, cloudTexture, 0, box ); prevTime = time; diff --git a/examples/webgl_materials_texture_partialupdate.html b/examples/webgl_materials_texture_partialupdate.html index 5c7be1c1b27ea2..c1149f249856db 100644 --- a/examples/webgl_materials_texture_partialupdate.html +++ b/examples/webgl_materials_texture_partialupdate.html @@ -104,10 +104,7 @@ // perform copy from src to dest texture to a random position - box.min.set( 0, 0 ); - box.max.set( dataTexture.image.width, dataTexture.image.height ); - - renderer.copyTextureToTexture( box, position, dataTexture, diffuseMap ); + renderer.copyTextureToTexture( position, dataTexture, diffuseMap ); } From e6dade6eddedb5678f8c7fedf45a92d6afdde804 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Tue, 7 May 2024 00:11:24 +0900 Subject: [PATCH 11/16] Remove unused Box2 --- examples/webgl_materials_texture_partialupdate.html | 1 - src/renderers/WebGLRenderer.js | 1 - 2 files changed, 2 deletions(-) diff --git a/examples/webgl_materials_texture_partialupdate.html b/examples/webgl_materials_texture_partialupdate.html index c1149f249856db..504b9c4be575a7 100644 --- a/examples/webgl_materials_texture_partialupdate.html +++ b/examples/webgl_materials_texture_partialupdate.html @@ -31,7 +31,6 @@ let last = 0; const position = new THREE.Vector2(); const color = new THREE.Color(); - const box = new THREE.Box2(); init(); diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index f02be9a7e7d6e8..6a7dcbb363fbec 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -56,7 +56,6 @@ import { WebGLMaterials } from './webgl/WebGLMaterials.js'; import { WebGLUniformsGroups } from './webgl/WebGLUniformsGroups.js'; import { createCanvasElement } from '../utils.js'; import { ColorManagement } from '../math/ColorManagement.js'; -import { Box2 } from '../math/Box2.js'; class WebGLRenderer { From a23be2fd6f3718cf72313fb2c8434bb9fd8e9f8d Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Tue, 7 May 2024 00:12:22 +0900 Subject: [PATCH 12/16] Add comment --- src/renderers/WebGLRenderer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 6a7dcbb363fbec..c5c33852d93961 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -2447,6 +2447,7 @@ class WebGLRenderer { this.copyTextureToTexture3D = function ( position, srcTexture, dstTexture, level = 0, sourceBox = null ) { + // support previous signature with source box first if ( position.isBox3 === true ) { // @deprecated, r165 From f4f22aec5f3374e3d885a9b90bdf595372156189 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Tue, 7 May 2024 18:13:35 +0900 Subject: [PATCH 13/16] Update function signatures --- src/renderers/WebGLRenderer.js | 87 +++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 23 deletions(-) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index c5c33852d93961..3d06c37f42e8e8 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -2371,15 +2371,29 @@ class WebGLRenderer { }; - this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0, sourceBox = null ) { + this.copyTextureToTexture = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) { + + // support previous signature with source box first + if ( srcTexture.isVector3 === true ) { + + // @deprecated, r165 + console.warn( 'WebGLRenderer: copyTextureToTexture function signature has changed.' ); + + dstPosition = arguments[ 0 ] || null; + srcTexture = arguments[ 1 ]; + dstTexture = arguments[ 2 ]; + level = arguments[ 3 ] || 0; + + } let width, height, minX, minY; - if ( sourceBox !== null ) { + let dstX, dstY; + if ( srcRegion !== null ) { - width = sourceBox.max.x - sourceBox.min.x; - height = sourceBox.max.y - sourceBox.min.y; - minX = sourceBox.min.x; - minY = sourceBox.min.y; + width = srcRegion.max.x - srcRegion.min.x; + height = srcRegion.max.y - srcRegion.min.y; + minX = srcRegion.min.x; + minY = srcRegion.min.y; } else { @@ -2390,6 +2404,18 @@ class WebGLRenderer { } + if ( dstPosition !== null ) { + + dstX = dstPosition.x; + dstY = dstPosition.y; + + } else { + + dstX = 0; + dstY = 0; + + } + const glFormat = utils.convert( dstTexture.format ); const glType = utils.convert( dstTexture.type ); @@ -2416,17 +2442,17 @@ class WebGLRenderer { if ( srcTexture.isDataTexture ) { - _gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, width, height, glFormat, glType, image.data ); + _gl.texSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image.data ); } else { if ( srcTexture.isCompressedTexture ) { - _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, image.width, image.height, glFormat, image.data ); + _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, image.width, image.height, glFormat, image.data ); } else { - _gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, image ); + _gl.texSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, glFormat, glType, image ); } @@ -2445,16 +2471,16 @@ class WebGLRenderer { }; - this.copyTextureToTexture3D = function ( position, srcTexture, dstTexture, level = 0, sourceBox = null ) { + this.copyTextureToTexture3D = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) { // support previous signature with source box first - if ( position.isBox3 === true ) { + if ( srcTexture.isBox3 === true ) { // @deprecated, r165 console.warn( 'WebGLRenderer: copyTextureToTexture3D function signature has changed.' ); - sourceBox = arguments[ 0 ]; - position = arguments[ 1 ]; + srcRegion = arguments[ 0 ] || null; + dstPosition = arguments[ 1 ] || null; srcTexture = arguments[ 2 ]; dstTexture = arguments[ 3 ]; level = arguments[ 4 ] || 0; @@ -2462,15 +2488,16 @@ class WebGLRenderer { } let width, height, depth, minX, minY, minZ; + let dstX, dstY, dstZ; const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image; - if ( sourceBox !== null ) { + if ( srcRegion !== null ) { - width = sourceBox.max.x - sourceBox.min.x; - height = sourceBox.max.y - sourceBox.min.y; - depth = sourceBox.max.z - sourceBox.min.z; - minX = sourceBox.min.x; - minY = sourceBox.min.y; - minZ = sourceBox.min.z; + width = srcRegion.max.x - srcRegion.min.x; + height = srcRegion.max.y - srcRegion.min.y; + depth = srcRegion.max.z - srcRegion.min.z; + minX = srcRegion.min.x; + minY = srcRegion.min.y; + minZ = srcRegion.min.z; } else { @@ -2483,6 +2510,20 @@ class WebGLRenderer { } + if ( dstPosition !== null ) { + + dstX = dstPosition.x; + dstY = dstPosition.y; + dstZ = dstPosition.z; + + } else { + + dstX = 0; + dstY = 0; + dstZ = 0; + + } + const glFormat = utils.convert( dstTexture.format ); const glType = utils.convert( dstTexture.type ); let glTarget; @@ -2522,17 +2563,17 @@ class WebGLRenderer { if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) { - _gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image.data ); + _gl.texSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image.data ); } else { if ( dstTexture.isCompressedArrayTexture ) { - _gl.compressedTexSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, image.data ); + _gl.compressedTexSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, image.data ); } else { - _gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image ); + _gl.texSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image ); } From 23273943a06f824b2575a40bed21e2400fe3cb81 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Tue, 7 May 2024 18:17:38 +0900 Subject: [PATCH 14/16] examples update --- examples/webgl2_materials_texture3d_partialupdate.html | 2 +- examples/webgl_materials_texture_partialupdate.html | 2 +- src/renderers/WebGLRenderer.js | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/webgl2_materials_texture3d_partialupdate.html b/examples/webgl2_materials_texture3d_partialupdate.html index 5f313408bc10fb..5140e5fa3c6d53 100644 --- a/examples/webgl2_materials_texture3d_partialupdate.html +++ b/examples/webgl2_materials_texture3d_partialupdate.html @@ -343,7 +343,7 @@ const scaleFactor = ( Math.random() + 0.5 ) * 0.5; const source = generateCloudTexture( perElementPaddedSize, scaleFactor ); - renderer.copyTextureToTexture3D( position, source, cloudTexture, 0, box ); + renderer.copyTextureToTexture3D( source, cloudTexture, box, position ); prevTime = time; diff --git a/examples/webgl_materials_texture_partialupdate.html b/examples/webgl_materials_texture_partialupdate.html index 504b9c4be575a7..842597e357697a 100644 --- a/examples/webgl_materials_texture_partialupdate.html +++ b/examples/webgl_materials_texture_partialupdate.html @@ -103,7 +103,7 @@ // perform copy from src to dest texture to a random position - renderer.copyTextureToTexture( position, dataTexture, diffuseMap ); + renderer.copyTextureToTexture( dataTexture, diffuseMap, null, position ); } diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 3d06c37f42e8e8..291ca60320d3cc 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -2374,7 +2374,7 @@ class WebGLRenderer { this.copyTextureToTexture = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) { // support previous signature with source box first - if ( srcTexture.isVector3 === true ) { + if ( srcTexture.isTexture !== true ) { // @deprecated, r165 console.warn( 'WebGLRenderer: copyTextureToTexture function signature has changed.' ); @@ -2383,6 +2383,7 @@ class WebGLRenderer { srcTexture = arguments[ 1 ]; dstTexture = arguments[ 2 ]; level = arguments[ 3 ] || 0; + srcRegion = null; } @@ -2474,7 +2475,7 @@ class WebGLRenderer { this.copyTextureToTexture3D = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) { // support previous signature with source box first - if ( srcTexture.isBox3 === true ) { + if ( srcTexture.isTexture !== true ) { // @deprecated, r165 console.warn( 'WebGLRenderer: copyTextureToTexture3D function signature has changed.' ); From 37fe3b78c032b1776037667dbd09eb266e6585ee Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Tue, 7 May 2024 18:18:55 +0900 Subject: [PATCH 15/16] docs update --- docs/api/en/renderers/WebGLRenderer.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/api/en/renderers/WebGLRenderer.html b/docs/api/en/renderers/WebGLRenderer.html index 424782ebe84b87..bb9f3628189749 100644 --- a/docs/api/en/renderers/WebGLRenderer.html +++ b/docs/api/en/renderers/WebGLRenderer.html @@ -376,20 +376,20 @@

- [method:undefined copyTextureToTexture]( [param:Vector2 position], [param:Texture srcTexture], [param:Texture dstTexture], [param:Number level], [param:Box2 sourceBox] ) + [method:undefined copyTextureToTexture]( [param:Texture srcTexture], [param:Texture dstTexture], [param:Box2 srcRegion], [param:Vector2 dstPosition], [param:Number level] )

- Copies the pixels of a texture in the bounds '[page:Box2 sourceBox]' in + Copies the pixels of a texture in the bounds '[page:Box2 srcRegion]' in the destination texture starting from the given position. Enables access to [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texSubImage2D WebGLRenderingContext.texSubImage2D].

- [method:undefined copyTextureToTexture3D]( [param:Vector3 position], [param:Texture srcTexture], [param:Texture dstTexture], [param:Number level], [param:Box3 sourceBox] ) + [method:undefined copyTextureToTexture3D]( [param:Texture srcTexture], [param:Texture dstTexture], [param:Vector3 dstPosition], [param:Box3 srcRegion], [param:Number level] )

- Copies the pixels of a texture in the bounds '[page:Box3 sourceBox]' in + Copies the pixels of a texture in the bounds '[page:Box3 srcRegion]' in the destination texture starting from the given position. Enables access to [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/texSubImage3D WebGL2RenderingContext.texSubImage3D]. From afc4869c9410511ab059b23cd7f57cff44324770 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Tue, 7 May 2024 18:19:19 +0900 Subject: [PATCH 16/16] Fix docs --- docs/api/en/renderers/WebGLRenderer.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/en/renderers/WebGLRenderer.html b/docs/api/en/renderers/WebGLRenderer.html index bb9f3628189749..8c091070b73ba3 100644 --- a/docs/api/en/renderers/WebGLRenderer.html +++ b/docs/api/en/renderers/WebGLRenderer.html @@ -386,7 +386,7 @@

- [method:undefined copyTextureToTexture3D]( [param:Texture srcTexture], [param:Texture dstTexture], [param:Vector3 dstPosition], [param:Box3 srcRegion], [param:Number level] ) + [method:undefined copyTextureToTexture3D]( [param:Texture srcTexture], [param:Texture dstTexture], [param:Box3 srcRegion], [param:Vector3 dstPosition], [param:Number level] )

Copies the pixels of a texture in the bounds '[page:Box3 srcRegion]' in