config.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 "../rasterizer_gles3.h"
  33. #include "texture_storage.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. int64_t max_extensions = 0;
  41. glGetInteger64v(GL_NUM_EXTENSIONS, &max_extensions);
  42. for (int64_t 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. 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");
  52. astc_hdr_supported = extensions.has("GL_KHR_texture_compression_astc_ldr");
  53. astc_layered_supported = extensions.has("GL_KHR_texture_compression_astc_sliced_3d");
  54. if (RasterizerGLES3::is_gles_over_gl()) {
  55. float_texture_supported = true;
  56. etc2_supported = false;
  57. s3tc_supported = true;
  58. rgtc_supported = true; //RGTC - core since OpenGL version 3.0
  59. } else {
  60. float_texture_supported = extensions.has("GL_EXT_color_buffer_float");
  61. etc2_supported = true;
  62. #if defined(ANDROID_ENABLED) || defined(IOS_ENABLED)
  63. // Some Android devices report support for S3TC but we don't expect that and don't export the textures.
  64. // This could be fixed but so few devices support it that it doesn't seem useful (and makes bigger APKs).
  65. // For good measure we do the same hack for iOS, just in case.
  66. s3tc_supported = false;
  67. #else
  68. s3tc_supported = extensions.has("GL_EXT_texture_compression_dxt1") || extensions.has("GL_EXT_texture_compression_s3tc") || extensions.has("WEBGL_compressed_texture_s3tc");
  69. #endif
  70. rgtc_supported = extensions.has("GL_EXT_texture_compression_rgtc") || extensions.has("GL_ARB_texture_compression_rgtc") || extensions.has("EXT_texture_compression_rgtc");
  71. }
  72. glGetInteger64v(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max_vertex_texture_image_units);
  73. glGetInteger64v(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_image_units);
  74. glGetInteger64v(GL_MAX_TEXTURE_SIZE, &max_texture_size);
  75. glGetInteger64v(GL_MAX_UNIFORM_BLOCK_SIZE, &max_uniform_buffer_size);
  76. glGetInteger64v(GL_MAX_VIEWPORT_DIMS, max_viewport_size);
  77. support_anisotropic_filter = extensions.has("GL_EXT_texture_filter_anisotropic");
  78. if (support_anisotropic_filter) {
  79. glGetFloatv(_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_level);
  80. anisotropic_level = MIN(float(1 << int(GLOBAL_GET("rendering/textures/default_filters/anisotropic_filtering_level"))), anisotropic_level);
  81. }
  82. multiview_supported = extensions.has("GL_OVR_multiview2") || extensions.has("GL_OVR_multiview");
  83. #ifdef ANDROID_ENABLED
  84. if (multiview_supported) {
  85. eglFramebufferTextureMultiviewOVR = (PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC)eglGetProcAddress("glFramebufferTextureMultiviewOVR");
  86. if (eglFramebufferTextureMultiviewOVR == nullptr) {
  87. multiview_supported = false;
  88. }
  89. }
  90. #endif
  91. force_vertex_shading = false; //GLOBAL_GET("rendering/quality/shading/force_vertex_shading");
  92. use_nearest_mip_filter = GLOBAL_GET("rendering/textures/default_filters/use_nearest_mipmap_filter");
  93. use_depth_prepass = bool(GLOBAL_GET("rendering/driver/depth_prepass/enable"));
  94. if (use_depth_prepass) {
  95. String vendors = GLOBAL_GET("rendering/driver/depth_prepass/disable_for_vendors");
  96. Vector<String> vendor_match = vendors.split(",");
  97. const String &renderer = String::utf8((const char *)glGetString(GL_RENDERER));
  98. for (int i = 0; i < vendor_match.size(); i++) {
  99. String v = vendor_match[i].strip_edges();
  100. if (v == String()) {
  101. continue;
  102. }
  103. if (renderer.findn(v) != -1) {
  104. use_depth_prepass = false;
  105. }
  106. }
  107. }
  108. max_renderable_elements = GLOBAL_GET("rendering/limits/opengl/max_renderable_elements");
  109. max_renderable_lights = GLOBAL_GET("rendering/limits/opengl/max_renderable_lights");
  110. max_lights_per_object = GLOBAL_GET("rendering/limits/opengl/max_lights_per_object");
  111. }
  112. Config::~Config() {
  113. singleton = nullptr;
  114. }
  115. #endif // GLES3_ENABLED