[osg-users] Multiple shared contexts VBO

117 views
Skip to first unread message

Filip Arlet

unread,
Jul 10, 2014, 11:11:09 AM7/10/14
to osg-...@lists.openscenegraph.org
Hi,

I have on big VBO rendered in multiple windows and osg (v 3.0.1) creates new glBuffers for each, not shares them. I thought when two contexts are shared, I dont need to recreate VBO again. Its a feature ? What can I do about it ? Its posible to use osg with one context and multiple windows (same pixel format) ?

Thank you!

Cheers,
Filip

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





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

Trajce Nikolov NICK

unread,
Jul 10, 2014, 4:30:40 PM7/10/14
to OpenSceneGraph Users
Ahoj Filip,

yes, you can have shared context among viewers. Have a look at osg::GraphicsContext::Traits, there is a sharedContext member you can set. osgcompositeviewer example shows you how to set up a viewer from traits

Nick
--
trajce nikolov nick

Filip Arlet

unread,
Jul 11, 2014, 1:55:23 AM7/11/14
to osg-...@lists.openscenegraph.org
Hi,
I know that, but when I debug my app, render will call getOrCreateGLBufferObject() with new contextID without knowledge of sharing context and creates new VBO.

Thank you!

Cheers,
Filip

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

Trajce Nikolov NICK

unread,
Jul 11, 2014, 3:03:47 AM7/11/14
to OpenSceneGraph Users
I know I solved this in MDI application somehow. My grep on _contextID found me this if it helps

 /** Set the current OpenGL context uniqueID.
         *  The ContextID is used by classes like osg::StateAttribute's and osg::Drawable's to
         *  help manage seperate OpenGL objects, such as display lists, vertex buffer objects
         *  and texture object for each graphics context. The ContextID simply acts as an index
         *  into arrays that these classes maintain for the purpose of storing GL object handles.
         *
         *  Note, osgViewer::GraphicsWindow will automatically set up the ContextID for you,
         *  so you will rearely need to set this yourself.
         *
         *  The exception is when creating your own graphics context, where you should set
         *  the ContextID uniquely for each graphics context.
         *
         *  Typical settings for ContextID are 0,1,2,3... up to the maximum
         *  number of graphics contexts you have set up. By default contextID is 0.
         */
        inline void setContextID(unsigned int contextID) { _contextID=contextID; }

in State (header)

Nick
--
trajce nikolov nick

Trajce Nikolov NICK

unread,
Jul 11, 2014, 3:14:06 AM7/11/14
to OpenSceneGraph Users
further, in GraphicsWindow (header) 

void init()
        {
            if (valid())
            {
                setState( new osg::State );
                getState()->setGraphicsContext(this);

                if (_traits.valid() && _traits->sharedContext.valid())
                {
                    getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
                    incrementContextIDUsageCount( getState()->getContextID() );
                }
                else
                {
                    getState()->setContextID( osg::GraphicsContext::createNewContextID() );
                }
            }
        }

Nick
--
trajce nikolov nick

Filip Arlet

unread,
Jul 11, 2014, 7:45:14 AM7/11/14
to osg-...@lists.openscenegraph.org
Hi,

Thank you! But I hope it wont break any other part of OSG that cant be shared between contexts.

Cheers,
Filip

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

Trajce Nikolov NICK

unread,
Jul 11, 2014, 8:02:28 AM7/11/14
to OpenSceneGraph Users
you have to try. I was thinking about your problem and maybe I will achieve it in a way where I create the GL objects myself - you specify the contextID to which against your are creating your object and set it for further use. Have a look at these calls:

void setGLBufferObject(unsigned int contextID, GLBufferObject* glbo) { _glBufferObjects[contextID] = glbo; }

in BufferObject (header)

Nick
--
trajce nikolov nick

Robert Osfield

unread,
Jul 14, 2014, 5:13:34 AM7/14/14
to OpenSceneGraph Users
Hi Flilip,

If the shared contexts are set up correctly then the ContextID will be automatically shared for you (see the GraphicsWindowWin32::GraphicsWindowWin32(Traits*) constructor in OpenSceneGraph/src/osgViewer/GraphicsWindowWin32.cpp for an example of how it manages the ContextID).  If you do use shared contexts you'll need to avoid having multi-threading as the OSG doesn't provide any low level mutexing of OpenGL objects to allow multi-threading of shared contexts - such support would be very costly for performance.

Robert.

Filip Arlet

unread,
Jul 17, 2014, 6:44:04 AM7/17/14
to osg-...@lists.openscenegraph.org
Hi,

It was Qt<->osg problem. I wanted to use my custom QGLWidget using GraphicsWindowQt::GraphicsWindowQt( GLWidget* widget ). Sharing is not possible, because it creates its own traits in function GraphicsWindowQt::createTraits( const QGLWidget* widget ). And then passes it into GraphicsWindowQt::init(...) function. There is no way you can setup shared context this way, you can only set contextID after creation and remove new contextID. Also if you use GraphicsWindowQt::GraphicsWindowQt( osg::GraphicsContext::Traits* traits, QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f ) you HAVE to use traits variable sharedContext and shareWidget is not mandatory, it can be computed in GraphicsWindowQt::init(...) function.

And i found another problem: if I change layout in Qt app -> move gl widget somewhere else, Qt will make another context. So I need to call state->reset() or vertex arrays stop working (they are disabled by default).

It works now (althought i had to ged rid of my custom QGLWidget with reimplemented sizeHint()). But I have another problem. In that app (MDI application) if I close one window with shared contexts, it will call GLBufferObject::deleteAllBufferObjects(unsigned int contextID) and I DO NOT want to delete shared objets. What can I do ?


Thank you!

Cheers,
Filip

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