config.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*************************************************************************/
  2. /* config.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. #ifdef GLES3_ENABLED
  31. #include "config.h"
  32. #include "core/config/project_settings.h"
  33. #include "core/templates/vector.h"
  34. using namespace GLES3;
  35. #define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
  36. Config *Config::singleton = nullptr;
  37. Config::Config() {
  38. singleton = this;
  39. {
  40. GLint max_extensions = 0;
  41. glGetIntegerv(GL_NUM_EXTENSIONS, &max_extensions);
  42. for (int i = 0; i < max_extensions; i++) {
  43. const GLubyte *s = glGetStringi(GL_EXTENSIONS, i);
  44. if (!s) {
  45. break;
  46. }
  47. extensions.insert((const char *)s);
  48. }
  49. }
  50. bptc_supported = extensions.has("GL_ARB_texture_compression_bptc") || extensions.has("EXT_texture_compression_bptc");
  51. #ifdef GLES_OVER_GL
  52. float_texture_supported = true;
  53. etc2_supported = false;
  54. s3tc_supported = true;
  55. rgtc_supported = true; //RGTC - core since OpenGL version 3.0
  56. #else
  57. float_texture_supported = extensions.has("GL_ARB_texture_float") || extensions.has("GL_OES_texture_float");
  58. etc2_supported = true;
  59. #if defined(ANDROID_ENABLED) || defined(IOS_ENABLED)
  60. // Some Android devices report support for S3TC but we don't expect that and don't export the textures.
  61. // This could be fixed but so few devices support it that it doesn't seem useful (and makes bigger APKs).
  62. // For good measure we do the same hack for iOS, just in case.
  63. s3tc_supported = false;
  64. #else
  65. s3tc_supported = extensions.has("GL_EXT_texture_compression_dxt1") || extensions.has("GL_EXT_texture_compression_s3tc") || extensions.has("WEBGL_compressed_texture_s3tc");
  66. #endif
  67. rgtc_supported = extensions.has("GL_EXT_texture_compression_rgtc") || extensions.has("GL_ARB_texture_compression_rgtc") || extensions.has("EXT_texture_compression_rgtc");
  68. #endif
  69. #ifdef GLES_OVER_GL
  70. use_rgba_2d_shadows = false;
  71. #else
  72. use_rgba_2d_shadows = !(float_texture_supported && extensions.has("GL_EXT_texture_rg"));
  73. #endif
  74. glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max_vertex_texture_image_units);
  75. glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_image_units);
  76. glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
  77. glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &max_uniform_buffer_size);
  78. glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &uniform_buffer_offset_alignment);
  79. // the use skeleton software path should be used if either float texture is not supported,
  80. // OR max_vertex_texture_image_units is zero
  81. use_skeleton_software = (float_texture_supported == false) || (max_vertex_texture_image_units == 0);
  82. support_anisotropic_filter = extensions.has("GL_EXT_texture_filter_anisotropic");
  83. if (support_anisotropic_filter) {
  84. glGetFloatv(_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_level);
  85. anisotropic_level = MIN(float(1 << int(GLOBAL_GET("rendering/textures/default_filters/anisotropic_filtering_level"))), anisotropic_level);
  86. }
  87. force_vertex_shading = false; //GLOBAL_GET("rendering/quality/shading/force_vertex_shading");
  88. use_nearest_mip_filter = GLOBAL_GET("rendering/textures/default_filters/use_nearest_mipmap_filter");
  89. use_depth_prepass = bool(GLOBAL_GET("rendering/driver/depth_prepass/enable"));
  90. if (use_depth_prepass) {
  91. String vendors = GLOBAL_GET("rendering/driver/depth_prepass/disable_for_vendors");
  92. Vector<String> vendor_match = vendors.split(",");
  93. String renderer = (const char *)glGetString(GL_RENDERER);
  94. for (int i = 0; i < vendor_match.size(); i++) {
  95. String v = vendor_match[i].strip_edges();
  96. if (v == String()) {
  97. continue;
  98. }
  99. if (renderer.findn(v) != -1) {
  100. use_depth_prepass = false;
  101. }
  102. }
  103. }
  104. max_renderable_elements = GLOBAL_GET("rendering/limits/opengl/max_renderable_elements");
  105. max_renderable_lights = GLOBAL_GET("rendering/limits/opengl/max_renderable_lights");
  106. max_lights_per_object = GLOBAL_GET("rendering/limits/opengl/max_lights_per_object");
  107. }
  108. Config::~Config() {
  109. singleton = nullptr;
  110. }
  111. #endif // GLES3_ENABLED