Răsfoiți Sursa

avoid creating float32 array each uniform upload

foijord 8 ani în urmă
părinte
comite
3be3659435
3 a modificat fișierele cu 45 adăugiri și 6 ștergeri
  1. 15 2
      build/three.js
  2. 15 2
      build/three.module.js
  3. 15 2
      src/renderers/webgl/WebGLUniforms.js

+ 15 - 2
build/three.js

@@ -4372,6 +4372,10 @@
 	var arrayCacheF32 = [];
 	var arrayCacheI32 = [];
 
+	// Float32Array cache used for uploading Matrix4 uniform
+
+	var mat4array = new Float32Array(16);
+
 	// Flattening for arrays of vectors and matrices
 
 	function flatten( array, nBlocks, blockSize ) {
@@ -4482,8 +4486,17 @@
 
 	function setValue4fm( gl, v ) {
 
-		if ( v.elements === undefined ) { gl.uniformMatrix4fv( this.addr, false, v ); }
-		else { gl.uniformMatrix4fv( this.addr, false, new Float32Array(v.elements) ); }
+		if ( v.elements === undefined ) {
+			
+			gl.uniformMatrix4fv( this.addr, false, v );
+			
+		}
+		else {
+			
+			mat4array.set(v.elements);
+			gl.uniformMatrix4fv( this.addr, false, mat4array );
+			
+		}
 		
 	}
 

+ 15 - 2
build/three.module.js

@@ -4366,6 +4366,10 @@ function UniformContainer() {
 var arrayCacheF32 = [];
 var arrayCacheI32 = [];
 
+// Float32Array cache used for uploading Matrix4 uniform
+
+var mat4array = new Float32Array(16);
+
 // Flattening for arrays of vectors and matrices
 
 function flatten( array, nBlocks, blockSize ) {
@@ -4476,8 +4480,17 @@ function setValue3fm( gl, v ) {
 
 function setValue4fm( gl, v ) {
 
-	if ( v.elements === undefined ) { gl.uniformMatrix4fv( this.addr, false, v ); }
-	else { gl.uniformMatrix4fv( this.addr, false, new Float32Array(v.elements) ); }
+	if ( v.elements === undefined ) {
+		
+		gl.uniformMatrix4fv( this.addr, false, v );
+		
+	}
+	else {
+		
+		mat4array.set(v.elements);
+		gl.uniformMatrix4fv( this.addr, false, mat4array );
+		
+	}
 	
 }
 

+ 15 - 2
src/renderers/webgl/WebGLUniforms.js

@@ -69,6 +69,10 @@ function UniformContainer() {
 var arrayCacheF32 = [];
 var arrayCacheI32 = [];
 
+// Float32Array cache used for uploading Matrix4 uniform
+
+var mat4array = new Float32Array(16);
+
 // Flattening for arrays of vectors and matrices
 
 function flatten( array, nBlocks, blockSize ) {
@@ -179,8 +183,17 @@ function setValue3fm( gl, v ) {
 
 function setValue4fm( gl, v ) {
 
-	if ( v.elements === undefined ) { gl.uniformMatrix4fv( this.addr, false, v ); }
-	else { gl.uniformMatrix4fv( this.addr, false, new Float32Array(v.elements) ); }
+	if ( v.elements === undefined ) {
+		
+		gl.uniformMatrix4fv( this.addr, false, v );
+		
+	}
+	else {
+		
+		mat4array.set(v.elements);
+		gl.uniformMatrix4fv( this.addr, false, mat4array );
+		
+	}
 	
 }