From c9ed9108798207d01123d28fb2f027e4066f930a Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Sat, 12 May 2018 17:36:45 -0500 Subject: [PATCH] Last pass filter. --- gtk/src/gtk_display_driver_opengl.cpp | 2 +- gtk/src/shaders/glsl.cpp | 16 ++++++++++++---- gtk/src/shaders/glsl.h | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/gtk/src/gtk_display_driver_opengl.cpp b/gtk/src/gtk_display_driver_opengl.cpp index 6b8c78d0..30b8aea0 100644 --- a/gtk/src/gtk_display_driver_opengl.cpp +++ b/gtk/src/gtk_display_driver_opengl.cpp @@ -226,7 +226,7 @@ S9xOpenGLDisplayDriver::update (int width, int height, int yoffset) if (using_shaders && using_glsl_shaders) { - glsl_shader->render (texmap, width, height, w, h); + glsl_shader->render (texmap, width, height, w, h, x, allocation.height - y - h); glViewport (x, allocation.height - y - h, w, h); } else if (using_shaders && using_cg_shaders) diff --git a/gtk/src/shaders/glsl.cpp b/gtk/src/shaders/glsl.cpp index b824710b..95d2785a 100644 --- a/gtk/src/shaders/glsl.cpp +++ b/gtk/src/shaders/glsl.cpp @@ -152,7 +152,7 @@ bool GLSLShader::load_shader_file (char *filename) GLSLPass pass; snprintf(key, 256, "::filter_linear%u", i); - pass.filter = conf.Exists(key) ? conf.GetBool(key) ? GL_LINEAR : GL_NEAREST : GLSL_UNDEFINED; + pass.filter = conf.Exists(key) ? (conf.GetBool(key) ? GL_LINEAR : GL_NEAREST) : GLSL_UNDEFINED; sprintf(key, "::scale_type%u", i); const char* scaleType = conf.GetString(key, ""); @@ -543,7 +543,7 @@ bool GLSLShader::load_shader (char *filename) return true; } -void GLSLShader::render(GLuint &orig, int width, int height, int viewport_width, int viewport_height) +void GLSLShader::render(GLuint &orig, int width, int height, int viewport_width, int viewport_height, int viewport_x, int viewport_y) { frame_count++; @@ -557,6 +557,8 @@ void GLSLShader::render(GLuint &orig, int width, int height, int viewport_width, */ for (unsigned int i = 1; i < pass.size(); i++) { + bool lastpass = (i == pass.size() - 1); + switch (pass[i].scale_type_x) { case GLSL_ABSOLUTE: @@ -631,14 +633,20 @@ void GLSLShader::render(GLuint &orig, int width, int height, int viewport_width, 0); // set up input texture (output of previous pass) and apply filter settings + + GLuint filter = (pass[i].filter == GLSL_UNDEFINED) ? + (lastpass ? + (gui_config->bilinear_filter ? GL_LINEAR : GL_NEAREST) : GL_NEAREST + ) : pass[i].filter; + glBindTexture(GL_TEXTURE_2D, pass[i - 1].texture); glPixelStorei(GL_UNPACK_ROW_LENGTH, (GLint) pass[i - 1].width); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, - pass[i].filter == GLSL_UNDEFINED ? GL_NEAREST : pass[i].filter); + filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, - pass[i].filter == GLSL_UNDEFINED ? GL_NEAREST : pass[i].filter); + filter); glTexCoordPointer(2, GL_FLOAT, 0, tex_coords); diff --git a/gtk/src/shaders/glsl.h b/gtk/src/shaders/glsl.h index a5927f65..1c04f780 100644 --- a/gtk/src/shaders/glsl.h +++ b/gtk/src/shaders/glsl.h @@ -106,7 +106,7 @@ typedef struct { bool load_shader (char *filename); bool load_shader_file (char *filename); - void render (GLuint &orig, int width, int height, int viewport_width, int viewport_height); + void render (GLuint &orig, int width, int height, int viewport_width, int viewport_height, int viewport_x, int viewport_y); void set_shader_vars (int pass); void clear_shader_vars (void); void strip_parameter_pragmas(char *buffer);