浏览代码

WebGLUniforms: Add unsigned vector array support for uniform. (#21316)

* Add unsigned vector / array support for uniform

* Rewrite comment and arrange code
SuperSodaSea 4 年之前
父节点
当前提交
9eeefa69d9
共有 1 个文件被更改,包括 158 次插入76 次删除
  1. 158 76
      src/renderers/webgl/WebGLUniforms.js

+ 158 - 76
src/renderers/webgl/WebGLUniforms.js

@@ -265,7 +265,7 @@ function setValueV4f( gl, v ) {
 
 
 }
 }
 
 
-// Single matrix (from flat array or MatrixN)
+// Single matrix (from flat array or THREE.MatrixN)
 
 
 function setValueM2( gl, v ) {
 function setValueM2( gl, v ) {
 
 
@@ -348,133 +348,174 @@ function setValueM4( gl, v ) {
 
 
 }
 }
 
 
-// Single texture (2D / Cube)
+// Single integer / boolean
 
 
-function setValueT1( gl, v, textures ) {
+function setValueV1i( gl, v ) {
 
 
 	const cache = this.cache;
 	const cache = this.cache;
-	const unit = textures.allocateTextureUnit();
 
 
-	if ( cache[ 0 ] !== unit ) {
-
-		gl.uniform1i( this.addr, unit );
-		cache[ 0 ] = unit;
+	if ( cache[ 0 ] === v ) return;
 
 
-	}
+	gl.uniform1i( this.addr, v );
 
 
-	textures.safeSetTexture2D( v || emptyTexture, unit );
+	cache[ 0 ] = v;
 
 
 }
 }
 
 
-function setValueT2DArray1( gl, v, textures ) {
+// Single integer / boolean vector (from flat array)
 
 
-	const cache = this.cache;
-	const unit = textures.allocateTextureUnit();
+function setValueV2i( gl, v ) {
 
 
-	if ( cache[ 0 ] !== unit ) {
+	const cache = this.cache;
 
 
-		gl.uniform1i( this.addr, unit );
-		cache[ 0 ] = unit;
+	if ( arraysEqual( cache, v ) ) return;
 
 
-	}
+	gl.uniform2iv( this.addr, v );
 
 
-	textures.setTexture2DArray( v || emptyTexture2dArray, unit );
+	copyArray( cache, v );
 
 
 }
 }
 
 
-function setValueT3D1( gl, v, textures ) {
+function setValueV3i( gl, v ) {
 
 
 	const cache = this.cache;
 	const cache = this.cache;
-	const unit = textures.allocateTextureUnit();
-
-	if ( cache[ 0 ] !== unit ) {
 
 
-		gl.uniform1i( this.addr, unit );
-		cache[ 0 ] = unit;
+	if ( arraysEqual( cache, v ) ) return;
 
 
-	}
+	gl.uniform3iv( this.addr, v );
 
 
-	textures.setTexture3D( v || emptyTexture3d, unit );
+	copyArray( cache, v );
 
 
 }
 }
 
 
-function setValueT6( gl, v, textures ) {
+function setValueV4i( gl, v ) {
 
 
 	const cache = this.cache;
 	const cache = this.cache;
-	const unit = textures.allocateTextureUnit();
-
-	if ( cache[ 0 ] !== unit ) {
 
 
-		gl.uniform1i( this.addr, unit );
-		cache[ 0 ] = unit;
+	if ( arraysEqual( cache, v ) ) return;
 
 
-	}
+	gl.uniform4iv( this.addr, v );
 
 
-	textures.safeSetTextureCube( v || emptyCubeTexture, unit );
+	copyArray( cache, v );
 
 
 }
 }
 
 
-// Integer / Boolean vectors or arrays thereof (always flat arrays)
+// Single unsigned integer
 
 
-function setValueV1i( gl, v ) {
+function setValueV1ui( gl, v ) {
 
 
 	const cache = this.cache;
 	const cache = this.cache;
 
 
 	if ( cache[ 0 ] === v ) return;
 	if ( cache[ 0 ] === v ) return;
 
 
-	gl.uniform1i( this.addr, v );
+	gl.uniform1ui( this.addr, v );
 
 
 	cache[ 0 ] = v;
 	cache[ 0 ] = v;
 
 
 }
 }
 
 
-function setValueV2i( gl, v ) {
+// Single unsigned integer vector (from flat array)
+
+function setValueV2ui( gl, v ) {
 
 
 	const cache = this.cache;
 	const cache = this.cache;
 
 
 	if ( arraysEqual( cache, v ) ) return;
 	if ( arraysEqual( cache, v ) ) return;
 
 
-	gl.uniform2iv( this.addr, v );
+	gl.uniform2uiv( this.addr, v );
 
 
 	copyArray( cache, v );
 	copyArray( cache, v );
 
 
 }
 }
 
 
-function setValueV3i( gl, v ) {
+function setValueV3ui( gl, v ) {
 
 
 	const cache = this.cache;
 	const cache = this.cache;
 
 
 	if ( arraysEqual( cache, v ) ) return;
 	if ( arraysEqual( cache, v ) ) return;
 
 
-	gl.uniform3iv( this.addr, v );
+	gl.uniform3uiv( this.addr, v );
 
 
 	copyArray( cache, v );
 	copyArray( cache, v );
 
 
 }
 }
 
 
-function setValueV4i( gl, v ) {
+function setValueV4ui( gl, v ) {
 
 
 	const cache = this.cache;
 	const cache = this.cache;
 
 
 	if ( arraysEqual( cache, v ) ) return;
 	if ( arraysEqual( cache, v ) ) return;
 
 
-	gl.uniform4iv( this.addr, v );
+	gl.uniform4uiv( this.addr, v );
 
 
 	copyArray( cache, v );
 	copyArray( cache, v );
 
 
 }
 }
 
 
-// uint
 
 
-function setValueV1ui( gl, v ) {
+// Single texture (2D / Cube)
+
+function setValueT1( gl, v, textures ) {
 
 
 	const cache = this.cache;
 	const cache = this.cache;
+	const unit = textures.allocateTextureUnit();
 
 
-	if ( cache[ 0 ] === v ) return;
+	if ( cache[ 0 ] !== unit ) {
 
 
-	gl.uniform1ui( this.addr, v );
+		gl.uniform1i( this.addr, unit );
+		cache[ 0 ] = unit;
 
 
-	cache[ 0 ] = v;
+	}
+
+	textures.safeSetTexture2D( v || emptyTexture, unit );
+
+}
+
+function setValueT3D1( gl, v, textures ) {
+
+	const cache = this.cache;
+	const unit = textures.allocateTextureUnit();
+
+	if ( cache[ 0 ] !== unit ) {
+
+		gl.uniform1i( this.addr, unit );
+		cache[ 0 ] = unit;
+
+	}
+
+	textures.setTexture3D( v || emptyTexture3d, unit );
+
+}
+
+function setValueT6( gl, v, textures ) {
+
+	const cache = this.cache;
+	const unit = textures.allocateTextureUnit();
+
+	if ( cache[ 0 ] !== unit ) {
+
+		gl.uniform1i( this.addr, unit );
+		cache[ 0 ] = unit;
+
+	}
+
+	textures.safeSetTextureCube( v || emptyCubeTexture, unit );
+
+}
+
+function setValueT2DArray1( gl, v, textures ) {
+
+	const cache = this.cache;
+	const unit = textures.allocateTextureUnit();
+
+	if ( cache[ 0 ] !== unit ) {
+
+		gl.uniform1i( this.addr, unit );
+		cache[ 0 ] = unit;
+
+	}
+
+	textures.setTexture2DArray( v || emptyTexture2dArray, unit );
 
 
 }
 }
 
 
@@ -499,6 +540,9 @@ function getSingularSetter( type ) {
 		case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
 		case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
 
 
 		case 0x1405: return setValueV1ui; // UINT
 		case 0x1405: return setValueV1ui; // UINT
+		case 0x8dc6: return setValueV2ui; // _VEC2
+		case 0x8dc7: return setValueV3ui; // _VEC3
+		case 0x8dc8: return setValueV4ui; // _VEC4
 
 
 		case 0x8b5e: // SAMPLER_2D
 		case 0x8b5e: // SAMPLER_2D
 		case 0x8d66: // SAMPLER_EXTERNAL_OES
 		case 0x8d66: // SAMPLER_EXTERNAL_OES
@@ -528,40 +572,16 @@ function getSingularSetter( type ) {
 
 
 }
 }
 
 
+
 // Array of scalars
 // Array of scalars
+
 function setValueV1fArray( gl, v ) {
 function setValueV1fArray( gl, v ) {
 
 
 	gl.uniform1fv( this.addr, v );
 	gl.uniform1fv( this.addr, v );
 
 
 }
 }
 
 
-// Integer / Boolean vectors or arrays thereof (always flat arrays)
-function setValueV1iArray( gl, v ) {
-
-	gl.uniform1iv( this.addr, v );
-
-}
-
-function setValueV2iArray( gl, v ) {
-
-	gl.uniform2iv( this.addr, v );
-
-}
-
-function setValueV3iArray( gl, v ) {
-
-	gl.uniform3iv( this.addr, v );
-
-}
-
-function setValueV4iArray( gl, v ) {
-
-	gl.uniform4iv( this.addr, v );
-
-}
-
-
-// Array of vectors (flat or from THREE classes)
+// Array of vectors (from flat array or array of THREE.VectorN)
 
 
 function setValueV2fArray( gl, v ) {
 function setValueV2fArray( gl, v ) {
 
 
@@ -587,7 +607,7 @@ function setValueV4fArray( gl, v ) {
 
 
 }
 }
 
 
-// Array of matrices (flat or from THREE clases)
+// Array of matrices (from flat array or array of THREE.MatrixN)
 
 
 function setValueM2Array( gl, v ) {
 function setValueM2Array( gl, v ) {
 
 
@@ -613,6 +633,63 @@ function setValueM4Array( gl, v ) {
 
 
 }
 }
 
 
+// Array of integer / boolean
+
+function setValueV1iArray( gl, v ) {
+
+	gl.uniform1iv( this.addr, v );
+
+}
+
+// Array of integer / boolean vectors (from flat array)
+
+function setValueV2iArray( gl, v ) {
+
+	gl.uniform2iv( this.addr, v );
+
+}
+
+function setValueV3iArray( gl, v ) {
+
+	gl.uniform3iv( this.addr, v );
+
+}
+
+function setValueV4iArray( gl, v ) {
+
+	gl.uniform4iv( this.addr, v );
+
+}
+
+// Array of unsigned integer
+
+function setValueV1uiArray( gl, v ) {
+
+	gl.uniform1uiv( this.addr, v );
+
+}
+
+// Array of unsigned integer vectors (from flat array)
+
+function setValueV2uiArray( gl, v ) {
+
+	gl.uniform2uiv( this.addr, v );
+
+}
+
+function setValueV3uiArray( gl, v ) {
+
+	gl.uniform3uiv( this.addr, v );
+
+}
+
+function setValueV4uiArray( gl, v ) {
+
+	gl.uniform4uiv( this.addr, v );
+
+}
+
+
 // Array of textures (2D / Cube)
 // Array of textures (2D / Cube)
 
 
 function setValueT1Array( gl, v, textures ) {
 function setValueT1Array( gl, v, textures ) {
@@ -667,6 +744,11 @@ function getPureArraySetter( type ) {
 		case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
 		case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
 		case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
 		case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
 
 
+		case 0x1405: return setValueV1uiArray; // UINT
+		case 0x8dc6: return setValueV2uiArray; // _VEC2
+		case 0x8dc7: return setValueV3uiArray; // _VEC3
+		case 0x8dc8: return setValueV4uiArray; // _VEC4
+
 		case 0x8b5e: // SAMPLER_2D
 		case 0x8b5e: // SAMPLER_2D
 		case 0x8d66: // SAMPLER_EXTERNAL_OES
 		case 0x8d66: // SAMPLER_EXTERNAL_OES
 		case 0x8dca: // INT_SAMPLER_2D
 		case 0x8dca: // INT_SAMPLER_2D