gl_manager_macos_legacy.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**************************************************************************/
  2. /* gl_manager_macos_legacy.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #if defined(MACOS_ENABLED) && defined(GLES3_ENABLED)
  32. #include "core/os/os.h"
  33. #include "core/templates/local_vector.h"
  34. #include "servers/display_server.h"
  35. #import <AppKit/AppKit.h>
  36. #import <ApplicationServices/ApplicationServices.h>
  37. #import <CoreVideo/CoreVideo.h>
  38. GODOT_CLANG_WARNING_PUSH_AND_IGNORE("-Wdeprecated-declarations") // OpenGL is deprecated in macOS 10.14.
  39. typedef CGLError (*CGLEnablePtr)(CGLContextObj ctx, CGLContextEnable pname);
  40. typedef CGLError (*CGLSetParameterPtr)(CGLContextObj ctx, CGLContextParameter pname, const GLint *params);
  41. typedef CGLContextObj (*CGLGetCurrentContextPtr)(void);
  42. class GLManagerLegacy_MacOS {
  43. struct GLWindow {
  44. id window_view = nullptr;
  45. NSOpenGLContext *context = nullptr;
  46. };
  47. RBMap<DisplayServer::WindowID, GLWindow> windows;
  48. NSOpenGLContext *shared_context = nullptr;
  49. DisplayServer::WindowID current_window = DisplayServer::INVALID_WINDOW_ID;
  50. Error create_context(GLWindow &win);
  51. bool framework_loaded = false;
  52. bool use_vsync = false;
  53. CGLEnablePtr CGLEnable = nullptr;
  54. CGLSetParameterPtr CGLSetParameter = nullptr;
  55. CGLGetCurrentContextPtr CGLGetCurrentContext = nullptr;
  56. public:
  57. Error window_create(DisplayServer::WindowID p_window_id, id p_view, int p_width, int p_height);
  58. void window_destroy(DisplayServer::WindowID p_window_id);
  59. void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height);
  60. void release_current();
  61. void swap_buffers();
  62. void window_make_current(DisplayServer::WindowID p_window_id);
  63. void window_set_per_pixel_transparency_enabled(DisplayServer::WindowID p_window_id, bool p_enabled);
  64. Error initialize();
  65. void set_use_vsync(bool p_use);
  66. bool is_using_vsync() const;
  67. NSOpenGLContext *get_context(DisplayServer::WindowID p_window_id);
  68. GLManagerLegacy_MacOS();
  69. ~GLManagerLegacy_MacOS();
  70. };
  71. GODOT_CLANG_WARNING_PUSH
  72. #endif // MACOS_ENABLED && GLES3_ENABLED