Skip to content

Commit 624a48d

Browse files
committed
reject needed macros
1 parent e8b791b commit 624a48d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

wgpu_shadertoy/imgui.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,21 @@ def parse_constants(code:str, common_code) -> list[tuple[int, str, int|float, st
2121
# for multipass shader this might need to be per pass (rpass.value) ?
2222
# mataches the macro: #define NAME VALUE
2323
# TODO there can be characters in numerical literals, such as x and o for hex and octal representation or e for scientific notation
24+
# technically the macros can also be an expression that is evaluated to be a number... such as # define DOF 10..0/30.0 - so how do we deal with that?
2425
define_pattern = re.compile(r"#define\s+(\w+)\s+([\d.]+)")
26+
if_def_template = r"#(el)?if\s+" #preprocessor ifdef blocks can't become uniforms. replacing these dynamically will be difficult.
2527

2628
constants = []
2729
for li, line in enumerate(code.splitlines()):
2830
match = define_pattern.match(line.rstrip())
2931
if match:
3032
name, value = match.groups()
33+
if_def_pattern = re.compile(if_def_template + name)
34+
if if_def_pattern.findall(code):
35+
#.findall over .match because because not only the beginning matters here
36+
print(f"skipping constant {name}, it needs to stay a macro")
37+
continue
38+
3139
if "." in value: #value.isdecimal?
3240
# TODO: wgsl needs to be more specific (f32 for example?) - but there is no preprocessor anyways...
3341
dtype = "f" #default float (32bit)

0 commit comments

Comments
 (0)