OpenGL context sharing on OSX

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
hotmultimedia
Gnoblar
Posts: 5
Joined: Sat Nov 24, 2012 12:50 am

OpenGL context sharing on OSX

Post by hotmultimedia » Sat Nov 24, 2012 10:39 am

Hello everybody!

Basically I have QT5 scene graph and Ogre 1.8, both running on OSX.
The idea is to get Ogre initialized so that it uses the window and GL context created by QT,
and Ogre would just render it's output to a texture.
This texture would be then composited with the QT5 scene graph system.

What I have gathered, the window creation is always mandatory to get some internal structures
initialized, even if I just want to render to texture in existing context. (qmlogre example)
I also see that on OSX, the OpenGL backend doesn't even support "externalGLControl" or "externalGLContext" settings,
which makes me wonder if this is even possible to do on OSX without hacking the Ogre itself?

I have been tinkering for few days to get them working together, but as I have not found a real
solution, I thought I should ask here. I'd would be very nice if you could share your thoughts on the topic.

BR,
Markus
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: OpenGL context sharing on OSX

Post by masterfalcon » Sat Nov 24, 2012 10:44 am

Check out the externalWindowHandle parameter, sounds like that is what you're looking for.
0 x

hotmultimedia
Gnoblar
Posts: 5
Joined: Sat Nov 24, 2012 12:50 am

Re: OpenGL context sharing on OSX

Post by hotmultimedia » Sat Nov 24, 2012 6:56 pm

masterfalcon wrote:Check out the externalWindowHandle parameter, sounds like that is what you're looking for.
It seems that a new GL context is initialized no matter what. ExternalWindowHandle seems to just set the NSView for the newly created context, but doesn't prevent the creation.

In OgreOSXCocoaWindow.mm there's:

Code: Select all

glContext = [[NSOpenGLContext alloc] initWithFormat: openglFormat shareContext:shareContext];
Then there's a check for ExternalWindowHandle, which is used as mView, and finally

Code: Select all

[glContext setView:mView];
And that's it basically.

Or I'm I overlooking something here?

BR,
Markus
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: OpenGL context sharing on OSX

Post by masterfalcon » Sun Nov 25, 2012 2:23 am

Yeah, looks like you're right. In fact it seems that only Windows actually implements the externalGLControl and Context.
0 x

hotmultimedia
Gnoblar
Posts: 5
Joined: Sat Nov 24, 2012 12:50 am

Re: OpenGL context sharing on OSX

Post by hotmultimedia » Mon Nov 26, 2012 12:27 am

Hmm. I hacked ogre's CreateRenderWindow a bit, so it now accepts ExternalGLContext -parameter. This is basically NSOpenGLContext*, which (if supplied) skips this line, and uses the given context instead.

Code: Select all

            mGLContext = [[NSOpenGLContext alloc] initWithFormat:mGLPixelFormat shareContext:shareContext];
I have confirmed with XCode OpenGL profiler, that the QT's context is now being used. The problem is that result is still the same. QT window becomes just a white window. (which "works" but I can't see anything)
I'm guessing there's some other initialization going on, which I need to suppress. (pixel format changing maybe)
I'm also starting wonder if there's some completely other mechanism to get ogre in RTT mode. (no window, just rendering to a texture)

Could you point me into direction please?

BR,
Markus
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: OpenGL context sharing on OSX

Post by masterfalcon » Mon Nov 26, 2012 1:26 am

Could be that the view is not being updated(or rendered to). Check for that and also in the log for any errors.
0 x

hotmultimedia
Gnoblar
Posts: 5
Joined: Sat Nov 24, 2012 12:50 am

Re: OpenGL context sharing on OSX

Post by hotmultimedia » Mon Nov 26, 2012 9:28 pm

Log doesn't show anything odd. I guess I'm going to have a long read through osx cgl documentation. :(
0 x

golgobot
Gnoblar
Posts: 18
Joined: Tue Oct 03, 2017 11:26 pm

Re: OpenGL context sharing on OSX

Post by golgobot » Thu Oct 19, 2017 4:07 pm

Hey, was anyone able to get this working?

Thanks
0 x

Post Reply