Discussion:
[osg-users] Graphics context issues
Ryan Thoryk
2018-07-09 07:00:14 UTC
Permalink
Hi,

I'm trying to query GL parameters such as GL_VENDOR, which require an active graphics context to work. I looked another thread on this forum which explains how to do it, but it only works for a single-threaded viewer. I'm running the viewer in multithreaded mode, and am getting crashes due to context issues. Does anyone have an idea on how to do this?
Thanks

Example code. Usually crashes at the makeCurrent() line:

Code:

//get renderer information
osgViewer::ViewerBase::Contexts contexts;
viewer->getContexts(contexts, true);
contexts[0]->makeCurrent();
std::string vendor = (const char*)glGetString(GL_VENDOR);
Report("Vendor: " + vendor);
contexts[0]->releaseContext();




Ryan

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74276#74276
Sebastian Messerschmidt
2018-07-09 07:23:12 UTC
Permalink
Hi Ryan,

I guess your interfering with the currently set context. You're not
explaining where/when you call your snippet, but usually this would be
done inside a "realizeOperation".

A small example operation:

<code>
class TestSupportOperation: public osg::GraphicsOperation
{
public:

TestSupportOperation()
: osg::GraphicsOperation("TestSupportOperation",false){}

virtual void operator () (osg::GraphicsContext* gc)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
unsigned int contextID = gc->getState()->getContextID();

osg::GLExtensions* glext = osg::GLExtensions::Get(contextID, true);
if (!glext->isOpenGL20Supported)
{
std::cerr << No 2.0++ suppport available\n";
}
}
OpenThreads::Mutex mMutex;
};
</code>

In your viewer you simply add:

viewer->setRealizeOperation(new TestSupportOperation);


Hope that helps,
Sebastian
Post by Ryan Thoryk
Hi,
I'm trying to query GL parameters such as GL_VENDOR, which require an active graphics context to work. I looked another thread on this forum which explains how to do it, but it only works for a single-threaded viewer. I'm running the viewer in multithreaded mode, and am getting crashes due to context issues. Does anyone have an idea on how to do this?
Thanks
//get renderer information
osgViewer::ViewerBase::Contexts contexts;
viewer->getContexts(contexts, true);
contexts[0]->makeCurrent();
std::string vendor = (const char*)glGetString(GL_VENDOR);
Report("Vendor: " + vendor);
contexts[0]->releaseContext();
Ryan
------------------
http://forum.openscenegraph.org/viewtopic.php?p=74276#74276
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Ryan Thoryk
2018-07-09 18:37:47 UTC
Permalink
Post by Sebastian Messerschmidt
I guess your interfering with the currently set context. You're not
explaining where/when you call your snippet, but usually this would be
done inside a "realizeOperation".
I'll try your code. I was doing the code snippet right after a "viewer->realize()" call.

Ryan

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74292#74292
Ryan Thoryk
2018-07-09 21:13:30 UTC
Permalink
Your code works when my laptop is using Intel graphics, but when I switch to Nvidia graphics, the glGetString calls fail for some reason (maybe the GL context isn't switching?). Strange.
Switching the whole app to single-threaded works for both.

Ryan

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74297#74297
Sebastian Messerschmidt
2018-07-10 07:42:42 UTC
Permalink
Hi Ryan,
Post by Ryan Thoryk
Your code works when my laptop is using Intel graphics, but when I switch to Nvidia graphics, the glGetString calls fail for some reason (maybe the GL context isn't switching?). Strange.
Switching the whole app to single-threaded works for both.
That's indeed strange. The snippet I provided might not do all the
necessary checks however. I use a similar piece of code in my projects
to ensure compatibility and it worked on a wide range of GPU/driver
combinations at least on Windows and Mac-Platforms.

Can you create a minimal _compilable_ example, so more people might
check what is wrong?

Cheers
Sebastian
Post by Ryan Thoryk
Ryan
------------------
http://forum.openscenegraph.org/viewtopic.php?p=74297#74297
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Ryan Thoryk
2018-07-10 08:39:04 UTC
Permalink
Post by Sebastian Messerschmidt
Hi Ryan,
Can you create a minimal _compilable_ example, so more people might
check what is wrong?
Sure - I've attached an osglight-derived example. Compile with:

Code:

g++ -o osglight osglight.cpp -losg -lOpenThreads -lGL -losgUtil -losgViewer -losgDB




Ryan
[/code]

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




Attachments:
http://forum.openscenegraph.org//files/osglight_161.cpp
Sebastian Messerschmidt
2018-07-10 10:30:42 UTC
Permalink
Windows tells me:

Screen 0:
Windows Error #170: [Screen #0]
GraphicsWindowWin32::makeCurrentImplementation() - Unable to set current
OpenGL rendering context. Reason: The requested resource is in use.

If I move your code into the callback it displays the correct
information however. Tested on Windows7:

Vendor: NVIDIA Corporation
Renderer: GeForce GTX TITAN Black/PCIe/SSE2
GL Version: 4.5.0 NVIDIA 372.90


Tested on Windows 10 (Nvidia Optimus) as well. The output in the console
is fine, but I see invalid rendering too.
Intel drivers aren't known to be a good reference for OpenGL
implementations, so I'd stick to Robert's advice and go for a
shader-based approach.

Cheers
Sebastian
Post by Ryan Thoryk
Post by Sebastian Messerschmidt
Hi Ryan,
Can you create a minimal _compilable_ example, so more people might
check what is wrong?
g++ -o osglight osglight.cpp -losg -lOpenThreads -lGL -losgUtil -losgViewer -losgDB
Ryan
[/code]
------------------
http://forum.openscenegraph.org/viewtopic.php?p=74301#74301
http://forum.openscenegraph.org//files/osglight_161.cpp
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Continue reading on narkive:
Loading...