2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* config.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2022-03-12 12:19:59 +01:00
|
|
|
|
|
|
|
#ifdef GLES3_ENABLED
|
|
|
|
|
|
|
|
#include "config.h"
|
2022-02-20 01:08:53 +01:00
|
|
|
#include "core/config/project_settings.h"
|
2022-03-12 12:19:59 +01:00
|
|
|
#include "core/templates/vector.h"
|
|
|
|
|
2022-09-04 16:56:24 +02:00
|
|
|
#ifdef ANDROID_ENABLED
|
|
|
|
#include <GLES3/gl3.h>
|
|
|
|
#include <GLES3/gl3ext.h>
|
|
|
|
#include <GLES3/gl3platform.h>
|
|
|
|
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <EGL/eglext.h>
|
|
|
|
#endif
|
|
|
|
|
2022-03-12 12:19:59 +01:00
|
|
|
using namespace GLES3;
|
|
|
|
|
2022-02-20 01:08:53 +01:00
|
|
|
#define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
|
|
|
|
|
2022-03-12 12:19:59 +01:00
|
|
|
Config *Config::singleton = nullptr;
|
|
|
|
|
|
|
|
Config::Config() {
|
|
|
|
singleton = this;
|
2022-04-07 16:00:51 +02:00
|
|
|
|
2022-03-12 12:19:59 +01:00
|
|
|
{
|
2023-08-23 01:32:37 +02:00
|
|
|
int64_t max_extensions = 0;
|
|
|
|
glGetInteger64v(GL_NUM_EXTENSIONS, &max_extensions);
|
|
|
|
for (int64_t i = 0; i < max_extensions; i++) {
|
2022-02-20 01:08:53 +01:00
|
|
|
const GLubyte *s = glGetStringi(GL_EXTENSIONS, i);
|
|
|
|
if (!s) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
extensions.insert((const char *)s);
|
2022-03-12 12:19:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-18 17:04:41 +02:00
|
|
|
bptc_supported = extensions.has("GL_ARB_texture_compression_bptc") || extensions.has("EXT_texture_compression_bptc");
|
2023-01-25 12:17:11 +01:00
|
|
|
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");
|
|
|
|
astc_hdr_supported = extensions.has("GL_KHR_texture_compression_astc_ldr");
|
|
|
|
astc_layered_supported = extensions.has("GL_KHR_texture_compression_astc_sliced_3d");
|
|
|
|
|
2022-03-12 12:19:59 +01:00
|
|
|
#ifdef GLES_OVER_GL
|
|
|
|
float_texture_supported = true;
|
2022-05-18 17:04:41 +02:00
|
|
|
etc2_supported = false;
|
2022-03-12 12:19:59 +01:00
|
|
|
s3tc_supported = true;
|
2022-05-18 17:04:41 +02:00
|
|
|
rgtc_supported = true; //RGTC - core since OpenGL version 3.0
|
2022-03-12 12:19:59 +01:00
|
|
|
#else
|
2022-10-19 02:59:31 +02:00
|
|
|
float_texture_supported = extensions.has("GL_EXT_color_buffer_float");
|
2022-05-18 17:04:41 +02:00
|
|
|
etc2_supported = true;
|
2022-08-08 16:51:31 +02:00
|
|
|
#if defined(ANDROID_ENABLED) || defined(IOS_ENABLED)
|
2022-08-04 18:27:56 +02:00
|
|
|
// Some Android devices report support for S3TC but we don't expect that and don't export the textures.
|
|
|
|
// This could be fixed but so few devices support it that it doesn't seem useful (and makes bigger APKs).
|
|
|
|
// For good measure we do the same hack for iOS, just in case.
|
|
|
|
s3tc_supported = false;
|
|
|
|
#else
|
2022-05-18 17:04:41 +02:00
|
|
|
s3tc_supported = extensions.has("GL_EXT_texture_compression_dxt1") || extensions.has("GL_EXT_texture_compression_s3tc") || extensions.has("WEBGL_compressed_texture_s3tc");
|
2022-08-04 18:27:56 +02:00
|
|
|
#endif
|
2022-05-18 17:04:41 +02:00
|
|
|
rgtc_supported = extensions.has("GL_EXT_texture_compression_rgtc") || extensions.has("GL_ARB_texture_compression_rgtc") || extensions.has("EXT_texture_compression_rgtc");
|
2022-03-12 12:19:59 +01:00
|
|
|
#endif
|
|
|
|
|
2023-08-23 01:32:37 +02:00
|
|
|
glGetInteger64v(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max_vertex_texture_image_units);
|
|
|
|
glGetInteger64v(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_image_units);
|
|
|
|
glGetInteger64v(GL_MAX_TEXTURE_SIZE, &max_texture_size);
|
|
|
|
glGetInteger64v(GL_MAX_UNIFORM_BLOCK_SIZE, &max_uniform_buffer_size);
|
|
|
|
glGetInteger64v(GL_MAX_VIEWPORT_DIMS, max_viewport_size);
|
2022-03-12 12:19:59 +01:00
|
|
|
|
2022-02-20 01:08:53 +01:00
|
|
|
support_anisotropic_filter = extensions.has("GL_EXT_texture_filter_anisotropic");
|
|
|
|
if (support_anisotropic_filter) {
|
|
|
|
glGetFloatv(_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_level);
|
2022-10-18 16:43:37 +02:00
|
|
|
anisotropic_level = MIN(float(1 << int(GLOBAL_GET("rendering/textures/default_filters/anisotropic_filtering_level"))), anisotropic_level);
|
2022-02-20 01:08:53 +01:00
|
|
|
}
|
2022-03-12 12:19:59 +01:00
|
|
|
|
2022-09-04 16:56:24 +02:00
|
|
|
multiview_supported = extensions.has("GL_OVR_multiview2") || extensions.has("GL_OVR_multiview");
|
|
|
|
#ifdef ANDROID_ENABLED
|
|
|
|
if (multiview_supported) {
|
|
|
|
eglFramebufferTextureMultiviewOVR = (PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC)eglGetProcAddress("glFramebufferTextureMultiviewOVR");
|
|
|
|
if (eglFramebufferTextureMultiviewOVR == nullptr) {
|
|
|
|
multiview_supported = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-03-12 12:19:59 +01:00
|
|
|
force_vertex_shading = false; //GLOBAL_GET("rendering/quality/shading/force_vertex_shading");
|
2022-02-20 01:08:53 +01:00
|
|
|
use_nearest_mip_filter = GLOBAL_GET("rendering/textures/default_filters/use_nearest_mipmap_filter");
|
2022-05-10 19:02:44 +02:00
|
|
|
|
|
|
|
use_depth_prepass = bool(GLOBAL_GET("rendering/driver/depth_prepass/enable"));
|
|
|
|
if (use_depth_prepass) {
|
|
|
|
String vendors = GLOBAL_GET("rendering/driver/depth_prepass/disable_for_vendors");
|
|
|
|
Vector<String> vendor_match = vendors.split(",");
|
|
|
|
String renderer = (const char *)glGetString(GL_RENDERER);
|
|
|
|
for (int i = 0; i < vendor_match.size(); i++) {
|
|
|
|
String v = vendor_match[i].strip_edges();
|
|
|
|
if (v == String()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (renderer.findn(v) != -1) {
|
|
|
|
use_depth_prepass = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
max_renderable_elements = GLOBAL_GET("rendering/limits/opengl/max_renderable_elements");
|
|
|
|
max_renderable_lights = GLOBAL_GET("rendering/limits/opengl/max_renderable_lights");
|
|
|
|
max_lights_per_object = GLOBAL_GET("rendering/limits/opengl/max_lights_per_object");
|
2022-03-12 12:19:59 +01:00
|
|
|
}
|
|
|
|
|
2022-04-19 18:54:30 +02:00
|
|
|
Config::~Config() {
|
|
|
|
singleton = nullptr;
|
|
|
|
}
|
|
|
|
|
2022-03-12 12:19:59 +01:00
|
|
|
#endif // GLES3_ENABLED
|