@@ -14099,7 +14099,7 @@ function WebGLState(gl, extensions, capabilities) {
1409914099 const depthBuffer = new DepthBuffer();
1410014100 const stencilBuffer = new StencilBuffer();
1410114101 const uboBindings = new WeakMap();
14102- const uboProgamMap = new WeakMap();
14102+ const uboProgramMap = new WeakMap();
1410314103 let enabledCapabilities = {};
1410414104 let currentBoundFramebuffers = {};
1410514105 let currentDrawbuffers = new WeakMap();
@@ -14560,10 +14560,10 @@ function WebGLState(gl, extensions, capabilities) {
1456014560 }
1456114561 }
1456214562 function updateUBOMapping(uniformsGroup, program) {
14563- let mapping = uboProgamMap .get(program);
14563+ let mapping = uboProgramMap .get(program);
1456414564 if (mapping === undefined) {
1456514565 mapping = new WeakMap();
14566- uboProgamMap .set(program, mapping);
14566+ uboProgramMap .set(program, mapping);
1456714567 }
1456814568 let blockIndex = mapping.get(uniformsGroup);
1456914569 if (blockIndex === undefined) {
@@ -14572,13 +14572,12 @@ function WebGLState(gl, extensions, capabilities) {
1457214572 }
1457314573 }
1457414574 function uniformBlockBinding(uniformsGroup, program) {
14575- const mapping = uboProgamMap .get(program);
14575+ const mapping = uboProgramMap .get(program);
1457614576 const blockIndex = mapping.get(uniformsGroup);
14577- if (uboBindings.get(uniformsGroup ) !== blockIndex) {
14577+ if (uboBindings.get(program ) !== blockIndex) {
1457814578 // bind shader specific block index to global block point
14579-
1458014579 gl.uniformBlockBinding(program, blockIndex, uniformsGroup.__bindingPointIndex);
14581- uboBindings.set(uniformsGroup , blockIndex);
14580+ uboBindings.set(program , blockIndex);
1458214581 }
1458314582 }
1458414583
@@ -17242,32 +17241,36 @@ function WebGLUniformsGroups(gl, info, capabilities, state) {
1724217241 // partly update the buffer if necessary
1724317242
1724417243 if (hasUniformChanged(uniform, i, cache) === true) {
17245- const value = uniform.value;
1724617244 const offset = uniform.__offset;
17247- if (typeof value === 'number') {
17248- uniform.__data[0] = value;
17249- gl.bufferSubData(gl.UNIFORM_BUFFER, offset, uniform.__data);
17250- } else {
17251- if (uniform.value.isMatrix3) {
17245+ const values = Array.isArray(uniform.value) ? uniform.value : [uniform.value];
17246+ let arrayOffset = 0;
17247+ for (let i = 0; i < values.length; i++) {
17248+ const value = values[i];
17249+ const info = getUniformSize(value);
17250+ if (typeof value === 'number') {
17251+ uniform.__data[0] = value;
17252+ gl.bufferSubData(gl.UNIFORM_BUFFER, offset + arrayOffset, uniform.__data);
17253+ } else if (value.isMatrix3) {
1725217254 // manually converting 3x3 to 3x4
1725317255
17254- uniform.__data[0] = uniform. value.elements[0];
17255- uniform.__data[1] = uniform. value.elements[1];
17256- uniform.__data[2] = uniform. value.elements[2];
17257- uniform.__data[3] = uniform. value.elements[0];
17258- uniform.__data[4] = uniform. value.elements[3];
17259- uniform.__data[5] = uniform. value.elements[4];
17260- uniform.__data[6] = uniform. value.elements[5];
17261- uniform.__data[7] = uniform. value.elements[0];
17262- uniform.__data[8] = uniform. value.elements[6];
17263- uniform.__data[9] = uniform. value.elements[7];
17264- uniform.__data[10] = uniform. value.elements[8];
17265- uniform.__data[11] = uniform. value.elements[0];
17256+ uniform.__data[0] = value.elements[0];
17257+ uniform.__data[1] = value.elements[1];
17258+ uniform.__data[2] = value.elements[2];
17259+ uniform.__data[3] = value.elements[0];
17260+ uniform.__data[4] = value.elements[3];
17261+ uniform.__data[5] = value.elements[4];
17262+ uniform.__data[6] = value.elements[5];
17263+ uniform.__data[7] = value.elements[0];
17264+ uniform.__data[8] = value.elements[6];
17265+ uniform.__data[9] = value.elements[7];
17266+ uniform.__data[10] = value.elements[8];
17267+ uniform.__data[11] = value.elements[0];
1726617268 } else {
17267- value.toArray(uniform.__data);
17269+ value.toArray(uniform.__data, arrayOffset);
17270+ arrayOffset += info.storage / Float32Array.BYTES_PER_ELEMENT;
1726817271 }
17269- gl.bufferSubData(gl.UNIFORM_BUFFER, offset, uniform.__data);
1727017272 }
17273+ gl.bufferSubData(gl.UNIFORM_BUFFER, offset, uniform.__data);
1727117274 }
1727217275 }
1727317276 gl.bindBuffer(gl.UNIFORM_BUFFER, null);
@@ -17280,7 +17283,12 @@ function WebGLUniformsGroups(gl, info, capabilities, state) {
1728017283 if (typeof value === 'number') {
1728117284 cache[index] = value;
1728217285 } else {
17283- cache[index] = value.clone();
17286+ const values = Array.isArray(value) ? value : [value];
17287+ const tempValues = [];
17288+ for (let i = 0; i < values.length; i++) {
17289+ tempValues.push(values[i].clone());
17290+ }
17291+ cache[index] = tempValues;
1728417292 }
1728517293 return true;
1728617294 } else {
@@ -17292,10 +17300,14 @@ function WebGLUniformsGroups(gl, info, capabilities, state) {
1729217300 return true;
1729317301 }
1729417302 } else {
17295- const cachedObject = cache[index];
17296- if (cachedObject.equals(value) === false) {
17297- cachedObject.copy(value);
17298- return true;
17303+ const cachedObjects = Array.isArray(cache[index]) ? cache[index] : [cache[index]];
17304+ const values = Array.isArray(value) ? value : [value];
17305+ for (let i = 0; i < cachedObjects.length; i++) {
17306+ const cachedObject = cachedObjects[i];
17307+ if (cachedObject.equals(values[i]) === false) {
17308+ cachedObject.copy(values[i]);
17309+ return true;
17310+ }
1729917311 }
1730017312 }
1730117313 }
@@ -17312,11 +17324,23 @@ function WebGLUniformsGroups(gl, info, capabilities, state) {
1731217324
1731317325 for (let i = 0, l = uniforms.length; i < l; i++) {
1731417326 const uniform = uniforms[i];
17315- const info = getUniformSize(uniform);
17327+ const infos = {
17328+ boundary: 0,
17329+ // bytes
17330+ storage: 0 // bytes
17331+ };
17332+
17333+ const values = Array.isArray(uniform.value) ? uniform.value : [uniform.value];
17334+ for (let j = 0, jl = values.length; j < jl; j++) {
17335+ const value = values[j];
17336+ const info = getUniformSize(value);
17337+ infos.boundary += info.boundary;
17338+ infos.storage += info.storage;
17339+ }
1731617340
1731717341 // the following two properties will be used for partial buffer updates
1731817342
17319- uniform.__data = new Float32Array(info .storage / Float32Array.BYTES_PER_ELEMENT);
17343+ uniform.__data = new Float32Array(infos .storage / Float32Array.BYTES_PER_ELEMENT);
1732017344 uniform.__offset = offset;
1732117345
1732217346 //
@@ -17327,14 +17351,14 @@ function WebGLUniformsGroups(gl, info, capabilities, state) {
1732717351
1732817352 // check for chunk overflow
1732917353
17330- if (chunkOffset !== 0 && remainingSizeInChunk - info .boundary < 0) {
17354+ if (chunkOffset !== 0 && remainingSizeInChunk - infos .boundary < 0) {
1733117355 // add padding and adjust offset
1733217356
1733317357 offset += chunkSize - chunkOffset;
1733417358 uniform.__offset = offset;
1733517359 }
1733617360 }
17337- offset += info .storage;
17361+ offset += infos .storage;
1733817362 }
1733917363
1734017364 // ensure correct final padding
@@ -17348,8 +17372,7 @@ function WebGLUniformsGroups(gl, info, capabilities, state) {
1734817372 uniformsGroup.__cache = {};
1734917373 return this;
1735017374 }
17351- function getUniformSize(uniform) {
17352- const value = uniform.value;
17375+ function getUniformSize(value) {
1735317376 const info = {
1735417377 boundary: 0,
1735517378 // bytes
0 commit comments