View previous topic :: View next topic |
|
Author |
Message |
eventhorizon5 Newbie
Joined: 06 Jul 2018 Posts: 6
|
Posted: Mon Jul 09, 2018 7:00 am Post subject: Graphics context issues |
|
|
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 |
|
Back to top |
|
 |
SMesserschmidt (Sebastian Messerschmidt) Forum Moderator
Joined: 10 Sep 2013 Posts: 824
|
Posted: Mon Jul 09, 2018 7:23 am Post subject: Graphics context issues |
|
|
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
Quote:
|
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
|
------------------
Post generated by Mail2Forum |
|
Back to top |
|
 |
eventhorizon5 Newbie
Joined: 06 Jul 2018 Posts: 6
|
Posted: Mon Jul 09, 2018 6:37 pm Post subject: Re: Graphics context issues |
|
|
SMesserschmidt wrote:
|
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 |
|
Back to top |
|
 |
eventhorizon5 Newbie
Joined: 06 Jul 2018 Posts: 6
|
Posted: Mon Jul 09, 2018 9:13 pm Post subject: |
|
|
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 |
|
Back to top |
|
 |
SMesserschmidt (Sebastian Messerschmidt) Forum Moderator
Joined: 10 Sep 2013 Posts: 824
|
Posted: Tue Jul 10, 2018 7:43 am Post subject: Graphics context issues |
|
|
Hi Ryan,
Quote:
|
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
Quote:
|
Ryan
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74297#74297
|
------------------
Post generated by Mail2Forum |
|
Back to top |
|
 |
eventhorizon5 Newbie
Joined: 06 Jul 2018 Posts: 6
|
Posted: Tue Jul 10, 2018 8:38 am Post subject: Re: Graphics context issues |
|
|
SMesserschmidt wrote:
|
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 |
|
Back to top |
|
 |
SMesserschmidt (Sebastian Messerschmidt) Forum Moderator
Joined: 10 Sep 2013 Posts: 824
|
Posted: Tue Jul 10, 2018 10:31 am Post subject: Graphics context issues |
|
|
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
Am 10.07.2018 um 10:39 schrieb Ryan Thoryk:
Quote:
|
SMesserschmidt wrote:
Quote:
|
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
|
------------------
Post generated by Mail2Forum |
|
Back to top |
|
 |
|