GLSL: Use a viewport callback to size final pass.

This commit is contained in:
Brandon Wright 2018-05-21 14:15:31 -05:00
parent 206523ee17
commit b9b60a8e60
3 changed files with 39 additions and 4 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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);