gl_manager_x11.h 4.5 KB

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