Pārlūkot izejas kodu

Merge pull request #12763 from Mugen87/dev6

VideoTexture: Refactor update
Mr.doob 7 gadi atpakaļ
vecāks
revīzija
d2d91d2966

+ 4 - 0
src/renderers/WebGLRenderer.js

@@ -1128,6 +1128,10 @@ function WebGLRenderer( parameters ) {
 
 		//
 
+		textures.updateVideoTextures();
+
+		//
+
 		if ( _clippingEnabled ) _clipping.beginShadows();
 
 		shadowMap.render( shadowsArray, scene, camera );

+ 24 - 1
src/renderers/webgl/WebGLTextures.js

@@ -8,6 +8,7 @@ import { _Math } from '../../math/Math.js';
 function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, infoMemory ) {
 
 	var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof window.WebGL2RenderingContext );
+	var _videoTextures = {};
 
 	//
 
@@ -102,8 +103,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 		deallocateTexture( texture );
 
-		infoMemory.textures --;
+		if ( texture.isVideoTexture ) {
+
+			delete _videoTextures[ texture.id ];
+
+		}
 
+		infoMemory.textures --;
 
 	}
 
@@ -405,6 +411,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 			textureProperties.__webglTexture = _gl.createTexture();
 
+			if ( texture.isVideoTexture ) {
+
+				_videoTextures[ texture.id ] = texture;
+
+			}
+
 			infoMemory.textures ++;
 
 		}
@@ -786,11 +798,22 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 	}
 
+	function updateVideoTextures() {
+
+		for ( var id in _videoTextures ) {
+
+			_videoTextures[ id ].update();
+
+		}
+
+	}
+
 	this.setTexture2D = setTexture2D;
 	this.setTextureCube = setTextureCube;
 	this.setTextureCubeDynamic = setTextureCubeDynamic;
 	this.setupRenderTarget = setupRenderTarget;
 	this.updateRenderTargetMipmap = updateRenderTargetMipmap;
+	this.updateVideoTextures = updateVideoTextures;
 
 }
 

+ 12 - 12
src/textures/VideoTexture.js

@@ -9,29 +9,29 @@ function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, forma
 	Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
 
 	this.generateMipmaps = false;
+	this.needsUpdate = true;
 
-	var scope = this;
+}
 
-	function update() {
+VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
 
-		var video = scope.image;
+	constructor: VideoTexture,
 
-		if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
+	isVideoTexture: true,
 
-			scope.needsUpdate = true;
+	update: function () {
 
-		}
+		var video = this.image;
 
-		requestAnimationFrame( update );
+		if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
 
-	}
+			this.needsUpdate = true;
 
-	requestAnimationFrame( update );
+		}
 
-}
+	}
 
-VideoTexture.prototype = Object.create( Texture.prototype );
-VideoTexture.prototype.constructor = VideoTexture;
+} );
 
 
 export { VideoTexture };