CmOSXWindow.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #pragma once
  25. #include <Carbon/Carbon.h>
  26. #include "CmRenderWindow.h"
  27. #include "CmOSXContext.h"
  28. #include <OpenGL/OpenGL.h>
  29. #include <OpenGL/CGLTypes.h>
  30. namespace CamelotEngine
  31. {
  32. class OSXWindow : public RenderWindow
  33. {
  34. public:
  35. OSXWindow();
  36. virtual ~OSXWindow();
  37. /** Overridden - see RenderWindow */
  38. void create( const String& name, unsigned int width, unsigned int height,
  39. bool fullScreen, const NameValuePairList *miscParams ) = 0;
  40. /** Overridden - see RenderWindow */
  41. virtual void destroy( void ) = 0;
  42. /** Overridden - see RenderWindow */
  43. virtual bool isActive( void ) const = 0;
  44. /** Overridden - see RenderWindow */
  45. virtual bool isClosed( void ) const = 0;
  46. /** Overridden - see RenderWindow */
  47. virtual void reposition( int left, int top ) = 0;
  48. /** Overridden - see RenderWindow */
  49. virtual void resize( unsigned int width, unsigned int height ) = 0;
  50. /** Overridden - see RenderWindow */
  51. virtual void swapBuffers( bool waitForVSync ) = 0;
  52. /** Overridden - see RenderTarget */
  53. virtual void copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer);
  54. /** Overridden - see RenderTarget */
  55. virtual void windowMovedOrResized() {};
  56. protected:
  57. OSXContext* mContext;
  58. CGLContextObj mCGLContextObj;
  59. #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  60. CGDisplayModeRef mOriginalDisplayMode;
  61. #else
  62. CFDictionaryRef mOriginalDisplayMode;
  63. #endif
  64. /** Switch to full screen mode using CGL */
  65. void createCGLFullscreen(unsigned int width, unsigned int height, unsigned int depth, unsigned int fsaa, CGLContextObj sharedContext);
  66. /** Kill full screen mode, and return to default windowed mode */
  67. void destroyCGLFullscreen(void);
  68. /** Update the full screen context */
  69. void swapCGLBuffers(void);
  70. #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  71. uint32 bitDepthFromDisplayMode(CGDisplayModeRef mode);
  72. #endif
  73. };
  74. #define ENABLE_CG_CHECK 0
  75. #if ENABLE_CG_CHECK
  76. #define CG_CHECK_ERROR(e) \
  77. { \
  78. if((CGError)e != kCGErrorSuccess) \
  79. { \
  80. CGReleaseAllDisplays(); \
  81. OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, String("CG Error: " + StringConverter::toString(e) + + \
  82. " Line # " + StringConverter::toString(__LINE__)), __PRETTY_FUNCTION__); \
  83. } \
  84. }
  85. #else
  86. #define CG_CHECK_ERROR(e) {}
  87. #endif
  88. #if ENABLE_CG_CHECK
  89. #define CGL_CHECK_ERROR(e) \
  90. { \
  91. if((CGLError)e != kCGLNoError) \
  92. { \
  93. CGReleaseAllDisplays(); \
  94. OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, String("CGL Error: " + String(CGLErrorString(e)) + \
  95. " Line # " + StringConverter::toString(__LINE__)), __PRETTY_FUNCTION__); \
  96. } \
  97. }
  98. #else
  99. #define CGL_CHECK_ERROR(e) {}
  100. #endif
  101. }