| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#if defined(X11_ENABLED) && defined(GLES3_ENABLED) |
| 34 |
|
| 35 |
#include "core/os/os.h" |
| 36 |
#include "core/templates/local_vector.h" |
| 37 |
#include "servers/display/display_server.h" |
| 38 |
|
| 39 |
#ifdef SOWRAP_ENABLED |
| 40 |
#include "dynwrappers/xlib-so_wrap.h" |
| 41 |
|
| 42 |
#include "dynwrappers/xext-so_wrap.h" |
| 43 |
#include "dynwrappers/xrender-so_wrap.h" |
| 44 |
#else |
| 45 |
#include <X11/XKBlib.h> |
| 46 |
#include <X11/Xlib.h> |
| 47 |
#include <X11/Xutil.h> |
| 48 |
|
| 49 |
#include <X11/extensions/Xext.h> |
| 50 |
#include <X11/extensions/Xrender.h> |
| 51 |
#include <X11/extensions/shape.h> |
| 52 |
#endif |
| 53 |
|
| 54 |
struct GLManager_X11_Private; |
| 55 |
|
| 56 |
class GLManager_X11 { |
| 57 |
public: |
| 58 |
enum ContextType { |
| 59 |
GLES_3_0_COMPATIBLE, |
| 60 |
}; |
| 61 |
|
| 62 |
private: |
| 63 |
|
| 64 |
struct GLWindow { |
| 65 |
bool in_use = false; |
| 66 |
|
| 67 |
|
| 68 |
DisplayServer::WindowID window_id = DisplayServer::INVALID_WINDOW_ID; |
| 69 |
int width = 0; |
| 70 |
int height = 0; |
| 71 |
::Window x11_window; |
| 72 |
int gldisplay_id = 0; |
| 73 |
}; |
| 74 |
|
| 75 |
struct GLDisplay { |
| 76 |
GLDisplay() {} |
| 77 |
~GLDisplay(); |
| 78 |
GLManager_X11_Private *context = nullptr; |
| 79 |
::Display *x11_display = nullptr; |
| 80 |
XVisualInfo x_vi = {}; |
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
struct XWinDisp { |
| 85 |
::Window x11_window; |
| 86 |
::Display *x11_display = nullptr; |
| 87 |
} _x_windisp; |
| 88 |
|
| 89 |
LocalVector<GLWindow> _windows; |
| 90 |
LocalVector<GLDisplay> _displays; |
| 91 |
|
| 92 |
GLWindow *_current_window = nullptr; |
| 93 |
|
| 94 |
void _internal_set_current_window(GLWindow *p_win); |
| 95 |
|
| 96 |
GLWindow &get_window(unsigned int id) { return _windows[id]; } |
| 97 |
const GLWindow &get_window(unsigned int id) const { return _windows[id]; } |
| 98 |
|
| 99 |
const GLDisplay &get_current_display() const { return _displays[_current_window->gldisplay_id]; } |
| 100 |
const GLDisplay &get_display(unsigned int id) { return _displays[id]; } |
| 101 |
|
| 102 |
bool double_buffer; |
| 103 |
bool direct_render; |
| 104 |
int glx_minor, glx_major; |
| 105 |
bool use_vsync; |
| 106 |
ContextType context_type; |
| 107 |
|
| 108 |
private: |
| 109 |
int _find_or_create_display(Display *p_x11_display); |
| 110 |
Error _create_context(GLDisplay &gl_display); |
| 111 |
|
| 112 |
public: |
| 113 |
XVisualInfo get_vi(Display *p_display, Error &r_error); |
| 114 |
Error window_create(DisplayServer::WindowID p_window_id, ::Window p_window, Display *p_display, int p_width, int p_height); |
| 115 |
void window_destroy(DisplayServer::WindowID p_window_id); |
| 116 |
void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height); |
| 117 |
|
| 118 |
void release_current(); |
| 119 |
void swap_buffers(); |
| 120 |
|
| 121 |
void window_make_current(DisplayServer::WindowID p_window_id); |
| 122 |
|
| 123 |
Error initialize(Display *p_display); |
| 124 |
|
| 125 |
void set_use_vsync(bool p_use); |
| 126 |
bool is_using_vsync() const; |
| 127 |
|
| 128 |
void *get_glx_context(DisplayServer::WindowID p_window_id); |
| 129 |
|
| 130 |
Error open_display(Display *p_display); |
| 131 |
GLManager_X11(const Vector2i &p_size, ContextType p_context_type); |
| 132 |
~GLManager_X11(); |
| 133 |
}; |
| 134 |
|
| 135 |
#endif |