From 21eb341b8dc3b178bd964732875cae9a6bac51d5 Mon Sep 17 00:00:00 2001 From: fzurita Date: Sun, 5 Sep 2021 12:43:55 -0400 Subject: [PATCH] Fix some shader compilation errors --- .../GLSL/glsl_CombinerProgramBuilder.cpp | 19 ++++++++++++++----- .../GLSL/glsl_SpecialShadersFactory.cpp | 3 --- .../OpenGLContext/opengl_ContextImpl.cpp | 9 +++++++-- src/Graphics/OpenGLContext/opengl_GLInfo.cpp | 3 +++ src/Graphics/OpenGLContext/opengl_GLInfo.h | 1 + 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp index c615b723..141f5451 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp @@ -553,7 +553,9 @@ public: ss << "#extension GL_NV_fragment_shader_interlock : enable" << std::endl << "layout(pixel_interlock_ordered) in;" << std::endl; } - } + } else if (_glinfo.fetch_depth) + ss << "#extension GL_ARM_shader_framebuffer_fetch_depth_stencil : enable" << std::endl; + ss << "# define IN in" << std::endl << "# define OUT out" << std::endl << "# define texture2D texture" << std::endl; @@ -579,6 +581,7 @@ public: ss << "#extension GL_INTEL_fragment_shader_ordering : enable" << std::endl; } } + ss << "# define IN in" << std::endl << "# define OUT out" << std::endl << "# define texture2D texture" << std::endl; @@ -2048,8 +2051,8 @@ public: // Fetch from texture atlas // First 8 texels contain info about tile size and offset, 1 texel per tile " mediump vec2 texSize = uTextureSize[1]; \n" - " mediump vec4 texWdthAndOff0 = 255.0 * texture(tex, vec2(0.5, 0.5)/texSize); \n" - " mediump vec4 texWdthAndOff = 255.0 * texture(tex, vec2(lod + 0.5, 0.5)/texSize); \n" + " mediump vec4 texWdthAndOff0 = 255.0 * texture2D(tex, vec2(0.5, 0.5)/texSize); \n" + " mediump vec4 texWdthAndOff = 255.0 * texture2D(tex, vec2(lod + 0.5, 0.5)/texSize); \n" " mediump vec2 lod_scale = texWdthAndOff.ba / texWdthAndOff0.ba; \n" " mediump float offset = texWdthAndOff.r + texWdthAndOff.g * 256.0; \n" " mediump float width = texWdthAndOff.b; \n" @@ -2119,11 +2122,17 @@ public: ; } m_part += - " lowp int max_tile = min(uTextureDetail != 2 ? 7 : 6, uMaxTile); \n" + "#define MIN(x, y) y < x ? y : x \n" + "#define MAX(x, y) x < y ? y : x \n" + " lowp int lod_max_tile = uTextureDetail != 2 ? 7 : 6; \n" + " lowp int max_tile = MIN(lod_max_tile, uMaxTile); \n" " mediump float min_lod = uTextureDetail != 0 ? uMinLod : 1.0; \n" " mediump float max_lod = pow(2.0, float(max_tile)) - 1.0 / 32.0; \n" " mediump float lod_clamp = min(max(lod, min_lod), max_lod); \n" - " lowp int lod_tile = clamp(int(log2(lod_clamp)), 0 , max_tile); \n" + // Simulate clamp function, needed for GLES 2.0 and integer types + " mediump int lod_clamp_int = int(log2(lod_clamp)); \n" + " mediump int lod_clamp_max = MAX(lod_clamp_int, 0); \n" + " lowp int lod_tile = MIN(lod_clamp_max, max_tile); \n" " lowp int tile0 = 0; \n" " lowp int tile1 = 1; \n" " if (uEnableLod != 0) { \n" diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp index e771f667..839054c4 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp @@ -130,9 +130,6 @@ namespace glsl { " fragColor = vec4(uFogColor.rgb, get_alpha()); \n" "} \n" ; - - if (config.frameBufferEmulation.N64DepthCompare == Config::dcDisable && _glinfo.fetch_depth) - m_part = "#extension GL_ARM_shader_framebuffer_fetch_depth_stencil : enable \n" + m_part; } }; diff --git a/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp b/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp index ef094d63..14f9e844 100644 --- a/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp +++ b/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp @@ -276,8 +276,13 @@ s32 ContextImpl::getMaxTextureSize() const f32 ContextImpl::getMaxAnisotropy() const { GLfloat maxInisotropy = 0.0f; - glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxInisotropy); - return maxInisotropy; + + if (m_glInfo.anisotropic_filtering) { + glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxInisotropy); + return maxInisotropy; + } else { + return 0.0f; + } } void ContextImpl::bindImageTexture(const graphics::Context::BindImageTextureParameters & _params) diff --git a/src/Graphics/OpenGLContext/opengl_GLInfo.cpp b/src/Graphics/OpenGLContext/opengl_GLInfo.cpp index 44ddc9a1..18fb8ff9 100644 --- a/src/Graphics/OpenGLContext/opengl_GLInfo.cpp +++ b/src/Graphics/OpenGLContext/opengl_GLInfo.cpp @@ -180,6 +180,7 @@ void GLInfo::init() { ext_fetch_arm = Utils::isExtensionSupported(*this, "GL_ARM_shader_framebuffer_fetch") && !ext_fetch; dual_source_blending = !isGLESX || (Utils::isExtensionSupported(*this, "GL_EXT_blend_func_extended") && !isAnyAdreno); + anisotropic_filtering = Utils::isExtensionSupported(*this, "GL_EXT_texture_filter_anisotropic"); #ifdef OS_ANDROID eglImage = eglImage && @@ -223,6 +224,8 @@ void GLInfo::init() { } #endif + + #ifdef GL_DEBUG glDebugMessageCallback(on_gl_error, nullptr); glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); diff --git a/src/Graphics/OpenGLContext/opengl_GLInfo.h b/src/Graphics/OpenGLContext/opengl_GLInfo.h index be3c40b7..3ab2b82f 100644 --- a/src/Graphics/OpenGLContext/opengl_GLInfo.h +++ b/src/Graphics/OpenGLContext/opengl_GLInfo.h @@ -39,6 +39,7 @@ struct GLInfo { bool eglImage = false; bool eglImageFramebuffer = false; bool dual_source_blending = false; + bool anisotropic_filtering = false; bool coverage = false; Renderer renderer = Renderer::Other;