gl_manager_macos_legacy.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #ifndef GL_MANAGER_MACOS_LEGACY_H
  31. #define GL_MANAGER_MACOS_LEGACY_H
  32. #if defined(MACOS_ENABLED) && defined(GLES3_ENABLED)
  33. #include "core/error/error_list.h"
  34. #include "core/os/os.h"
  35. #include "core/templates/local_vector.h"
  36. #include "servers/display_server.h"
  37. #import <AppKit/AppKit.h>
  38. #import <ApplicationServices/ApplicationServices.h>
  39. #import <CoreVideo/CoreVideo.h>
  40. #pragma clang diagnostic push
  41. #pragma clang diagnostic ignored "-Wdeprecated-declarations" // OpenGL is deprecated in macOS 10.14
  42. class GLManager_MacOS {
  43. public:
  44. enum ContextType {
  45. GLES_3_0_COMPATIBLE,
  46. };
  47. private:
  48. struct GLWindow {
  49. int width = 0;
  50. int height = 0;
  51. id window_view = nullptr;
  52. NSOpenGLContext *context = nullptr;
  53. };
  54. RBMap<DisplayServer::WindowID, GLWindow> windows;
  55. NSOpenGLContext *shared_context = nullptr;
  56. DisplayServer::WindowID current_window = DisplayServer::INVALID_WINDOW_ID;
  57. Error create_context(GLWindow &win);
  58. bool use_vsync = false;
  59. ContextType context_type;
  60. public:
  61. Error window_create(DisplayServer::WindowID p_window_id, id p_view, int p_width, int p_height);
  62. void window_destroy(DisplayServer::WindowID p_window_id);
  63. void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height);
  64. int window_get_width(DisplayServer::WindowID p_window_id = 0);
  65. int window_get_height(DisplayServer::WindowID p_window_id = 0);
  66. void release_current();
  67. void make_current();
  68. void swap_buffers();
  69. void window_make_current(DisplayServer::WindowID p_window_id);
  70. void window_update(DisplayServer::WindowID p_window_id);
  71. void window_set_per_pixel_transparency_enabled(DisplayServer::WindowID p_window_id, bool p_enabled);
  72. Error initialize();
  73. void set_use_vsync(bool p_use);
  74. bool is_using_vsync() const;
  75. NSOpenGLContext *get_context(DisplayServer::WindowID p_window_id);
  76. GLManager_MacOS(ContextType p_context_type);
  77. ~GLManager_MacOS();
  78. };
  79. #pragma clang diagnostic push
  80. #endif // MACOS_ENABLED && GLES3_ENABLED
  81. #endif // GL_MANAGER_MACOS_LEGACY_H