From a408595c2543715a1e05b6cdffe9ed99ae08d3e4 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Fri, 17 May 2024 23:46:24 -0400 Subject: [PATCH] WebGLRenderer: Enable subframe upload in copyTextureToTexture, align API to 3d version (#956) * WebGLRenderer: Enable subframe upload in copyTextureToTexture * Update three.js * Add examples * Update patch * Delete examples --- examples-testing/changes.patch | 10 ++++---- three.js | 2 +- types/three/src/renderers/WebGLRenderer.d.ts | 27 ++++++++++++++------ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/examples-testing/changes.patch b/examples-testing/changes.patch index fcb0f1c41..4a543b611 100644 --- a/examples-testing/changes.patch +++ b/examples-testing/changes.patch @@ -1952,7 +1952,7 @@ index 977dbadb..fb1460ca 100644 material.uniforms['u_renderthreshold'].value = volconfig.isothreshold; // For ISO renderstyle material.uniforms['u_cmdata'].value = cmtextures[volconfig.colormap]; diff --git a/examples-testing/examples/webgl2_materials_texture3d_partialupdate.ts b/examples-testing/examples/webgl2_materials_texture3d_partialupdate.ts -index fc2fc783..cd17b027 100644 +index 1ad6d264..10b32582 100644 --- a/examples-testing/examples/webgl2_materials_texture3d_partialupdate.ts +++ b/examples-testing/examples/webgl2_materials_texture3d_partialupdate.ts @@ -6,14 +6,14 @@ import { GUI } from 'three/addons/libs/lil-gui.module.min.js'; @@ -1987,8 +1987,8 @@ index fc2fc783..cd17b027 100644 const scaleFactor = (Math.random() + 0.5) * 0.5; const source = generateCloudTexture(perElementPaddedSize, scaleFactor); -- renderer.copyTextureToTexture3D(box, position, source, cloudTexture); -+ renderer.copyTextureToTexture3D(box, position, source, cloudTexture!); +- renderer.copyTextureToTexture3D(source, cloudTexture, box, position); ++ renderer.copyTextureToTexture3D(source, cloudTexture!, box, position); prevTime = time; @@ -5901,7 +5901,7 @@ index adfcfddf..d26cee37 100644 INTERSECTED = null; } diff --git a/examples-testing/examples/webgl_interactive_cubes_gpu.ts b/examples-testing/examples/webgl_interactive_cubes_gpu.ts -index 313b023a..7e77fbc5 100644 +index 2644469c..d48fa232 100644 --- a/examples-testing/examples/webgl_interactive_cubes_gpu.ts +++ b/examples-testing/examples/webgl_interactive_cubes_gpu.ts @@ -5,12 +5,12 @@ import Stats from 'three/addons/libs/stats.module.js'; @@ -9104,7 +9104,7 @@ index 24bd4eb9..5d5e77b6 100644 mouseY = event.clientY - windowHalfY; } diff --git a/examples-testing/examples/webgl_materials_texture_partialupdate.ts b/examples-testing/examples/webgl_materials_texture_partialupdate.ts -index 04844817..2f734b77 100644 +index 5adfc8e6..55d802e3 100644 --- a/examples-testing/examples/webgl_materials_texture_partialupdate.ts +++ b/examples-testing/examples/webgl_materials_texture_partialupdate.ts @@ -1,6 +1,11 @@ diff --git a/three.js b/three.js index 7a0247592..3bc0cc715 160000 --- a/three.js +++ b/three.js @@ -1 +1 @@ -Subproject commit 7a02475928a0f6e0b7f37c5db6bc6de48f358d2d +Subproject commit 3bc0cc71548aad53c1b6c3450c7fe657d2f799f5 diff --git a/types/three/src/renderers/WebGLRenderer.d.ts b/types/three/src/renderers/WebGLRenderer.d.ts index da0127b94..150578622 100644 --- a/types/three/src/renderers/WebGLRenderer.d.ts +++ b/types/three/src/renderers/WebGLRenderer.d.ts @@ -4,6 +4,7 @@ import { TypedArray } from "../core/BufferAttribute.js"; import { BufferGeometry } from "../core/BufferGeometry.js"; import { Object3D } from "../core/Object3D.js"; import { Material } from "../materials/Material.js"; +import { Box2 } from "../math/Box2.js"; import { Box3 } from "../math/Box3.js"; import { Color, ColorRepresentation } from "../math/Color.js"; import { Plane } from "../math/Plane.js"; @@ -447,28 +448,38 @@ export class WebGLRenderer implements Renderer { copyFramebufferToTexture(position: Vector2, texture: Texture, level?: number): void; /** - * Copies srcTexture to the specified level of dstTexture, offset by the input position. + * Copies the pixels of a texture in the bounds `srcRegion` in the destination texture starting from the given + * position. * - * @param position Specifies the pixel offset into the dstTexture where the copy will occur. * @param srcTexture Specifies the source texture. * @param dstTexture Specifies the destination texture. + * @param srcRegion Specifies the bounds + * @param dstPosition Specifies the pixel offset into the dstTexture where the copy will occur. * @param level Specifies the destination mipmap level of the texture. */ - copyTextureToTexture(position: Vector2, srcTexture: Texture, dstTexture: Texture, level?: number): void; + copyTextureToTexture( + srcTexture: Texture, + dstTexture: Texture, + srcRegion?: Box2 | null, + dstPosition?: Vector2 | null, + level?: number, + ): void; /** - * Copies the pixels of a texture in the bounds sourceBox in the desination texture starting from the given position. - * @param sourceBox Specifies the bounds - * @param position Specifies the pixel offset into the dstTexture where the copy will occur. + * Copies the pixels of a texture in the bounds `srcRegion` in the destination texture starting from the given + * position. + * * @param srcTexture Specifies the source texture. * @param dstTexture Specifies the destination texture. + * @param srcRegion Specifies the bounds + * @param dstPosition Specifies the pixel offset into the dstTexture where the copy will occur. * @param level Specifies the destination mipmap level of the texture. */ copyTextureToTexture3D( - sourceBox: Box3, - position: Vector3, srcTexture: Texture, dstTexture: Data3DTexture | DataArrayTexture, + srcRegion?: Box3 | null, + dstPosition?: Vector3 | null, level?: number, ): void;