gl_manager_windows.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*************************************************************************/
  2. /* gl_manager_windows.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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_WINDOWS_H
  31. #define GL_MANAGER_WINDOWS_H
  32. #if defined(WINDOWS_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. #include <windows.h>
  38. typedef bool(APIENTRY *PFNWGLSWAPINTERVALEXTPROC)(int interval);
  39. typedef int(APIENTRY *PFNWGLGETSWAPINTERVALEXTPROC)(void);
  40. class GLManager_Windows {
  41. public:
  42. enum ContextType {
  43. GLES_3_0_COMPATIBLE,
  44. };
  45. private:
  46. // any data specific to the window
  47. struct GLWindow {
  48. GLWindow() { in_use = false; }
  49. bool in_use;
  50. // the external ID .. should match the GL window number .. unused I think
  51. DisplayServer::WindowID window_id;
  52. int width;
  53. int height;
  54. // windows specific
  55. HDC hDC;
  56. HWND hwnd;
  57. int gldisplay_id;
  58. };
  59. struct GLDisplay {
  60. // windows specific
  61. HGLRC hRC;
  62. };
  63. LocalVector<GLWindow> _windows;
  64. LocalVector<GLDisplay> _displays;
  65. GLWindow *_current_window;
  66. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
  67. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT;
  68. // funcs
  69. void _internal_set_current_window(GLWindow *p_win);
  70. GLWindow &get_window(unsigned int id) { return _windows[id]; }
  71. const GLWindow &get_window(unsigned int id) const { return _windows[id]; }
  72. const GLDisplay &get_current_display() const { return _displays[_current_window->gldisplay_id]; }
  73. const GLDisplay &get_display(unsigned int id) { return _displays[id]; }
  74. bool direct_render;
  75. int glx_minor, glx_major;
  76. bool use_vsync;
  77. ContextType context_type;
  78. private:
  79. int _find_or_create_display(GLWindow &win);
  80. Error _create_context(GLWindow &win, GLDisplay &gl_display);
  81. public:
  82. Error window_create(DisplayServer::WindowID p_window_id, HWND p_hwnd, HINSTANCE p_hinstance, int p_width, int p_height);
  83. void window_destroy(DisplayServer::WindowID p_window_id);
  84. void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height);
  85. // get directly from the cached GLWindow
  86. int window_get_width(DisplayServer::WindowID p_window_id = 0);
  87. int window_get_height(DisplayServer::WindowID p_window_id = 0);
  88. void release_current();
  89. void make_current();
  90. void swap_buffers();
  91. void window_make_current(DisplayServer::WindowID p_window_id);
  92. Error initialize();
  93. void set_use_vsync(bool p_use);
  94. bool is_using_vsync() const;
  95. GLManager_Windows(ContextType p_context_type);
  96. ~GLManager_Windows();
  97. };
  98. #endif // defined(WINDOWS_ENABLED) && defined(GLES3_ENABLED)
  99. #endif // GL_MANAGER_WINDOWS_H