Browse Source

Merge pull request #6848 from dubejf/texture-version

Use version counter for texture updates.
Ricardo Cabello 10 years ago
parent
commit
2454d414ec
3 changed files with 12 additions and 59 deletions
  1. 10 10
      src/renderers/WebGLRenderer.js
  2. 0 41
      src/renderers/webgl/WebGLTextures.js
  3. 2 8
      src/textures/Texture.js

+ 10 - 10
src/renderers/WebGLRenderer.js

@@ -3217,9 +3217,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 	}
 	}
 
 
-	this.uploadTexture = function ( texture, slot ) {
-
-		var textureProperties = properties.get( texture );
+	function uploadTexture( textureProperties, texture, slot ) {
 
 
 		if ( textureProperties.__webglInit === undefined ) {
 		if ( textureProperties.__webglInit === undefined ) {
 
 
@@ -3329,15 +3327,17 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 		if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
 		if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
 
 
-		texture.needsUpdate = false;
+		textureProperties.__version = texture.version;
 
 
 		if ( texture.onUpdate ) texture.onUpdate( texture );
 		if ( texture.onUpdate ) texture.onUpdate( texture );
 
 
-	};
+	}
 
 
 	this.setTexture = function ( texture, slot ) {
 	this.setTexture = function ( texture, slot ) {
 
 
-		if ( texture.needsUpdate === true ) {
+		var textureProperties = properties.get( texture );
+
+		if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
 
 
 			var image = texture.image;
 			var image = texture.image;
 
 
@@ -3355,13 +3355,13 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 			}
 			}
 
 
-			_this.uploadTexture( texture, slot );
+			uploadTexture( textureProperties, texture, slot );
 			return;
 			return;
 
 
 		}
 		}
 
 
 		state.activeTexture( _gl.TEXTURE0 + slot );
 		state.activeTexture( _gl.TEXTURE0 + slot );
-		state.bindTexture( _gl.TEXTURE_2D, properties.get( texture ).__webglTexture );
+		state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
 
 
 	};
 	};
 
 
@@ -3397,7 +3397,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 		if ( texture.image.length === 6 ) {
 		if ( texture.image.length === 6 ) {
 
 
-			if ( texture.needsUpdate ) {
+			if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
 
 
 				if ( ! textureProperties.__image__webglTextureCube ) {
 				if ( ! textureProperties.__image__webglTextureCube ) {
 
 
@@ -3492,7 +3492,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 				}
 				}
 
 
-				texture.needsUpdate = false;
+				textureProperties.__version = texture.version;
 
 
 				if ( texture.onUpdate ) texture.onUpdate( texture );
 				if ( texture.onUpdate ) texture.onUpdate( texture );
 
 

+ 0 - 41
src/renderers/webgl/WebGLTextures.js

@@ -1,41 +0,0 @@
-/**
-* @author mrdoob / http://mrdoob.com/
-*/
-
-THREE.WebGLTextures = function ( gl ) {
-
-	var textures = {};
-
-	this.get = function ( texture ) {
-
-		if ( textures[ texture.id ] !== undefined ) {
-
-			return textures[ texture.id ];
-
-		}
-
-		return this.create( texture );
-
-	};
-
-	this.create = function ( texture ) {
-
-		texture.addEventListener( 'dispose', this.delete );
-
-		textures[ texture.id ] = gl.createTexture();
-
-		return textures[ texture.id ];
-
-	};
-
-	this.delete = function ( texture ) {
-
-		texture.removeEventListener( 'dispose', this.delete );
-
-		gl.deleteTexture( textures[ texture.id ] );
-
-		delete textures[ texture.id ];
-
-	};
-
-};

+ 2 - 8
src/textures/Texture.js

@@ -37,7 +37,7 @@ THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, f
 	this.flipY = true;
 	this.flipY = true;
 	this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
 	this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
 
 
-	this._needsUpdate = false;
+	this.version = 0;
 	this.onUpdate = null;
 	this.onUpdate = null;
 
 
 };
 };
@@ -49,17 +49,11 @@ THREE.Texture.prototype = {
 
 
 	constructor: THREE.Texture,
 	constructor: THREE.Texture,
 
 
-	get needsUpdate () {
-
-		return this._needsUpdate;
-
-	},
-
 	set needsUpdate ( value ) {
 	set needsUpdate ( value ) {
 
 
 		if ( value === true ) this.update();
 		if ( value === true ) this.update();
 
 
-		this._needsUpdate = value;
+		this.version ++;
 
 
 	},
 	},