Explorar o código

WebGLTextures: Fix onpaint handler for multiple HTMLTextures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mr.doob hai 1 semana
pai
achega
060c05361f
Modificáronse 1 ficheiros con 22 adicións e 3 borrados
  1. 22 3
      src/renderers/webgl/WebGLTextures.js

+ 22 - 3
src/renderers/webgl/WebGLTextures.js

@@ -11,6 +11,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 	const _imageDimensions = new Vector2();
 	const _videoTextures = new WeakMap();
+	const _htmlTextures = new Set();
 	let _canvas;
 
 	const _sources = new WeakMap(); // maps WebglTexture objects to instances of Source
@@ -312,6 +313,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 		}
 
+		if ( texture.isHTMLTexture ) {
+
+			_htmlTextures.delete( texture );
+
+		}
+
 	}
 
 	function onRenderTargetDispose( event ) {
@@ -1230,10 +1237,22 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 						canvas.appendChild( image );
 
-						// Wait for the browser to paint the element before uploading.
-						canvas.onpaint = () => {
+						// Register and set up a shared paint callback for all HTMLTextures.
+						_htmlTextures.add( texture );
+
+						canvas.onpaint = ( event ) => {
+
+							const changed = event.changedElements;
 
-							texture.needsUpdate = true;
+							for ( const t of _htmlTextures ) {
+
+								if ( changed.includes( t.image ) ) {
+
+									t.needsUpdate = true;
+
+								}
+
+							}
 
 						};
 

粤ICP备19079148号