diff --git a/gtk/src/gtk_display_driver_opengl.cpp b/gtk/src/gtk_display_driver_opengl.cpp index 8aea0bb9..276f77e0 100644 --- a/gtk/src/gtk_display_driver_opengl.cpp +++ b/gtk/src/gtk_display_driver_opengl.cpp @@ -14,6 +14,21 @@ #include "shaders/shader_helpers.h" #include "shaders/CGLCG.h" +static void S9xViewportCallback (int src_width, int src_height, + int viewport_x, int viewport_y, + int viewport_width, int viewport_height, + int *out_x, int *out_y, + int *out_width, int *out_height) +{ + + S9xApplyAspect (src_width, src_height, viewport_width, viewport_height); + *out_x = src_width + viewport_x; + *out_y = src_height + viewport_y; + *out_width = viewport_width; + *out_height = viewport_height; + return; +} + S9xOpenGLDisplayDriver::S9xOpenGLDisplayDriver (Snes9xWindow *window, Snes9xConfig *config) { @@ -226,7 +241,7 @@ S9xOpenGLDisplayDriver::update (int width, int height, int yoffset) if (using_shaders && using_glsl_shaders) { - glsl_shader->render (texmap, width, height, w, h, x, allocation.height - y - h); + glsl_shader->render (texmap, width, height, x, allocation.height - y - h, w, h, S9xViewportCallback); gl_swap (); return; } diff --git a/shaders/glsl.cpp b/shaders/glsl.cpp index b4dc228f..110a43b2 100644 --- a/shaders/glsl.cpp +++ b/shaders/glsl.cpp @@ -552,7 +552,11 @@ bool GLSLShader::load_shader (char *filename) return true; } -void GLSLShader::render(GLuint &orig, int width, int height, int viewport_width, int viewport_height, int viewport_x, int viewport_y) +void GLSLShader::render(GLuint &orig, + int width, int height, + int viewport_x, int viewport_y, + int viewport_width, int viewport_height, + GLSLViewportCallback vpcallback) { frame_count++; @@ -641,9 +645,19 @@ void GLSLShader::render(GLuint &orig, int width, int height, int viewport_width, } else { + int out_x = 0; + int out_y = 0; + int out_width = 0; + int out_height = 0; + // output to the screen glBindFramebuffer(GL_FRAMEBUFFER, 0); - glViewport(viewport_x, viewport_y, viewport_width, viewport_height); + vpcallback (pass[i].width, pass[i].height, + viewport_x, viewport_y, + viewport_width, viewport_height, + &out_x, &out_y, + &out_width, &out_height); + glViewport(out_x, out_y, out_width, out_height); } // set up input texture (output of previous pass) and apply filter settings diff --git a/shaders/glsl.h b/shaders/glsl.h index 9f7a271e..3e5c22ff 100644 --- a/shaders/glsl.h +++ b/shaders/glsl.h @@ -6,6 +6,12 @@ static const unsigned int glsl_max_passes = 20; +typedef void (* GLSLViewportCallback) (int source_width, int source_height, + int viewport_x, int viewport_y, + int viewport_width, int viewport_height, + int *out_dst_x, int *out_dst_y, + int *out_dst_width, int *out_dst_height); + enum GLSLScaleType { GLSL_NONE = 0, @@ -107,7 +113,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, int viewport_x, int viewport_y); + void render (GLuint &orig, int width, int height, int viewport_width, int viewport_height, int viewport_x, int viewport_y, GLSLViewportCallback vpcallback); void set_shader_vars (unsigned int pass); void clear_shader_vars (void); void strip_parameter_pragmas(char *buffer);