[osg-users] Saving and restoring GL state with OpenSceneGraph

132 views
Skip to first unread message

Preet

unread,
Jul 5, 2012, 10:47:31 PM7/5/12
to OpenSceneGraph Users
Hi,

I'm trying to find out a bit more about how to get OpenSceneGraph to
share an OpenGL context with another library... and to do that
properly i'd like to isolate both by saving and restoring state as
appropriate. I know this isn't the 'right' way to use OSG, and I know
that this kills performance, especially since OSG is designed to use
lazy state updating... but sometimes its a necessary evil. I'm
targeting OpenGL ES2.

Looking through some other posts, I've gathered:

You can get/save the current stateset by calling something like:
myViewer->getCamera()->getGraphicsContext()->getState()->captureCurrentState(myStateSet);

You can reset the current state by calling reset:
myViewer->getCamera()->getGraphicsContext()->getState()->reset();

You can apply a saved state by calling apply:
myViewer->getCamera()->getGraphicsContext()->getState()->apply(myStateSet);

But I'm not sure about a few things:

When should the osg::State be first saved? So basically, when is the
scene graph first traversed and the osg::State built up so that it's
appropriate for OSG to go ahead and render something? Does the initial
OpenGL state when OSG first builds up osg::State matter (I'm guessing
no)?

After saving this valid state, i'd do something like this to restore
it and render my scene...
// draw call
myViewer->getCamera()->getGraphicsContext()->getState()->reset(); //
is this line necessary?
myViewer->getCamera()->getGraphicsContext()->getState()->apply(myStateSet);
myViewer->frame();
// save state again if I modified the scene

Does that seem reasonable? Any advice/input would be appreciated.


Thanks

Preet
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Frank Kane

unread,
Jul 6, 2012, 3:52:26 PM7/6/12
to osg-...@lists.openscenegraph.org
From what I've read, captureCurrentState just returns the current state attributes in OSG - it's not actually capturing the current GL state.

But, you could flip the problem on its head and capture the actual OpenGL state just prior to calling your library, and then restoring it when your library is done with its drawing. Here is some code to start from that catches most of the stuff that's likely to change; for completeness, you'd want to capture all of the state documented at http://www.khronos.org/opengles/sdk/1.1/docs/man/glGet.xml as well.


Code:

typedef struct glState_S {
GLboolean depthTest, blend, cullFace;
GLboolean dither, colorLogicOp, polygonOffsetLine, polygonOffsetFill;
GLboolean polygonOffsetPoint, polygonSmooth, scissorTest, stencilTest;
} glState;

static std::stack<glState> stateStack;

SILVERLININGDLL_API bool PushAllState(void)
{
glState state;

state.blend = glIsEnabled(GL_BLEND);
state.depthTest = glIsEnabled(GL_DEPTH_TEST);
state.cullFace = glIsEnabled(GL_CULL_FACE);
state.dither = glIsEnabled(GL_DITHER);
state.polygonOffsetFill = glIsEnabled(GL_POLYGON_OFFSET_FILL);
state.scissorTest = glIsEnabled(GL_SCISSOR_TEST);
state.stencilTest = glIsEnabled(GL_STENCIL_TEST);

stateStack.push(state);

CheckError(__LINE__);

return true;
}

SILVERLININGDLL_API bool PopAllState(void)
{
if (!stateStack.empty()) {
glState state = stateStack.top();

if (state.blend) glEnable(GL_BLEND); else glDisable(GL_BLEND);
if (state.depthTest) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
if (state.cullFace) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
if (state.dither) glEnable(GL_DITHER); else glDisable(GL_DITHER);
if (state.polygonOffsetFill) glEnable(GL_POLYGON_OFFSET_FILL); else glDisable(GL_POLYGON_OFFSET_FILL);
if (state.scissorTest) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
if (state.stencilTest) glEnable(GL_STENCIL_TEST); else glDisable(GL_STENCIL_TEST);

stateStack.pop();
}

CheckError(__LINE__);

return true;
}




Best regards,
Frank Kane
Founder, Sundog Software LLC

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48737#48737

John Richardson

unread,
Jul 6, 2012, 5:59:27 PM7/6/12
to osg-...@lists.openscenegraph.org
Greetings and Salutations,

The OpenScenegraph Siggraph 2012 BOF will be held in the Los Angeles
Convention Center on 8 August 2012 at 10AM.

This is the second Call for Presentations [32 days until the BOF]

Highlight your work.
Show off your institution.
Hawk your consulting skills.

As long as it is OSG related. Step up now and be virtual.

Notes: Robert will get a default 10-15 minute slot to give a state of OSG
report or whatever he wants to give and presented by whoever he designates.
That leaves 3 15 minutes slots [more if we get enough presenters but no slot <
10 minutes]. First come first allocated. More time if less presenters.

John F. Richardson

Preet

unread,
Jul 6, 2012, 10:40:37 PM7/6/12
to osg-...@lists.openscenegraph.org
Hi Frank,

Thanks for the reply! I'll try setting up something similar in my application.

Alejandro Aguilar Sierra

unread,
Jul 17, 2012, 1:29:48 PM7/17/12
to OpenSceneGraph Users
Hi John,

I will present work about plate tectonics simulation.

See you there!

-- A.

John Richardson

unread,
Jul 23, 2012, 2:22:28 PM7/23/12
to osg-...@lists.openscenegraph.org
Greetings and Salutations,



There is ONE 15 minute slot left. The DEADLINE is 27 July 2012 to claim the
slot. After that I will give the other presenters 5 more minutes or plan a
panel at the end. I need to plan the final agenda.



The OpenScenegraph Siggraph 2012 BOF will be held in the Los Angeles
Convention Center on 8 August 2012 at 10AM.

Highlight your work.
Show off your institution.
Hawk your consulting skills.

As long as it is OSG related. Step up now and be virtual.


John F. Richardson

David Glenn

unread,
Jul 23, 2012, 7:50:38 PM7/23/12
to osg-...@lists.openscenegraph.org
Greeting John!

Gee, I wish I could help you, but I haven't done any OSG stuff that I'm alowed to show off this year, but I will be there to see all the fun!

------------------------
David Glenn
---------------
D Glenn 3D Computer Graphics &amp; Media Systems.
www.dglenn.com

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49006#49006

Alejandro Aguilar Sierra

unread,
Jul 23, 2012, 7:57:23 PM7/23/12
to OpenSceneGraph Users
Hello John,

I'd like to present a work I have been preparing with one of my
undergrads. It is about a simulation of the plate tectonics evolution
over the sphere during the geologic eras. Of course it is all over
OSG.

Is there still a spot in the agenda?

Thanks in advance.

--
Alejandro Sierra
National University of Mexico

Art Tevs

unread,
Jul 24, 2012, 4:07:22 PM7/24/12
to osg-...@lists.openscenegraph.org
Hi,

finally I am also coming to this year's Siggraph, yeah :)
Unfortunately I have nothing to present, since last years I didn't worked with OSG much and hence almost no development in osgPPU.

However, how about a small announcement that we are looking for forum moderators and admins at the BOF? At least I will certainly join the BOF.


Cheers,
Art

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49029#49029

John Richardson

unread,
Jul 24, 2012, 6:01:28 PM7/24/12
to osg-...@lists.openscenegraph.org
Hello Art,

Will add the announcement to the Into. If you have preferred text for the
announcement, please send to me.

John F. Richardson

John Richardson

unread,
Jul 24, 2012, 6:14:16 PM7/24/12
to OpenSceneGraph Users
Hello Alejandro,

You asked for a slot on 17 July and so you already had a slot reserved.

You, Robert's state of OSG slides and Tassilo Glander have the 3 currently
confirmed 15 minute slots.

Could you send me a title slide with any abstract or logos or intro type
text for my agenda slides.

One still up for grabs.....:)

John F. Richardson

-----Original Message-----
From: osg-user...@lists.openscenegraph.org
[mailto:osg-user...@lists.openscenegraph.org] On Behalf Of Alejandro
Aguilar Sierra
Sent: Monday, July 23, 2012 4:57 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] OpenScenegraph Siggraph 2012 BOF Final Call for
Presentations

David Glenn

unread,
Jul 26, 2012, 1:14:16 PM7/26/12
to osg-...@lists.openscenegraph.org
> <> wrote:
>
> > Greetings and Salutations,
> >
> >
> >
> > There is ONE 15 minute slot left. The DEADLINE is 27 July 2012 to claim
> >
> the
>
> > slot. After that I will give the other presenters 5 more minutes or plan a
> > panel at the end. I need to plan the final agenda.
> >
> >
> >
> > The OpenScenegraph Siggraph 2012 BOF will be held in the Los Angeles
> > Convention Center on 8 August 2012 at 10AM.
> >
> > Highlight your work.
> > Show off your institution.
> > Hawk your consulting skills.
> >
> > As long as it is OSG related. Step up now and be virtual.
> >
> >
> > John F. Richardson
> >
> > _______________________________________________
> > osg-users mailing list
> >
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
> >
> _______________________________________________
> osg-users mailing list
>
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
> _______________________________________________
> osg-users mailing list
>
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
> ------------------
> Post generated by Mail2Forum


Just thinking up ideas to fill that time.

Did you docket enough time to introduce OSG to Newbes? What it is, what it can do, what it's not and what can fill that role?
What to do you need to install it: In windows, In Linux or In Mac?

Maybe you want to fill in people on add on products Delta 3D that uses OSG?
or Virtual Planet Builder or osgEarth or the progress OSG on embedded systems.

D Glenn

------------------------
David Glenn
---------------
D Glenn 3D Computer Graphics &amp; Media Systems.
www.dglenn.com

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49079#49079

John Richardson

unread,
Jul 26, 2012, 4:12:03 PM7/26/12
to osg-...@lists.openscenegraph.org
Hello David,

If nobody claims the last slot the panel will discuss all this.

Last year Jean-Sébastien Guay gave a complete how to compile and build OSG
tutorial. That did take some time. Well worth it but time consuming.
John F. Richardson

-----Original Message-----
From: osg-user...@lists.openscenegraph.org
[mailto:osg-user...@lists.openscenegraph.org] On Behalf Of David Glenn
Sent: Thursday, July 26, 2012 10:14 AM
To: osg-...@lists.openscenegraph.org

John Richardson

unread,
Jul 26, 2012, 7:00:33 PM7/26/12
to OpenSceneGraph Users
Hello Alejandro,

Did you send me a title slide or informational slide? I would appreciate it
for the list of presenters list. Can you also send a short abstract so I can
say nice comments about your talk to the audience.

John F. Richardson

-----Original Message-----
From: osg-user...@lists.openscenegraph.org
[mailto:osg-user...@lists.openscenegraph.org] On Behalf Of Alejandro
Aguilar Sierra
Sent: Monday, July 23, 2012 4:57 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] OpenScenegraph Siggraph 2012 BOF Final Call for
Presentations

Eric Sokolowsky

unread,
Jul 27, 2012, 2:05:17 AM7/27/12
to OpenSceneGraph Users
I'm interested in giving a very short (probably no more than 5-10 minutes) presentation on the work I do with OSG. I wrote an OSG application many years ago and still use it, but now I use it primarily on a display wall in my work at NASA. I run one instance of my application on each screen to show very large animations on either a 3x3 or a 5x3 display wall.

I am also interested in consulting opportunities for OSG particularly, but also graphics and computer programming in general. At one time I was quite active on the OSG mailing lists and have contributed many enhancements and fixes, and want to get back into this arena once more.

Eric

Torben Dannhauer

unread,
Jul 27, 2012, 2:11:21 AM7/27/12
to osg-...@lists.openscenegraph.org
Hi,

I would have some intersting topics to talk about, unfortunately I cannot join the siggraph this year (again..).
Nevertheless, for next year I plan to visit SIGGRAPH the first time.
I hope the new OSG geometrical distortion framework will be finished and submitted, also the CiGi interface should be in a presentable form..

Enjoy the SIGGRAPH!

Cheers,
Torben

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49084#49084

David Glenn

unread,
Jul 27, 2012, 4:54:15 PM7/27/12
to osg-...@lists.openscenegraph.org
Yep! I remember that one, I was there!
It was very informative and well done!

D Glenn


John Richardson wrote:
> Hello David,
>
> If nobody claims the last slot the panel will discuss all this.
>
> Last year Jean-Sébastien Guay gave a complete how to compile and build OSG
> tutorial. That did take some time. Well worth it but time consuming.

> John F. Richardson
>
> -----Original Message-----
> From:

> [mailto:] On Behalf Of David Glenn
> Sent: Thursday, July 26, 2012 10:14 AM
> To:

> Subject: Re: OpenScenegraph Siggraph 2012 BOF Final Call for
> Presentations
>
>

> John Richardson wrote:
>
> > Hello Alejandro,
> >
> > You asked for a slot on 17 July and so you already had a slot reserved.
> >
> > You, Robert's state of OSG slides and Tassilo Glander have the 3 currently
> > confirmed 15 minute slots.
> >
> > Could you send me a title slide with any abstract or logos or intro type
> > text for my agenda slides.
> >
> > One still up for grabs.....:)
> >

> > John F. Richardson
> >
> > -----Original Message-----
> > From:
> > [mailto:] On Behalf Of Alejandro
> > Aguilar Sierra
> > Sent: Monday, July 23, 2012 4:57 PM
> > To: OpenSceneGraph Users
> > Subject: Re: OpenScenegraph Siggraph 2012 BOF Final Call for
> > Presentations
> >
> > Hello John,
> >
> > I'd like to present a work I have been preparing with one of my
> > undergrads. It is about a simulation of the plate tectonics evolution
> > over the sphere during the geologic eras. Of course it is all over
> > OSG.
> >
> > Is there still a spot in the agenda?
> >
> > Thanks in advance.
> >
> > --
> > Alejandro Sierra
> > National University of Mexico
> >
> >
> > On Mon, Jul 23, 2012 at 1:22 PM, John Richardson

> > <> wrote:
> >
> >
> > > Greetings and Salutations,
> > >
> > >
> > >
> > > There is ONE 15 minute slot left. The DEADLINE is 27 July 2012 to claim
> > >
> > >
> > the
> >
> >
> > > slot. After that I will give the other presenters 5 more minutes or plan
> > >
> >
> a
>
> >
> > > panel at the end. I need to plan the final agenda.
> > >
> > >
> > >
> > > The OpenScenegraph Siggraph 2012 BOF will be held in the Los Angeles
> > > Convention Center on 8 August 2012 at 10AM.
> > >
> > > Highlight your work.
> > > Show off your institution.
> > > Hawk your consulting skills.
> > >
> > > As long as it is OSG related. Step up now and be virtual.
> > >
> > >
> > > John F. Richardson
> > >
> > > _______________________________________________
> > > osg-users mailing list
> > >
> > >
> > >
> >

> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
> > _______________________________________________
> > osg-users mailing list
> >
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
> > _______________________________________________
> > osg-users mailing list
> >

> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
> > ------------------
> > Post generated by Mail2Forum
> >
>
>
> Just thinking up ideas to fill that time.
>
> Did you docket enough time to introduce OSG to Newbes? What it is, what it
> can do, what it's not and what can fill that role?
> What to do you need to install it: In windows, In Linux or In Mac?
>
> Maybe you want to fill in people on add on products Delta 3D that uses OSG?
> or Virtual Planet Builder or osgEarth or the progress OSG on embedded
> systems.
>
> D Glenn
>
> ------------------------
> David Glenn
> ---------------
> D Glenn 3D Computer Graphics &amp; Media Systems.
> www.dglenn.com
>

> ------------------
> Read this topic online here:

> http://forum.openscenegraph.org/viewtopic.php?p=49079#49079
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
>

> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
> _______________________________________________
> osg-users mailing list
>

> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
> ------------------
> Post generated by Mail2Forum

------------------------
David Glenn
---------------
D Glenn 3D Computer Graphics &amp; Media Systems.
www.dglenn.com

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


Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=49095#49095

Art Tevs

unread,
Aug 1, 2012, 8:20:42 AM8/1/12
to osg-...@lists.openscenegraph.org

John Richardson wrote:
> Hello Art,
>
> Will add the announcement to the Into. If you have preferred text for the
> announcement, please send to me.
>
> John F. Richardson
>


Hi John. Would you like to have some slides from me? I'll post you them in the beginning of the next week (would prepare them on the flight).

cheers,
art

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49130#49130

David Glenn

unread,
Aug 10, 2012, 1:51:30 PM8/10/12
to osg-...@lists.openscenegraph.org
Greetings eveyone that attened the OSG BOF for SIGGRAPH 2012

Had a good time at the BOF, look forward to next year.

Thank you!

------------------------
David Glenn
---------------
D Glenn 3D Computer Graphics &amp; Media Systems.
www.dglenn.com

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49227#49227
Reply all
Reply to author
Forward
0 new messages