Here's my code snippet... // shader code done at setup time tgpProgram = new osg::Program(); tgpState = tgp.view->getCamera()->getOrCreateStateSet(); tgpVertexObject = new osg::Shader(osg::Shader::VERTEX); tgpFLIRFragmentObject = new osg::Shader(osg::Shader::FRAGMENT); tgpProgram->addShader(tgpFLIRFragmentObject); tgpProgram->addShader(tgpVertexObject); loadShaderSource(tgpVertexObject, "shaders\\texture.vert"); loadShaderSource(tgpFLIRFragmentObject, "shaders\\flirwh_texture.frag"); tgpState->setAttributesAndModes(tgpProgram, osg::StateAttribute::ON);
emptyProgram = new osg::Program();
.
.
.
// callback hit at runtime
struct TGPPostDrawCallback : public osg::Camera::DrawCallback
{
TGPPostDrawCallback(){}
virtual void operator () (const osg::Camera& camera) const
{
// turn shader off
tgpState->setAttributeAndModes(emptyProgram);
RenderTGPOverlay();
// turn shaders back on? This line crashes the app with an
access violation!
tgpState->setAttributesAndModes(tgpProgram,
osg::StateAttributes::ON);
}
}
On the above callback, I've also tried removing the attributes, adding and
removing the shaders from the program, and nothing has worked.
If I modify the above callback with the following instead, then it works...
struct TGPPostDrawCallback : public osg::Camera::DrawCallback
{
TGPPostDrawCallback(){}
virtual void operator () (const osg::Camera& camera) const
{
// turn shaders off
emptyProgram->apply(*(tgp.view->getCamera()->getGraphicsContext()->getState(
))));
RenderTGPOverlay();
// turn shaders back on
tgpProgram->apply(*(tgp.view->getCamera()->getGraphicsContext()->getState())
));
}
}
I would just like to see a code snippet that cleanly allows switching
between multiple shaders or turning shaders on and off for a given object. I
know I can do this easily in OpenGL. OSG is proving to be otherwise.
Any ideas on what I'm doing wrong or what I'm missing?
I'm all ears...
-Shayne
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Mike
Weiblen
Sent: Friday, November 14, 2008 10:16 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] shaders in OSG...
hmm, I was unaware of crash bugs in Program switching. If you could
create a simple repro, I'd be interested.
-- mew
On Fri, Nov 14, 2008 at 9:48 AM, Tueller, Shayne R Civ USAF AFMC 519
SMXS/MXDEC <[EMAIL PROTECTED]> wrote:
> Mike,
>
> Thanks for the reply. There was an exchange on this subject back on August
> 28 in the archives. I tried all the suggested solutions to the problem to
no
> avail. I have tried binding to an "empty" program as you suggest by using
> the call ss->SetAttributesAndModes(new osg::Program()) which does indeed
> turn off the shader (back to fixed functionality). But when I attempt to
> switch back to the shader with another call to
> ss->SetAttributesAndModes(MyShaderProgram), it crashes my OpenSceneGraph
> app.
>
> I've tried the other suggestions such as removing the shaders from the
> program and then adding them back on for enable/disable and also the call
> ss->RemoveAttribute(MyShaderProgram) which have also caused a crash on the
> ensuing call ss->SetAttributesAndModes(MyShaderProgram). The only
mechanism
> that has worked cleanly for me is if I create two programs, one that is
> empty and one that has my vertex/fragment shaders attached. When I call
each
> programs "apply" method to switch the shaders off and on, this seems to
> work. I'm not sure if this the correct way to do it though.
>
> I've also noticed that there is no clean way of switching between multiple
> programs attached to a single object during runtime. At least I haven't
> found a way to get it to work in OSG. In OpenGL, I've always been able to
> have multiple programs that I can swap in and out via the call to
> glUseProgram() with the appropriate program handle (including the call
> glUseProgram(0) to switch to the fixed pipe). I don't see an equivalent
> mechanism in OpenSceneGraph to achieve the same functionality.
>
> If you or anyone else can enlighten me, it would be most appreciated...
>
> -Shayne
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Mike
> Weiblen
> Sent: Thursday, November 13, 2008 11:33 AM
> To: OpenSceneGraph Users
> Subject: Re: [osg-users] shaders in OSG...
>
> The only way to turn off a glProgram in GL is glUseProgram(0), there
> is no glEnable/glDisable.
>
> In OSG you do that by creating an "empty" osg::Program, one with no
> osg::Shaders attached. Just attach that empty osg::Program where you
> want to revert to fixed-function. Further details in
> http://mew.cx/osg_glsl_july2005.pdf
>
> cheers
> -- mew
>
>
>
> On Wed, Nov 12, 2008 at 2:55 PM, Tueller, Shayne R Civ USAF AFMC 519
> SMXS/MXDEC <[EMAIL PROTECTED]> wrote:
>> Hello,
>>
>>
>>
>> Is there a "light weight" way to turn off shaders in OSG without
unloading
>> the vertex and fragment shaders from the shader program?
>>
>>
>>
>> My application needs to switch back and forth from the shader pipeline to
>> the fixed pipeline and vice versa during runtime. This can be done at the
>> OpenGL level by calling the function glUseProgramObject() to make the
> quick
>> switch. Is there an equivalent in OpenSceneGraph?
>>
>>
>>
>> Thanks in advance,
>>
>> -Shayne
>>
>> _______________________________________________
>> osg-users mailing list
>> [email protected]
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>>
>
>
>
> --
> Mike Weiblen -- Boulder Colorado USA -- http://mew.cx/
> _______________________________________________
> 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
>
>
--
Mike Weiblen -- Boulder Colorado USA -- http://mew.cx/
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

