CmOSXCarbonWindow.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. // 64-bit Mac OS X doesn't support Carbon UI API
  25. #ifndef __LP64__
  26. #include "CmOSXCarbonWindow.h"
  27. #include "CmGLRenderSystem.h"
  28. #include "CmWindowEventUtilities.h"
  29. namespace CamelotEngine
  30. {
  31. //-------------------------------------------------------------------------------------------------//
  32. OSXCarbonWindow::OSXCarbonWindow() : mWindow(NULL), mEventHandlerRef(NULL), mView(NULL), mAGLContext(NULL), mAGLPixelFormat(NULL),
  33. mWindowTitle(""), mCGLContext(NULL), mCarbonContext(NULL), mActive(false), mClosed(false), mCreated(false), mHasResized(false),
  34. mIsExternal(false), mVisible(false)
  35. {
  36. mIsFullScreen = false;
  37. mContext = NULL;
  38. mColourDepth = 32;
  39. }
  40. //-------------------------------------------------------------------------------------------------//
  41. OSXCarbonWindow::~OSXCarbonWindow()
  42. {
  43. destroy();
  44. }
  45. //-------------------------------------------------------------------------------------------------//
  46. void OSXCarbonWindow::create( const String& name, unsigned int width, unsigned int height,
  47. bool fullScreen, const NameValuePairList *miscParams )
  48. {
  49. bool hasDepthBuffer = false;
  50. String title = name;
  51. size_t fsaa_samples = 0;
  52. int left = 0;
  53. int top = 0;
  54. int depth = 32;
  55. if( miscParams )
  56. {
  57. NameValuePairList::const_iterator opt(NULL);
  58. // Full screen anti aliasing
  59. opt = miscParams->find( "FSAA" );
  60. if( opt != miscParams->end() )
  61. fsaa_samples = StringConverter::parseUnsignedInt( opt->second );
  62. opt = miscParams->find( "left" );
  63. if( opt != miscParams->end() )
  64. left = StringConverter::parseUnsignedInt( opt->second );
  65. opt = miscParams->find( "top" );
  66. if( opt != miscParams->end() )
  67. top = StringConverter::parseUnsignedInt( opt->second );
  68. opt = miscParams->find( "title" );
  69. if( opt != miscParams->end() )
  70. title = opt->second;
  71. opt = miscParams->find( "depthBuffer" );
  72. if( opt != miscParams->end() )
  73. hasDepthBuffer = StringConverter::parseBool( opt->second );
  74. opt = miscParams->find( "colourDepth" );
  75. if( opt != miscParams->end() )
  76. depth = StringConverter::parseUnsignedInt( opt->second );
  77. opt = miscParams->find( "Full Screen" );
  78. if( opt != miscParams->end() )
  79. fullScreen = StringConverter::parseBool( opt->second );
  80. }
  81. mName = name;
  82. mWidth = width;
  83. mHeight = height;
  84. mColourDepth = depth;
  85. mFSAA = fsaa_samples;
  86. mIsFullScreen = fullScreen;
  87. if(fullScreen)
  88. {
  89. setFullscreen(fullScreen, width, height);
  90. }
  91. else
  92. {
  93. createAGLContext(fsaa_samples, depth);
  94. NameValuePairList::const_iterator opt(NULL);
  95. if(miscParams)
  96. opt = miscParams->find("externalWindowHandle");
  97. if(!miscParams || opt == miscParams->end())
  98. createNewWindow(width, height, title.c_str());
  99. else
  100. createWindowFromExternal((HIViewRef)StringConverter::parseUnsignedLong(opt->second));
  101. // Set the drawable, and current context
  102. // If you do this last, there is a moment before the rendering window pops-up
  103. // This could go once inside each case above, before the window is displayed,
  104. // if desired.
  105. #if defined(MAC_OS_X_VERSION_10_4) && MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
  106. aglSetDrawable(mAGLContext, GetWindowPort(mWindow));
  107. #else
  108. aglSetWindowRef(mAGLContext, mWindow);
  109. #endif
  110. aglSetCurrentContext(mAGLContext);
  111. // Give a copy of our context to the render system
  112. if(!mCarbonContext)
  113. {
  114. mCarbonContext = OGRE_NEW OSXCarbonContext(mAGLContext, mAGLPixelFormat);
  115. mContext = mCarbonContext;
  116. }
  117. }
  118. mActive = true;
  119. mClosed = false;
  120. mCreated = true;
  121. }
  122. void OSXCarbonWindow::createAGLContext(size_t fsaa_samples, int depth)
  123. {
  124. if(!mAGLContext)
  125. {
  126. int i = 0;
  127. GLint attribs[ 20 ];
  128. attribs[ i++ ] = AGL_NO_RECOVERY;
  129. attribs[ i++ ] = GL_TRUE;
  130. attribs[ i++ ] = AGL_ACCELERATED;
  131. attribs[ i++ ] = GL_TRUE;
  132. attribs[ i++ ] = AGL_RGBA;
  133. attribs[ i++ ] = AGL_DOUBLEBUFFER;
  134. attribs[ i++ ] = AGL_ALPHA_SIZE;
  135. attribs[ i++ ] = 8;
  136. attribs[ i++ ] = AGL_STENCIL_SIZE;
  137. attribs[ i++ ] = 8;
  138. attribs[ i++ ] = AGL_DEPTH_SIZE;
  139. attribs[ i++ ] = depth;
  140. if(fsaa_samples > 1)
  141. {
  142. attribs[ i++ ] = AGL_MULTISAMPLE;
  143. attribs[ i++ ] = AGL_SAMPLE_BUFFERS_ARB;
  144. attribs[ i++ ] = 1;
  145. attribs[ i++ ] = AGL_SAMPLES_ARB;
  146. attribs[ i++ ] = fsaa_samples;
  147. }
  148. attribs[ i++ ] = AGL_NONE;
  149. mAGLPixelFormat = aglChoosePixelFormat( NULL, 0, attribs );
  150. if(!mAGLPixelFormat)
  151. {
  152. OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR,
  153. "Unable to create a valid pixel format with selected attributes.",
  154. "OSXCarbonWindow::createAGLContext" );
  155. }
  156. // Create the AGLContext from our pixel format
  157. // Share it with main
  158. GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem());
  159. OSXContext* mainContext = static_cast<OSXContext*>( rs->_getMainContext() );
  160. if(mainContext == 0 || !(mainContext->getContextType() == "AGL"))
  161. {
  162. mAGLContext = aglCreateContext(mAGLPixelFormat, NULL);
  163. }
  164. else
  165. {
  166. OSXCarbonContext* context = static_cast<OSXCarbonContext*>( rs->_getMainContext() );
  167. mAGLContext = aglCreateContext(mAGLPixelFormat, context->getContext());
  168. }
  169. }
  170. }
  171. void OSXCarbonWindow::createNewWindow(unsigned int width, unsigned int height, String title)
  172. {
  173. if(!mWindow)
  174. {
  175. // Create the window rect in global coords
  176. ::Rect windowRect;
  177. windowRect.left = 0;
  178. windowRect.top = 0;
  179. windowRect.right = width;
  180. windowRect.bottom = height;
  181. // Set the default attributes for the window
  182. WindowAttributes windowAttrs = kWindowStandardDocumentAttributes; // default: "resize"
  183. windowAttrs |= kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute | kWindowHideOnFullScreenAttribute | kWindowNoShadowAttribute;
  184. // Create the window
  185. CreateNewWindow(kDocumentWindowClass, windowAttrs, &windowRect, &mWindow);
  186. // Color the window background black
  187. SetThemeWindowBackground(mWindow, kThemeBrushBlack, true);
  188. // Set the title of our window
  189. CFStringRef titleRef = CFStringCreateWithCString( kCFAllocatorDefault, title.c_str(), kCFStringEncodingASCII );
  190. SetWindowTitleWithCFString( mWindow, titleRef );
  191. mWindowTitle = title;
  192. // Center our window on the screen
  193. RepositionWindow( mWindow, NULL, kWindowCenterOnMainScreen );
  194. // Get our view
  195. HIViewFindByID( HIViewGetRoot( mWindow ), kHIViewWindowContentID, &mView );
  196. // Set up our UPP for Window Events
  197. EventTypeSpec eventSpecs[] = {
  198. {kEventClassWindow, kEventWindowActivated},
  199. {kEventClassWindow, kEventWindowDeactivated},
  200. {kEventClassWindow, kEventWindowShown},
  201. {kEventClassWindow, kEventWindowHidden},
  202. {kEventClassWindow, kEventWindowDragCompleted},
  203. {kEventClassWindow, kEventWindowBoundsChanged},
  204. {kEventClassWindow, kEventWindowExpanded},
  205. {kEventClassWindow, kEventWindowCollapsed},
  206. {kEventClassWindow, kEventWindowClosed},
  207. {kEventClassWindow, kEventWindowClose}
  208. };
  209. EventHandlerUPP handlerUPP = NewEventHandlerUPP(WindowEventUtilities::_CarbonWindowHandler);
  210. // Install the standard event handler for the window
  211. EventTargetRef target = GetWindowEventTarget(mWindow);
  212. InstallStandardEventHandler(target);
  213. // We also need to install the WindowEvent Handler, we pass along the window with our requests
  214. InstallEventHandler(target, handlerUPP, 10, eventSpecs, (void*)this, &mEventHandlerRef);
  215. }
  216. HIRect winBounds = CGRectZero;
  217. HIViewRef root = HIViewGetRoot(HIViewGetWindow(mView));
  218. HIViewGetBounds(root, &winBounds);
  219. HIRect viewBounds = CGRectZero;
  220. HIViewGetBounds(mView, &viewBounds);
  221. // Display and select our window
  222. ShowWindow(mWindow);
  223. SelectWindow(mWindow);
  224. // Add our window to the window event listener class
  225. WindowEventUtilities::_addRenderWindow(this);
  226. }
  227. void OSXCarbonWindow::createWindowFromExternal(HIViewRef viewRef)
  228. {
  229. // TODO: The Control is going to report the incorrect location with a
  230. // Metalic / Textured window. The default windows work just fine.
  231. // First get the HIViewRef / ControlRef
  232. mView = viewRef;
  233. mWindow = GetControlOwner(mView);
  234. // Lets try hiding the HIView
  235. //HIViewSetVisible(mView, false);
  236. // Get the rect bounds
  237. ::Rect ctrlBounds;
  238. GetControlBounds(mView, &ctrlBounds);
  239. GLint bufferRect[4];
  240. bufferRect[0] = ctrlBounds.left; // left edge
  241. bufferRect[1] = ctrlBounds.bottom; // bottom edge
  242. bufferRect[2] = ctrlBounds.right - ctrlBounds.left; // width of buffer rect
  243. bufferRect[3] = ctrlBounds.bottom - ctrlBounds.top; // height of buffer rect
  244. aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect);
  245. aglEnable(mAGLContext, AGL_BUFFER_RECT);
  246. mIsExternal = true;
  247. }
  248. //-------------------------------------------------------------------------------------------------//
  249. void OSXCarbonWindow::destroy(void)
  250. {
  251. if(!mCreated)
  252. return;
  253. if(mIsFullScreen)
  254. {
  255. // Handle fullscreen destruction
  256. destroyCGLFullscreen();
  257. }
  258. else
  259. {
  260. // Handle windowed destruction
  261. // Destroy the Ogre context
  262. if(mCGLContext)
  263. {
  264. OGRE_DELETE mCGLContext;
  265. mCGLContext = NULL;
  266. }
  267. if(mCarbonContext)
  268. {
  269. OGRE_DELETE mCarbonContext;
  270. mCarbonContext = NULL;
  271. }
  272. if(mContext)
  273. {
  274. // mContext is a reference to either the AGL or CGL context, already deleted.
  275. // Just clear the variable
  276. mContext = NULL;
  277. }
  278. if(!mIsExternal)
  279. {
  280. // Remove the window from the Window listener
  281. WindowEventUtilities::_removeRenderWindow( this );
  282. // Remove our event handler
  283. if(mEventHandlerRef)
  284. RemoveEventHandler(mEventHandlerRef);
  285. }
  286. if(mAGLContext)
  287. aglDestroyContext(mAGLContext);
  288. if(mWindow)
  289. DisposeWindow(mWindow);
  290. }
  291. mActive = false;
  292. mClosed = true;
  293. mCreated = false;
  294. }
  295. //-------------------------------------------------------------------------------------------------//
  296. bool OSXCarbonWindow::isActive() const
  297. {
  298. return mActive;
  299. }
  300. //-------------------------------------------------------------------------------------------------//
  301. bool OSXCarbonWindow::isClosed() const
  302. {
  303. return mClosed;
  304. }
  305. //-------------------------------------------------------------------------------------------------//
  306. void OSXCarbonWindow::reposition(int left, int top)
  307. {
  308. if(mWindow)
  309. MoveWindow(mWindow, left, top, true);
  310. }
  311. //-------------------------------------------------------------------------------------------------//
  312. void OSXCarbonWindow::resize(unsigned int width, unsigned int height)
  313. {
  314. if(!mWindow)
  315. return;
  316. // Check if the window size really changed
  317. if(mWidth == width && mHeight == height)
  318. return;
  319. mWidth = width;
  320. mHeight = height;
  321. if (mIsExternal)
  322. {
  323. HIRect viewBounds = CGRectZero, winBounds = CGRectZero;
  324. HIViewGetBounds(mView, &viewBounds);
  325. HIViewRef root = HIViewGetRoot(HIViewGetWindow(mView));
  326. HIViewGetBounds(root, &winBounds);
  327. HIViewConvertRect(&viewBounds, mView, root);
  328. mLeft = viewBounds.origin.x;
  329. mTop = winBounds.size.height - (viewBounds.origin.y + viewBounds.size.height);
  330. // Set the AGL buffer rectangle (i.e. the bounds that we will use)
  331. GLint bufferRect[4];
  332. bufferRect[0] = mLeft; // 0 = left edge
  333. bufferRect[1] = mTop; // 0 = bottom edge
  334. bufferRect[2] = mWidth; // width of buffer rect
  335. bufferRect[3] = mHeight; // height of buffer rect
  336. aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect);
  337. for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it)
  338. {
  339. (*it).second->_updateDimensions();
  340. }
  341. }
  342. else
  343. {
  344. SizeWindow(mWindow, width, height, true);
  345. }
  346. }
  347. void OSXCarbonWindow::setVisible( bool visible )
  348. {
  349. mVisible = visible;
  350. if(mIsExternal && !visible) {
  351. GLint bufferRect[4] = {0, 0, 0, 0};
  352. aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect);
  353. }
  354. }
  355. bool OSXCarbonWindow::isVisible( void ) const
  356. {
  357. return mVisible;
  358. }
  359. //-------------------------------------------------------------------------------------------------//
  360. void OSXCarbonWindow::windowHasResized()
  361. {
  362. mHasResized = true;
  363. // Ensure the context is current
  364. if(!mIsFullScreen)
  365. aglSwapBuffers(mAGLContext);
  366. else
  367. swapCGLBuffers();
  368. }
  369. //-------------------------------------------------------------------------------------------------//
  370. void OSXCarbonWindow::windowResized()
  371. {
  372. // Ensure the context is current
  373. if(!mIsFullScreen)
  374. {
  375. // Determine the AGL_BUFFER_RECT for the view. The coordinate
  376. // system for this rectangle is relative to the owning window, with
  377. // the origin at the bottom left corner and the y-axis inverted.
  378. HIRect newFrame = CGRectMake(mLeft, mTop+22, mWidth, mHeight);
  379. HIRect viewBounds = CGRectZero, winBounds = CGRectZero;
  380. SizeWindow(mWindow, mWidth, mHeight, true);
  381. HIViewSetFrame(mView, &newFrame);
  382. HIViewGetBounds(mView, &viewBounds);
  383. HIViewRef root = HIViewGetRoot(HIViewGetWindow(mView));
  384. HIViewGetBounds(root, &winBounds);
  385. HIViewConvertRect(&viewBounds, mView, root);
  386. // Set the AGL buffer rectangle (i.e. the bounds that we will use)
  387. GLint bufferRect[4];
  388. bufferRect[0] = viewBounds.origin.x; // 0 = left edge
  389. bufferRect[1] = winBounds.size.height - (viewBounds.origin.y + viewBounds.size.height); // 0 = bottom edge
  390. bufferRect[2] = viewBounds.size.width; // width of buffer rect
  391. bufferRect[3] = viewBounds.size.height; // height of buffer rect
  392. aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect);
  393. aglEnable(mAGLContext, AGL_BUFFER_RECT);
  394. aglUpdateContext(mAGLContext);
  395. mLeft = viewBounds.origin.x;
  396. mTop = bufferRect[1];
  397. }
  398. else
  399. {
  400. swapCGLBuffers();
  401. }
  402. for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it)
  403. {
  404. (*it).second->_updateDimensions();
  405. }
  406. }
  407. //-------------------------------------------------------------------------------------------------//
  408. void OSXCarbonWindow::windowMovedOrResized()
  409. {
  410. // External windows will call this method.
  411. if(mView != NULL)
  412. {
  413. // Determine the AGL_BUFFER_RECT for the view. The coordinate
  414. // system for this rectangle is relative to the owning window, with
  415. // the origin at the bottom left corner and the y-axis inverted.
  416. // Also, when leaving fullscreen, the display properties are not guaranteed to be
  417. // the same as when we were windowed previously. So resize the window and views back
  418. // to their original dimensions.
  419. HIRect newFrame = CGRectMake(mLeft, mTop+22, mWidth, mHeight);
  420. HIRect viewBounds = CGRectZero, winBounds = CGRectZero;
  421. SizeWindow(mWindow, mWidth, mHeight, true);
  422. HIViewSetFrame(mView, &newFrame);
  423. HIViewGetBounds(mView, &viewBounds);
  424. HIViewRef root = HIViewGetRoot(HIViewGetWindow(mView));
  425. HIViewGetBounds(root, &winBounds);
  426. HIViewConvertRect(&viewBounds, mView, root);
  427. // Set the AGL buffer rectangle (i.e. the bounds that we will use)
  428. GLint bufferRect[4];
  429. bufferRect[0] = viewBounds.origin.x; // 0 = left edge
  430. bufferRect[1] = winBounds.size.height - (viewBounds.origin.y + viewBounds.size.height); // 0 = bottom edge
  431. bufferRect[2] = viewBounds.size.width; // width of buffer rect
  432. bufferRect[3] = viewBounds.size.height; // height of buffer rect
  433. aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect);
  434. aglEnable(mAGLContext, AGL_BUFFER_RECT);
  435. aglUpdateContext(mAGLContext);
  436. mLeft = viewBounds.origin.x;
  437. mTop = bufferRect[1];
  438. }
  439. for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it)
  440. {
  441. (*it).second->_updateDimensions();
  442. }
  443. }
  444. //-------------------------------------------------------------------------------------------------//
  445. void OSXCarbonWindow::swapBuffers( bool waitForVSync )
  446. {
  447. if(!mIsFullScreen)
  448. {
  449. if(mAGLContext != aglGetCurrentContext())
  450. aglSetCurrentContext(mAGLContext);
  451. aglSwapBuffers(mAGLContext);
  452. }
  453. else
  454. {
  455. swapCGLBuffers();
  456. }
  457. if(mHasResized)
  458. {
  459. windowResized();
  460. mHasResized = false;
  461. }
  462. }
  463. //-------------------------------------------------------------------------------------------------//
  464. void OSXCarbonWindow::getCustomAttribute( const String& name, void* pData )
  465. {
  466. if( name == "GLCONTEXT" )
  467. {
  468. *static_cast<OSXContext**>(pData) = mContext;
  469. return;
  470. }
  471. else if( name == "WINDOW" )
  472. {
  473. if(mIsFullScreen)
  474. {
  475. // A fullscreen application uses CGL and thus has no window.
  476. pData = 0;
  477. return;
  478. }
  479. else
  480. {
  481. *static_cast<WindowRef*>(pData) = mWindow;
  482. }
  483. return;
  484. }
  485. }
  486. void OSXCarbonWindow::setFullscreen(bool fullScreen, unsigned int width, unsigned int height)
  487. {
  488. if (mIsFullScreen != fullScreen || width != mWidth || height != mHeight)
  489. {
  490. // Set the full screen flag
  491. mIsFullScreen = fullScreen;
  492. createAGLContext(mFSAA, mColourDepth);
  493. if (mIsFullScreen)
  494. {
  495. GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem());
  496. CGLContextObj share = NULL;
  497. aglGetCGLContext(mAGLContext, (void**)&share);
  498. // Create the CGL context object if it doesn't already exist, sharing the AGL context.
  499. if(!mCGLContext)
  500. {
  501. void *cglPixFormat;
  502. aglGetCGLPixelFormat(mAGLPixelFormat, (void **)&cglPixFormat);
  503. mCGLContext = OGRE_NEW OSXCGLContext(mCGLContextObj, (CGLPixelFormatObj) cglPixFormat);
  504. }
  505. // Create the context, keeping the current colour depth and FSAA settings
  506. createCGLFullscreen(width, height, getColourDepth(), getFSAA(), share);
  507. rs->_switchContext(mContext);
  508. // Hide the Carbon window
  509. HideWindow(mWindow);
  510. // And tell the rendersystem to stop rendering to it too
  511. WindowEventUtilities::_removeRenderWindow(this);
  512. }
  513. else
  514. {
  515. // Create a new AGL context and pixel format if necessary
  516. createAGLContext(mFSAA, mColourDepth);
  517. // Create a window if we haven't already, existence check is done within the functions
  518. if(!mWindow)
  519. {
  520. if(mIsExternal)
  521. createWindowFromExternal(mView);
  522. else
  523. createNewWindow(width, height, mWindowTitle);
  524. }
  525. // Destroy the current CGL context, we will create a new one when/if we go back to full screen
  526. destroyCGLFullscreen();
  527. // Set the drawable, and current context
  528. // If you do this last, there is a moment before the rendering window pops-up
  529. #if defined(MAC_OS_X_VERSION_10_4) && MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
  530. aglSetDrawable(mAGLContext, GetWindowPort(mWindow));
  531. #else
  532. aglSetWindowRef(mAGLContext, mWindow);
  533. #endif
  534. aglSetCurrentContext(mAGLContext);
  535. if(!mCarbonContext)
  536. {
  537. mCarbonContext = OGRE_NEW OSXCarbonContext(mAGLContext, mAGLPixelFormat);
  538. }
  539. GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem());
  540. mContext = mCarbonContext;
  541. rs->_switchContext(mContext);
  542. WindowEventUtilities::_addRenderWindow(this);
  543. ShowWindow(mWindow);
  544. SelectWindow(mWindow);
  545. RepositionWindow(mWindow, NULL, kWindowCenterOnMainScreen);
  546. }
  547. mWidth = width;
  548. mHeight = height;
  549. }
  550. }
  551. }
  552. #endif // __LP64__