context_gl_osx.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*************************************************************************/
  2. /* context_gl_osx.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "context_gl_osx.h"
  30. #ifdef OSX_ENABLED
  31. #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
  32. #include <stdio.h>
  33. #include <unistd.h>
  34. #include <stdlib.h>
  35. #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
  36. #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
  37. void ContextGL_OSX::release_current() {
  38. aglSetCurrentContext( context );
  39. }
  40. void ContextGL_OSX::make_current() {
  41. aglSetCurrentContext( NULL );
  42. }
  43. void ContextGL_OSX::swap_buffers() {
  44. aglSwapBuffers( context );
  45. }
  46. Error ContextGL_OSX::initialize() {
  47. if ( (Ptr) kUnresolvedCFragSymbolAddress == (Ptr) aglChoosePixelFormat )
  48. return FAILED;
  49. GLint attributes[] = { AGL_RGBA,
  50. AGL_DOUBLEBUFFER,
  51. AGL_DEPTH_SIZE, 32,
  52. AGL_NO_RECOVERY,
  53. AGL_NONE,
  54. AGL_NONE };
  55. AGLPixelFormat format = NULL;
  56. format = aglChoosePixelFormat( NULL, 0, attributes );
  57. if ( !format )
  58. return FAILED;
  59. context = aglCreateContext( format, 0 );
  60. if ( !context )
  61. return FAILED;
  62. aglDestroyPixelFormat( format );
  63. aglSetWindowRef( context, window );
  64. GLint swapInterval = 1;
  65. aglSetInteger( context, AGL_SWAP_INTERVAL, &swapInterval );
  66. aglSetCurrentContext( context );
  67. return OK;
  68. }
  69. ContextGL_OSX::ContextGL_OSX(WindowRef p_window) {
  70. window = p_window;
  71. }
  72. ContextGL_OSX::~ContextGL_OSX() {
  73. if (context)
  74. aglDestroyContext(context);
  75. }
  76. #endif
  77. #endif