Browse Source

WebGLRenderer: Moved currentProgram to WebGLState.

Mr.doob 8 years ago
parent
commit
ac7a4dc884

+ 1 - 6
src/renderers/WebGLRenderer.js

@@ -112,7 +112,6 @@ function WebGLRenderer( parameters ) {
 
 		// internal state cache
 
-		_currentProgram = null,
 		_currentRenderTarget = null,
 		_currentFramebuffer = null,
 		_currentMaterialId = - 1,
@@ -316,7 +315,6 @@ function WebGLRenderer( parameters ) {
 
 	function resetGLState() {
 
-		_currentProgram = null;
 		_currentCamera = null;
 
 		_currentGeometryProgram = '';
@@ -1676,10 +1674,7 @@ function WebGLRenderer( parameters ) {
 			p_uniforms = program.getUniforms(),
 			m_uniforms = materialProperties.shader.uniforms;
 
-		if ( program.id !== _currentProgram ) {
-
-			_gl.useProgram( program.program );
-			_currentProgram = program.id;
+		if ( state.useProgram( program.program ) ) {
 
 			refreshProgram = true;
 			refreshMaterial = true;

+ 22 - 0
src/renderers/webgl/WebGLState.js

@@ -321,6 +321,8 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
 
 	var compressedTextureFormats = null;
 
+	var currentProgram = null;
+
 	var currentBlending = null;
 	var currentBlendEquation = null;
 	var currentBlendSrc = null;
@@ -511,6 +513,22 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
 
 	}
 
+	function useProgram( program ) {
+
+		if ( currentProgram !== program ) {
+
+			gl.useProgram( program );
+
+			currentProgram = program;
+
+			return true;
+
+		}
+
+		return false;
+
+	}
+
 	function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
 
 		if ( blending !== NoBlending ) {
@@ -878,6 +896,8 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
 		currentTextureSlot = null;
 		currentBoundTextures = {};
 
+		currentProgram = null;
+
 		currentBlending = null;
 
 		currentFlipSided = null;
@@ -906,6 +926,8 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
 		disable: disable,
 		getCompressedTextureFormats: getCompressedTextureFormats,
 
+		useProgram: useProgram,
+
 		setBlending: setBlending,
 		setMaterial: setMaterial,
 

+ 1 - 1
src/renderers/webgl/plugins/LensFlarePlugin.js

@@ -208,7 +208,7 @@ function LensFlarePlugin( renderer, flares ) {
 
 		}
 
-		gl.useProgram( program );
+		state.useProgram( program );
 
 		state.initAttributes();
 		state.enableAttribute( attributes.vertex );

+ 1 - 1
src/renderers/webgl/plugins/SpritePlugin.js

@@ -100,7 +100,7 @@ function SpritePlugin( renderer, sprites ) {
 
 		}
 
-		gl.useProgram( program );
+		state.useProgram( program );
 
 		state.initAttributes();
 		state.enableAttribute( attributes.position );