Page 1 of 1

OpenGL context sharing on OSX

Posted: Sat Nov 24, 2012 10:39 am
by hotmultimedia
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

Re: OpenGL context sharing on OSX

Posted: Sat Nov 24, 2012 10:44 am
by masterfalcon
Check out the externalWindowHandle parameter, sounds like that is what you're looking for.

Re: OpenGL context sharing on OSX

Posted: Sat Nov 24, 2012 6:56 pm
by hotmultimedia
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

Re: OpenGL context sharing on OSX

Posted: Sun Nov 25, 2012 2:23 am
by masterfalcon
Yeah, looks like you're right. In fact it seems that only Windows actually implements the externalGLControl and Context.

Re: OpenGL context sharing on OSX

Posted: Mon Nov 26, 2012 12:27 am
by hotmultimedia
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

Re: OpenGL context sharing on OSX

Posted: Mon Nov 26, 2012 1:26 am
by masterfalcon
Could be that the view is not being updated(or rendered to). Check for that and also in the log for any errors.

Re: OpenGL context sharing on OSX

Posted: Mon Nov 26, 2012 9:28 pm
by hotmultimedia
Log doesn't show anything odd. I guess I'm going to have a long read through osx cgl documentation. :(

Re: OpenGL context sharing on OSX

Posted: Thu Oct 19, 2017 4:07 pm
by golgobot
Hey, was anyone able to get this working?

Thanks