mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-18 14:19: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) {
|
if (innerType == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const innerTypeData = getTypeData(innerType, [], otherStructLayouts);
|
const elementTypeData = getTypeData(innerType, [], otherStructLayouts);
|
||||||
|
|
||||||
const mult = parseInt(fixedSize ?? "0");
|
const mult = parseInt(fixedSize ?? "0");
|
||||||
let align = innerTypeData.align;
|
const align = elementTypeData.align;
|
||||||
let size = Math.ceil(innerTypeData.size / align) * align * mult;
|
let stride = elementTypeData.byteOffset;
|
||||||
if (attributes.stride != null) {
|
if (attributes.stride != null) {
|
||||||
size = parseInt(attributes.stride) * mult;
|
stride = parseInt(attributes.stride);
|
||||||
}
|
}
|
||||||
|
const size = stride * mult;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isArray: true,
|
isArray: true,
|
||||||
isFixedSize: mult > 0,
|
isFixedSize: mult > 0,
|
||||||
innerTypeData,
|
elementTypeData,
|
||||||
mult,
|
mult,
|
||||||
size,
|
size,
|
||||||
align,
|
align,
|
||||||
|
stride,
|
||||||
defaultValue: () =>
|
defaultValue: () =>
|
||||||
Array(mult)
|
Array(mult)
|
||||||
.fill()
|
.fill()
|
||||||
.map((_) => innerTypeData.defaultValue()),
|
.map((_) => elementTypeData.defaultValue()),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
console.warn(`Unrecognized type ${type}.`);
|
console.warn(`Unrecognized type ${type}.`);
|
||||||
@@ -189,12 +191,12 @@ const writeField = (allLayouts, field, value, views, byteOffset, warnMissingFiel
|
|||||||
}
|
}
|
||||||
if (field.isArray) {
|
if (field.isArray) {
|
||||||
const count = field.isFixedSize ? field.mult : value.length;
|
const count = field.isFixedSize ? field.mult : value.length;
|
||||||
for (let i = 0; i < field.mult; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
writeField(allLayouts, field.innerTypeData, value[i], views, byteOffset + field.innerTypeData.byteOffset * i, warnMissingFields);
|
writeField(allLayouts, field.elementTypeData, value[i], views, byteOffset + field.stride * i, warnMissingFields);
|
||||||
}
|
}
|
||||||
} else if (field.isStruct) {
|
} else if (field.isStruct) {
|
||||||
for (const innerField of field.innerLayout.fields) {
|
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 {
|
} else {
|
||||||
const view = views[field.baseType];
|
const view = views[field.baseType];
|
||||||
|
|||||||
Reference in New Issue
Block a user