evanw / glslx

A GLSL type checker, code formatter, and minifier for WebGL
http://evanw.github.io/glslx/
MIT License
408 stars 28 forks source link

errors on symbols that will later be dynamically #defined #1

Closed psulat closed 8 years ago

psulat commented 8 years ago

I currently use google's compiler and I was giving glslx a try.

I'm running into one issue. I have several #defines that get dynamically added to my shaders after the minimization process. For example, I use "SRGB_EXT_DEFINE" in my glsl code and then in javascript I add #define SRGB_EXT_DEFINE to true or false based on what is actually available. This doesn't work in glslx because the SRGB_EXT_DEFINE symbol can't be found. How do I modify glslx to not complain about specific symbols that have yet to be defined? Thanks!

Pete

evanw commented 8 years ago

GLSLX isn't designed to interact with the preprocessor. That said, your use case should be pretty easy to get working. I added extensions to GLSL to make this kind of stuff easy to add yourself. Just add an import and the compiler will emit that identifier unmangled in the final output:

import bool SRGB_EXT_DEFINE;

export void main() {
  gl_FragColor = vec4(SRGB_EXT_DEFINE ? 1.0 : 0.0);
}

As long as your macro is well-behaved (doesn't make drastic changes to the syntax tree), it should be easy to model it using an import statement. Does that work?

psulat commented 8 years ago

That worked. Thanks!