Debian Codegraph @

drivers/gles3/storage/config.cpp

raw symbols SCIP
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_3d_supported = extensions.has("GL_OES_texture_compression_astc");
82 astc_hdr_supported = astc_3d_supported || extensions.has("GL_KHR_texture_compression_astc_hdr");
83 astc_layered_supported = astc_hdr_supported || extensions.has("GL_KHR_texture_compression_astc_sliced_3d");
84 astc_supported = astc_layered_supported || extensions.has("GL_KHR_texture_compression_astc_ldr") || extensions.has("WEBGL_compressed_texture_astc");
85
86 if (RasterizerGLES3::is_gles_over_gl()) {
87 float_texture_supported = true;
88 float_texture_linear_supported = true;
89 etc2_supported = false;
90 s3tc_supported = true;
91 rgtc_supported = true; //RGTC - core since OpenGL version 3.0
92 srgb_framebuffer_supported = true;
93 unorm16_texture_supported = true;
94 } else {
95 float_texture_supported = extensions.has("GL_EXT_color_buffer_float");
96 float_texture_linear_supported = extensions.has("GL_OES_texture_float_linear");
97 etc2_supported = true;
98 #if defined(ANDROID_ENABLED) || defined(IOS_ENABLED)
99 // Some Android devices report support for S3TC but we don't expect that and don't export the textures.
100 // This could be fixed but so few devices support it that it doesn't seem useful (and makes bigger APKs).
101 // For good measure we do the same hack for iOS, just in case.
102 s3tc_supported = false;
103 #else
104 s3tc_supported = extensions.has("GL_EXT_texture_compression_dxt1") || extensions.has("GL_EXT_texture_compression_s3tc") || extensions.has("WEBGL_compressed_texture_s3tc");
105 #endif
106 rgtc_supported = extensions.has("GL_EXT_texture_compression_rgtc") || extensions.has("GL_ARB_texture_compression_rgtc");
107 srgb_framebuffer_supported = extensions.has("GL_EXT_sRGB_write_control");
108 unorm16_texture_supported = extensions.has("GL_EXT_texture_norm16");
109 }
110
111 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max_vertex_texture_image_units);
112 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_image_units);
113 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
114 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, max_viewport_size);
115 glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs);
116 glGetInteger64v(GL_MAX_UNIFORM_BLOCK_SIZE, &max_uniform_buffer_size);
117 GLint max_vertex_output;
118 glGetIntegerv(GL_MAX_VERTEX_OUTPUT_COMPONENTS, &max_vertex_output);
119 GLint max_fragment_input;
120 glGetIntegerv(GL_MAX_FRAGMENT_INPUT_COMPONENTS, &max_fragment_input);
121 max_shader_varyings = (uint32_t)MIN(max_vertex_output, max_fragment_input) / 4;
122
123 // sanity clamp buffer size to 16K..1MB
124 max_uniform_buffer_size = CLAMP(max_uniform_buffer_size, 16384, 1048576);
125
126 support_anisotropic_filter = extensions.has("GL_EXT_texture_filter_anisotropic");
127 if (support_anisotropic_filter) {
128 glGetFloatv(_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_level);
129 anisotropic_level = MIN(float(1 << int(GLOBAL_GET("rendering/textures/default_filters/anisotropic_filtering_level"))), anisotropic_level);
130 }
131
132 glGetIntegerv(GL_MAX_SAMPLES, &msaa_max_samples);
133 #ifdef WEB_ENABLED
134 msaa_supported = (msaa_max_samples > 0);
135 #else
136 msaa_supported = true;
137 #endif
138 #ifndef IOS_ENABLED
139 #ifdef WEB_ENABLED
140 msaa_multiview_supported = extensions.has("OCULUS_multiview");
141 rt_msaa_multiview_supported = msaa_multiview_supported;
142 #else
143 msaa_multiview_supported = extensions.has("GL_EXT_multiview_texture_multisample");
144 #endif
145
146 multiview_supported = extensions.has("OCULUS_multiview") || extensions.has("GL_OVR_multiview2") || extensions.has("GL_OVR_multiview");
147 #endif
148
149 #ifdef ANDROID_ENABLED
150 // These are GLES only
151 rt_msaa_supported = extensions.has("GL_EXT_multisampled_render_to_texture");
152 rt_msaa_multiview_supported = extensions.has("GL_OVR_multiview_multisampled_render_to_texture");
153 external_texture_supported = extensions.has("GL_OES_EGL_image_external_essl3");
154
155 if (multiview_supported) {
156 eglFramebufferTextureMultiviewOVR = (PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC)eglGetProcAddress("glFramebufferTextureMultiviewOVR");
157 if (eglFramebufferTextureMultiviewOVR == nullptr) {
158 multiview_supported = false;
159 }
160 }
161
162 if (msaa_multiview_supported) {
163 eglTexStorage3DMultisample = (PFNGLTEXSTORAGE3DMULTISAMPLEPROC)eglGetProcAddress("glTexStorage3DMultisample");
164 if (eglTexStorage3DMultisample == nullptr) {
165 msaa_multiview_supported = false;
166 }
167 }
168
169 if (rt_msaa_supported) {
170 eglFramebufferTexture2DMultisampleEXT = (PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC)eglGetProcAddress("glFramebufferTexture2DMultisampleEXT");
171 if (eglFramebufferTexture2DMultisampleEXT == nullptr) {
172 rt_msaa_supported = false;
173 }
174 }
175
176 if (rt_msaa_multiview_supported) {
177 eglFramebufferTextureMultisampleMultiviewOVR = (PFNGLFRAMEBUFFERTEXTUREMULTISAMPLEMULTIVIEWOVRPROC)eglGetProcAddress("glFramebufferTextureMultisampleMultiviewOVR");
178 if (eglFramebufferTextureMultisampleMultiviewOVR == nullptr) {
179 rt_msaa_multiview_supported = false;
180 }
181 }
182
183 if (external_texture_supported) {
184 eglEGLImageTargetTexture2DOES = (PFNEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
185 if (eglEGLImageTargetTexture2DOES == nullptr) {
186 external_texture_supported = false;
187 }
188 }
189 #endif
190
191 force_vertex_shading = GLOBAL_GET("rendering/shading/overrides/force_vertex_shading");
192 specular_occlusion = GLOBAL_GET("rendering/reflections/specular_occlusion/enabled");
193 use_nearest_mip_filter = GLOBAL_GET("rendering/textures/default_filters/use_nearest_mipmap_filter");
194
195 use_depth_prepass = bool(GLOBAL_GET("rendering/driver/depth_prepass/enable"));
196 if (use_depth_prepass) {
197 String vendors = GLOBAL_GET("rendering/driver/depth_prepass/disable_for_vendors");
198 Vector<String> vendor_match = vendors.split(",");
199 const String &renderer = String::utf8((const char *)glGetString(GL_RENDERER));
200 for (int i = 0; i < vendor_match.size(); i++) {
201 String v = vendor_match[i].strip_edges();
202 if (v == String()) {
203 continue;
204 }
205
206 if (renderer.containsn(v)) {
207 use_depth_prepass = false;
208 }
209 }
210 }
211
212 max_renderable_elements = GLOBAL_GET("rendering/limits/opengl/max_renderable_elements");
213 max_renderable_lights = GLOBAL_GET("rendering/limits/opengl/max_renderable_lights");
214 max_lights_per_object = GLOBAL_GET("rendering/limits/opengl/max_lights_per_object");
215
216 //Adreno 3xx Compatibility
217 const String rendering_device_name = String::utf8((const char *)glGetString(GL_RENDERER));
218 if (rendering_device_name.left(13) == "Adreno (TM) 3") {
219 disable_particles_workaround = true;
220
221 // ignore driver version 331+
222 const String gl_version = String::utf8((const char *)glGetString(GL_VERSION));
223 // Adreno 3xx examples (https://opengles.gpuinfo.org/listreports.php):
224 // ===========================================================================
225 // OpenGL ES 3.0 [email protected] AU@ (CL@)
226 // OpenGL ES 3.0 [email protected] AU@ (GIT@I96aee987eb)
227 // OpenGL ES 3.0 [email protected] AU@ (GIT@Ifd751822f5)
228 // OpenGL ES 3.0 [email protected] [email protected] (GIT@Ie4790512f3)
229 // OpenGL ES 3.0 [email protected] AU@ (GIT@I109c45a694)
230 // OpenGL ES 3.0 [email protected] (GIT@35e467f, Ice9844a736) (Date:04/15/19)
231 // OpenGL ES 3.0 [email protected] (GIT@d39f783, I79de86aa2c, 1591296226) (Date:06/04/20)
232 // OpenGL ES 3.0 [email protected] (GIT@09fef447e8, I1fe547a144, 1661493934) (Date:08/25/22)
233 String driver_version = gl_version.get_slice("V@", 1).get_slicec(' ', 0);
234 if (driver_version.is_valid_float() && driver_version.to_float() >= 331.0) {
235 //TODO: also 'GPUParticles'?
236 //https://github.com/godotengine/godot/issues/92662#issuecomment-2161199477
237 //disable_particles_workaround = false;
238 }
239 } else if (rendering_device_name.contains("PowerVR")) {
240 disable_transform_feedback_shader_cache = true;
241 }
242
243 if (OS::get_singleton()->get_current_rendering_driver_name() == "opengl3_angle") {
244 polyfill_half2float = false;
245 }
246 #ifdef WEB_ENABLED
247 polyfill_half2float = false;
248 #endif
249 }
250
251 Config::~Config() {
252 singleton = nullptr;
253 }
254
255 #endif // GLES3_ENABLED