| 188 | } |
| 189 | export const wgslBackend = { |
| 190 | hookEntry(hookType) { |
| 191 | const params = hookType.parameters.map((param) => { |
| 192 | // For struct types, use a raw prefix since we'll create a mutable copy |
| 193 | const paramName = param.type.properties ? `_p5_strands_raw_${param.name}` : `${HOOK_PARAM_PREFIX}${param.name}`; |
| 194 | return `${paramName}: ${param.type.typeName}`; |
| 195 | }).join(', '); |
| 196 | |
| 197 | const firstLine = `(${params}) {`; |
| 198 | |
| 199 | // Generate mutable copies for struct parameters |
| 200 | const mutableCopies = hookType.parameters |
| 201 | .filter(param => param.type.properties) // Only struct types |
| 202 | .map(param => ` var ${HOOK_PARAM_PREFIX}${param.name} = _p5_strands_raw_${param.name};`) |
| 203 | .join('\n'); |
| 204 | |
| 205 | return mutableCopies ? firstLine + '\n' + mutableCopies : firstLine; |
| 206 | }, |
| 207 | addTextureBindingsToDeclarations(strandsContext) { |
| 208 | // Add texture and sampler bindings for sampler2D uniforms to both vertex and fragment declarations |
| 209 | if (!strandsContext.renderer || !strandsContext.baseShader) return; |