mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-14 12:29:30 -07:00
Refining gpu-uniforms warnings, which are now only emitted if requested. Hypothetically a user could call write() on the ArrayBuffer to update only some of its values.
This commit is contained in:
@@ -93,7 +93,7 @@ const getTypeData = (type, attributes, otherStructLayouts) => {
|
||||
.map((_) => innerTypeData.defaultValue()),
|
||||
};
|
||||
} else {
|
||||
console.warn(`Unsupported type: ${type}`);
|
||||
console.warn(`Unrecognized type ${type}.`);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -165,19 +165,21 @@ const parseStructLayoutsFromShader = (wgsl) => {
|
||||
|
||||
const makeDataForLayout = (structLayouts, layout) => Object.fromEntries(layout.fields.map((field) => [field.identifier, field.defaultValue()]));
|
||||
|
||||
const writeField = (allLayouts, field, value, views, byteOffset) => {
|
||||
const writeField = (allLayouts, field, value, views, byteOffset, warnMissingFields) => {
|
||||
if (value == null) {
|
||||
console.warn(`Property missing: ${field.identifier}`);
|
||||
if (warnMissingFields) {
|
||||
console.warn(`Property missing from data: ${field.identifier}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
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);
|
||||
writeField(allLayouts, field.innerTypeData, value[i], views, byteOffset + field.innerTypeData.byteOffset * i, warnMissingFields);
|
||||
}
|
||||
} else if (field.isStruct) {
|
||||
for (const innerField of field.innerLayout.fields) {
|
||||
writeField(allLayouts, innerField, value[innerField.identifier], views, byteOffset + field.byteOffset);
|
||||
writeField(allLayouts, innerField, value[innerField.identifier], views, byteOffset + field.byteOffset, warnMissingFields);
|
||||
}
|
||||
} else {
|
||||
const view = views[field.baseType];
|
||||
@@ -191,7 +193,7 @@ const makeGenerator = (layout, structLayouts) => {
|
||||
return Object.freeze({
|
||||
minSize,
|
||||
create: () => makeDataForLayout(structLayouts, layout),
|
||||
write: (object, destination) => {
|
||||
write: (object, destination, warnMissingFields = false) => {
|
||||
destination ??= new ArrayBuffer(layout.sizeInBytes); // TODO: expand to support runtime-sized arrays, via the length of the array on the data object
|
||||
|
||||
const views = {
|
||||
@@ -201,7 +203,7 @@ const makeGenerator = (layout, structLayouts) => {
|
||||
};
|
||||
|
||||
for (const field of layout.fields) {
|
||||
writeField(structLayouts, field, object[field.identifier], views, 0);
|
||||
writeField(structLayouts, field, object[field.identifier], views, 0, warnMissingFields);
|
||||
}
|
||||
|
||||
return destination;
|
||||
|
||||
Reference in New Issue
Block a user