mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-14 12:29:30 -07:00
Fixing what I think was a stride bug in gpu-uniforms. This library seriously needs some extensive unit testing.
This commit is contained in:
@@ -87,26 +87,28 @@ const getTypeData = (type, attributes, otherStructLayouts) => {
|
||||
if (innerType == null) {
|
||||
return null;
|
||||
}
|
||||
const innerTypeData = getTypeData(innerType, [], otherStructLayouts);
|
||||
const elementTypeData = getTypeData(innerType, [], otherStructLayouts);
|
||||
|
||||
const mult = parseInt(fixedSize ?? "0");
|
||||
let align = innerTypeData.align;
|
||||
let size = Math.ceil(innerTypeData.size / align) * align * mult;
|
||||
const align = elementTypeData.align;
|
||||
let stride = elementTypeData.byteOffset;
|
||||
if (attributes.stride != null) {
|
||||
size = parseInt(attributes.stride) * mult;
|
||||
stride = parseInt(attributes.stride);
|
||||
}
|
||||
const size = stride * mult;
|
||||
|
||||
return {
|
||||
isArray: true,
|
||||
isFixedSize: mult > 0,
|
||||
innerTypeData,
|
||||
elementTypeData,
|
||||
mult,
|
||||
size,
|
||||
align,
|
||||
stride,
|
||||
defaultValue: () =>
|
||||
Array(mult)
|
||||
.fill()
|
||||
.map((_) => innerTypeData.defaultValue()),
|
||||
.map((_) => elementTypeData.defaultValue()),
|
||||
};
|
||||
} else {
|
||||
console.warn(`Unrecognized type ${type}.`);
|
||||
@@ -189,12 +191,12 @@ const writeField = (allLayouts, field, value, views, byteOffset, warnMissingFiel
|
||||
}
|
||||
if (field.isArray) {
|
||||
const count = field.isFixedSize ? field.mult : value.length;
|
||||
for (let i = 0; i < field.mult; i++) {
|
||||
writeField(allLayouts, field.innerTypeData, value[i], views, byteOffset + field.innerTypeData.byteOffset * i, warnMissingFields);
|
||||
for (let i = 0; i < count; i++) {
|
||||
writeField(allLayouts, field.elementTypeData, value[i], views, byteOffset + field.stride * i, warnMissingFields);
|
||||
}
|
||||
} else if (field.isStruct) {
|
||||
for (const innerField of field.innerLayout.fields) {
|
||||
writeField(allLayouts, innerField, value[innerField.identifier], views, byteOffset + field.byteOffset, warnMissingFields);
|
||||
writeField(allLayouts, innerField, value[innerField.identifier], views, byteOffset + field.stride * i, warnMissingFields);
|
||||
}
|
||||
} else {
|
||||
const view = views[field.baseType];
|
||||
|
||||
Reference in New Issue
Block a user