OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Graphics context issues


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
eventhorizon5
Newbie


Joined: 06 Jul 2018
Posts: 6

PostPosted: Mon Jul 09, 2018 7:00 am    Post subject:
Graphics context issues
Reply with 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
Back to top
View user's profile Send private message
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 822

PostPosted: Mon Jul 09, 2018 7:23 am    Post subject:
Graphics context issues
Reply with quote

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
View user's profile Send private message
eventhorizon5
Newbie


Joined: 06 Jul 2018
Posts: 6

PostPosted: Mon Jul 09, 2018 6:37 pm    Post subject:
Re: Graphics context issues
Reply with quote

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
View user's profile Send private message
eventhorizon5
Newbie


Joined: 06 Jul 2018
Posts: 6

PostPosted: Mon Jul 09, 2018 9:13 pm    Post subject:
Reply with 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.

Ryan
Back to top
View user's profile Send private message
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 822

PostPosted: Tue Jul 10, 2018 7:43 am    Post subject:
Graphics context issues
Reply with quote

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
View user's profile Send private message
eventhorizon5
Newbie


Joined: 06 Jul 2018
Posts: 6

PostPosted: Tue Jul 10, 2018 8:38 am    Post subject:
Re: Graphics context issues
Reply with quote

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
View user's profile Send private message
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 822

PostPosted: Tue Jul 10, 2018 10:31 am    Post subject:
Graphics context issues
Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts context IDs andyskinner General 39 Mon Sep 17, 2018 6:13 pm View latest post
No new posts GL profiles issues on Windows Riccardo Corsi General 11 Tue Sep 04, 2018 8:46 pm View latest post
No new posts osgText: two thread-safety issues gwaldron General 1 Tue Jul 31, 2018 2:54 pm View latest post
No new posts Volume rendering issues... tommwilliamson General 4 Wed Jul 25, 2018 12:19 pm View latest post
No new posts osglight demo problems with Intel gra... eventhorizon5 General 2 Mon Jul 09, 2018 8:52 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP