From b019c39d77d4f319ef2ce28fd218de9dc1a7bf85 Mon Sep 17 00:00:00 2001 From: Renaud Rohlinger Date: Fri, 1 Dec 2023 18:48:02 +0900 Subject: [PATCH] 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 --- src/renderers/webgl/WebGLUniformsGroups.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/renderers/webgl/WebGLUniformsGroups.js b/src/renderers/webgl/WebGLUniformsGroups.js index 601eebb7c64e59..b7059b1579af9b 100644 --- a/src/renderers/webgl/WebGLUniformsGroups.js +++ b/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;