On 03/12/2012 01:15 PM, Ethan Fahy wrote:
Does that mean that an osg::StateSet can only have one osg::Program?  I have 
one application that uses a nodeVisitor to assign my generic vertex attribute 
and sets a program with the generic vertex names.  After saving the result as 
an ive file I have another application that reads in that ive file and attaches 
a shader program and renders the node.  Is it possible to either have multiple 
osg::Programs per stateset or to combine osg::Programs?

Yes, there can be only one GLSL program active at any time (this is an OpenGL rule), hence there is only one osg::Program allowed per StateSet. Currently, there is no provision in OSG for combining Shaders or Programs (though I believe this is on the to-do list).

For now, though, you'll have to do the combining yourself. There are several tricks you can use to get different code to execute from the same shader. One simple method is to define an if/else block and switch code paths based on the value of a Uniform.

You can also define a function in one shader, and have it called from another shader. This way, you can switch behavior by using different implementations of the same function. Shader A implements the shader's main() function and defines the prototype for function foo(), which is called in main(). Function foo() is implemented in both shader A and shader B, using the prototype defined in shader A, but each having different code. In one case, you attach shaders A and C to the program, and in the other case, you attach shaders B and C.

--"J"
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to