Browse Source

When no texture is set, default to a dummy 1x1 black RGB texture to ensure no warnings are thrown in WebGL2

mattdesl 9 years ago
parent
commit
3a91c98c91
1 changed files with 8 additions and 1 deletions
  1. 8 1
      src/renderers/webgl/WebGLState.js

+ 8 - 1
src/renderers/webgl/WebGLState.js

@@ -58,6 +58,13 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
 	var currentScissor = new THREE.Vector4();
 	var currentViewport = new THREE.Vector4();
 
+	var emptyTexture = gl.createTexture();
+	gl.bindTexture(gl.TEXTURE_2D, emptyTexture);
+	gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
+	gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, 1, 1, 0, gl.RGB, gl.UNSIGNED_BYTE, new Uint8Array([
+		0, 0, 0
+	]));
+
 	this.init = function () {
 
 		this.clearColor( 0, 0, 0, 1 );
@@ -551,7 +558,7 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
 
 		if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
 
-			gl.bindTexture( webglType, webglTexture );
+			gl.bindTexture( webglType, webglTexture || emptyTexture );
 
 			boundTexture.type = webglType;
 			boundTexture.texture = webglTexture;