Skip to content

Commit 479b2ab

Browse files
committed
Merge pull request #91466 from Riteo/gles-ftw
Wayland: Add support for OpenGL ES driver
2 parents c968374 + d3279fa commit 479b2ab

File tree

5 files changed

+161
-18
lines changed

5 files changed

+161
-18
lines changed

platform/linuxbsd/wayland/SCsub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ if env["vulkan"]:
199199

200200
if env["opengl3"]:
201201
source_files.append("egl_manager_wayland.cpp")
202+
source_files.append("egl_manager_wayland_gles.cpp")
202203

203204
objects = []
204205

platform/linuxbsd/wayland/display_server_wayland.cpp

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
#ifdef GLES3_ENABLED
4747
#include "detect_prime_egl.h"
4848
#include "drivers/gles3/rasterizer_gles3.h"
49+
#include "wayland/egl_manager_wayland.h"
50+
#include "wayland/egl_manager_wayland_gles.h"
4951
#endif
5052

5153
String DisplayServerWayland::_get_app_id_from_context(Context p_context) {
@@ -1208,6 +1210,7 @@ Vector<String> DisplayServerWayland::get_rendering_drivers_func() {
12081210

12091211
#ifdef GLES3_ENABLED
12101212
drivers.push_back("opengl3");
1213+
drivers.push_back("opengl3_es");
12111214
#endif
12121215

12131216
return drivers;
@@ -1258,14 +1261,14 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win
12581261

12591262
#ifdef RD_ENABLED
12601263
#ifdef VULKAN_ENABLED
1261-
if (p_rendering_driver == "vulkan") {
1264+
if (rendering_driver == "vulkan") {
12621265
rendering_context = memnew(RenderingContextDriverVulkanWayland);
12631266
}
12641267
#endif
12651268

12661269
if (rendering_context) {
12671270
if (rendering_context->initialize() != OK) {
1268-
ERR_PRINT(vformat("Could not initialize %s", p_rendering_driver));
1271+
ERR_PRINT(vformat("Could not initialize %s", rendering_driver));
12691272
memdelete(rendering_context);
12701273
rendering_context = nullptr;
12711274
r_error = ERR_CANT_CREATE;
@@ -1275,7 +1278,14 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win
12751278
#endif
12761279

12771280
#ifdef GLES3_ENABLED
1278-
if (p_rendering_driver == "opengl3") {
1281+
if (rendering_driver == "opengl3" || rendering_driver == "opengl3_es") {
1282+
#ifdef SOWRAP_ENABLED
1283+
if (initialize_wayland_egl(dylibloader_verbose) != 0) {
1284+
WARN_PRINT("Can't load the Wayland EGL library.");
1285+
return;
1286+
}
1287+
#endif // SOWRAP_ENABLED
1288+
12791289
if (getenv("DRI_PRIME") == nullptr) {
12801290
int prime_idx = -1;
12811291

@@ -1318,23 +1328,38 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win
13181328
}
13191329
}
13201330

1321-
egl_manager = memnew(EGLManagerWayland);
1331+
if (rendering_driver == "opengl3") {
1332+
egl_manager = memnew(EGLManagerWayland);
13221333

1323-
#ifdef SOWRAP_ENABLED
1324-
if (initialize_wayland_egl(dylibloader_verbose) != 0) {
1325-
WARN_PRINT("Can't load the Wayland EGL library.");
1326-
return;
1327-
}
1328-
#endif // SOWRAP_ENABLED
1334+
if (egl_manager->initialize() != OK || egl_manager->open_display(wayland_thread.get_wl_display()) != OK) {
1335+
memdelete(egl_manager);
1336+
egl_manager = nullptr;
13291337

1330-
if (egl_manager->initialize() != OK) {
1331-
memdelete(egl_manager);
1332-
egl_manager = nullptr;
1333-
r_error = ERR_CANT_CREATE;
1334-
ERR_FAIL_MSG("Could not initialize GLES3.");
1338+
bool fallback = GLOBAL_GET("rendering/gl_compatibility/fallback_to_gles");
1339+
if (fallback) {
1340+
WARN_PRINT("Your video card drivers seem not to support the required OpenGL version, switching to OpenGLES.");
1341+
rendering_driver = "opengl3_es";
1342+
} else {
1343+
r_error = ERR_UNAVAILABLE;
1344+
ERR_FAIL_MSG("Could not initialize OpenGL.");
1345+
}
1346+
} else {
1347+
RasterizerGLES3::make_current(true);
1348+
}
13351349
}
13361350

1337-
RasterizerGLES3::make_current(true);
1351+
if (rendering_driver == "opengl3_es") {
1352+
egl_manager = memnew(EGLManagerWaylandGLES);
1353+
1354+
if (egl_manager->initialize() != OK) {
1355+
memdelete(egl_manager);
1356+
egl_manager = nullptr;
1357+
r_error = ERR_CANT_CREATE;
1358+
ERR_FAIL_MSG("Could not initialize GLES3.");
1359+
}
1360+
1361+
RasterizerGLES3::make_current(false);
1362+
}
13381363
}
13391364
#endif // GLES3_ENABLED
13401365

platform/linuxbsd/wayland/display_server_wayland.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#endif //RD_ENABLED
4646

4747
#ifdef GLES3_ENABLED
48-
#include "wayland/egl_manager_wayland.h"
48+
#include "drivers/egl/egl_manager.h"
4949
#endif
5050

5151
#if defined(SPEECHD_ENABLED)
@@ -126,7 +126,7 @@ class DisplayServerWayland : public DisplayServer {
126126
#endif
127127

128128
#ifdef GLES3_ENABLED
129-
EGLManagerWayland *egl_manager = nullptr;
129+
EGLManager *egl_manager = nullptr;
130130
#endif
131131

132132
#ifdef SPEECHD_ENABLED
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**************************************************************************/
2+
/* egl_manager_wayland_gles.cpp */
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+
#include "egl_manager_wayland_gles.h"
32+
33+
#ifdef WAYLAND_ENABLED
34+
#ifdef EGL_ENABLED
35+
#ifdef GLES3_ENABLED
36+
37+
const char *EGLManagerWaylandGLES::_get_platform_extension_name() const {
38+
return "EGL_KHR_platform_wayland";
39+
}
40+
41+
EGLenum EGLManagerWaylandGLES::_get_platform_extension_enum() const {
42+
return EGL_PLATFORM_WAYLAND_KHR;
43+
}
44+
45+
EGLenum EGLManagerWaylandGLES::_get_platform_api_enum() const {
46+
return EGL_OPENGL_ES_API;
47+
}
48+
49+
Vector<EGLAttrib> EGLManagerWaylandGLES::_get_platform_display_attributes() const {
50+
return Vector<EGLAttrib>();
51+
}
52+
53+
Vector<EGLint> EGLManagerWaylandGLES::_get_platform_context_attribs() const {
54+
Vector<EGLint> ret;
55+
ret.push_back(EGL_CONTEXT_MAJOR_VERSION);
56+
ret.push_back(3);
57+
ret.push_back(EGL_NONE);
58+
59+
return ret;
60+
}
61+
62+
#endif // GLES3_ENABLED
63+
#endif // EGL_ENABLED
64+
#endif // WAYLAND_ENABLED
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**************************************************************************/
2+
/* egl_manager_wayland_gles.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 EGL_MANAGER_WAYLAND_GLES_H
32+
#define EGL_MANAGER_WAYLAND_GLES_H
33+
34+
#ifdef WAYLAND_ENABLED
35+
#ifdef EGL_ENABLED
36+
#ifdef GLES3_ENABLED
37+
38+
#include "drivers/egl/egl_manager.h"
39+
40+
class EGLManagerWaylandGLES : public EGLManager {
41+
public:
42+
virtual const char *_get_platform_extension_name() const override;
43+
virtual EGLenum _get_platform_extension_enum() const override;
44+
virtual EGLenum _get_platform_api_enum() const override;
45+
virtual Vector<EGLAttrib> _get_platform_display_attributes() const override;
46+
virtual Vector<EGLint> _get_platform_context_attribs() const override;
47+
};
48+
49+
#endif // GLES3_ENABLED
50+
#endif // EGL_ENABLED
51+
#endif // WAYLAND_ENABLED
52+
53+
#endif // EGL_MANAGER_WAYLAND_GLES_H

0 commit comments

Comments
 (0)