gl_manager_windows_native.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**************************************************************************/
  2. /* gl_manager_windows_native.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(WINDOWS_ENABLED) && defined(GLES3_ENABLED)
  32. #include "core/os/os.h"
  33. #include "core/templates/local_vector.h"
  34. #include "servers/display_server.h"
  35. #include <windows.h>
  36. typedef bool(APIENTRY *PFNWGLSWAPINTERVALEXTPROC)(int interval);
  37. typedef int(APIENTRY *PFNWGLGETSWAPINTERVALEXTPROC)(void);
  38. class GLManagerNative_Windows {
  39. private:
  40. // any data specific to the window
  41. struct GLWindow {
  42. bool use_vsync = false;
  43. // windows specific
  44. HDC hDC;
  45. HWND hwnd;
  46. int gldisplay_id = 0;
  47. };
  48. struct GLDisplay {
  49. // windows specific
  50. HGLRC hRC;
  51. };
  52. RBMap<DisplayServer::WindowID, GLWindow> _windows;
  53. LocalVector<GLDisplay> _displays;
  54. GLWindow *_current_window = nullptr;
  55. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = nullptr;
  56. GLWindow &get_window(unsigned int id) { return _windows[id]; }
  57. const GLWindow &get_window(unsigned int id) const { return _windows[id]; }
  58. const GLDisplay &get_current_display() const { return _displays[_current_window->gldisplay_id]; }
  59. const GLDisplay &get_display(unsigned int id) { return _displays[id]; }
  60. bool direct_render;
  61. int glx_minor, glx_major;
  62. private:
  63. void _nvapi_setup_profile();
  64. int _find_or_create_display(GLWindow &win);
  65. Error _create_context(GLWindow &win, GLDisplay &gl_display);
  66. public:
  67. Error window_create(DisplayServer::WindowID p_window_id, HWND p_hwnd, HINSTANCE p_hinstance, int p_width, int p_height);
  68. void window_destroy(DisplayServer::WindowID p_window_id);
  69. void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height) {}
  70. void release_current();
  71. void swap_buffers();
  72. void window_make_current(DisplayServer::WindowID p_window_id);
  73. Error initialize();
  74. void set_use_vsync(DisplayServer::WindowID p_window_id, bool p_use);
  75. bool is_using_vsync(DisplayServer::WindowID p_window_id) const;
  76. HDC get_hdc(DisplayServer::WindowID p_window_id);
  77. HGLRC get_hglrc(DisplayServer::WindowID p_window_id);
  78. GLManagerNative_Windows();
  79. ~GLManagerNative_Windows();
  80. };
  81. #endif // WINDOWS_ENABLED && GLES3_ENABLED