[osg-users] Modern GLSL and OSG

Garth D garthy_gso at entropicsoftware.com
Wed Sep 23 19:44:18 PDT 2015


Replying to myself with what I have managed to figure out so far to 
provide some information in case it comes up in a search. I can't vouch 
for the accuracy as this is still new to me. Anyway:

- Compile messages end up being sent through the osg::NotifyHandler 
mechanism.

- Shaders don't appear to be compiled immediately, but if you use them 
(by attaching an osg::Program to a osg::StateSet with 
setAttributeAndModes()), they end up being compiled and used at a later 
point.

- osg::StateSet::addUniform() with a osg::Uniform argument seems to be 
the way to specify uniforms.

- osg::Program::addBindAttribLocation() is a means of binding variables 
to a specific attribute index (output location), which you need for 
other calls. I believe location layout qualifiers in the shaders 
themselves can be used as well.

- osg::Program::getAttribBindingList() seems to only return the 
variables set with addBindAttribLocation(), and not ones specified in 
the shader itself. This might be a timing issue, perhaps the results 
change after the shaders are actually compiled and linked?

- osg::State::setUseModelViewAndProjectUniforms(true) can be used to 
automatically hook up variables such as "osg_ModelViewProjectionMatrix", 
which seems to be an OSG analogue to  "gl_ModelViewProjectionMatrix". 
This seems to be a useful bridge while trying to figure things out.

- The compile messages can be used to confirm the actual attribute 
indexes used.

- Variables that aren't used may be optimised out, which makes them 
unavailable.

- Using Geometry::setVertexAttribArray with the last argument set 
correctly (eg. BIND_PER_VERTEX) seems to be the way that you can pass 
texture coordinates to shaders. I'm guessing other information such as 
vertices and normals are handled similarly.

Hopefully this helps someone in a similar situation to the one I was in.

On 23/09/15 22:14, Garth D wrote:
> Hi all,
>
> I was wondering if anyone can make some suggestions as to resources that
> are useful for learning GLSL in modern OpenGL (say, 3.0+) with a
> specific focus on use with OSG.
>
> My existing GLSL knowledge is weak compared to my general 3D knowledge,
> and mostly dates back to the early days of shaders. A lot of what I have
> personally done with OpenGL and OSG has involved the fixed-function
> pipeline, or things that map to it fairly closely.
>
> Thus far I've been digging around online for GLSL resources, but tend to
> frequently find myself doing it the wrong way as I'm using features that
> have since become deprecated. On the OSG side I tend to dig around in
> the OSG examples and search the source to try to find the OSG
> equivalents to OpenGL calls I see mentioned in the GLSL resources. I
> then put these together and if I'm lucky something useful comes out. :)
>
> I think I'll figure things out eventually if I continue to crash around
> blindly as I have been, but if anyone can suggest some better starting
> points for GLSL use in OSG specifically, it would be much appreciated. :)
>
> Cheers,
> Garth
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>




More information about the osg-users mailing list