PDA

View Full Version : Conditional shader compile



Zengar
02-18-2004, 09:35 PM
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.

Humus
02-19-2004, 05:13 PM
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.

Zengar
02-20-2004, 01:21 AM
Oh... Sometimes I'm simply stupid http://www.opengl.org/discussion_boards/ubb/smile.gif