Skip to content

Commit

Permalink
Merge pull request #3 from Spiri0/wgslTypeLib-extension
Browse files Browse the repository at this point in the history
Update WGSLNodeBuilder.js
  • Loading branch information
Spiri0 authored Dec 2, 2024
2 parents 3716f3e + b5e685c commit 381bb94
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 381bb94

Please sign in to comment.