Browse Source

Refactored VideoTexture updating code. See #13053

Mr.doob 7 years ago
parent
commit
6b7ee3e493
3 changed files with 13 additions and 29 deletions
  1. 1 5
      src/renderers/WebGLRenderer.js
  2. 12 11
      src/renderers/webgl/WebGLTextures.js
  3. 0 13
      src/textures/VideoTexture.js

+ 1 - 5
src/renderers/WebGLRenderer.js

@@ -273,7 +273,7 @@ function WebGLRenderer( parameters ) {
 		state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
 
 		properties = new WebGLProperties();
-		textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, _infoMemory );
+		textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, _infoMemory, _infoRender );
 		attributes = new WebGLAttributes( _gl );
 		geometries = new WebGLGeometries( _gl, attributes, _infoMemory );
 		objects = new WebGLObjects( geometries, _infoRender );
@@ -1132,10 +1132,6 @@ function WebGLRenderer( parameters ) {
 
 		//
 
-		textures.updateVideoTextures();
-
-		//
-
 		if ( _clippingEnabled ) _clipping.beginShadows();
 
 		shadowMap.render( shadowsArray, scene, camera );

+ 12 - 11
src/renderers/webgl/WebGLTextures.js

@@ -5,7 +5,7 @@
 import { LinearFilter, NearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, ClampToEdgeWrapping, NearestMipMapLinearFilter, NearestMipMapNearestFilter } from '../../constants.js';
 import { _Math } from '../../math/Math.js';
 
-function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, infoMemory ) {
+function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, infoMemory, infoRender ) {
 
 	var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext );
 	var _videoTextures = {};
@@ -200,6 +200,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 		var textureProperties = properties.get( texture );
 
+		if ( texture.isVideoTexture ) updateVideoTexture( texture );
+
 		if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
 
 			var image = texture.image;
@@ -411,12 +413,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 			textureProperties.__webglTexture = _gl.createTexture();
 
-			if ( texture.isVideoTexture ) {
-
-				_videoTextures[ texture.id ] = texture;
-
-			}
-
 			infoMemory.textures ++;
 
 		}
@@ -798,11 +794,17 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 	}
 
-	function updateVideoTextures() {
+	function updateVideoTexture( texture ) {
+
+		var id = texture.id;
+		var frame = infoRender.frame;
+
+		// Check the last frame we updated the VideoTexture
 
-		for ( var id in _videoTextures ) {
+		if ( _videoTextures[ id ] !== frame ) {
 
-			_videoTextures[ id ].update();
+			_videoTextures[ id ] = frame;
+			texture.update();
 
 		}
 
@@ -813,7 +815,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 	this.setTextureCubeDynamic = setTextureCubeDynamic;
 	this.setupRenderTarget = setupRenderTarget;
 	this.updateRenderTargetMipmap = updateRenderTargetMipmap;
-	this.updateVideoTextures = updateVideoTextures;
 
 }
 

+ 0 - 13
src/textures/VideoTexture.js

@@ -10,19 +10,6 @@ function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, forma
 
 	this.generateMipmaps = false;
 
-	// Set needsUpdate when first frame is ready
-
-	var scope = this;
-
-	function onLoaded() {
-
-		video.removeEventListener( 'loadeddata', onLoaded, false );
-		scope.needsUpdate = true;
-
-	}
-
-	video.addEventListener( 'loadeddata', onLoaded, false );
-
 }
 
 VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {