Skip to content

Commit

Permalink
Prefix structs and defines
Browse files Browse the repository at this point in the history
  • Loading branch information
vanruesc committed Apr 26, 2024
1 parent 7e09d0e commit c7a22d9
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/utils/EffectShaderData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ export class EffectShaderData implements ShaderData {
}

const functionRegExp = /\w+\s+(\w+)\([\w\s,]*\)\s*{/g;
const structRegExp = /struct\s+(\w*)/g;
const defineRegExp = /^\s*#define\s+(\w*)/gm;

if(vertexShader !== null && effect.hasMainSupportFunction) {

Expand All @@ -192,13 +194,24 @@ export class EffectShaderData implements ShaderData {

}

// Collect names of functions.
for(const m of vertexShader.matchAll(functionRegExp)) {

names.add(m[1]);

}

for(const m of vertexShader.matchAll(structRegExp)) {

names.add(m[1]);

}

for(const m of vertexShader.matchAll(defineRegExp)) {

names.add(m[1]);

}

}

for(const m of fragmentShader.matchAll(functionRegExp)) {
Expand All @@ -207,6 +220,18 @@ export class EffectShaderData implements ShaderData {

}

for(const m of fragmentShader.matchAll(structRegExp)) {

names.add(m[1]);

}

for(const m of fragmentShader.matchAll(defineRegExp)) {

names.add(m[1]);

}

for(const d of effect.input.defines.keys()) {

// Ignore parameters of function-like macros.
Expand Down

0 comments on commit c7a22d9

Please sign in to comment.