Browse Source

WebGLRenderer: Moved empty texture handling to WebGLUniforms.

Mr.doob 9 years ago
parent
commit
1e0cc8ab1a

+ 1 - 3
src/renderers/WebGLRenderer.js

@@ -31,8 +31,6 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	var morphInfluences = new Float32Array( 8 );
 
-	var emptyTexture = new THREE.Texture();
-
 	var sprites = [];
 	var lensFlares = [];
 
@@ -2217,7 +2215,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 			intensity = light.intensity;
 			distance = light.distance;
 
-			shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : emptyTexture;
+			shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
 
 			if ( light instanceof THREE.AmbientLight ) {
 

+ 5 - 8
src/renderers/webgl/WebGLTextures.js

@@ -224,20 +224,17 @@ THREE.WebGLTextures = function ( _gl, extensions, state, properties, capabilitie
 			if ( image === undefined ) {
 
 				console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
-				return;
-
-			}
 
-			if ( image.complete === false ) {
+			} else if ( image.complete === false ) {
 
 				console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
-				return;
 
-			}
+			} else {
 
-			uploadTexture( textureProperties, texture, slot );
+				uploadTexture( textureProperties, texture, slot );
+				return;
 
-			return;
+			}
 
 		}
 

+ 7 - 7
src/renderers/webgl/WebGLUniforms.js

@@ -55,6 +55,9 @@
 
 THREE.WebGLUniforms = ( function() { // scope
 
+	var emptyTexture = new THREE.Texture();
+	var emptyCubeTexture = new THREE.CubeTexture();
+
 	// --- Base for inner nodes (including the root) ---
 
 	var UniformContainer = function() {
@@ -198,7 +201,7 @@ THREE.WebGLUniforms = ( function() { // scope
 
 			var unit = renderer.allocTextureUnit();
 			gl.uniform1i( this.addr, unit );
-			if ( v ) renderer.setTexture2D( v, unit );
+			renderer.setTexture2D( v || emptyTexture, unit );
 
 		},
 
@@ -206,7 +209,7 @@ THREE.WebGLUniforms = ( function() { // scope
 
 			var unit = renderer.allocTextureUnit();
 			gl.uniform1i( this.addr, unit );
-			if ( v ) renderer.setTextureCube( v, unit );
+			renderer.setTextureCube( v || emptyCubeTexture, unit );
 
 		},
 
@@ -299,8 +302,7 @@ THREE.WebGLUniforms = ( function() { // scope
 
 			for ( var i = 0; i !== n; ++ i ) {
 
-				var tex = v[ i ];
-				if ( tex ) renderer.setTexture2D( tex, units[ i ] );
+				renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
 
 			}
 
@@ -315,8 +317,7 @@ THREE.WebGLUniforms = ( function() { // scope
 
 			for ( var i = 0; i !== n; ++ i ) {
 
-				var tex = v[ i ];
-				if ( tex ) renderer.setTextureCube( tex, units[ i ] );
+				renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
 
 			}
 
@@ -599,4 +600,3 @@ THREE.WebGLUniforms = ( function() { // scope
 	return WebGLUniforms;
 
 } )();
-