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#include "core/config/project_settings.h"
35#include "core/templates/vector.h"
36
37#ifdef ANDROID_ENABLED
38#include <GLES3/gl3.h>
39#include <GLES3/gl3ext.h>
40#include <GLES3/gl3platform.h>
41
42#include <EGL/egl.h>
43#include <EGL/eglext.h>
44#endif
45
46using namespace GLES3;
47
48#define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
49
50Config *Config::singleton = nullptr;
51
52Config::Config() {
53 singleton = this;
54
55 {
56 int64_t max_extensions = 0;
57 glGetInteger64v(GL_NUM_EXTENSIONS, &max_extensions);
58 for (int64_t i = 0; i < max_extensions; i++) {
59 const GLubyte *s = glGetStringi(GL_EXTENSIONS, i);
60 if (!s) {
61 break;
62 }
63 extensions.insert((const char *)s);
64 }
65 }
66
67 bptc_supported = extensions.has("GL_ARB_texture_compression_bptc") || extensions.has("EXT_texture_compression_bptc");
68 astc_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("GL_KHR_texture_compression_astc_hdr");
69 astc_hdr_supported = extensions.has("GL_KHR_texture_compression_astc_ldr");
70 astc_layered_supported = extensions.has("GL_KHR_texture_compression_astc_sliced_3d");
71
72#ifdef GLES_OVER_GL
73 float_texture_supported = true;
74 etc2_supported = false;
75 s3tc_supported = true;
76 rgtc_supported = true; //RGTC - core since OpenGL version 3.0
77#else
78 float_texture_supported = extensions.has("GL_EXT_color_buffer_float");
79 etc2_supported = true;
80#if defined(ANDROID_ENABLED) || defined(IOS_ENABLED)
81 // Some Android devices report support for S3TC but we don't expect that and don't export the textures.
82 // This could be fixed but so few devices support it that it doesn't seem useful (and makes bigger APKs).
83 // For good measure we do the same hack for iOS, just in case.
84 s3tc_supported = false;
85#else
86 s3tc_supported = extensions.has("GL_EXT_texture_compression_dxt1") || extensions.has("GL_EXT_texture_compression_s3tc") || extensions.has("WEBGL_compressed_texture_s3tc");
87#endif
88 rgtc_supported = extensions.has("GL_EXT_texture_compression_rgtc") || extensions.has("GL_ARB_texture_compression_rgtc") || extensions.has("EXT_texture_compression_rgtc");
89#endif
90
91 glGetInteger64v(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max_vertex_texture_image_units);
92 glGetInteger64v(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_image_units);
93 glGetInteger64v(GL_MAX_TEXTURE_SIZE, &max_texture_size);
94 glGetInteger64v(GL_MAX_UNIFORM_BLOCK_SIZE, &max_uniform_buffer_size);
95 glGetInteger64v(GL_MAX_VIEWPORT_DIMS, max_viewport_size);
96
97 support_anisotropic_filter = extensions.has("GL_EXT_texture_filter_anisotropic");
98 if (support_anisotropic_filter) {
99 glGetFloatv(_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_level);
100 anisotropic_level = MIN(float(1 << int(GLOBAL_GET("rendering/textures/default_filters/anisotropic_filtering_level"))), anisotropic_level);
101 }
102
103 multiview_supported = extensions.has("GL_OVR_multiview2") || extensions.has("GL_OVR_multiview");
104#ifdef ANDROID_ENABLED
105 if (multiview_supported) {
106 eglFramebufferTextureMultiviewOVR = (PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC)eglGetProcAddress("glFramebufferTextureMultiviewOVR");
107 if (eglFramebufferTextureMultiviewOVR == nullptr) {
108 multiview_supported = false;
109 }
110 }
111#endif
112
113 force_vertex_shading = false; //GLOBAL_GET("rendering/quality/shading/force_vertex_shading");
114 use_nearest_mip_filter = GLOBAL_GET("rendering/textures/default_filters/use_nearest_mipmap_filter");
115
116 use_depth_prepass = bool(GLOBAL_GET("rendering/driver/depth_prepass/enable"));
117 if (use_depth_prepass) {
118 String vendors = GLOBAL_GET("rendering/driver/depth_prepass/disable_for_vendors");
119 Vector<String> vendor_match = vendors.split(",");
120 String renderer = (const char *)glGetString(GL_RENDERER);
121 for (int i = 0; i < vendor_match.size(); i++) {
122 String v = vendor_match[i].strip_edges();
123 if (v == String()) {
124 continue;
125 }
126
127 if (renderer.findn(v) != -1) {
128 use_depth_prepass = false;
129 }
130 }
131 }
132
133 max_renderable_elements = GLOBAL_GET("rendering/limits/opengl/max_renderable_elements");
134 max_renderable_lights = GLOBAL_GET("rendering/limits/opengl/max_renderable_lights");
135 max_lights_per_object = GLOBAL_GET("rendering/limits/opengl/max_lights_per_object");
136}
137
138Config::~Config() {
139 singleton = nullptr;
140}
141
142#endif // GLES3_ENABLED
143