This one has been bugging me for a while now. In the GL_ARB_shader_objects spec, under 2.14.2 Program Objects, it says
It is permissible to attach multiple shader objects of the same type to a single program object, and it is permissible to attach a shader object to more than one program object.
The latter half of this is fine (sharing vertex/fragment shaders across multiple programs).
The former half, though, has got me exercising those little grey cells. So I think I must be missing something fundamental.
Why would you want to attach two (or more) vertex/fragment shaders to a program object? What purpose does this achieve?
Are they run on each vertex/fragment in the order in which they are attached?
Is it for having “combo” effects, such that you don’t have to write specialist shaders for each combination; instead just attach different effects?
What are the performance implications of doing so?
If anyone can shed any light on this, it’d be appreciated.
I think the meaning of this to have a shader object for a function. For example in Vertex Shader one function that translates the gl_vertex to gl_position. I think that you are able to use one seperate shader object for this function and this function can then be called by another shader object.
Maybe I’m wrong but I think this is the idea behind that.
Ooh, right, so instead of inlining functions other than ‘main’ in a single shader object, you separate them (hence allowing code sharing) into different source files and hence different shader objects.
There’s no #include preprocessor directive in the language so I guess you won’t need prototypes… and I guess any missing functions would be picked up as a linkage error.
Yeah, you have to define the function.
Without that the shader won’t be compiled. Info Log:
ERROR: 0:7: ‘Translate’ : no matching overloaded function found
ERROR: 0:7: ‘assign’ : cannot convert from ‘const float’ to ‘Position 4-component vector of float’
ERROR: 2 compilation errors. No code generated.
[This message has been edited by Corrail (edited 12-16-2003).]
There isn’t a #include header definition, but you are allowed to pass multiple strings in to the shader compiler for a single shader. That way, you can create standard includes that you can share between different shaders that are going to be linked together.