Browse Source

WebGLState: Added clearColor()

Mr.doob 9 years ago
parent
commit
6e79e63569
2 changed files with 19 additions and 3 deletions
  1. 1 1
      src/renderers/WebGLRenderer.js
  2. 18 2
      src/renderers/webgl/WebGLState.js

+ 1 - 1
src/renderers/WebGLRenderer.js

@@ -234,7 +234,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 		}
 		}
 
 
-		_gl.clearColor( r, g, b, a );
+		state.clearColor( r, g, b, a );
 
 
 	}
 	}
 
 

+ 18 - 2
src/renderers/webgl/WebGLState.js

@@ -6,6 +6,8 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
 
 
 	var _this = this;
 	var _this = this;
 
 
+	var color = new THREE.Vector4();
+
 	var newAttributes = new Uint8Array( 16 );
 	var newAttributes = new Uint8Array( 16 );
 	var enabledAttributes = new Uint8Array( 16 );
 	var enabledAttributes = new Uint8Array( 16 );
 	var attributeDivisors = new Uint8Array( 16 );
 	var attributeDivisors = new Uint8Array( 16 );
@@ -49,12 +51,13 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
 	var currentTextureSlot = undefined;
 	var currentTextureSlot = undefined;
 	var currentBoundTextures = {};
 	var currentBoundTextures = {};
 
 
+	var currentClearColor = new THREE.Vector4();
 	var currentScissor = new THREE.Vector4();
 	var currentScissor = new THREE.Vector4();
 	var currentViewport = new THREE.Vector4();
 	var currentViewport = new THREE.Vector4();
 
 
 	this.init = function () {
 	this.init = function () {
 
 
-		gl.clearColor( 0, 0, 0, 1 );
+		this.clearColor( 0, 0, 0, 1 );
 		gl.clearDepth( 1 );
 		gl.clearDepth( 1 );
 		gl.clearStencil( 0 );
 		gl.clearStencil( 0 );
 
 
@@ -523,7 +526,7 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
 
 
 		}
 		}
 
 
-	}
+	};
 
 
 	this.bindTexture = function ( webglType, webglTexture ) {
 	this.bindTexture = function ( webglType, webglTexture ) {
 
 
@@ -583,6 +586,19 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
 
 
 	//
 	//
 
 
+	this.clearColor = function ( r, g, b, a ) {
+
+		color.set( r, g, b, a );
+
+		if ( currentClearColor.equals( color ) === false ) {
+
+			gl.clearColor( r, g, b, a );
+			currentClearColor.copy( color );
+
+		}
+
+	};
+
 	this.scissor = function ( scissor ) {
 	this.scissor = function ( scissor ) {
 
 
 		if ( currentScissor.equals( scissor ) === false ) {
 		if ( currentScissor.equals( scissor ) === false ) {