From 32251e02643125df79b34aaa1e1909ba1e94283e Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 12 Mar 2022 14:22:27 +0100 Subject: [PATCH] Fixed multiple issues with the shader post-processing. Also removed an unnecessary parameter for the createTexture() function. --- es-app/src/Screensaver.cpp | 3 +-- es-core/src/components/VideoFFmpegComponent.cpp | 3 +-- es-core/src/renderers/Renderer.h | 4 ++-- es-core/src/renderers/Renderer_GL21.cpp | 14 +++++++++----- es-core/src/resources/Font.cpp | 4 ++-- es-core/src/resources/TextureData.cpp | 3 +-- es-core/src/resources/TextureData.h | 3 --- es-core/src/resources/TextureResource.h | 1 - resources/shaders/glsl/core.glsl | 8 +++++--- 9 files changed, 21 insertions(+), 22 deletions(-) diff --git a/es-app/src/Screensaver.cpp b/es-app/src/Screensaver.cpp index 12ceb5fdc..d11155fda 100644 --- a/es-app/src/Screensaver.cpp +++ b/es-app/src/Screensaver.cpp @@ -348,11 +348,10 @@ void Screensaver::renderScreensaver() #if defined(USE_OPENGL_21) Renderer::postProcessingParams dimParameters; dimParameters.dimming = mDimValue; + dimParameters.saturation = mSaturationAmount; Renderer::shaderPostprocessing(Renderer::SHADER_CORE, dimParameters); if (mDimValue > 0.63) mDimValue = glm::clamp(mDimValue - 0.015f, 0.68f, 1.0f); - dimParameters.saturation = mSaturationAmount; - Renderer::shaderPostprocessing(Renderer::SHADER_CORE, dimParameters); if (mSaturationAmount > 0.0) mSaturationAmount = glm::clamp(mSaturationAmount - 0.035f, 0.0f, 1.0f); #else diff --git a/es-core/src/components/VideoFFmpegComponent.cpp b/es-core/src/components/VideoFFmpegComponent.cpp index 5f02c6468..056c0fa37 100644 --- a/es-core/src/components/VideoFFmpegComponent.cpp +++ b/es-core/src/components/VideoFFmpegComponent.cpp @@ -209,8 +209,7 @@ void VideoFFmpegComponent::render(const glm::mat4& parentTrans) // Render scanlines if this option is enabled. However, if this is the media viewer // or the video screensaver, then skip this as the scanline rendering is then handled - // in those modules as a postprocessing step. - + // in those modules as a post-processing step. if (!mScreensaverMode && !mMediaViewerMode) { vertices[0].opacity = mFadeIn * mThemeOpacity; if ((mLegacyTheme && Settings::getInstance()->getBool("GamelistVideoScanlines")) || diff --git a/es-core/src/renderers/Renderer.h b/es-core/src/renderers/Renderer.h index ea78693c4..713b82273 100644 --- a/es-core/src/renderers/Renderer.h +++ b/es-core/src/renderers/Renderer.h @@ -96,7 +96,8 @@ namespace Renderer namespace Texture { enum Type { - RGBA, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0). + RGB, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0). + RGBA, BGRA, ALPHA }; @@ -186,7 +187,6 @@ namespace Renderer bool createContext(); void destroyContext(); unsigned int createTexture(const Texture::Type type, - const Texture::Type format, const bool linearMinify, const bool linearMagnify, const bool repeat, diff --git a/es-core/src/renderers/Renderer_GL21.cpp b/es-core/src/renderers/Renderer_GL21.cpp index 92d3a089d..758878d47 100644 --- a/es-core/src/renderers/Renderer_GL21.cpp +++ b/es-core/src/renderers/Renderer_GL21.cpp @@ -46,6 +46,7 @@ namespace Renderer { // clang-format off switch (_type) { + case Texture::RGB: { return GL_RGB; } break; case Texture::RGBA: { return GL_RGBA; } break; case Texture::BGRA: { return GL_BGRA; } break; case Texture::ALPHA: { return GL_LUMINANCE_ALPHA; } break; @@ -144,16 +145,18 @@ namespace Renderer return false; } - postProcTexture1 = createTexture(Texture::RGBA, Texture::RGBA, false, false, false, + // For the post-processing textures we want to discard the alpha channel to avoid + // weird problems with some graphics drivers. + postProcTexture1 = createTexture(Texture::RGB, false, false, false, static_cast(getScreenWidth()), static_cast(getScreenHeight()), nullptr); - postProcTexture2 = createTexture(Texture::RGBA, Texture::RGBA, false, false, false, + postProcTexture2 = createTexture(Texture::RGB, false, false, false, static_cast(getScreenWidth()), static_cast(getScreenHeight()), nullptr); uint8_t data[4] = {255, 255, 255, 255}; - whiteTexture = createTexture(Texture::RGBA, Texture::RGBA, false, false, true, 1, 1, data); + whiteTexture = createTexture(Texture::RGBA, false, false, true, 1, 1, data); GL_CHECK_ERROR(glClearColor(0.0f, 0.0f, 0.0f, 1.0f)); GL_CHECK_ERROR(glEnable(GL_TEXTURE_2D)); @@ -183,7 +186,6 @@ namespace Renderer } unsigned int createTexture(const Texture::Type type, - const Texture::Type /*format*/, const bool linearMinify, const bool linearMagnify, const bool repeat, @@ -448,7 +450,7 @@ namespace Renderer GLuint height {static_cast(heightf)}; // Set vertex positions and texture coordinates to full screen as all - // postprocessing is applied to the complete screen area. + // post-processing is applied to the complete screen area. // clang-format off vertices[0] = {{0.0f, 0.0f }, {0.0f, 1.0f}, 0xFFFFFFFF}; vertices[1] = {{0.0f, heightf}, {0.0f, 0.0f}, 0xFFFFFFFF}; @@ -524,12 +526,14 @@ namespace Renderer bindTexture(postProcTexture2); GL_CHECK_ERROR(glBindFramebuffer(GL_READ_FRAMEBUFFER, shaderFBO2)); GL_CHECK_ERROR(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, shaderFBO1)); + GL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT)); firstFBO = false; } else { bindTexture(postProcTexture1); GL_CHECK_ERROR(glBindFramebuffer(GL_READ_FRAMEBUFFER, shaderFBO1)); GL_CHECK_ERROR(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, shaderFBO2)); + GL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT)); firstFBO = true; } } diff --git a/es-core/src/resources/Font.cpp b/es-core/src/resources/Font.cpp index b9275afbc..afdec8366 100644 --- a/es-core/src/resources/Font.cpp +++ b/es-core/src/resources/Font.cpp @@ -199,8 +199,8 @@ bool Font::FontTexture::findEmpty(const glm::ivec2& size, glm::ivec2& cursor_out void Font::FontTexture::initTexture() { assert(textureId == 0); - textureId = Renderer::createTexture(Renderer::Texture::ALPHA, Renderer::Texture::ALPHA, false, - false, false, textureSize.x, textureSize.y, nullptr); + textureId = Renderer::createTexture(Renderer::Texture::ALPHA, false, false, false, + textureSize.x, textureSize.y, nullptr); } void Font::FontTexture::deinitTexture() diff --git a/es-core/src/resources/TextureData.cpp b/es-core/src/resources/TextureData.cpp index 631207c9d..a07ce4fff 100644 --- a/es-core/src/resources/TextureData.cpp +++ b/es-core/src/resources/TextureData.cpp @@ -27,7 +27,6 @@ TextureData::TextureData(bool tile) : mTile {tile} , mTextureID {0} , mDataRGBA {} - , mFormat {Renderer::Texture::RGBA} , mWidth {0} , mHeight {0} , mSourceWidth {0.0f} @@ -219,7 +218,7 @@ bool TextureData::uploadAndBind() // Upload texture. mTextureID = - Renderer::createTexture(Renderer::Texture::RGBA, mFormat, true, mLinearMagnify, mTile, + Renderer::createTexture(Renderer::Texture::RGBA, true, mLinearMagnify, mTile, static_cast(mWidth), static_cast(mHeight), mDataRGBA.data()); } diff --git a/es-core/src/resources/TextureData.h b/es-core/src/resources/TextureData.h index 08ac57e30..48c38fe36 100644 --- a/es-core/src/resources/TextureData.h +++ b/es-core/src/resources/TextureData.h @@ -64,8 +64,6 @@ public: // Whether to rasterize the image even if a size has not been set yet. void setForceRasterization(bool setting) { mForceRasterization = setting; } - void setFormat(Renderer::Texture::Type format) { mFormat = format; } - // Has the image been loaded but not yet been rasterized as the size was not known? bool getPendingRasterization() { return mPendingRasterization; } @@ -80,7 +78,6 @@ private: std::string mPath; std::atomic mTextureID; std::vector mDataRGBA; - Renderer::Texture::Type mFormat; std::atomic mWidth; std::atomic mHeight; std::atomic mSourceWidth; diff --git a/es-core/src/resources/TextureResource.h b/es-core/src/resources/TextureResource.h index 1ea4d1f75..cdefb03ce 100644 --- a/es-core/src/resources/TextureResource.h +++ b/es-core/src/resources/TextureResource.h @@ -45,7 +45,6 @@ public: return (mTextureData != nullptr ? mTextureData->getPendingRasterization() : false); } - void setFormat(Renderer::Texture::Type format) { mTextureData->setFormat(format); } void setLinearMagnify(bool setting) { mTextureData->setLinearMagnify(setting); } std::string getTextureFilePath(); diff --git a/resources/shaders/glsl/core.glsl b/resources/shaders/glsl/core.glsl index 91a423406..5f673cd9d 100644 --- a/resources/shaders/glsl/core.glsl +++ b/resources/shaders/glsl/core.glsl @@ -56,14 +56,16 @@ void main() // Saturation. if (saturation != 1.0f) { - vec3 grayscale = vec3(dot(color.rgb, vec3(0.3f, 0.59f, 0.11f))); + vec3 grayscale = vec3(dot(color.rgb, vec3(0.34f, 0.55f, 0.11f))); vec3 blendedColor = mix(grayscale, color.rgb, saturation); color = vec4(blendedColor, color.a); } // Dimming - vec4 dimColor = vec4(dimming, dimming, dimming, 1.0f); - color = vec4(color.rgba) * dimColor; + if (dimming != 1.0f) { + vec4 dimColor = vec4(dimming, dimming, dimming, 1.0f); + color *= dimColor; + } // BGRA to RGBA conversion. if (BGRAToRGBA == 1)