gl_manager_macos_legacy.h 4.1 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. #pragma clang diagnostic push
  39. #pragma clang diagnostic ignored "-Wdeprecated-declarations" // OpenGL is deprecated in macOS 10.14
  40. typedef CGLError (*CGLEnablePtr)(CGLContextObj ctx, CGLContextEnable pname);
  41. typedef CGLError (*CGLSetParameterPtr)(CGLContextObj ctx, CGLContextParameter pname, const GLint *params);
  42. typedef CGLContextObj (*CGLGetCurrentContextPtr)(void);
  43. class GLManagerLegacy_MacOS {
  44. struct GLWindow {
  45. id window_view = nullptr;
  46. NSOpenGLContext *context = nullptr;
  47. };
  48. RBMap<DisplayServer::WindowID, GLWindow> windows;
  49. NSOpenGLContext *shared_context = nullptr;
  50. DisplayServer::WindowID current_window = DisplayServer::INVALID_WINDOW_ID;
  51. Error create_context(GLWindow &win);
  52. bool framework_loaded = false;
  53. bool use_vsync = false;
  54. CGLEnablePtr CGLEnable = nullptr;
  55. CGLSetParameterPtr CGLSetParameter = nullptr;
  56. CGLGetCurrentContextPtr CGLGetCurrentContext = nullptr;
  57. public:
  58. Error window_create(DisplayServer::WindowID p_window_id, id p_view, int p_width, int p_height);
  59. void window_destroy(DisplayServer::WindowID p_window_id);
  60. void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height);
  61. void release_current();
  62. void swap_buffers();
  63. void window_make_current(DisplayServer::WindowID p_window_id);
  64. void window_set_per_pixel_transparency_enabled(DisplayServer::WindowID p_window_id, bool p_enabled);
  65. Error initialize();
  66. void set_use_vsync(bool p_use);
  67. bool is_using_vsync() const;
  68. NSOpenGLContext *get_context(DisplayServer::WindowID p_window_id);
  69. GLManagerLegacy_MacOS();
  70. ~GLManagerLegacy_MacOS();
  71. };
  72. #pragma clang diagnostic push
  73. #endif // MACOS_ENABLED && GLES3_ENABLED