From f7f8060447a2446998d6ee4016973b4fe962246f Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 9 Aug 2021 17:48:07 +1000 Subject: [PATCH] [client] egl: allow setting an output scale for a post-process shader --- client/renderers/EGL/texture.c | 16 ++++++++++++---- client/renderers/EGL/texture.h | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/client/renderers/EGL/texture.c b/client/renderers/EGL/texture.c index 7b95574e..22d0995c 100644 --- a/client/renderers/EGL/texture.c +++ b/client/renderers/EGL/texture.c @@ -42,6 +42,9 @@ typedef struct RenderStep GLuint fb; GLuint tex; EGL_Shader * shader; + float scale; + + unsigned int width, height; } RenderStep; @@ -117,12 +120,15 @@ void egl_textureFree(EGL_Texture ** tex) bool setupRenderStep(EGL_Texture * this, RenderStep * step) { + step->width = this->format.width * step->scale; + step->height = this->format.height * step->scale; + glBindTexture(GL_TEXTURE_2D, step->tex); glTexImage2D(GL_TEXTURE_2D, 0, this->format.intFormat, - this->format.width, - this->format.height, + step->width, + step->height, 0, this->format.format, this->format.dataType, @@ -292,7 +298,7 @@ enum EGL_TexStatus egl_textureBind(EGL_Texture * this) else glBindFramebuffer(GL_FRAMEBUFFER, step->fb); - glViewport(0, 0, this->format.width, this->format.height); + glViewport(0, 0, step->width, step->height); egl_shaderUse(step->shader); egl_modelRender(this->model); @@ -319,7 +325,8 @@ enum EGL_TexStatus egl_textureBind(EGL_Texture * this) return EGL_TEX_STATUS_OK; } -enum EGL_TexStatus egl_textureAddShader(EGL_Texture * this, EGL_Shader * shader) +enum EGL_TexStatus egl_textureAddShader(EGL_Texture * this, EGL_Shader * shader, + float outputScale) { if (!this->render) { @@ -331,6 +338,7 @@ enum EGL_TexStatus egl_textureAddShader(EGL_Texture * this, EGL_Shader * shader) RenderStep * step = calloc(1, sizeof(*step)); glGenTextures(1, &step->tex); step->shader = shader; + step->scale = outputScale; if (this->formatValid) if (!setupRenderStep(this, step)) diff --git a/client/renderers/EGL/texture.h b/client/renderers/EGL/texture.h index cde00f7e..ccd089e8 100644 --- a/client/renderers/EGL/texture.h +++ b/client/renderers/EGL/texture.h @@ -166,4 +166,5 @@ enum EGL_TexStatus egl_textureProcess(EGL_Texture * texture); enum EGL_TexStatus egl_textureBind(EGL_Texture * texture); -enum EGL_TexStatus egl_textureAddShader(EGL_Texture * texture, EGL_Shader * shader); +enum EGL_TexStatus egl_textureAddShader(EGL_Texture * texture, + EGL_Shader * shader, float outputScale);