gl_manager_x11.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**************************************************************************/
  2. /* gl_manager_x11.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_X11_H
  31. #define GL_MANAGER_X11_H
  32. #if defined(X11_ENABLED) && defined(GLES3_ENABLED)
  33. #include "core/os/os.h"
  34. #include "core/templates/local_vector.h"
  35. #include "servers/display_server.h"
  36. #ifdef SOWRAP_ENABLED
  37. #include "dynwrappers/xlib-so_wrap.h"
  38. #include "dynwrappers/xext-so_wrap.h"
  39. #include "dynwrappers/xrender-so_wrap.h"
  40. #else
  41. #include <X11/XKBlib.h>
  42. #include <X11/Xlib.h>
  43. #include <X11/Xutil.h>
  44. #include <X11/extensions/Xext.h>
  45. #include <X11/extensions/Xrender.h>
  46. #include <X11/extensions/shape.h>
  47. #endif
  48. struct GLManager_X11_Private;
  49. class GLManager_X11 {
  50. public:
  51. enum ContextType {
  52. GLES_3_0_COMPATIBLE,
  53. };
  54. private:
  55. // any data specific to the window
  56. struct GLWindow {
  57. bool in_use = false;
  58. // the external ID .. should match the GL window number .. unused I think
  59. DisplayServer::WindowID window_id = DisplayServer::INVALID_WINDOW_ID;
  60. int width = 0;
  61. int height = 0;
  62. ::Window x11_window;
  63. int gldisplay_id = 0;
  64. };
  65. struct GLDisplay {
  66. GLDisplay() {}
  67. ~GLDisplay();
  68. GLManager_X11_Private *context = nullptr;
  69. ::Display *x11_display = nullptr;
  70. XVisualInfo x_vi = {};
  71. };
  72. // just for convenience, window and display struct
  73. struct XWinDisp {
  74. ::Window x11_window;
  75. ::Display *x11_display = nullptr;
  76. } _x_windisp;
  77. LocalVector<GLWindow> _windows;
  78. LocalVector<GLDisplay> _displays;
  79. GLWindow *_current_window = nullptr;
  80. void _internal_set_current_window(GLWindow *p_win);
  81. GLWindow &get_window(unsigned int id) { return _windows[id]; }
  82. const GLWindow &get_window(unsigned int id) const { return _windows[id]; }
  83. const GLDisplay &get_current_display() const { return _displays[_current_window->gldisplay_id]; }
  84. const GLDisplay &get_display(unsigned int id) { return _displays[id]; }
  85. bool double_buffer;
  86. bool direct_render;
  87. int glx_minor, glx_major;
  88. bool use_vsync;
  89. ContextType context_type;
  90. private:
  91. int _find_or_create_display(Display *p_x11_display);
  92. Error _create_context(GLDisplay &gl_display);
  93. public:
  94. XVisualInfo get_vi(Display *p_display, Error &r_error);
  95. Error window_create(DisplayServer::WindowID p_window_id, ::Window p_window, Display *p_display, int p_width, int p_height);
  96. void window_destroy(DisplayServer::WindowID p_window_id);
  97. void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height);
  98. void release_current();
  99. void swap_buffers();
  100. void window_make_current(DisplayServer::WindowID p_window_id);
  101. Error initialize(Display *p_display);
  102. void set_use_vsync(bool p_use);
  103. bool is_using_vsync() const;
  104. void *get_glx_context(DisplayServer::WindowID p_window_id);
  105. Error open_display(Display *p_display);
  106. GLManager_X11(const Vector2i &p_size, ContextType p_context_type);
  107. ~GLManager_X11();
  108. };
  109. #endif // X11_ENABLED && GLES3_ENABLED
  110. #endif // GL_MANAGER_X11_H