瀏覽代碼

WebGLUniformsGroups: UBO Boolean support and fix cache on number (#27285)

* add boolean support and fix number cache

* fix const assignment

* good fix assignment to local var

* Update WebGLUniformsGroups.js

Improve comment.

---------

Co-authored-by: Michael Herzog <[email protected]>
Renaud Rohlinger 1 年之前
父節點
當前提交
b019c39d77
共有 1 個文件被更改,包括 15 次插入6 次删除
  1. 15 6
      src/renderers/webgl/WebGLUniformsGroups.js

+ 15 - 6
src/renderers/webgl/WebGLUniformsGroups.js

@@ -114,7 +114,7 @@ function WebGLUniformsGroups( gl, info, capabilities, state ) {
 
 					const info = getUniformSize( value );
 
-					if ( typeof value === 'number' ) {
+					if ( typeof value === 'number' || typeof value === 'boolean' ) {
 
 						uniform.__data[ 0 ] = value;
 						gl.bufferSubData( gl.UNIFORM_BUFFER, offset + arrayOffset, uniform.__data );
@@ -164,7 +164,7 @@ function WebGLUniformsGroups( gl, info, capabilities, state ) {
 
 			// cache entry does not exist so far
 
-			if ( typeof value === 'number' ) {
+			if ( typeof value === 'number' || typeof value === 'boolean' ) {
 
 				cache[ index ] = value;
 
@@ -190,7 +190,7 @@ function WebGLUniformsGroups( gl, info, capabilities, state ) {
 
 			// compare current value with cached entry
 
-			if ( typeof value === 'number' ) {
+			if ( typeof value === 'number' || typeof value === 'boolean' ) {
 
 				if ( cache[ index ] !== value ) {
 
@@ -208,7 +208,16 @@ function WebGLUniformsGroups( gl, info, capabilities, state ) {
 
 					const cachedObject = cachedObjects[ i ];
 
-					if ( cachedObject.equals( values[ i ] ) === false ) {
+					if ( typeof cachedObject === 'number' || typeof cachedObject === 'boolean' ) {
+
+						if ( cachedObject !== values[ i ] ) {
+
+							cachedObjects[ i ] = values[ i ];
+							return true;
+
+						}
+
+					} else if ( cachedObject.equals( values[ i ] ) === false ) {
 
 						cachedObject.copy( values[ i ] );
 						return true;
@@ -312,9 +321,9 @@ function WebGLUniformsGroups( gl, info, capabilities, state ) {
 
 		// determine sizes according to STD140
 
-		if ( typeof value === 'number' ) {
+		if ( typeof value === 'number' || typeof value === 'boolean' ) {
 
-			// float/int
+			// float/int/bool
 
 			info.boundary = 4;
 			info.storage = 4;