|
@@ -14099,7 +14099,7 @@ function WebGLState(gl, extensions, capabilities) {
|
|
|
const depthBuffer = new DepthBuffer();
|
|
|
const stencilBuffer = new StencilBuffer();
|
|
|
const uboBindings = new WeakMap();
|
|
|
- const uboProgamMap = new WeakMap();
|
|
|
+ const uboProgramMap = new WeakMap();
|
|
|
let enabledCapabilities = {};
|
|
|
let currentBoundFramebuffers = {};
|
|
|
let currentDrawbuffers = new WeakMap();
|
|
@@ -14560,10 +14560,10 @@ function WebGLState(gl, extensions, capabilities) {
|
|
|
}
|
|
|
}
|
|
|
function updateUBOMapping(uniformsGroup, program) {
|
|
|
- let mapping = uboProgamMap.get(program);
|
|
|
+ let mapping = uboProgramMap.get(program);
|
|
|
if (mapping === undefined) {
|
|
|
mapping = new WeakMap();
|
|
|
- uboProgamMap.set(program, mapping);
|
|
|
+ uboProgramMap.set(program, mapping);
|
|
|
}
|
|
|
let blockIndex = mapping.get(uniformsGroup);
|
|
|
if (blockIndex === undefined) {
|
|
@@ -14572,13 +14572,12 @@ function WebGLState(gl, extensions, capabilities) {
|
|
|
}
|
|
|
}
|
|
|
function uniformBlockBinding(uniformsGroup, program) {
|
|
|
- const mapping = uboProgamMap.get(program);
|
|
|
+ const mapping = uboProgramMap.get(program);
|
|
|
const blockIndex = mapping.get(uniformsGroup);
|
|
|
- if (uboBindings.get(uniformsGroup) !== blockIndex) {
|
|
|
+ if (uboBindings.get(program) !== blockIndex) {
|
|
|
// bind shader specific block index to global block point
|
|
|
-
|
|
|
gl.uniformBlockBinding(program, blockIndex, uniformsGroup.__bindingPointIndex);
|
|
|
- uboBindings.set(uniformsGroup, blockIndex);
|
|
|
+ uboBindings.set(program, blockIndex);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -17242,32 +17241,36 @@ function WebGLUniformsGroups(gl, info, capabilities, state) {
|
|
|
// partly update the buffer if necessary
|
|
|
|
|
|
if (hasUniformChanged(uniform, i, cache) === true) {
|
|
|
- const value = uniform.value;
|
|
|
const offset = uniform.__offset;
|
|
|
- if (typeof value === 'number') {
|
|
|
- uniform.__data[0] = value;
|
|
|
- gl.bufferSubData(gl.UNIFORM_BUFFER, offset, uniform.__data);
|
|
|
- } else {
|
|
|
- if (uniform.value.isMatrix3) {
|
|
|
+ const values = Array.isArray(uniform.value) ? uniform.value : [uniform.value];
|
|
|
+ let arrayOffset = 0;
|
|
|
+ for (let i = 0; i < values.length; i++) {
|
|
|
+ const value = values[i];
|
|
|
+ const info = getUniformSize(value);
|
|
|
+ if (typeof value === 'number') {
|
|
|
+ uniform.__data[0] = value;
|
|
|
+ gl.bufferSubData(gl.UNIFORM_BUFFER, offset + arrayOffset, uniform.__data);
|
|
|
+ } else if (value.isMatrix3) {
|
|
|
// manually converting 3x3 to 3x4
|
|
|
|
|
|
- uniform.__data[0] = uniform.value.elements[0];
|
|
|
- uniform.__data[1] = uniform.value.elements[1];
|
|
|
- uniform.__data[2] = uniform.value.elements[2];
|
|
|
- uniform.__data[3] = uniform.value.elements[0];
|
|
|
- uniform.__data[4] = uniform.value.elements[3];
|
|
|
- uniform.__data[5] = uniform.value.elements[4];
|
|
|
- uniform.__data[6] = uniform.value.elements[5];
|
|
|
- uniform.__data[7] = uniform.value.elements[0];
|
|
|
- uniform.__data[8] = uniform.value.elements[6];
|
|
|
- uniform.__data[9] = uniform.value.elements[7];
|
|
|
- uniform.__data[10] = uniform.value.elements[8];
|
|
|
- uniform.__data[11] = uniform.value.elements[0];
|
|
|
+ uniform.__data[0] = value.elements[0];
|
|
|
+ uniform.__data[1] = value.elements[1];
|
|
|
+ uniform.__data[2] = value.elements[2];
|
|
|
+ uniform.__data[3] = value.elements[0];
|
|
|
+ uniform.__data[4] = value.elements[3];
|
|
|
+ uniform.__data[5] = value.elements[4];
|
|
|
+ uniform.__data[6] = value.elements[5];
|
|
|
+ uniform.__data[7] = value.elements[0];
|
|
|
+ uniform.__data[8] = value.elements[6];
|
|
|
+ uniform.__data[9] = value.elements[7];
|
|
|
+ uniform.__data[10] = value.elements[8];
|
|
|
+ uniform.__data[11] = value.elements[0];
|
|
|
} else {
|
|
|
- value.toArray(uniform.__data);
|
|
|
+ value.toArray(uniform.__data, arrayOffset);
|
|
|
+ arrayOffset += info.storage / Float32Array.BYTES_PER_ELEMENT;
|
|
|
}
|
|
|
- gl.bufferSubData(gl.UNIFORM_BUFFER, offset, uniform.__data);
|
|
|
}
|
|
|
+ gl.bufferSubData(gl.UNIFORM_BUFFER, offset, uniform.__data);
|
|
|
}
|
|
|
}
|
|
|
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
@@ -17280,7 +17283,12 @@ function WebGLUniformsGroups(gl, info, capabilities, state) {
|
|
|
if (typeof value === 'number') {
|
|
|
cache[index] = value;
|
|
|
} else {
|
|
|
- cache[index] = value.clone();
|
|
|
+ const values = Array.isArray(value) ? value : [value];
|
|
|
+ const tempValues = [];
|
|
|
+ for (let i = 0; i < values.length; i++) {
|
|
|
+ tempValues.push(values[i].clone());
|
|
|
+ }
|
|
|
+ cache[index] = tempValues;
|
|
|
}
|
|
|
return true;
|
|
|
} else {
|
|
@@ -17292,10 +17300,14 @@ function WebGLUniformsGroups(gl, info, capabilities, state) {
|
|
|
return true;
|
|
|
}
|
|
|
} else {
|
|
|
- const cachedObject = cache[index];
|
|
|
- if (cachedObject.equals(value) === false) {
|
|
|
- cachedObject.copy(value);
|
|
|
- return true;
|
|
|
+ const cachedObjects = Array.isArray(cache[index]) ? cache[index] : [cache[index]];
|
|
|
+ const values = Array.isArray(value) ? value : [value];
|
|
|
+ for (let i = 0; i < cachedObjects.length; i++) {
|
|
|
+ const cachedObject = cachedObjects[i];
|
|
|
+ if (cachedObject.equals(values[i]) === false) {
|
|
|
+ cachedObject.copy(values[i]);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -17312,11 +17324,23 @@ function WebGLUniformsGroups(gl, info, capabilities, state) {
|
|
|
|
|
|
for (let i = 0, l = uniforms.length; i < l; i++) {
|
|
|
const uniform = uniforms[i];
|
|
|
- const info = getUniformSize(uniform);
|
|
|
+ const infos = {
|
|
|
+ boundary: 0,
|
|
|
+ // bytes
|
|
|
+ storage: 0 // bytes
|
|
|
+ };
|
|
|
+
|
|
|
+ const values = Array.isArray(uniform.value) ? uniform.value : [uniform.value];
|
|
|
+ for (let j = 0, jl = values.length; j < jl; j++) {
|
|
|
+ const value = values[j];
|
|
|
+ const info = getUniformSize(value);
|
|
|
+ infos.boundary += info.boundary;
|
|
|
+ infos.storage += info.storage;
|
|
|
+ }
|
|
|
|
|
|
// the following two properties will be used for partial buffer updates
|
|
|
|
|
|
- uniform.__data = new Float32Array(info.storage / Float32Array.BYTES_PER_ELEMENT);
|
|
|
+ uniform.__data = new Float32Array(infos.storage / Float32Array.BYTES_PER_ELEMENT);
|
|
|
uniform.__offset = offset;
|
|
|
|
|
|
//
|
|
@@ -17327,14 +17351,14 @@ function WebGLUniformsGroups(gl, info, capabilities, state) {
|
|
|
|
|
|
// check for chunk overflow
|
|
|
|
|
|
- if (chunkOffset !== 0 && remainingSizeInChunk - info.boundary < 0) {
|
|
|
+ if (chunkOffset !== 0 && remainingSizeInChunk - infos.boundary < 0) {
|
|
|
// add padding and adjust offset
|
|
|
|
|
|
offset += chunkSize - chunkOffset;
|
|
|
uniform.__offset = offset;
|
|
|
}
|
|
|
}
|
|
|
- offset += info.storage;
|
|
|
+ offset += infos.storage;
|
|
|
}
|
|
|
|
|
|
// ensure correct final padding
|
|
@@ -17348,8 +17372,7 @@ function WebGLUniformsGroups(gl, info, capabilities, state) {
|
|
|
uniformsGroup.__cache = {};
|
|
|
return this;
|
|
|
}
|
|
|
- function getUniformSize(uniform) {
|
|
|
- const value = uniform.value;
|
|
|
+ function getUniformSize(value) {
|
|
|
const info = {
|
|
|
boundary: 0,
|
|
|
// bytes
|