Hi Jeremy, nice to see you back writing graphics code!

In the past, when I've needed to have a contextID in a custom Drawable, I've always gotten it from inside my drawable's drawImplementation. IIRC it gets a State pointer and this contains a valid contextID. Same when I've needed to create a custom StateAttribute or something, in its apply() method it gets a State pointer with a valid contextID or something like that.

So you can have a scheme where you defer doing any initialization until your first Drawable / StateAttribute needs to be traversed for actual rendering, and then you get a valid contextID, do your initialization and further ones will use that since initialization has been done already.

You need to make sure you consider the case where your Drawable / StateAttribute will be used in multiple contexts. IIRC OSG uses the BufferedValue to store resources associated with a context, and I used the same pattern. Again IIRC, there were some order of initialization issues where I assumed some initialization had been done for a context before drawing but it hadn't, but that just involved a bit of pretty simple debugging to get fixed.

Hope this helps,

J-S


On 20/08/2012 12:48 PM, Jeremy Moles wrote:
On Mon, 2012-08-20 at 10:44 -0600, Paul Martz wrote:
What you seem to be saying is that you want to set some OpenGL state once that
applies to all contexts, and not have to set it every frame. AND, you don't want
to have to add, then remove, a Camera draw callback just to make this happen).
Is that a good synopsis of the issue?
It's close; I don't actually mind using a Camera draw callback for this
purpose if it's appropriate.

A real summarizing question is: under what conditions is it "safe" to
query for support of a particular extension? And what is the preferred
API for either fetching or being provided the contextID with which to do
this?

You could keep a bool buffered_value that tells you whether or not you've set
the initial/global state for that particular context. Initially false, then set
the global state for a context and flip it to true. Would something like that 
help?
     -Paul
Certainly, but I'm still stuck on actually SETTING the state in the
first place. :)

On 8/20/2012 10:27 AM, Jeremy Moles wrote:
Hello everyone! I have a bit of a strange question here, so please bear
with me. I'll try to be as descriptive as I possibly can, though I'm
certain I will misuse some terminology.

I am adding support for the NV_path_rendering extension to
OpenSceneGraph. This extension adds a number of new functions to OpenGL
when using an NVidia card which take on the form:

        glPath{_function_}NV

http://osgnvpr.googlecode.com

In order to create pointers to these new extension functions, I create
an Extensions object in OSG using the contextID given to me during the
compileGLObjects method of my overridden Drawable class. This works
fine, and the code is running as I expect.

https://code.google.com/p/osgnvpr/source/browse/trunk/src/PathCommands.cpp#45

HOWEVER, this paradigm really only works when I need to call extension
functions associated with an instance (or instances) of my Drawable.
There are other functions in the NV_path_rendering API that simply set
global state, and it is with these functions that I'm having difficulty.

The biggest problem here is that in order to get a pointer to the
Extensions static object, I need a valid GraphicsContext contextID.
However, I've tried a number of methods to obtain one of these, but
every attempt I make actually breaks the entire codebase. I wish I could
explain it better than that...

For example, if I try to use some code like the following:

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

Windows windows;

viewer.getWindows(window);

cID = windows[0]->getState()->getContextID();

osgNVPR::getNVPRExtensions(cID);

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

...then I seem to get an invalid contextID and all subsequent attempts
to use that contextID (even by OSG itself) won't work. The entire
rendering process seems to be broken in this manner.

If instead I create a Camera::DrawCallback object and use the RenderInfo
there instead, then everything works fine. However, I feel like I'm
grossly misusing a Camera::DrawCallback just to set and unset state...

My question is: if I need to set global state like this once, somewhere
high in the scenegraph, what is the best way--keeping in mind that I
also need a valid contextID in order to access my Extensions functions
per-context?

Thanks!

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


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

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



--
______________________________________________________
Jean-Sebastien Guay              jean_...@videotron.ca
                    http://whitestar02.dyndns-web.com/

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

Reply via email to