Browse Source

WebGLRenderer: Moved doubleSided/flipSided code to WebGLState.

Mr.doob 10 years ago
parent
commit
0eb402d354
2 changed files with 55 additions and 50 deletions
  1. 2 41
      src/renderers/WebGLRenderer.js
  2. 53 9
      src/renderers/webgl/WebGLState.js

+ 2 - 41
src/renderers/WebGLRenderer.js

@@ -118,11 +118,6 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	_usedTextureUnits = 0,
 
-	// GL state cache
-
-	_currentDoubleSided = - 1,
-	_currentFlipSided = - 1,
-
 	_viewportX = 0,
 	_viewportY = 0,
 	_viewportWidth = _canvas.width,
@@ -280,8 +275,6 @@ THREE.WebGLRenderer = function ( parameters ) {
 		_currentProgram = null;
 		_currentCamera = null;
 
-		_currentDoubleSided = - 1;
-		_currentFlipSided = - 1;
 		_currentGeometryProgram = '';
 		_currentMaterialId = - 1;
 
@@ -5442,40 +5435,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	this.setMaterialFaces = function ( material ) {
 
-		var doubleSided = material.side === THREE.DoubleSide;
-		var flipSided = material.side === THREE.BackSide;
-
-		if ( _currentDoubleSided !== doubleSided ) {
-
-			if ( doubleSided ) {
-
-				_gl.disable( _gl.CULL_FACE );
-
-			} else {
-
-				_gl.enable( _gl.CULL_FACE );
-
-			}
-
-			_currentDoubleSided = doubleSided;
-
-		}
-
-		if ( _currentFlipSided !== flipSided ) {
-
-			if ( flipSided ) {
-
-				_gl.frontFace( _gl.CW );
-
-			} else {
-
-				_gl.frontFace( _gl.CCW );
-
-			}
-
-			_currentFlipSided = flipSided;
-
-		}
+		state.setDoubleSided( material.side === THREE.DoubleSide );
+		state.setFlipSided( material.side === THREE.BackSide );
 
 	};
 

+ 53 - 9
src/renderers/webgl/WebGLState.js

@@ -12,6 +12,18 @@ THREE.WebGLState = function ( gl, paramThreeToGL ) {
 	var currentBlendSrcAlpha = - 1;
 	var currentBlendDstAlpha = - 1;
 
+	var currentDepthTest = - 1;
+	var currentDepthWrite = - 1;
+
+	var currentDoubleSided = - 1;
+	var currentFlipSided = - 1;
+
+	var currentLineWidth = null;
+
+	var currentPolygonOffset = null;
+	var currentPolygonOffsetFactor = null;
+	var currentPolygonOffsetUnits = null;
+
 	this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
 
 		if ( blending !== currentBlending ) {
@@ -95,8 +107,6 @@ THREE.WebGLState = function ( gl, paramThreeToGL ) {
 
 	};
 
-	var currentDepthTest = - 1;
-
 	this.setDepthTest = function ( depthTest ) {
 
 		if ( currentDepthTest !== depthTest ) {
@@ -117,8 +127,6 @@ THREE.WebGLState = function ( gl, paramThreeToGL ) {
 
 	};
 
-	var currentDepthWrite = - 1;
-
 	this.setDepthWrite = function ( depthWrite ) {
 
 		if ( currentDepthWrite !== depthWrite ) {
@@ -130,7 +138,45 @@ THREE.WebGLState = function ( gl, paramThreeToGL ) {
 
 	};
 
-	var currentLineWidth = null;
+	this.setDoubleSided = function ( doubleSided ) {
+
+		if ( currentDoubleSided !== doubleSided ) {
+
+			if ( doubleSided ) {
+
+				gl.disable( gl.CULL_FACE );
+
+			} else {
+
+				gl.enable( gl.CULL_FACE );
+
+			}
+
+			currentDoubleSided = doubleSided;
+
+		}
+
+	};
+
+	this.setFlipSided = function ( flipSided ) {
+
+		if ( currentFlipSided !== flipSided ) {
+
+			if ( flipSided ) {
+
+				gl.frontFace( gl.CW );
+
+			} else {
+
+				gl.frontFace( gl.CCW );
+
+			}
+
+			currentFlipSided = flipSided;
+
+		}
+
+	};
 
 	this.setLineWidth = function ( width ) {
 
@@ -144,10 +190,6 @@ THREE.WebGLState = function ( gl, paramThreeToGL ) {
 
 	};
 
-	var currentPolygonOffset = null;
-	var currentPolygonOffsetFactor = null;
-	var currentPolygonOffsetUnits = null;
-
 	this.setPolygonOffset = function ( polygonoffset, factor, units ) {
 
 		if ( currentPolygonOffset !== polygonoffset ) {
@@ -182,6 +224,8 @@ THREE.WebGLState = function ( gl, paramThreeToGL ) {
 		currentBlending = - 1;
 		currentDepthTest = - 1;
 		currentDepthWrite = - 1;
+		currentDoubleSided = - 1;
+		currentFlipSided = - 1;
 
 	};