config.cpp 6.4 KB

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