(shader, hookName)
| 3083 | } |
| 3084 | |
| 3085 | getShaderHookTypes(shader, hookName) { |
| 3086 | // Create mapping from WGSL types to DataType entries |
| 3087 | const wgslToDataType = { |
| 3088 | 'f32': DataType.float1, |
| 3089 | 'vec2<f32>': DataType.float2, |
| 3090 | 'vec3<f32>': DataType.float3, |
| 3091 | 'vec4<f32>': DataType.float4, |
| 3092 | 'vec2f': DataType.float2, |
| 3093 | 'vec3f': DataType.float3, |
| 3094 | 'vec4f': DataType.float4, |
| 3095 | 'i32': DataType.int1, |
| 3096 | 'vec2<i32>': DataType.int2, |
| 3097 | 'vec3<i32>': DataType.int3, |
| 3098 | 'vec4<i32>': DataType.int4, |
| 3099 | 'bool': DataType.bool1, |
| 3100 | 'vec2<bool>': DataType.bool2, |
| 3101 | 'vec3<bool>': DataType.bool3, |
| 3102 | 'vec4<bool>': DataType.bool4, |
| 3103 | 'mat2x2<f32>': DataType.mat2, |
| 3104 | 'mat3x3<f32>': DataType.mat3, |
| 3105 | 'mat4x4<f32>': DataType.mat4, |
| 3106 | 'texture_2d<f32>': DataType.sampler2D |
| 3107 | }; |
| 3108 | |
| 3109 | let fullSrc = shader._vertSrc; |
| 3110 | let body = shader.hooks.vertex[hookName]; |
| 3111 | if (!body) { |
| 3112 | body = shader.hooks.fragment[hookName]; |
| 3113 | fullSrc = shader._fragSrc; |
| 3114 | } |
| 3115 | if (!body) { |
| 3116 | body = shader.hooks.compute[hookName]; |
| 3117 | fullSrc = shader._computeSrc; |
| 3118 | } |
| 3119 | if (!body) { |
| 3120 | throw new Error(`Can't find hook ${hookName}!`); |
| 3121 | } |
| 3122 | const nameParts = hookName.split(/\s+/g); |
| 3123 | const functionName = nameParts.pop(); |
| 3124 | const returnType = nameParts.pop(); |
| 3125 | const returnQualifiers = [...nameParts]; |
| 3126 | const parameterMatch = /\(([^\)]*)\)/.exec(body); |
| 3127 | if (!parameterMatch) { |
| 3128 | throw new Error(`Couldn't find function parameters in hook body:\n${body}`); |
| 3129 | } |
| 3130 | |
| 3131 | const structProperties = structName => { |
| 3132 | // WGSL struct parsing: struct StructName { field1: Type, field2: Type } |
| 3133 | const structDefMatch = new RegExp(`struct\\s+${structName}\\s*{([^}]*)}`).exec(fullSrc); |
| 3134 | if (!structDefMatch) return undefined; |
| 3135 | const properties = []; |
| 3136 | |
| 3137 | // Parse WGSL struct fields (e.g., "texCoord: vec2<f32>,") |
| 3138 | for (const fieldSrc of structDefMatch[1].split(',')) { |
| 3139 | const trimmed = fieldSrc.trim(); |
| 3140 | if (!trimmed) continue; |
| 3141 | |
| 3142 | // Remove location decorations and parse field |
nothing calls this directly
no test coverage detected