Browse Source

WebGLUniforms: Clean up

Mugen87 7 years ago
parent
commit
332471b857
1 changed files with 31 additions and 10 deletions
  1. 31 10
      src/renderers/webgl/WebGLUniforms.js

+ 31 - 10
src/renderers/webgl/WebGLUniforms.js

@@ -372,12 +372,13 @@ function setValue4fm( gl, v ) {
 
 
 function setValueT1( gl, v, renderer ) {
 function setValueT1( gl, v, renderer ) {
 
 
+	var cache = this.cache;
 	var unit = renderer.allocTextureUnit();
 	var unit = renderer.allocTextureUnit();
 
 
-	if ( this.cache[ 0 ] !== unit ) {
+	if ( cache[ 0 ] !== unit ) {
 
 
 		gl.uniform1i( this.addr, unit );
 		gl.uniform1i( this.addr, unit );
-		this.cache[ 0 ] = unit;
+		cache[ 0 ] = unit;
 
 
 	}
 	}
 
 
@@ -387,12 +388,13 @@ function setValueT1( gl, v, renderer ) {
 
 
 function setValueT6( gl, v, renderer ) {
 function setValueT6( gl, v, renderer ) {
 
 
+	var cache = this.cache;
 	var unit = renderer.allocTextureUnit();
 	var unit = renderer.allocTextureUnit();
 
 
-	if ( this.cache[ 0 ] !== unit ) {
+	if ( cache[ 0 ] !== unit ) {
 
 
 		gl.uniform1i( this.addr, unit );
 		gl.uniform1i( this.addr, unit );
-		this.cache[ 0 ] = unit;
+		cache[ 0 ] = unit;
 
 
 	}
 	}
 
 
@@ -404,31 +406,37 @@ function setValueT6( gl, v, renderer ) {
 
 
 function setValue2iv( gl, v ) {
 function setValue2iv( gl, v ) {
 
 
-	if ( arraysEqual( this.cache, v ) ) return;
+	var cache = this.cache;
+
+	if ( arraysEqual( cache, v ) ) return;
 
 
 	gl.uniform2iv( this.addr, v );
 	gl.uniform2iv( this.addr, v );
 
 
-	copyArray( this.cache, v );
+	copyArray( cache, v );
 
 
 }
 }
 
 
 function setValue3iv( gl, v ) {
 function setValue3iv( gl, v ) {
 
 
-	if ( arraysEqual( this.cache, v ) ) return;
+	var cache = this.cache;
+
+	if ( arraysEqual( cache, v ) ) return;
 
 
 	gl.uniform3iv( this.addr, v );
 	gl.uniform3iv( this.addr, v );
 
 
-	copyArray( this.cache, v );
+	copyArray( cache, v );
 
 
 }
 }
 
 
 function setValue4iv( gl, v ) {
 function setValue4iv( gl, v ) {
 
 
-	if ( arraysEqual( this.cache, v ) ) return;
+	var cache = this.cache;
+
+	if ( arraysEqual( cache, v ) ) return;
 
 
 	gl.uniform4iv( this.addr, v );
 	gl.uniform4iv( this.addr, v );
 
 
-	copyArray( this.cache, v );
+	copyArray( cache, v );
 
 
 }
 }
 
 
@@ -463,13 +471,25 @@ function getSingularSetter( type ) {
 
 
 function setValue1fv( gl, v ) {
 function setValue1fv( gl, v ) {
 
 
+	var cache = this.cache;
+
+	if ( arraysEqual( cache, v ) ) return;
+
 	gl.uniform1fv( this.addr, v );
 	gl.uniform1fv( this.addr, v );
 
 
+	copyArray( cache, v );
+
 }
 }
 function setValue1iv( gl, v ) {
 function setValue1iv( gl, v ) {
 
 
+	var cache = this.cache;
+
+	if ( arraysEqual( cache, v ) ) return;
+
 	gl.uniform1iv( this.addr, v );
 	gl.uniform1iv( this.addr, v );
 
 
+	copyArray( cache, v );
+
 }
 }
 
 
 // Array of vectors (flat or from THREE classes)
 // Array of vectors (flat or from THREE classes)
@@ -588,6 +608,7 @@ function PureArrayUniform( id, activeInfo, addr ) {
 
 
 	this.id = id;
 	this.id = id;
 	this.addr = addr;
 	this.addr = addr;
+	this.cache = [];
 	this.size = activeInfo.size;
 	this.size = activeInfo.size;
 	this.setValue = getPureArraySetter( activeInfo.type );
 	this.setValue = getPureArraySetter( activeInfo.type );