Using currentGLContext with Carbon and Cocoa

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
Pyrakra
Gnoblar
Posts: 1
Joined: Sat Jul 10, 2010 12:42 am

Using currentGLContext with Carbon and Cocoa

Post by Pyrakra »

I was interested in using SDL as the window manager and having Ogre draw directly to the created window. Upon reading the Ogre documentation it seemed that passing in the parameters “currentGLContext"="true" and "macAPI"="cocoa” (since SDL uses cocoa) when calling createRenderWindow would solve this problem. However, a second window would always get created. Upon delving into the Ogre source code I discovered that the flag currentGLContext never gets checked when creating Carbon or Cocoa windows. The only way to get Ogre to use the window created by SDL would be to use the externalWindowHandle parameter, except that there doesn’t appear to be a way to get a cocoa handle from SDL.

It’s possible this problem has already been addressed, if it has I haven’t seen the solution. In order to solve the problem I modified the OgreOSXCocoaWindow.mm and OgreOSXCarbonWindow.cpp files as follows:

Original OgreOSXCocoaWindow.mm:

Code: Select all

NameValuePairList::const_iterator opt(NULL);
NameValuePairList::const_iterator param_useNSView_pair(NULL);
if(miscParams) {
	opt = miscParams->find("externalWindowHandle");
	param_useNSView_pair = miscParams->find("macAPICocoaUseNSView") ;


}

if(!miscParams || opt == miscParams->end())
{
	...
}
else
{
	...
}
Modified OgreOSXCocoaWindow.mm:

Code: Select all

bool useCurrentGLContext = false;
if(miscParams) {
	NameValuePairList::const_iterator opt = miscParams->find("currentGLContext");
				
	if (opt != miscParams->end())
		useCurrentGLContext = StringConverter::parseBool(opt->second);
}
			
if(!useCurrentGLContext) {
	NameValuePairList::const_iterator opt(NULL);
	NameValuePairList::const_iterator param_useNSView_pair(NULL);
	if(miscParams) {
		opt = miscParams->find("externalWindowHandle");
		param_useNSView_pair = miscParams->find("macAPICocoaUseNSView") ;

					
	}
				
	if(!miscParams || opt == miscParams->end())
	{
		...
	}
	else
	{
		...
	}
}

else
{
	mView = [[NSOpenGLContext currentContext] view];
}
I did the same basic modification in OgreOSXCarbonWindow.cpp except that instead of

Code: Select all

else
{
	mView = [[NSOpenGLContext currentContext] view];
}
I put

Code: Select all

else
{
	mWindow = HIApplicationGetFocus(true);
	mView = HIViewGetRoot(mWindow);
}
I hope this helps anybody who’s wanted a fix for this kind of problem. Note that I’m not 100% sure this will work in all cases. I know for sure that if the Cocoa window is in fullscreen mode when createRenderWindow is called this method will not work.
User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126
Contact:

Re: Using currentGLContext with Carbon and Cocoa

Post by masterfalcon »

The best thing to do would probably clean it up, try to test out every situation that you can think of then submit a patch.
pencilcheck
Kobold
Posts: 38
Joined: Sat Feb 05, 2011 8:08 am

Re: Using currentGLContext with Carbon and Cocoa

Post by pencilcheck »

is this fix submitted yet? Does it work?
User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126
Contact:

Re: Using currentGLContext with Carbon and Cocoa

Post by masterfalcon »

Yeah, it was submitted a while ago. As far as I know, it still works.
guillaumequest
Kobold
Posts: 32
Joined: Thu Aug 11, 2011 10:00 pm

Re: Using currentGLContext with Carbon and Cocoa

Post by guillaumequest »

I think I'm having the same problem : in Windows and Linux everything runs smoothly but on Mac I get two windows (I'm using the Ogre SDK 1.7.3). Do you know if the patch is already in that version ?
User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126
Contact:

Re: Using currentGLContext with Carbon and Cocoa

Post by masterfalcon »

It was probably just committed to the 1.8 branch, but it may have been applied to 1.7 after the 1.7.3 release.
Post Reply