diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2021-11-12 14:49:49 +0200 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2023-09-21 14:21:00 +0300 |
commit | 1887a9df19ea689bfb69f55454f0598bd09ab95f (patch) | |
tree | b303d94caa33c5ee0f27544057f8cea1ced36a5e /drivers/gles3 | |
parent | 59139df16e7a10c3b9176f697d23b557af46601e (diff) | |
download | redot-engine-1887a9df19ea689bfb69f55454f0598bd09ab95f.tar.gz |
[macOS/Windows] Add optional ANGLE backed OpenGL renderer support. Add EGL_ANDROID_blob_cache caching.
Co-authored-by: Riteo <riteo@posteo.net>
Diffstat (limited to 'drivers/gles3')
-rw-r--r-- | drivers/gles3/environment/gi.h | 7 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_canvas_gles3.cpp | 7 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_gles3.cpp | 144 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_gles3.h | 8 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.cpp | 83 | ||||
-rw-r--r-- | drivers/gles3/shader_gles3.cpp | 37 | ||||
-rw-r--r-- | drivers/gles3/shader_gles3.h | 8 | ||||
-rw-r--r-- | drivers/gles3/storage/config.cpp | 42 | ||||
-rw-r--r-- | drivers/gles3/storage/config.h | 10 | ||||
-rw-r--r-- | drivers/gles3/storage/light_storage.h | 9 | ||||
-rw-r--r-- | drivers/gles3/storage/mesh_storage.h | 7 | ||||
-rw-r--r-- | drivers/gles3/storage/particles_storage.h | 7 | ||||
-rw-r--r-- | drivers/gles3/storage/render_scene_buffers_gles3.h | 7 | ||||
-rw-r--r-- | drivers/gles3/storage/texture_storage.cpp | 225 | ||||
-rw-r--r-- | drivers/gles3/storage/texture_storage.h | 16 | ||||
-rw-r--r-- | drivers/gles3/storage/utilities.cpp | 24 | ||||
-rw-r--r-- | drivers/gles3/storage/utilities.h | 7 |
17 files changed, 348 insertions, 300 deletions
diff --git a/drivers/gles3/environment/gi.h b/drivers/gles3/environment/gi.h index 713c3ef3a5..41958e43e6 100644 --- a/drivers/gles3/environment/gi.h +++ b/drivers/gles3/environment/gi.h @@ -38,12 +38,7 @@ #include "core/templates/self_list.h" #include "servers/rendering/environment/renderer_gi.h" -#include "platform_config.h" -#ifndef OPENGL_INCLUDE_H -#include <GLES3/gl3.h> -#else -#include OPENGL_INCLUDE_H -#endif +#include "platform_gl.h" namespace GLES3 { diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index 4c4a2cd76f..2894f4164f 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -33,6 +33,7 @@ #ifdef GLES3_ENABLED #include "core/os/os.h" +#include "rasterizer_gles3.h" #include "rasterizer_scene_gles3.h" #include "core/config/project_settings.h" @@ -1561,7 +1562,8 @@ void RasterizerCanvasGLES3::light_update_shadow(RID p_rid, int p_shadow_index, c glEnable(GL_SCISSOR_TEST); glScissor(0, p_shadow_index * 2, state.shadow_texture_size, 2); glClearColor(p_far, p_far, p_far, 1.0); - glClearDepth(1.0); + RasterizerGLES3::clear_depth(1.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glCullFace(GL_BACK); @@ -1682,7 +1684,8 @@ void RasterizerCanvasGLES3::light_update_directional_shadow(RID p_rid, int p_sha glEnable(GL_SCISSOR_TEST); glScissor(0, p_shadow_index * 2, state.shadow_texture_size, 2); glClearColor(1.0, 1.0, 1.0, 1.0); - glClearDepth(1.0); + RasterizerGLES3::clear_depth(1.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glCullFace(GL_BACK); diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index cc35ea72e2..c048e9bf37 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -76,19 +76,14 @@ #define CAN_DEBUG #endif -#if !defined(GLES_OVER_GL) && defined(CAN_DEBUG) -#include <GLES3/gl3.h> -#include <GLES3/gl3ext.h> -#include <GLES3/gl3platform.h> - -#include <EGL/egl.h> -#include <EGL/eglext.h> -#endif +#include "platform_gl.h" #if defined(MINGW_ENABLED) || defined(_MSC_VER) #define strcpy strcpy_s #endif +bool RasterizerGLES3::gles_over_gl = true; + void RasterizerGLES3::begin_frame(double frame_step) { frame++; delta = frame_step; @@ -115,6 +110,19 @@ void RasterizerGLES3::end_frame(bool p_swap_buffers) { } } +void RasterizerGLES3::clear_depth(float p_depth) { +#ifdef GL_API_ENABLED + if (is_gles_over_gl()) { + glClearDepth(p_depth); + } +#endif // GL_API_ENABLED +#ifdef GLES_API_ENABLED + if (!is_gles_over_gl()) { + glClearDepthf(p_depth); + } +#endif // GLES_API_ENABLED +} + #ifdef CAN_DEBUG static void GLAPIENTRY _gl_debug_print(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const GLvoid *userParam) { if (type == _EXT_DEBUG_TYPE_OTHER_ARB) { @@ -169,7 +177,7 @@ static void GLAPIENTRY _gl_debug_print(GLenum source, GLenum type, GLuint id, GL } #endif -typedef void (*DEBUGPROCARB)(GLenum source, +typedef void(GLAPIENTRY *DEBUGPROCARB)(GLenum source, GLenum type, GLuint id, GLenum severity, @@ -177,7 +185,7 @@ typedef void (*DEBUGPROCARB)(GLenum source, const char *message, const void *userParam); -typedef void (*DebugMessageCallbackARB)(DEBUGPROCARB callback, const void *userParam); +typedef void(GLAPIENTRY *DebugMessageCallbackARB)(DEBUGPROCARB callback, const void *userParam); void RasterizerGLES3::initialize() { print_line(vformat("OpenGL API %s - Compatibility - Using Device: %s - %s", RS::get_singleton()->get_video_adapter_api_version(), RS::get_singleton()->get_video_adapter_vendor(), RS::get_singleton()->get_video_adapter_name())); @@ -200,61 +208,99 @@ void RasterizerGLES3::finalize() { RasterizerGLES3 *RasterizerGLES3::singleton = nullptr; +#ifdef EGL_ENABLED +void *_egl_load_function_wrapper(const char *p_name) { + return (void *)eglGetProcAddress(p_name); +} +#endif + RasterizerGLES3::RasterizerGLES3() { singleton = this; #ifdef GLAD_ENABLED - if (!gladLoaderLoadGL()) { - ERR_PRINT("Error initializing GLAD"); - // FIXME this is an early return from a constructor. Any other code using this instance will crash or the finalizer will crash, because none of - // the members of this instance are initialized, so this just makes debugging harder. It should either crash here intentionally, - // or we need to actually test for this situation before constructing this. - return; - } + bool glad_loaded = false; + +#ifdef EGL_ENABLED + // There should be a more flexible system for getting the GL pointer, as + // different DisplayServers can have different ways. We can just use the GLAD + // version global to see if it loaded for now though, otherwise we fall back to + // the generic loader below. +#if defined(EGL_STATIC) + bool has_egl = true; +#else + bool has_egl = (eglGetProcAddress != nullptr); #endif -#ifdef GLAD_ENABLED - if (OS::get_singleton()->is_stdout_verbose()) { - if (GLAD_GL_ARB_debug_output) { - glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB); - glDebugMessageCallbackARB(_gl_debug_print, nullptr); - glEnable(_EXT_DEBUG_OUTPUT); - } else { - print_line("OpenGL debugging not supported!"); + if (gles_over_gl) { + if (has_egl && !glad_loaded && gladLoadGL((GLADloadfunc)&_egl_load_function_wrapper)) { + glad_loaded = true; + } + } else { + if (has_egl && !glad_loaded && gladLoadGLES2((GLADloadfunc)&_egl_load_function_wrapper)) { + glad_loaded = true; + } + } +#endif // EGL_ENABLED + + if (gles_over_gl) { + if (!glad_loaded && gladLoaderLoadGL()) { + glad_loaded = true; + } + } else { + if (!glad_loaded && gladLoaderLoadGLES2()) { + glad_loaded = true; + } + } + + // FIXME this is an early return from a constructor. Any other code using this instance will crash or the finalizer will crash, because none of + // the members of this instance are initialized, so this just makes debugging harder. It should either crash here intentionally, + // or we need to actually test for this situation before constructing this. + ERR_FAIL_COND_MSG(!glad_loaded, "Error initializing GLAD."); + + if (gles_over_gl) { + if (OS::get_singleton()->is_stdout_verbose()) { + if (GLAD_GL_ARB_debug_output) { + glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB); + glDebugMessageCallbackARB((GLDEBUGPROCARB)_gl_debug_print, nullptr); + glEnable(_EXT_DEBUG_OUTPUT); + } else { + print_line("OpenGL debugging not supported!"); + } } } #endif // GLAD_ENABLED // For debugging #ifdef CAN_DEBUG -#ifdef GLES_OVER_GL - if (OS::get_singleton()->is_stdout_verbose() && GLAD_GL_ARB_debug_output) { - glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_ERROR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); - glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); - glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); - glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_PORTABILITY_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); - glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_PERFORMANCE_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); - glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_OTHER_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); - // glDebugMessageInsertARB( - // GL_DEBUG_SOURCE_API_ARB, - // GL_DEBUG_TYPE_OTHER_ARB, 1, - // GL_DEBUG_SEVERITY_HIGH_ARB, 5, "hello"); - } -#else - if (OS::get_singleton()->is_stdout_verbose()) { - DebugMessageCallbackARB callback = (DebugMessageCallbackARB)eglGetProcAddress("glDebugMessageCallback"); - if (!callback) { - callback = (DebugMessageCallbackARB)eglGetProcAddress("glDebugMessageCallbackKHR"); +#ifdef GL_API_ENABLED + if (gles_over_gl) { + if (OS::get_singleton()->is_stdout_verbose() && GLAD_GL_ARB_debug_output) { + glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_ERROR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); + glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); + glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); + glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_PORTABILITY_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); + glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_PERFORMANCE_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); + glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_OTHER_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE); } + } +#endif // GL_API_ENABLED +#ifdef GLES_API_ENABLED + if (!gles_over_gl) { + if (OS::get_singleton()->is_stdout_verbose()) { + DebugMessageCallbackARB callback = (DebugMessageCallbackARB)eglGetProcAddress("glDebugMessageCallback"); + if (!callback) { + callback = (DebugMessageCallbackARB)eglGetProcAddress("glDebugMessageCallbackKHR"); + } - if (callback) { - print_line("godot: ENABLING GL DEBUG"); - glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB); - callback(_gl_debug_print, NULL); - glEnable(_EXT_DEBUG_OUTPUT); + if (callback) { + print_line("godot: ENABLING GL DEBUG"); + glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB); + callback((DEBUGPROCARB)_gl_debug_print, NULL); + glEnable(_EXT_DEBUG_OUTPUT); + } } } -#endif // GLES_OVER_GL +#endif // GLES_API_ENABLED #endif // CAN_DEBUG { diff --git a/drivers/gles3/rasterizer_gles3.h b/drivers/gles3/rasterizer_gles3.h index e29ccefdbd..b19ca0e9c9 100644 --- a/drivers/gles3/rasterizer_gles3.h +++ b/drivers/gles3/rasterizer_gles3.h @@ -54,6 +54,8 @@ private: double time_total = 0.0; + static bool gles_over_gl; + protected: GLES3::Config *config = nullptr; GLES3::Utilities *utilities = nullptr; @@ -99,7 +101,11 @@ public: return memnew(RasterizerGLES3); } - static void make_current() { + static bool is_gles_over_gl() { return gles_over_gl; } + static void clear_depth(float p_depth); + + static void make_current(bool p_gles_over_gl) { + gles_over_gl = p_gles_over_gl; _create_func = _create_current; low_end = true; } diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 257d310075..de2de54c44 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -29,15 +29,18 @@ /**************************************************************************/ #include "rasterizer_scene_gles3.h" -#include "core/config/project_settings.h" -#include "core/templates/sort_array.h" -#include "servers/rendering/rendering_server_default.h" -#include "servers/rendering/rendering_server_globals.h" + +#include "rasterizer_gles3.h" #include "storage/config.h" #include "storage/mesh_storage.h" #include "storage/particles_storage.h" #include "storage/texture_storage.h" +#include "core/config/project_settings.h" +#include "core/templates/sort_array.h" +#include "servers/rendering/rendering_server_default.h" +#include "servers/rendering/rendering_server_globals.h" + #ifdef GLES3_ENABLED RasterizerSceneGLES3 *RasterizerSceneGLES3::singleton = nullptr; @@ -528,19 +531,24 @@ void RasterizerSceneGLES3::_update_dirty_skys() { glGenTextures(1, &sky->radiance); glBindTexture(GL_TEXTURE_CUBE_MAP, sky->radiance); -#ifdef GLES_OVER_GL - GLenum format = GL_RGBA; - GLenum type = GL_UNSIGNED_INT_2_10_10_10_REV; - //TODO, on low-end compare this to allocating each face of each mip individually - // see: https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glTexStorage2D.xhtml - for (int i = 0; i < 6; i++) { - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internal_format, sky->radiance_size, sky->radiance_size, 0, format, type, nullptr); - } +#ifdef GL_API_ENABLED + if (RasterizerGLES3::is_gles_over_gl()) { + GLenum format = GL_RGBA; + GLenum type = GL_UNSIGNED_INT_2_10_10_10_REV; + //TODO, on low-end compare this to allocating each face of each mip individually + // see: https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glTexStorage2D.xhtml + for (int i = 0; i < 6; i++) { + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internal_format, sky->radiance_size, sky->radiance_size, 0, format, type, nullptr); + } - glGenerateMipmap(GL_TEXTURE_CUBE_MAP); -#else - glTexStorage2D(GL_TEXTURE_CUBE_MAP, sky->mipmap_count, internal_format, sky->radiance_size, sky->radiance_size); -#endif + glGenerateMipmap(GL_TEXTURE_CUBE_MAP); + } +#endif // GL_API_ENABLED +#ifdef GLES_API_ENABLED + if (!RasterizerGLES3::is_gles_over_gl()) { + glTexStorage2D(GL_TEXTURE_CUBE_MAP, sky->mipmap_count, internal_format, sky->radiance_size, sky->radiance_size); + } +#endif // GLES_API_ENABLED glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -553,17 +561,24 @@ void RasterizerSceneGLES3::_update_dirty_skys() { glGenTextures(1, &sky->raw_radiance); glBindTexture(GL_TEXTURE_CUBE_MAP, sky->raw_radiance); -#ifdef GLES_OVER_GL - //TODO, on low-end compare this to allocating each face of each mip individually - // see: https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glTexStorage2D.xhtml - for (int i = 0; i < 6; i++) { - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internal_format, sky->radiance_size, sky->radiance_size, 0, format, type, nullptr); - } +#ifdef GL_API_ENABLED + if (RasterizerGLES3::is_gles_over_gl()) { + GLenum format = GL_RGBA; + GLenum type = GL_UNSIGNED_INT_2_10_10_10_REV; + //TODO, on low-end compare this to allocating each face of each mip individually + // see: https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glTexStorage2D.xhtml + for (int i = 0; i < 6; i++) { + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internal_format, sky->radiance_size, sky->radiance_size, 0, format, type, nullptr); + } - glGenerateMipmap(GL_TEXTURE_CUBE_MAP); -#else - glTexStorage2D(GL_TEXTURE_CUBE_MAP, sky->mipmap_count, internal_format, sky->radiance_size, sky->radiance_size); -#endif + glGenerateMipmap(GL_TEXTURE_CUBE_MAP); + } +#endif // GL_API_ENABLED +#ifdef GLES_API_ENABLED + if (!RasterizerGLES3::is_gles_over_gl()) { + glTexStorage2D(GL_TEXTURE_CUBE_MAP, sky->mipmap_count, internal_format, sky->radiance_size, sky->radiance_size); + } +#endif // GLES_API_ENABLED glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -1944,7 +1959,8 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_ glDisable(GL_SCISSOR_TEST); glColorMask(0, 0, 0, 0); - glClearDepth(1.0f); + RasterizerGLES3::clear_depth(1.0); + glClear(GL_DEPTH_BUFFER_BIT); uint64_t spec_constant = SceneShaderGLES3::DISABLE_FOG | SceneShaderGLES3::DISABLE_LIGHT_DIRECTIONAL | SceneShaderGLES3::DISABLE_LIGHTMAP | SceneShaderGLES3::DISABLE_LIGHT_OMNI | @@ -1979,7 +1995,7 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_ scene_state.current_depth_draw = GLES3::SceneShaderData::DEPTH_DRAW_ALWAYS; if (!fb_cleared) { - glClearDepth(1.0f); + RasterizerGLES3::clear_depth(1.0); glClear(GL_DEPTH_BUFFER_BIT); } @@ -2505,7 +2521,8 @@ void RasterizerSceneGLES3::render_particle_collider_heightfield(RID p_collider, scene_state.cull_mode = GLES3::SceneShaderData::CULL_BACK; glColorMask(0, 0, 0, 0); - glClearDepth(1.0f); + RasterizerGLES3::clear_depth(1.0); + glClear(GL_DEPTH_BUFFER_BIT); RenderListParameters render_list_params(render_list[RENDER_LIST_SECONDARY].elements.ptr(), render_list[RENDER_LIST_SECONDARY].elements.size(), false, 31, false); @@ -2778,9 +2795,11 @@ void sky() { glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind } -#ifdef GLES_OVER_GL - glEnable(_EXT_TEXTURE_CUBE_MAP_SEAMLESS); -#endif +#ifdef GL_API_ENABLED + if (RasterizerGLES3::is_gles_over_gl()) { + glEnable(_EXT_TEXTURE_CUBE_MAP_SEAMLESS); + } +#endif // GL_API_ENABLED // MultiMesh may read from color when color is disabled, so make sure that the color defaults to white instead of black; glVertexAttrib4f(RS::ARRAY_COLOR, 1.0, 1.0, 1.0, 1.0); diff --git a/drivers/gles3/shader_gles3.cpp b/drivers/gles3/shader_gles3.cpp index dfc500ea83..51fed4da98 100644 --- a/drivers/gles3/shader_gles3.cpp +++ b/drivers/gles3/shader_gles3.cpp @@ -36,6 +36,8 @@ #include "core/io/dir_access.h" #include "core/io/file_access.h" +#include "drivers/gles3/rasterizer_gles3.h" + static String _mkid(const String &p_id) { String id = "m_" + p_id.replace("__", "_dus_"); return id.replace("__", "_dus_"); //doubleunderscore is reserved in glsl @@ -150,12 +152,12 @@ RID ShaderGLES3::version_create() { } void ShaderGLES3::_build_variant_code(StringBuilder &builder, uint32_t p_variant, const Version *p_version, StageType p_stage_type, uint64_t p_specialization) { -#ifdef GLES_OVER_GL - builder.append("#version 330\n"); - builder.append("#define USE_GLES_OVER_GL\n"); -#else - builder.append("#version 300 es\n"); -#endif + if (RasterizerGLES3::is_gles_over_gl()) { + builder.append("#version 330\n"); + builder.append("#define USE_GLES_OVER_GL\n"); + } else { + builder.append("#version 300 es\n"); + } for (int i = 0; i < specialization_count; i++) { if (p_specialization & (uint64_t(1) << uint64_t(i))) { @@ -199,11 +201,11 @@ void ShaderGLES3::_build_variant_code(StringBuilder &builder, uint32_t p_variant // Default to highp precision unless specified otherwise. builder.append("precision highp float;\n"); builder.append("precision highp int;\n"); -#ifndef GLES_OVER_GL - builder.append("precision highp sampler2D;\n"); - builder.append("precision highp samplerCube;\n"); - builder.append("precision highp sampler2DArray;\n"); -#endif + if (!RasterizerGLES3::is_gles_over_gl()) { + builder.append("precision highp sampler2D;\n"); + builder.append("precision highp samplerCube;\n"); + builder.append("precision highp sampler2DArray;\n"); + } const StageTemplate &stage_template = stage_templates[p_stage_type]; for (uint32_t i = 0; i < stage_template.chunks.size(); i++) { @@ -510,6 +512,11 @@ String ShaderGLES3::_version_get_sha1(Version *p_version) const { hash_build.append("[custom_defines:" + itos(i) + "]"); hash_build.append(p_version->custom_defines[i].get_data()); } + if (RasterizerGLES3::is_gles_over_gl()) { + hash_build.append("[gl]"); + } else { + hash_build.append("[gles]"); + } return hash_build.as_string().sha1_text(); } @@ -523,8 +530,8 @@ bool ShaderGLES3::_load_from_cache(Version *p_version) { #ifdef WEB_ENABLED // not supported in webgl return false; #else -#ifdef GLES_OVER_GL - if (glProgramBinary == NULL) { // ARB_get_program_binary extension not available +#if !defined(ANDROID_ENABLED) && !defined(IOS_ENABLED) + if (RasterizerGLES3::is_gles_over_gl() && (glProgramBinary == NULL)) { // ARB_get_program_binary extension not available. return false; } #endif @@ -596,8 +603,8 @@ void ShaderGLES3::_save_to_cache(Version *p_version) { #ifdef WEB_ENABLED // not supported in webgl return; #else -#ifdef GLES_OVER_GL - if (glGetProgramBinary == NULL) { // ARB_get_program_binary extension not available +#if !defined(ANDROID_ENABLED) && !defined(IOS_ENABLED) + if (RasterizerGLES3::is_gles_over_gl() && (glGetProgramBinary == NULL)) { // ARB_get_program_binary extension not available. return; } #endif diff --git a/drivers/gles3/shader_gles3.h b/drivers/gles3/shader_gles3.h index fc16e01040..0cb53da316 100644 --- a/drivers/gles3/shader_gles3.h +++ b/drivers/gles3/shader_gles3.h @@ -43,13 +43,7 @@ #ifdef GLES3_ENABLED -// This must come first to avoid windows.h mess -#include "platform_config.h" -#ifndef OPENGL_INCLUDE_H -#include <GLES3/gl3.h> -#else -#include OPENGL_INCLUDE_H -#endif +#include "platform_gl.h" #include <stdio.h> diff --git a/drivers/gles3/storage/config.cpp b/drivers/gles3/storage/config.cpp index 03dde88d4b..be7555788a 100644 --- a/drivers/gles3/storage/config.cpp +++ b/drivers/gles3/storage/config.cpp @@ -31,17 +31,9 @@ #ifdef GLES3_ENABLED #include "config.h" -#include "core/config/project_settings.h" -#include "core/templates/vector.h" -#ifdef ANDROID_ENABLED -#include <GLES3/gl3.h> -#include <GLES3/gl3ext.h> -#include <GLES3/gl3platform.h> - -#include <EGL/egl.h> -#include <EGL/eglext.h> -#endif +#include "../rasterizer_gles3.h" +#include "texture_storage.h" using namespace GLES3; @@ -69,24 +61,24 @@ Config::Config() { astc_hdr_supported = extensions.has("GL_KHR_texture_compression_astc_ldr"); astc_layered_supported = extensions.has("GL_KHR_texture_compression_astc_sliced_3d"); -#ifdef GLES_OVER_GL - float_texture_supported = true; - etc2_supported = false; - s3tc_supported = true; - rgtc_supported = true; //RGTC - core since OpenGL version 3.0 -#else - float_texture_supported = extensions.has("GL_EXT_color_buffer_float"); - etc2_supported = true; + if (RasterizerGLES3::is_gles_over_gl()) { + float_texture_supported = true; + etc2_supported = false; + s3tc_supported = true; + rgtc_supported = true; //RGTC - core since OpenGL version 3.0 + } else { + float_texture_supported = extensions.has("GL_EXT_color_buffer_float"); + etc2_supported = true; #if defined(ANDROID_ENABLED) || defined(IOS_ENABLED) - // 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; + // 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 - s3tc_supported = extensions.has("GL_EXT_texture_compression_dxt1") || extensions.has("GL_EXT_texture_compression_s3tc") || extensions.has("WEBGL_compressed_texture_s3tc"); -#endif - rgtc_supported = extensions.has("GL_EXT_texture_compression_rgtc") || extensions.has("GL_ARB_texture_compression_rgtc") || extensions.has("EXT_texture_compression_rgtc"); + s3tc_supported = extensions.has("GL_EXT_texture_compression_dxt1") || extensions.has("GL_EXT_texture_compression_s3tc") || extensions.has("WEBGL_compressed_texture_s3tc"); #endif + rgtc_supported = extensions.has("GL_EXT_texture_compression_rgtc") || extensions.has("GL_ARB_texture_compression_rgtc") || extensions.has("EXT_texture_compression_rgtc"); + } glGetInteger64v(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max_vertex_texture_image_units); glGetInteger64v(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_image_units); diff --git a/drivers/gles3/storage/config.h b/drivers/gles3/storage/config.h index 6b90c8c359..b2dd98f025 100644 --- a/drivers/gles3/storage/config.h +++ b/drivers/gles3/storage/config.h @@ -33,16 +33,12 @@ #ifdef GLES3_ENABLED +#include "core/config/project_settings.h" #include "core/string/ustring.h" #include "core/templates/hash_set.h" +#include "core/templates/vector.h" -// This must come first to avoid windows.h mess -#include "platform_config.h" -#ifndef OPENGL_INCLUDE_H -#include <GLES3/gl3.h> -#else -#include OPENGL_INCLUDE_H -#endif +#include "platform_gl.h" #ifdef ANDROID_ENABLED typedef void (*PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC)(GLenum, GLenum, GLuint, GLint, GLint, GLsizei); diff --git a/drivers/gles3/storage/light_storage.h b/drivers/gles3/storage/light_storage.h index b141fbb3c4..8491b378fe 100644 --- a/drivers/gles3/storage/light_storage.h +++ b/drivers/gles3/storage/light_storage.h @@ -33,6 +33,8 @@ #ifdef GLES3_ENABLED +#include "platform_gl.h" + #include "core/templates/local_vector.h" #include "core/templates/rid_owner.h" #include "core/templates/self_list.h" @@ -41,13 +43,6 @@ #include "servers/rendering/storage/light_storage.h" #include "servers/rendering/storage/utilities.h" -#include "platform_config.h" -#ifndef OPENGL_INCLUDE_H -#include <GLES3/gl3.h> -#else -#include OPENGL_INCLUDE_H -#endif - namespace GLES3 { /* LIGHT */ diff --git a/drivers/gles3/storage/mesh_storage.h b/drivers/gles3/storage/mesh_storage.h index 1c0a2129f5..09212e4b5c 100644 --- a/drivers/gles3/storage/mesh_storage.h +++ b/drivers/gles3/storage/mesh_storage.h @@ -40,12 +40,7 @@ #include "servers/rendering/storage/mesh_storage.h" #include "servers/rendering/storage/utilities.h" -#include "platform_config.h" -#ifndef OPENGL_INCLUDE_H -#include <GLES3/gl3.h> -#else -#include OPENGL_INCLUDE_H -#endif +#include "platform_gl.h" namespace GLES3 { diff --git a/drivers/gles3/storage/particles_storage.h b/drivers/gles3/storage/particles_storage.h index be1799322a..5146dc5329 100644 --- a/drivers/gles3/storage/particles_storage.h +++ b/drivers/gles3/storage/particles_storage.h @@ -40,12 +40,7 @@ #include "servers/rendering/storage/particles_storage.h" #include "servers/rendering/storage/utilities.h" -#include "platform_config.h" -#ifndef OPENGL_INCLUDE_H -#include <GLES3/gl3.h> -#else -#include OPENGL_INCLUDE_H -#endif +#include "platform_gl.h" namespace GLES3 { diff --git a/drivers/gles3/storage/render_scene_buffers_gles3.h b/drivers/gles3/storage/render_scene_buffers_gles3.h index aa98797ed1..543e1aeb15 100644 --- a/drivers/gles3/storage/render_scene_buffers_gles3.h +++ b/drivers/gles3/storage/render_scene_buffers_gles3.h @@ -35,12 +35,7 @@ #include "servers/rendering/storage/render_scene_buffers.h" -#include "platform_config.h" -#ifndef OPENGL_INCLUDE_H -#include <GLES3/gl3.h> -#else -#include OPENGL_INCLUDE_H -#endif +#include "platform_gl.h" class RenderSceneBuffersGLES3 : public RenderSceneBuffers { GDCLASS(RenderSceneBuffersGLES3, RenderSceneBuffers); diff --git a/drivers/gles3/storage/texture_storage.cpp b/drivers/gles3/storage/texture_storage.cpp index 8257fa62d6..6ccd4246e6 100644 --- a/drivers/gles3/storage/texture_storage.cpp +++ b/drivers/gles3/storage/texture_storage.cpp @@ -31,8 +31,10 @@ #ifdef GLES3_ENABLED #include "texture_storage.h" + +#include "../effects/copy_effects.h" +#include "../rasterizer_gles3.h" #include "config.h" -#include "drivers/gles3/effects/copy_effects.h" #include "utilities.h" #ifdef ANDROID_ENABLED @@ -216,9 +218,11 @@ TextureStorage::TextureStorage() { sdf_shader.shader_version = sdf_shader.shader.version_create(); } -#ifdef GLES_OVER_GL - glEnable(GL_PROGRAM_POINT_SIZE); -#endif +#ifdef GL_API_ENABLED + if (RasterizerGLES3::is_gles_over_gl()) { + glEnable(GL_PROGRAM_POINT_SIZE); + } +#endif // GL_API_ENABLED } TextureStorage::~TextureStorage() { @@ -309,26 +313,26 @@ Ref<Image> TextureStorage::_get_gl_image_and_format(const Ref<Image> &p_image, I switch (p_format) { case Image::FORMAT_L8: { -#ifdef GLES_OVER_GL - r_gl_internal_format = GL_R8; - r_gl_format = GL_RED; - r_gl_type = GL_UNSIGNED_BYTE; -#else - r_gl_internal_format = GL_LUMINANCE; - r_gl_format = GL_LUMINANCE; - r_gl_type = GL_UNSIGNED_BYTE; -#endif + if (RasterizerGLES3::is_gles_over_gl()) { + r_gl_internal_format = GL_R8; + r_gl_format = GL_RED; + r_gl_type = GL_UNSIGNED_BYTE; + } else { + r_gl_internal_format = GL_LUMINANCE; + r_gl_format = GL_LUMINANCE; + r_gl_type = GL_UNSIGNED_BYTE; + } } break; case Image::FORMAT_LA8: { -#ifdef GLES_OVER_GL - r_gl_internal_format = GL_RG8; - r_gl_format = GL_RG; - r_gl_type = GL_UNSIGNED_BYTE; -#else - r_gl_internal_format = GL_LUMINANCE_ALPHA; - r_gl_format = GL_LUMINANCE_ALPHA; - r_gl_type = GL_UNSIGNED_BYTE; -#endif + if (RasterizerGLES3::is_gles_over_gl()) { + r_gl_internal_format = GL_RG8; + r_gl_format = GL_RG; + r_gl_type = GL_UNSIGNED_BYTE; + } else { + r_gl_internal_format = GL_LUMINANCE_ALPHA; + r_gl_format = GL_LUMINANCE_ALPHA; + r_gl_type = GL_UNSIGNED_BYTE; + } } break; case Image::FORMAT_R8: { r_gl_internal_format = GL_R8; @@ -946,105 +950,109 @@ Ref<Image> TextureStorage::texture_2d_get(RID p_texture) const { } #endif -#ifdef GLES_OVER_GL - // OpenGL 3.3 supports glGetTexImage which is faster and simpler than glReadPixels. - // It also allows for reading compressed textures, mipmaps, and more formats. - Vector<uint8_t> data; + Ref<Image> image; +#ifdef GL_API_ENABLED + if (RasterizerGLES3::is_gles_over_gl()) { + // OpenGL 3.3 supports glGetTexImage which is faster and simpler than glReadPixels. + // It also allows for reading compressed textures, mipmaps, and more formats. + Vector<uint8_t> data; - int data_size = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, texture->real_format, texture->mipmaps > 1); + int data_size = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, texture->real_format, texture->mipmaps > 1); - data.resize(data_size * 2); //add some memory at the end, just in case for buggy drivers - uint8_t *w = data.ptrw(); + data.resize(data_size * 2); // Add some memory at the end, just in case for buggy drivers. + uint8_t *w = data.ptrw(); - glActiveTexture(GL_TEXTURE0); + glActiveTexture(GL_TEXTURE0); - glBindTexture(texture->target, texture->tex_id); + glBindTexture(texture->target, texture->tex_id); - glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); - for (int i = 0; i < texture->mipmaps; i++) { - int ofs = Image::get_image_mipmap_offset(texture->alloc_width, texture->alloc_height, texture->real_format, i); + for (int i = 0; i < texture->mipmaps; i++) { + int ofs = Image::get_image_mipmap_offset(texture->alloc_width, texture->alloc_height, texture->real_format, i); - if (texture->compressed) { - glPixelStorei(GL_PACK_ALIGNMENT, 4); - glGetCompressedTexImage(texture->target, i, &w[ofs]); + if (texture->compressed) { + glPixelStorei(GL_PACK_ALIGNMENT, 4); + glGetCompressedTexImage(texture->target, i, &w[ofs]); - } else { - glPixelStorei(GL_PACK_ALIGNMENT, 1); + } else { + glPixelStorei(GL_PACK_ALIGNMENT, 1); - glGetTexImage(texture->target, i, texture->gl_format_cache, texture->gl_type_cache, &w[ofs]); + glGetTexImage(texture->target, i, texture->gl_format_cache, texture->gl_type_cache, &w[ofs]); + } } - } - data.resize(data_size); + data.resize(data_size); - ERR_FAIL_COND_V(data.size() == 0, Ref<Image>()); - Ref<Image> image = Image::create_from_data(texture->width, texture->height, texture->mipmaps > 1, texture->real_format, data); - ERR_FAIL_COND_V(image->is_empty(), Ref<Image>()); - if (texture->format != texture->real_format) { - image->convert(texture->format); + ERR_FAIL_COND_V(data.size() == 0, Ref<Image>()); + image = Image::create_from_data(texture->width, texture->height, texture->mipmaps > 1, texture->real_format, data); + ERR_FAIL_COND_V(image->is_empty(), Ref<Image>()); + if (texture->format != texture->real_format) { + image->convert(texture->format); + } } -#else - - Vector<uint8_t> data; +#endif // GL_API_ENABLED +#ifdef GLES_API_ENABLED + if (!RasterizerGLES3::is_gles_over_gl()) { + Vector<uint8_t> data; - // On web and mobile we always read an RGBA8 image with no mipmaps. - int data_size = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, Image::FORMAT_RGBA8, false); + // On web and mobile we always read an RGBA8 image with no mipmaps. + int data_size = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, Image::FORMAT_RGBA8, false); - data.resize(data_size * 2); //add some memory at the end, just in case for buggy drivers - uint8_t *w = data.ptrw(); + data.resize(data_size * 2); // Add some memory at the end, just in case for buggy drivers. + uint8_t *w = data.ptrw(); - GLuint temp_framebuffer; - glGenFramebuffers(1, &temp_framebuffer); + GLuint temp_framebuffer; + glGenFramebuffers(1, &temp_framebuffer); - GLuint temp_color_texture; - glGenTextures(1, &temp_color_texture); + GLuint temp_color_texture; + glGenTextures(1, &temp_color_texture); - glBindFramebuffer(GL_FRAMEBUFFER, temp_framebuffer); + glBindFramebuffer(GL_FRAMEBUFFER, temp_framebuffer); - glBindTexture(GL_TEXTURE_2D, temp_color_texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->alloc_width, texture->alloc_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, temp_color_texture, 0); + glBindTexture(GL_TEXTURE_2D, temp_color_texture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->alloc_width, texture->alloc_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glDepthMask(GL_FALSE); - glDisable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); - glDisable(GL_BLEND); - glDepthFunc(GL_LEQUAL); - glColorMask(1, 1, 1, 1); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, texture->tex_id); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, temp_color_texture, 0); + + glDepthMask(GL_FALSE); + glDisable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + glDisable(GL_BLEND); + glDepthFunc(GL_LEQUAL); + glColorMask(1, 1, 1, 1); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, texture->tex_id); - glViewport(0, 0, texture->alloc_width, texture->alloc_height); - glClearColor(0.0, 0.0, 0.0, 0.0); - glClear(GL_COLOR_BUFFER_BIT); + glViewport(0, 0, texture->alloc_width, texture->alloc_height); + glClearColor(0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); - CopyEffects::get_singleton()->copy_to_rect(Rect2i(0, 0, 1.0, 1.0)); + CopyEffects::get_singleton()->copy_to_rect(Rect2i(0, 0, 1.0, 1.0)); - glReadPixels(0, 0, texture->alloc_width, texture->alloc_height, GL_RGBA, GL_UNSIGNED_BYTE, &w[0]); + glReadPixels(0, 0, texture->alloc_width, texture->alloc_height, GL_RGBA, GL_UNSIGNED_BYTE, &w[0]); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glDeleteTextures(1, &temp_color_texture); - glDeleteFramebuffers(1, &temp_framebuffer); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glDeleteTextures(1, &temp_color_texture); + glDeleteFramebuffers(1, &temp_framebuffer); - data.resize(data_size); + data.resize(data_size); - ERR_FAIL_COND_V(data.size() == 0, Ref<Image>()); - Ref<Image> image = Image::create_from_data(texture->width, texture->height, false, Image::FORMAT_RGBA8, data); - ERR_FAIL_COND_V(image->is_empty(), Ref<Image>()); + ERR_FAIL_COND_V(data.size() == 0, Ref<Image>()); + image = Image::create_from_data(texture->width, texture->height, false, Image::FORMAT_RGBA8, data); + ERR_FAIL_COND_V(image->is_empty(), Ref<Image>()); - if (texture->format != Image::FORMAT_RGBA8) { - image->convert(texture->format); - } + if (texture->format != Image::FORMAT_RGBA8) { + image->convert(texture->format); + } - if (texture->mipmaps > 1) { - image->generate_mipmaps(); + if (texture->mipmaps > 1) { + image->generate_mipmaps(); + } } - -#endif +#endif // GLES_API_ENABLED #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint() && !texture->is_render_target) { @@ -1254,21 +1262,32 @@ void TextureStorage::_texture_set_data(RID p_texture, const Ref<Image> &p_image, #ifndef WEB_ENABLED switch (texture->format) { -#ifdef GLES_OVER_GL case Image::FORMAT_L8: { - glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_R, GL_RED); - glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_G, GL_RED); - glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_B, GL_RED); - glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_A, GL_ONE); + if (RasterizerGLES3::is_gles_over_gl()) { + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_R, GL_RED); + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_G, GL_RED); + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_B, GL_RED); + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_A, GL_ONE); + } else { + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_R, GL_RED); + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_G, GL_GREEN); + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_B, GL_BLUE); + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); + } } break; case Image::FORMAT_LA8: { - glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_R, GL_RED); - glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_G, GL_RED); - glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_B, GL_RED); - glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_A, GL_GREEN); + if (RasterizerGLES3::is_gles_over_gl()) { + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_R, GL_RED); + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_G, GL_RED); + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_B, GL_RED); + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_A, GL_GREEN); + } else { + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_R, GL_RED); + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_G, GL_GREEN); + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_B, GL_BLUE); + glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); + } } break; -#endif // GLES3_OVER_GL - case Image::FORMAT_ETC2_RA_AS_RG: case Image::FORMAT_DXT5_RA_AS_RG: { glTexParameteri(texture->target, GL_TEXTURE_SWIZZLE_R, GL_RED); diff --git a/drivers/gles3/storage/texture_storage.h b/drivers/gles3/storage/texture_storage.h index c25dbef288..87a07ebb36 100644 --- a/drivers/gles3/storage/texture_storage.h +++ b/drivers/gles3/storage/texture_storage.h @@ -33,6 +33,8 @@ #ifdef GLES3_ENABLED +#include "platform_gl.h" + #include "config.h" #include "core/os/os.h" #include "core/templates/rid_owner.h" @@ -41,14 +43,6 @@ #include "drivers/gles3/shaders/canvas_sdf.glsl.gen.h" -// This must come first to avoid windows.h mess -#include "platform_config.h" -#ifndef OPENGL_INCLUDE_H -#include <GLES3/gl3.h> -#else -#include OPENGL_INCLUDE_H -#endif - namespace GLES3 { #define _GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE @@ -118,10 +112,6 @@ namespace GLES3 { #define _EXT_TEXTURE_CUBE_MAP_SEAMLESS 0x884F -#ifndef GLES_OVER_GL -#define glClearDepth glClearDepthf -#endif //!GLES_OVER_GL - enum DefaultGLTexture { DEFAULT_GL_TEXTURE_WHITE, DEFAULT_GL_TEXTURE_BLACK, @@ -679,7 +669,7 @@ public: }; inline String TextureStorage::get_framebuffer_error(GLenum p_status) { -#if defined(DEBUG_ENABLED) && defined(GLES_OVER_GL) +#if defined(DEBUG_ENABLED) && defined(GL_API_ENABLED) if (p_status == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT) { return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT"; } else if (p_status == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) { diff --git a/drivers/gles3/storage/utilities.cpp b/drivers/gles3/storage/utilities.cpp index 3e6e72edad..07df445018 100644 --- a/drivers/gles3/storage/utilities.cpp +++ b/drivers/gles3/storage/utilities.cpp @@ -31,6 +31,8 @@ #ifdef GLES3_ENABLED #include "utilities.h" + +#include "../rasterizer_gles3.h" #include "config.h" #include "light_storage.h" #include "material_storage.h" @@ -253,9 +255,11 @@ void Utilities::capture_timestamps_begin() { void Utilities::capture_timestamp(const String &p_name) { ERR_FAIL_COND(frames[frame].timestamp_count >= max_timestamp_query_elements); -#ifdef GLES_OVER_GL - glQueryCounter(frames[frame].queries[frames[frame].timestamp_count], GL_TIMESTAMP); -#endif +#ifdef GL_API_ENABLED + if (RasterizerGLES3::is_gles_over_gl()) { + glQueryCounter(frames[frame].queries[frames[frame].timestamp_count], GL_TIMESTAMP); + } +#endif // GL_API_ENABLED frames[frame].timestamp_names[frames[frame].timestamp_count] = p_name; frames[frame].timestamp_cpu_values[frames[frame].timestamp_count] = OS::get_singleton()->get_ticks_usec(); @@ -265,13 +269,15 @@ void Utilities::capture_timestamp(const String &p_name) { void Utilities::_capture_timestamps_begin() { // frame is incremented at the end of the frame so this gives us the queries for frame - 2. By then they should be ready. if (frames[frame].timestamp_count) { -#ifdef GLES_OVER_GL - for (uint32_t i = 0; i < frames[frame].timestamp_count; i++) { - uint64_t temp = 0; - glGetQueryObjectui64v(frames[frame].queries[i], GL_QUERY_RESULT, &temp); - frames[frame].timestamp_result_values[i] = temp; +#ifdef GL_API_ENABLED + if (RasterizerGLES3::is_gles_over_gl()) { + for (uint32_t i = 0; i < frames[frame].timestamp_count; i++) { + uint64_t temp = 0; + glGetQueryObjectui64v(frames[frame].queries[i], GL_QUERY_RESULT, &temp); + frames[frame].timestamp_result_values[i] = temp; + } } -#endif +#endif // GL_API_ENABLED SWAP(frames[frame].timestamp_names, frames[frame].timestamp_result_names); SWAP(frames[frame].timestamp_cpu_values, frames[frame].timestamp_cpu_result_values); } diff --git a/drivers/gles3/storage/utilities.h b/drivers/gles3/storage/utilities.h index 243342014b..76e4d510de 100644 --- a/drivers/gles3/storage/utilities.h +++ b/drivers/gles3/storage/utilities.h @@ -35,12 +35,7 @@ #include "servers/rendering/storage/utilities.h" -#include "platform_config.h" -#ifndef OPENGL_INCLUDE_H -#include <GLES3/gl3.h> -#else -#include OPENGL_INCLUDE_H -#endif +#include "platform_gl.h" namespace GLES3 { |