Selaa lähdekoodia

Cache texture unit values when setting texture array uniforms (#24637)

Scott Nagy 2 vuotta sitten
vanhempi
commit
18f9047230
1 muutettua tiedostoa jossa 36 lisäystä ja 4 poistoa
  1. 36 4
      src/renderers/webgl/WebGLUniforms.js

+ 36 - 4
src/renderers/webgl/WebGLUniforms.js

@@ -694,11 +694,19 @@ function setValueV4uiArray( gl, v ) {
 
 
 function setValueT1Array( gl, v, textures ) {
 function setValueT1Array( gl, v, textures ) {
 
 
+	const cache = this.cache;
+
 	const n = v.length;
 	const n = v.length;
 
 
 	const units = allocTexUnits( textures, n );
 	const units = allocTexUnits( textures, n );
 
 
-	gl.uniform1iv( this.addr, units );
+	if ( ! arraysEqual( cache, units ) ) {
+
+		gl.uniform1iv( this.addr, units );
+
+		copyArray( cache, units );
+
+	}
 
 
 	for ( let i = 0; i !== n; ++ i ) {
 	for ( let i = 0; i !== n; ++ i ) {
 
 
@@ -710,11 +718,19 @@ function setValueT1Array( gl, v, textures ) {
 
 
 function setValueT3DArray( gl, v, textures ) {
 function setValueT3DArray( gl, v, textures ) {
 
 
+	const cache = this.cache;
+
 	const n = v.length;
 	const n = v.length;
 
 
 	const units = allocTexUnits( textures, n );
 	const units = allocTexUnits( textures, n );
 
 
-	gl.uniform1iv( this.addr, units );
+	if ( ! arraysEqual( cache, units ) ) {
+
+		gl.uniform1iv( this.addr, units );
+
+		copyArray( cache, units );
+
+	}
 
 
 	for ( let i = 0; i !== n; ++ i ) {
 	for ( let i = 0; i !== n; ++ i ) {
 
 
@@ -726,11 +742,19 @@ function setValueT3DArray( gl, v, textures ) {
 
 
 function setValueT6Array( gl, v, textures ) {
 function setValueT6Array( gl, v, textures ) {
 
 
+	const cache = this.cache;
+
 	const n = v.length;
 	const n = v.length;
 
 
 	const units = allocTexUnits( textures, n );
 	const units = allocTexUnits( textures, n );
 
 
-	gl.uniform1iv( this.addr, units );
+	if ( ! arraysEqual( cache, units ) ) {
+
+		gl.uniform1iv( this.addr, units );
+
+		copyArray( cache, units );
+
+	}
 
 
 	for ( let i = 0; i !== n; ++ i ) {
 	for ( let i = 0; i !== n; ++ i ) {
 
 
@@ -742,11 +766,19 @@ function setValueT6Array( gl, v, textures ) {
 
 
 function setValueT2DArrayArray( gl, v, textures ) {
 function setValueT2DArrayArray( gl, v, textures ) {
 
 
+	const cache = this.cache;
+
 	const n = v.length;
 	const n = v.length;
 
 
 	const units = allocTexUnits( textures, n );
 	const units = allocTexUnits( textures, n );
 
 
-	gl.uniform1iv( this.addr, units );
+	if ( ! arraysEqual( cache, units ) ) {
+
+		gl.uniform1iv( this.addr, units );
+
+		copyArray( cache, units );
+
+	}
 
 
 	for ( let i = 0; i !== n; ++ i ) {
 	for ( let i = 0; i !== n; ++ i ) {