From 6882e5c59f5ea74d0ba0897d7a322c2b5b9ff40a Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 9 Aug 2021 18:22:28 +1000 Subject: [PATCH] [client] egl: provide the texture scale to the desktop shader If the texture has a post-processing filter that has scaled the texture, the desktop fragment shader needs to know this if it's doing linear scaling. --- client/renderers/EGL/desktop.c | 17 ++++++++++++----- client/renderers/EGL/shader/desktop_rgb.frag | 3 ++- client/renderers/EGL/texture.c | 6 ++++++ client/renderers/EGL/texture.h | 3 +++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/client/renderers/EGL/desktop.c b/client/renderers/EGL/desktop.c index 19091a0e..9a84c820 100644 --- a/client/renderers/EGL/desktop.c +++ b/client/renderers/EGL/desktop.c @@ -43,6 +43,7 @@ struct DesktopShader EGL_Shader * shader; GLint uTransform; GLint uDesktopSize; + GLint uTextureScale; GLint uScaleAlgo; GLint uNVGain; GLint uCBMode; @@ -95,11 +96,12 @@ static bool egl_initDesktopShader( return false; } - shader->uTransform = egl_shaderGetUniform(shader->shader, "transform"); - shader->uDesktopSize = egl_shaderGetUniform(shader->shader, "size" ); - shader->uScaleAlgo = egl_shaderGetUniform(shader->shader, "scaleAlgo"); - shader->uNVGain = egl_shaderGetUniform(shader->shader, "nvGain" ); - shader->uCBMode = egl_shaderGetUniform(shader->shader, "cbMode" ); + shader->uTransform = egl_shaderGetUniform(shader->shader, "transform" ); + shader->uDesktopSize = egl_shaderGetUniform(shader->shader, "size" ); + shader->uTextureScale = egl_shaderGetUniform(shader->shader, "textureScale"); + shader->uScaleAlgo = egl_shaderGetUniform(shader->shader, "scaleAlgo" ); + shader->uNVGain = egl_shaderGetUniform(shader->shader, "nvGain" ); + shader->uCBMode = egl_shaderGetUniform(shader->shader, "cbMode" ); return true; } @@ -356,6 +358,11 @@ bool egl_desktopRender(EGL_Desktop * desktop, const float x, const float y, .location = shader->uDesktopSize, .f = { desktop->width, desktop->height }, }, + { + .type = EGL_UNIFORM_TYPE_1F, + .location = shader->uTextureScale, + .f = { egl_textureGetScale(desktop->texture) }, + }, { .type = EGL_UNIFORM_TYPE_M3x2FV, .location = shader->uTransform, diff --git a/client/renderers/EGL/shader/desktop_rgb.frag b/client/renderers/EGL/shader/desktop_rgb.frag index 5b722253..6de56b29 100644 --- a/client/renderers/EGL/shader/desktop_rgb.frag +++ b/client/renderers/EGL/shader/desktop_rgb.frag @@ -12,6 +12,7 @@ uniform sampler2D sampler1; uniform int scaleAlgo; uniform highp vec2 size; +uniform highp float textureScale; uniform highp float nvGain; uniform int cbMode; @@ -21,7 +22,7 @@ void main() switch (scaleAlgo) { case EGL_SCALE_NEAREST: - color = texelFetch(sampler1, ivec2(uv * size), 0); + color = texelFetch(sampler1, ivec2(uv * size * textureScale), 0); break; case EGL_SCALE_LINEAR: diff --git a/client/renderers/EGL/texture.c b/client/renderers/EGL/texture.c index 22d0995c..f08867d8 100644 --- a/client/renderers/EGL/texture.c +++ b/client/renderers/EGL/texture.c @@ -339,6 +339,7 @@ enum EGL_TexStatus egl_textureAddShader(EGL_Texture * this, EGL_Shader * shader, glGenTextures(1, &step->tex); step->shader = shader; step->scale = outputScale; + this->scale = outputScale; if (this->formatValid) if (!setupRenderStep(this, step)) @@ -351,3 +352,8 @@ enum EGL_TexStatus egl_textureAddShader(EGL_Texture * this, EGL_Shader * shader, ll_push(this->render, step); return EGL_TEX_STATUS_OK; } + +float egl_textureGetScale(EGL_Texture * this) +{ + return this->scale; +} diff --git a/client/renderers/EGL/texture.h b/client/renderers/EGL/texture.h index ccd089e8..760d3b78 100644 --- a/client/renderers/EGL/texture.h +++ b/client/renderers/EGL/texture.h @@ -144,6 +144,7 @@ struct EGL_Texture _Atomic(bool) updated; bool postProcessed; EGL_Model * model; + float scale; }; bool egl_textureInit(EGL * egl, EGL_Texture ** texture, EGLDisplay * display, @@ -168,3 +169,5 @@ enum EGL_TexStatus egl_textureBind(EGL_Texture * texture); enum EGL_TexStatus egl_textureAddShader(EGL_Texture * texture, EGL_Shader * shader, float outputScale); + +float egl_textureGetScale(EGL_Texture * texture);