config.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. #ifdef WEB_ENABLED
  34. #include <emscripten/html5_webgl.h>
  35. #endif
  36. using namespace GLES3;
  37. #define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
  38. Config *Config::singleton = nullptr;
  39. Config::Config() {
  40. singleton = this;
  41. #ifdef WEB_ENABLED
  42. // Starting with Emscripten 3.1.51, glGetStringi(GL_EXTENSIONS, i) will only ever return
  43. // a fixed list of extensions, regardless of what additional extensions are enabled. This
  44. // isn't very useful for us in determining which extensions we can rely on here. So, instead
  45. // we use emscripten_webgl_get_supported_extensions() to get all supported extensions, which
  46. // is what Emscripten 3.1.50 and earlier do.
  47. {
  48. char *extension_array_string = emscripten_webgl_get_supported_extensions();
  49. PackedStringArray extension_array = String((const char *)extension_array_string).split(" ");
  50. extensions.reserve(extension_array.size() * 2);
  51. for (const String &s : extension_array) {
  52. extensions.insert(s);
  53. extensions.insert("GL_" + s);
  54. }
  55. free(extension_array_string);
  56. }
  57. #else
  58. {
  59. GLint max_extensions = 0;
  60. glGetIntegerv(GL_NUM_EXTENSIONS, &max_extensions);
  61. for (int i = 0; i < max_extensions; i++) {
  62. const GLubyte *s = glGetStringi(GL_EXTENSIONS, i);
  63. if (!s) {
  64. break;
  65. }
  66. extensions.insert((const char *)s);
  67. }
  68. }
  69. #endif
  70. bptc_supported = extensions.has("GL_ARB_texture_compression_bptc") || extensions.has("GL_EXT_texture_compression_bptc");
  71. astc_hdr_supported = extensions.has("GL_KHR_texture_compression_astc_hdr");
  72. astc_supported = astc_hdr_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("WEBGL_compressed_texture_astc");
  73. astc_layered_supported = extensions.has("GL_KHR_texture_compression_astc_sliced_3d");
  74. if (RasterizerGLES3::is_gles_over_gl()) {
  75. float_texture_supported = true;
  76. float_texture_linear_supported = true;
  77. etc2_supported = false;
  78. s3tc_supported = true;
  79. rgtc_supported = true; //RGTC - core since OpenGL version 3.0
  80. srgb_framebuffer_supported = true;
  81. } else {
  82. float_texture_supported = extensions.has("GL_EXT_color_buffer_float");
  83. float_texture_linear_supported = extensions.has("GL_OES_texture_float_linear");
  84. etc2_supported = true;
  85. #if defined(ANDROID_ENABLED) || defined(IOS_ENABLED)
  86. // Some Android devices report support for S3TC but we don't expect that and don't export the textures.
  87. // This could be fixed but so few devices support it that it doesn't seem useful (and makes bigger APKs).
  88. // For good measure we do the same hack for iOS, just in case.
  89. s3tc_supported = false;
  90. #else
  91. s3tc_supported = extensions.has("GL_EXT_texture_compression_dxt1") || extensions.has("GL_EXT_texture_compression_s3tc") || extensions.has("WEBGL_compressed_texture_s3tc");
  92. #endif
  93. rgtc_supported = extensions.has("GL_EXT_texture_compression_rgtc") || extensions.has("GL_ARB_texture_compression_rgtc");
  94. srgb_framebuffer_supported = extensions.has("GL_EXT_sRGB_write_control");
  95. }
  96. glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max_vertex_texture_image_units);
  97. glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_image_units);
  98. glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
  99. glGetIntegerv(GL_MAX_VIEWPORT_DIMS, max_viewport_size);
  100. glGetInteger64v(GL_MAX_UNIFORM_BLOCK_SIZE, &max_uniform_buffer_size);
  101. GLint max_vertex_output;
  102. glGetIntegerv(GL_MAX_VERTEX_OUTPUT_COMPONENTS, &max_vertex_output);
  103. GLint max_fragment_input;
  104. glGetIntegerv(GL_MAX_FRAGMENT_INPUT_COMPONENTS, &max_fragment_input);
  105. max_shader_varyings = (uint32_t)MIN(max_vertex_output, max_fragment_input) / 4;
  106. // sanity clamp buffer size to 16K..1MB
  107. max_uniform_buffer_size = CLAMP(max_uniform_buffer_size, 16384, 1048576);
  108. support_anisotropic_filter = extensions.has("GL_EXT_texture_filter_anisotropic");
  109. if (support_anisotropic_filter) {
  110. glGetFloatv(_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_level);
  111. anisotropic_level = MIN(float(1 << int(GLOBAL_GET("rendering/textures/default_filters/anisotropic_filtering_level"))), anisotropic_level);
  112. }
  113. glGetIntegerv(GL_MAX_SAMPLES, &msaa_max_samples);
  114. #ifdef WEB_ENABLED
  115. msaa_supported = (msaa_max_samples > 0);
  116. #else
  117. msaa_supported = true;
  118. #endif
  119. #ifndef IOS_ENABLED
  120. #ifdef WEB_ENABLED
  121. msaa_multiview_supported = extensions.has("OCULUS_multiview");
  122. rt_msaa_multiview_supported = msaa_multiview_supported;
  123. #else
  124. msaa_multiview_supported = extensions.has("GL_EXT_multiview_texture_multisample");
  125. #endif
  126. multiview_supported = extensions.has("OCULUS_multiview") || extensions.has("GL_OVR_multiview2") || extensions.has("GL_OVR_multiview");
  127. #endif
  128. #ifdef ANDROID_ENABLED
  129. // These are GLES only
  130. rt_msaa_supported = extensions.has("GL_EXT_multisampled_render_to_texture");
  131. rt_msaa_multiview_supported = extensions.has("GL_OVR_multiview_multisampled_render_to_texture");
  132. external_texture_supported = extensions.has("GL_OES_EGL_image_external_essl3");
  133. if (multiview_supported) {
  134. eglFramebufferTextureMultiviewOVR = (PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC)eglGetProcAddress("glFramebufferTextureMultiviewOVR");
  135. if (eglFramebufferTextureMultiviewOVR == nullptr) {
  136. multiview_supported = false;
  137. }
  138. }
  139. if (msaa_multiview_supported) {
  140. eglTexStorage3DMultisample = (PFNGLTEXSTORAGE3DMULTISAMPLEPROC)eglGetProcAddress("glTexStorage3DMultisample");
  141. if (eglTexStorage3DMultisample == nullptr) {
  142. msaa_multiview_supported = false;
  143. }
  144. }
  145. if (rt_msaa_supported) {
  146. eglFramebufferTexture2DMultisampleEXT = (PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC)eglGetProcAddress("glFramebufferTexture2DMultisampleEXT");
  147. if (eglFramebufferTexture2DMultisampleEXT == nullptr) {
  148. rt_msaa_supported = false;
  149. }
  150. }
  151. if (rt_msaa_multiview_supported) {
  152. eglFramebufferTextureMultisampleMultiviewOVR = (PFNGLFRAMEBUFFERTEXTUREMULTISAMPLEMULTIVIEWOVRPROC)eglGetProcAddress("glFramebufferTextureMultisampleMultiviewOVR");
  153. if (eglFramebufferTextureMultisampleMultiviewOVR == nullptr) {
  154. rt_msaa_multiview_supported = false;
  155. }
  156. }
  157. if (external_texture_supported) {
  158. eglEGLImageTargetTexture2DOES = (PFNEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
  159. if (eglEGLImageTargetTexture2DOES == nullptr) {
  160. external_texture_supported = false;
  161. }
  162. }
  163. #endif
  164. force_vertex_shading = GLOBAL_GET("rendering/shading/overrides/force_vertex_shading");
  165. specular_occlusion = GLOBAL_GET("rendering/reflections/specular_occlusion/enabled");
  166. use_nearest_mip_filter = GLOBAL_GET("rendering/textures/default_filters/use_nearest_mipmap_filter");
  167. use_depth_prepass = bool(GLOBAL_GET("rendering/driver/depth_prepass/enable"));
  168. if (use_depth_prepass) {
  169. String vendors = GLOBAL_GET("rendering/driver/depth_prepass/disable_for_vendors");
  170. Vector<String> vendor_match = vendors.split(",");
  171. const String &renderer = String::utf8((const char *)glGetString(GL_RENDERER));
  172. for (int i = 0; i < vendor_match.size(); i++) {
  173. String v = vendor_match[i].strip_edges();
  174. if (v == String()) {
  175. continue;
  176. }
  177. if (renderer.containsn(v)) {
  178. use_depth_prepass = false;
  179. }
  180. }
  181. }
  182. max_renderable_elements = GLOBAL_GET("rendering/limits/opengl/max_renderable_elements");
  183. max_renderable_lights = GLOBAL_GET("rendering/limits/opengl/max_renderable_lights");
  184. max_lights_per_object = GLOBAL_GET("rendering/limits/opengl/max_lights_per_object");
  185. //Adreno 3xx Compatibility
  186. const String rendering_device_name = String::utf8((const char *)glGetString(GL_RENDERER));
  187. if (rendering_device_name.left(13) == "Adreno (TM) 3") {
  188. flip_xy_workaround = true;
  189. disable_particles_workaround = true;
  190. // ignore driver version 331+
  191. const String gl_version = String::utf8((const char *)glGetString(GL_VERSION));
  192. // Adreno 3xx examples (https://opengles.gpuinfo.org/listreports.php):
  193. // ===========================================================================
  194. // OpenGL ES 3.0 V@84.0 AU@ (CL@)
  195. // OpenGL ES 3.0 V@127.0 AU@ (GIT@I96aee987eb)
  196. // OpenGL ES 3.0 V@140.0 AU@ (GIT@Ifd751822f5)
  197. // OpenGL ES 3.0 V@251.0 AU@08.00.00.312.030 (GIT@Ie4790512f3)
  198. // OpenGL ES 3.0 V@269.0 AU@ (GIT@I109c45a694)
  199. // OpenGL ES 3.0 V@331.0 (GIT@35e467f, Ice9844a736) (Date:04/15/19)
  200. // OpenGL ES 3.0 V@415.0 (GIT@d39f783, I79de86aa2c, 1591296226) (Date:06/04/20)
  201. // OpenGL ES 3.0 V@0502.0 (GIT@09fef447e8, I1fe547a144, 1661493934) (Date:08/25/22)
  202. String driver_version = gl_version.get_slice("V@", 1).get_slicec(' ', 0);
  203. if (driver_version.is_valid_float() && driver_version.to_float() >= 331.0) {
  204. flip_xy_workaround = false;
  205. //TODO: also 'GPUParticles'?
  206. //https://github.com/godotengine/godot/issues/92662#issuecomment-2161199477
  207. //disable_particles_workaround = false;
  208. }
  209. } else if (rendering_device_name == "PowerVR Rogue GE8320") {
  210. disable_transform_feedback_shader_cache = true;
  211. }
  212. if (OS::get_singleton()->get_current_rendering_driver_name() == "opengl3_angle") {
  213. polyfill_half2float = false;
  214. }
  215. #ifdef WEB_ENABLED
  216. polyfill_half2float = false;
  217. #endif
  218. }
  219. Config::~Config() {
  220. singleton = nullptr;
  221. }
  222. #endif // GLES3_ENABLED