Skip to content

Commit

Permalink
Update WGSLNodeBuilder.js
Browse files Browse the repository at this point in the history
Arrays are not currently taken into account by the wgslTypeLib. However, with the struct extension mrdoob#29908, arrays will also become important as a type.
  • Loading branch information
Spiri0 authored Dec 2, 2024
1 parent 3716f3e commit b5e685c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,28 @@ const wgslTypeLib = {

mat2: 'mat2x2<f32>',
mat3: 'mat3x3<f32>',
mat4: 'mat4x4<f32>'
mat4: 'mat4x4<f32>',

//because arrays with their two degrees of freedom are special
array( elementType, count ) {

const isValidType = ( type ) => !! this[ type ];

if ( ! isValidType( elementType ) ) {

throw new Error( `Unknown type: ${elementType}` );

}

if ( typeof count !== 'number' || ! Number.isInteger( count ) || count < 1 ) {

throw new Error( `Invalid size: ${count}. Size must be a positive integer` );

}

return `array<${this[ elementType ]}, ${count}>`;

}
};

const wgslCodeCache = {};
Expand Down

0 comments on commit b5e685c

Please sign in to comment.