Conditional shader compile

It would be nice to have a possibility to declare #define-like constants from the main app code. This will allow for conditinal compiling of shader code without need for multiply sahders. Like:

App:
glDefineDeclARB(ProgramObject, “ADV_LIGHT”);

Shader:
#ifdef ADV_LIGHT

  • do some sort of advanced lighting
    #else
  • simple lighting
    #end

I think this possibility will allow better interaction with extensions. For example, nvidia has it’s glslang implementation based on cg. One could test the presence of EXT_cg_shader and make use of mixed precision. This could be nice(from my point of view) mechanism for glslang extensions - you can write one shader that would handle everything.
Of cource, a workaround is to manually add #define lines into the code string. But it’s not so elegant.

Defines already exist. Though you’ll have to set up the defines by including extra strings. This is one of the reasons why you pass an array of strings to the compile calls.

Oh… Sometimes I’m simply stupid

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.