Fix edge case on rotation with multiple pass shaders.

This commit is contained in:
Themaister 2012-04-02 17:26:23 +02:00
parent debba76dc4
commit 865229820a

View File

@ -561,17 +561,22 @@ static inline unsigned get_alignment(unsigned pitch)
return 8; return 8;
} }
static void set_projection(gl_t *gl) static void set_projection(gl_t *gl, bool allow_rotate)
{ {
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glRotatef(gl->rotation, 0, 0, 1);
if (allow_rotate)
glRotatef(gl->rotation, 0, 0, 1);
glOrtho(0, 1, 0, 1, -1, 1); glOrtho(0, 1, 0, 1, -1, 1);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
gl_shader_set_proj_matrix();
} }
static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full) static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate)
{ {
if (gl->keep_aspect && !force_full) if (gl->keep_aspect && !force_full)
{ {
@ -598,9 +603,7 @@ static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_f
else else
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
set_projection(gl); set_projection(gl, allow_rotate);
gl_shader_set_proj_matrix();
gl->vp_width = width; gl->vp_width = width;
gl->vp_height = height; gl->vp_height = height;
@ -619,7 +622,7 @@ static void gl_set_rotation(void *data, unsigned rotation)
{ {
gl_t *gl = (gl_t*)data; gl_t *gl = (gl_t*)data;
gl->rotation = 90 * rotation; gl->rotation = 90 * rotation;
set_projection(gl); set_projection(gl, true);
} }
#ifdef HAVE_FREETYPE #ifdef HAVE_FREETYPE
@ -772,7 +775,7 @@ static void gl_render_msg(gl_t *gl, const char *msg)
// Deactivate custom shaders. Enable the font texture. // Deactivate custom shaders. Enable the font texture.
gl_shader_use(0); gl_shader_use(0);
set_viewport(gl, gl->win_width, gl->win_height, false); set_viewport(gl, gl->win_width, gl->win_height, false, false);
glBindTexture(GL_TEXTURE_2D, gl->font_tex); glBindTexture(GL_TEXTURE_2D, gl->font_tex);
glTexCoordPointer(2, GL_FLOAT, 0, font_tex_coords); glTexCoordPointer(2, GL_FLOAT, 0, font_tex_coords);
@ -815,6 +818,7 @@ static void gl_render_msg(gl_t *gl, const char *msg)
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
glDisable(GL_BLEND); glDisable(GL_BLEND);
set_projection(gl, true);
} }
#else #else
static void gl_render_msg(gl_t *gl, const char *msg) static void gl_render_msg(gl_t *gl, const char *msg)
@ -920,7 +924,7 @@ static void gl_start_frame_fbo(gl_t *gl)
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[0]); pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[0]);
gl->render_to_tex = true; gl->render_to_tex = true;
set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true); set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true, false);
// Need to preserve the "flipped" state when in FBO as well to have // Need to preserve the "flipped" state when in FBO as well to have
// consistent texture coordinates. // consistent texture coordinates.
@ -1002,7 +1006,7 @@ static void gl_frame_fbo(gl_t *gl, const struct gl_tex_info *tex_info)
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
// Render to FBO with certain size. // Render to FBO with certain size.
set_viewport(gl, rect->img_width, rect->img_height, true); set_viewport(gl, rect->img_width, rect->img_height, true, false);
gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, gl_shader_set_params(prev_rect->img_width, prev_rect->img_height,
prev_rect->width, prev_rect->height, prev_rect->width, prev_rect->height,
gl->vp_width, gl->vp_height, gl->frame_count, gl->vp_width, gl->vp_height, gl->frame_count,
@ -1028,7 +1032,7 @@ static void gl_frame_fbo(gl_t *gl, const struct gl_tex_info *tex_info)
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
gl->render_to_tex = false; gl->render_to_tex = false;
set_viewport(gl, gl->win_width, gl->win_height, false); set_viewport(gl, gl->win_width, gl->win_height, false, true);
gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, gl_shader_set_params(prev_rect->img_width, prev_rect->img_height,
prev_rect->width, prev_rect->height, prev_rect->width, prev_rect->height,
gl->vp_width, gl->vp_height, gl->frame_count, gl->vp_width, gl->vp_height, gl->frame_count,
@ -1045,7 +1049,7 @@ static void gl_update_resize(gl_t *gl)
{ {
#ifdef HAVE_FBO #ifdef HAVE_FBO
if (!gl->render_to_tex) if (!gl->render_to_tex)
set_viewport(gl, gl->win_width, gl->win_height, false); set_viewport(gl, gl->win_width, gl->win_height, false, true);
else else
{ {
gl_check_fbo_dimensions(gl); gl_check_fbo_dimensions(gl);
@ -1054,7 +1058,7 @@ static void gl_update_resize(gl_t *gl)
gl_start_frame_fbo(gl); gl_start_frame_fbo(gl);
} }
#else #else
set_viewport(gl, gl->win_width, gl->win_height, false); set_viewport(gl, gl->win_width, gl->win_height, false, true);
#endif #endif
} }
@ -1290,9 +1294,9 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo
// Apparently need to set viewport for passes when we aren't using FBOs. // Apparently need to set viewport for passes when we aren't using FBOs.
gl_shader_use(0); gl_shader_use(0);
set_viewport(gl, gl->win_width, gl->win_height, false); set_viewport(gl, gl->win_width, gl->win_height, false, true);
gl_shader_use(1); gl_shader_use(1);
set_viewport(gl, gl->win_width, gl->win_height, false); set_viewport(gl, gl->win_width, gl->win_height, false, true);
bool force_smooth; bool force_smooth;
if (gl_shader_filter_type(1, &force_smooth)) if (gl_shader_filter_type(1, &force_smooth))
@ -1426,9 +1430,9 @@ static bool gl_xml_shader(void *data, const char *path)
// Apparently need to set viewport for passes when we aren't using FBOs. // Apparently need to set viewport for passes when we aren't using FBOs.
gl_shader_use(0); gl_shader_use(0);
set_viewport(gl, gl->win_width, gl->win_height, false); set_viewport(gl, gl->win_width, gl->win_height, false, true);
gl_shader_use(1); gl_shader_use(1);
set_viewport(gl, gl->win_width, gl->win_height, false); set_viewport(gl, gl->win_width, gl->win_height, false, true);
return true; return true;
} }