Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/drivers/gles3/storage/config.cpp
10005 views
1
/**************************************************************************/
2
/* config.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
#ifdef GLES3_ENABLED
32
33
#include "config.h"
34
35
#include "../rasterizer_gles3.h"
36
37
#ifdef WEB_ENABLED
38
#include <emscripten/html5_webgl.h>
39
#endif
40
41
using namespace GLES3;
42
43
#define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
44
45
Config *Config::singleton = nullptr;
46
47
Config::Config() {
48
singleton = this;
49
50
#ifdef WEB_ENABLED
51
// Starting with Emscripten 3.1.51, glGetStringi(GL_EXTENSIONS, i) will only ever return
52
// a fixed list of extensions, regardless of what additional extensions are enabled. This
53
// isn't very useful for us in determining which extensions we can rely on here. So, instead
54
// we use emscripten_webgl_get_supported_extensions() to get all supported extensions, which
55
// is what Emscripten 3.1.50 and earlier do.
56
{
57
char *extension_array_string = emscripten_webgl_get_supported_extensions();
58
PackedStringArray extension_array = String((const char *)extension_array_string).split(" ");
59
extensions.reserve(extension_array.size() * 2);
60
for (const String &s : extension_array) {
61
extensions.insert(s);
62
extensions.insert("GL_" + s);
63
}
64
free(extension_array_string);
65
}
66
#else
67
{
68
GLint max_extensions = 0;
69
glGetIntegerv(GL_NUM_EXTENSIONS, &max_extensions);
70
for (int i = 0; i < max_extensions; i++) {
71
const GLubyte *s = glGetStringi(GL_EXTENSIONS, i);
72
if (!s) {
73
break;
74
}
75
extensions.insert((const char *)s);
76
}
77
}
78
#endif
79
80
bptc_supported = extensions.has("GL_ARB_texture_compression_bptc") || extensions.has("GL_EXT_texture_compression_bptc");
81
astc_hdr_supported = extensions.has("GL_KHR_texture_compression_astc_hdr");
82
astc_supported = astc_hdr_supported || extensions.has("GL_KHR_texture_compression_astc") || extensions.has("GL_OES_texture_compression_astc") || extensions.has("GL_KHR_texture_compression_astc_ldr") || extensions.has("WEBGL_compressed_texture_astc");
83
astc_layered_supported = extensions.has("GL_KHR_texture_compression_astc_sliced_3d");
84
85
if (RasterizerGLES3::is_gles_over_gl()) {
86
float_texture_supported = true;
87
float_texture_linear_supported = true;
88
etc2_supported = false;
89
s3tc_supported = true;
90
rgtc_supported = true; //RGTC - core since OpenGL version 3.0
91
srgb_framebuffer_supported = true;
92
} else {
93
float_texture_supported = extensions.has("GL_EXT_color_buffer_float");
94
float_texture_linear_supported = extensions.has("GL_OES_texture_float_linear");
95
etc2_supported = true;
96
#if defined(ANDROID_ENABLED) || defined(IOS_ENABLED)
97
// Some Android devices report support for S3TC but we don't expect that and don't export the textures.
98
// This could be fixed but so few devices support it that it doesn't seem useful (and makes bigger APKs).
99
// For good measure we do the same hack for iOS, just in case.
100
s3tc_supported = false;
101
#else
102
s3tc_supported = extensions.has("GL_EXT_texture_compression_dxt1") || extensions.has("GL_EXT_texture_compression_s3tc") || extensions.has("WEBGL_compressed_texture_s3tc");
103
#endif
104
rgtc_supported = extensions.has("GL_EXT_texture_compression_rgtc") || extensions.has("GL_ARB_texture_compression_rgtc");
105
srgb_framebuffer_supported = extensions.has("GL_EXT_sRGB_write_control");
106
}
107
108
glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max_vertex_texture_image_units);
109
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_image_units);
110
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
111
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, max_viewport_size);
112
glGetInteger64v(GL_MAX_UNIFORM_BLOCK_SIZE, &max_uniform_buffer_size);
113
GLint max_vertex_output;
114
glGetIntegerv(GL_MAX_VERTEX_OUTPUT_COMPONENTS, &max_vertex_output);
115
GLint max_fragment_input;
116
glGetIntegerv(GL_MAX_FRAGMENT_INPUT_COMPONENTS, &max_fragment_input);
117
max_shader_varyings = (uint32_t)MIN(max_vertex_output, max_fragment_input) / 4;
118
119
// sanity clamp buffer size to 16K..1MB
120
max_uniform_buffer_size = CLAMP(max_uniform_buffer_size, 16384, 1048576);
121
122
support_anisotropic_filter = extensions.has("GL_EXT_texture_filter_anisotropic");
123
if (support_anisotropic_filter) {
124
glGetFloatv(_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_level);
125
anisotropic_level = MIN(float(1 << int(GLOBAL_GET("rendering/textures/default_filters/anisotropic_filtering_level"))), anisotropic_level);
126
}
127
128
glGetIntegerv(GL_MAX_SAMPLES, &msaa_max_samples);
129
#ifdef WEB_ENABLED
130
msaa_supported = (msaa_max_samples > 0);
131
#else
132
msaa_supported = true;
133
#endif
134
#ifndef IOS_ENABLED
135
#ifdef WEB_ENABLED
136
msaa_multiview_supported = extensions.has("OCULUS_multiview");
137
rt_msaa_multiview_supported = msaa_multiview_supported;
138
#else
139
msaa_multiview_supported = extensions.has("GL_EXT_multiview_texture_multisample");
140
#endif
141
142
multiview_supported = extensions.has("OCULUS_multiview") || extensions.has("GL_OVR_multiview2") || extensions.has("GL_OVR_multiview");
143
#endif
144
145
#ifdef ANDROID_ENABLED
146
// These are GLES only
147
rt_msaa_supported = extensions.has("GL_EXT_multisampled_render_to_texture");
148
rt_msaa_multiview_supported = extensions.has("GL_OVR_multiview_multisampled_render_to_texture");
149
external_texture_supported = extensions.has("GL_OES_EGL_image_external_essl3");
150
151
if (multiview_supported) {
152
eglFramebufferTextureMultiviewOVR = (PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC)eglGetProcAddress("glFramebufferTextureMultiviewOVR");
153
if (eglFramebufferTextureMultiviewOVR == nullptr) {
154
multiview_supported = false;
155
}
156
}
157
158
if (msaa_multiview_supported) {
159
eglTexStorage3DMultisample = (PFNGLTEXSTORAGE3DMULTISAMPLEPROC)eglGetProcAddress("glTexStorage3DMultisample");
160
if (eglTexStorage3DMultisample == nullptr) {
161
msaa_multiview_supported = false;
162
}
163
}
164
165
if (rt_msaa_supported) {
166
eglFramebufferTexture2DMultisampleEXT = (PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC)eglGetProcAddress("glFramebufferTexture2DMultisampleEXT");
167
if (eglFramebufferTexture2DMultisampleEXT == nullptr) {
168
rt_msaa_supported = false;
169
}
170
}
171
172
if (rt_msaa_multiview_supported) {
173
eglFramebufferTextureMultisampleMultiviewOVR = (PFNGLFRAMEBUFFERTEXTUREMULTISAMPLEMULTIVIEWOVRPROC)eglGetProcAddress("glFramebufferTextureMultisampleMultiviewOVR");
174
if (eglFramebufferTextureMultisampleMultiviewOVR == nullptr) {
175
rt_msaa_multiview_supported = false;
176
}
177
}
178
179
if (external_texture_supported) {
180
eglEGLImageTargetTexture2DOES = (PFNEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
181
if (eglEGLImageTargetTexture2DOES == nullptr) {
182
external_texture_supported = false;
183
}
184
}
185
#endif
186
187
force_vertex_shading = GLOBAL_GET("rendering/shading/overrides/force_vertex_shading");
188
specular_occlusion = GLOBAL_GET("rendering/reflections/specular_occlusion/enabled");
189
use_nearest_mip_filter = GLOBAL_GET("rendering/textures/default_filters/use_nearest_mipmap_filter");
190
191
use_depth_prepass = bool(GLOBAL_GET("rendering/driver/depth_prepass/enable"));
192
if (use_depth_prepass) {
193
String vendors = GLOBAL_GET("rendering/driver/depth_prepass/disable_for_vendors");
194
Vector<String> vendor_match = vendors.split(",");
195
const String &renderer = String::utf8((const char *)glGetString(GL_RENDERER));
196
for (int i = 0; i < vendor_match.size(); i++) {
197
String v = vendor_match[i].strip_edges();
198
if (v == String()) {
199
continue;
200
}
201
202
if (renderer.containsn(v)) {
203
use_depth_prepass = false;
204
}
205
}
206
}
207
208
max_renderable_elements = GLOBAL_GET("rendering/limits/opengl/max_renderable_elements");
209
max_renderable_lights = GLOBAL_GET("rendering/limits/opengl/max_renderable_lights");
210
max_lights_per_object = GLOBAL_GET("rendering/limits/opengl/max_lights_per_object");
211
212
//Adreno 3xx Compatibility
213
const String rendering_device_name = String::utf8((const char *)glGetString(GL_RENDERER));
214
if (rendering_device_name.left(13) == "Adreno (TM) 3") {
215
disable_particles_workaround = true;
216
217
// ignore driver version 331+
218
const String gl_version = String::utf8((const char *)glGetString(GL_VERSION));
219
// Adreno 3xx examples (https://opengles.gpuinfo.org/listreports.php):
220
// ===========================================================================
221
// OpenGL ES 3.0 [email protected] AU@ (CL@)
222
// OpenGL ES 3.0 [email protected] AU@ (GIT@I96aee987eb)
223
// OpenGL ES 3.0 [email protected] AU@ (GIT@Ifd751822f5)
224
// OpenGL ES 3.0 [email protected] [email protected] (GIT@Ie4790512f3)
225
// OpenGL ES 3.0 [email protected] AU@ (GIT@I109c45a694)
226
// OpenGL ES 3.0 [email protected] (GIT@35e467f, Ice9844a736) (Date:04/15/19)
227
// OpenGL ES 3.0 [email protected] (GIT@d39f783, I79de86aa2c, 1591296226) (Date:06/04/20)
228
// OpenGL ES 3.0 [email protected] (GIT@09fef447e8, I1fe547a144, 1661493934) (Date:08/25/22)
229
String driver_version = gl_version.get_slice("V@", 1).get_slicec(' ', 0);
230
if (driver_version.is_valid_float() && driver_version.to_float() >= 331.0) {
231
//TODO: also 'GPUParticles'?
232
//https://github.com/godotengine/godot/issues/92662#issuecomment-2161199477
233
//disable_particles_workaround = false;
234
}
235
} else if (rendering_device_name == "PowerVR Rogue GE8320") {
236
disable_transform_feedback_shader_cache = true;
237
}
238
239
if (OS::get_singleton()->get_current_rendering_driver_name() == "opengl3_angle") {
240
polyfill_half2float = false;
241
}
242
#ifdef WEB_ENABLED
243
polyfill_half2float = false;
244
#endif
245
}
246
247
Config::~Config() {
248
singleton = nullptr;
249
}
250
251
#endif // GLES3_ENABLED
252
253