Doesn't a Drawable's state get applied prior to the call to Drawable::drawImplementation()? If so, you could just put the _program in your Drawable's StateSet?

It's easy to verify that things are happening in the right order using a debugger with breakpoints set at your drawImplementation() and also at Program::apply().

If it doesn't happen as I describe above, then I believe what you're doing below is the most robust, as that code would work with all other rendering in the scene graph, both shader and non-shader rendering.

Honestly it's been too long since I played at this level. But I seem to recall that the difference between:
    _program->apply( state );
and
    state->apply( _program.get() );
is that the latter tracks the currently bound program, doesn't bother to apply it if it's already in use, and would probably allow you to remove the call to setLastAppliedProgramObject(0).
   -Paul


On 9/4/2012 9:58 AM, Jeremy Moles wrote:
I am creating a custom Drawable that needs to push a Fragment Shader
into the current rendering state and then, after a single extension
call, subsequently remove this shader from the state.

I have some code I noodled through to make this work, but I feel like
there is probably a better way. It goes something like this:

----------------------------------------

drawImplementaion(RenderInfo&  ri) {
        State* state = ri.getState();
        unsigned int contextID = state->getContextID();

        _program.apply(state);

        myExtensions->doMycall();

        GL2Extensions::Get(contextID, true)->glUseProgram(0);

        state->setLastAppliedProgramObject(0);
}

----------------------------------------

Like I said above, this "works", but I feel like there is probably a
cleaner way to achieve what I want. Note that _program is a ref_ptr to a
properly create osg::Program object, since I certainly do NOT want to
recreate all the goodness it provides. :)

Any API advice?

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


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

Reply via email to