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