From 838a85a719069c29c1ef42d2febc8f51ef126859 Mon Sep 17 00:00:00 2001 From: Themaister Date: Wed, 1 Jun 2011 12:19:48 +0200 Subject: [PATCH] Could make coordinate flipping consistent ... Finally. --- gfx/gl.c | 22 ++++++++++++++++++++++ gfx/shader_cg.c | 29 ----------------------------- gfx/shader_glsl.c | 14 -------------- 3 files changed, 22 insertions(+), 43 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index 380bdc6543..129c59b843 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -59,6 +59,13 @@ static const GLfloat vertexes[] = { 1, 0 }; +static const GLfloat vertexes_flipped[] = { + 0, 1, + 0, 0, + 1, 0, + 1, 1 +}; + static const GLfloat tex_coords[] = { 0, 1, 0, 0, @@ -800,6 +807,14 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei #ifdef HAVE_CG glBindTexture(GL_TEXTURE_2D, gl->texture); #endif + +#ifdef HAVE_FBO + // Need to preserve the "flipped" state when in FBO too to have + // consistent texture coordinates. + if (gl->render_to_tex) + glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), vertexes_flipped); +#endif + glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / gl->base_size); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, gl->texture_type, @@ -823,6 +838,10 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei #ifdef HAVE_FBO if (gl->fbo_inited) { + // Go back to non-flipped. + if (gl->render_to_tex) + glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), vertexes); + // Render the rest of our passes. glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), gl->fbo_tex_coords); @@ -895,8 +914,11 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei gl->vp_width, gl->vp_height, gl->frame_count, &tex_info, fbo_tex_info, fbo_tex_info_cnt); + glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), vertexes_flipped); + glDrawArrays(GL_QUADS, 0, 4); glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), gl->tex_coords); + glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), vertexes); } #endif diff --git a/gfx/shader_cg.c b/gfx/shader_cg.c index 13229701d2..7094037c7e 100644 --- a/gfx/shader_cg.c +++ b/gfx/shader_cg.c @@ -86,10 +86,8 @@ struct cg_fbo_params { CGparameter vid_size_f; CGparameter tex_size_f; - CGparameter pix_size_f; CGparameter vid_size_v; CGparameter tex_size_v; - CGparameter pix_size_v; CGparameter tex; CGparameter coord; }; @@ -105,12 +103,10 @@ struct cg_program CGparameter vid_size_f; CGparameter tex_size_f; CGparameter out_size_f; - CGparameter pix_size_f; CGparameter frame_cnt_f; CGparameter vid_size_v; CGparameter tex_size_v; CGparameter out_size_v; - CGparameter pix_size_v; CGparameter frame_cnt_v; CGparameter mvp; @@ -162,15 +158,11 @@ void gl_cg_set_params(unsigned width, unsigned height, set_param_2f(prg[active_index].tex_size_f, tex_width, tex_height); set_param_2f(prg[active_index].out_size_f, out_width, out_height); set_param_1f(prg[active_index].frame_cnt_f, (float)frame_count); - float pixel_width = 1.0f / tex_width; - float pixel_height = ((active_index == 1) ? -1.0f : 1.0f) / tex_height; - set_param_2f(prg[active_index].pix_size_f, pixel_width, pixel_height); set_param_2f(prg[active_index].vid_size_v, width, height); set_param_2f(prg[active_index].tex_size_v, tex_width, tex_height); set_param_2f(prg[active_index].out_size_v, out_width, out_height); set_param_1f(prg[active_index].frame_cnt_v, (float)frame_count); - set_param_2f(prg[active_index].pix_size_v, pixel_width, pixel_height); // Set orig texture. CGparameter param = prg[active_index].orig.tex; @@ -185,11 +177,6 @@ void gl_cg_set_params(unsigned width, unsigned height, set_param_2f(prg[active_index].orig.vid_size_f, info->input_size[0], info->input_size[1]); set_param_2f(prg[active_index].orig.tex_size_v, info->tex_size[0], info->tex_size[1]); set_param_2f(prg[active_index].orig.tex_size_f, info->tex_size[0], info->tex_size[1]); - float orig_pix_width = 1.0f / info->tex_size[0]; - float orig_pix_height = -1.0f / info->tex_size[1]; - set_param_2f(prg[active_index].orig.pix_size_v, orig_pix_width, orig_pix_height); - set_param_2f(prg[active_index].orig.pix_size_f, orig_pix_width, orig_pix_height); - if (prg[active_index].orig.coord) { cgGLSetParameterPointer(prg[active_index].orig.coord, 2, GL_FLOAT, 0, info->coord); @@ -229,14 +216,6 @@ void gl_cg_set_params(unsigned width, unsigned height, set_param_2f(prg[active_index].fbo[i].tex_size_f, fbo_info[i].tex_size[0], fbo_info[i].tex_size[1]); - float pix_width = 1.0f / fbo_info[i].tex_size[0]; - float pix_height = 1.0f / fbo_info[i].tex_size[1]; - - set_param_2f(prg[active_index].fbo[i].pix_size_v, - pix_width, pix_height); - set_param_2f(prg[active_index].fbo[i].pix_size_f, - pix_width, pix_height); - if (prg[active_index].fbo[i].coord) { cgGLSetParameterPointer(prg[active_index].fbo[i].coord, 2, GL_FLOAT, 0, fbo_info[i].coord); @@ -842,12 +821,10 @@ bool gl_cg_init(const char *path) prg[i].vid_size_f = cgGetNamedParameter(prg[i].fprg, "IN.video_size"); prg[i].tex_size_f = cgGetNamedParameter(prg[i].fprg, "IN.texture_size"); prg[i].out_size_f = cgGetNamedParameter(prg[i].fprg, "IN.output_size"); - prg[i].pix_size_f = cgGetNamedParameter(prg[i].fprg, "IN.pixel_size"); prg[i].frame_cnt_f = cgGetNamedParameter(prg[i].fprg, "IN.frame_count"); prg[i].vid_size_v = cgGetNamedParameter(prg[i].vprg, "IN.video_size"); prg[i].tex_size_v = cgGetNamedParameter(prg[i].vprg, "IN.texture_size"); prg[i].out_size_v = cgGetNamedParameter(prg[i].vprg, "IN.output_size"); - prg[i].pix_size_v = cgGetNamedParameter(prg[i].vprg, "IN.pixel_size"); prg[i].frame_cnt_v = cgGetNamedParameter(prg[i].vprg, "IN.frame_count"); prg[i].mvp = cgGetNamedParameter(prg[i].vprg, "modelViewProj"); if (prg[i].mvp) @@ -858,8 +835,6 @@ bool gl_cg_init(const char *path) prg[i].orig.vid_size_f = cgGetNamedParameter(prg[i].fprg, "ORIG.video_size"); prg[i].orig.tex_size_v = cgGetNamedParameter(prg[i].vprg, "ORIG.texture_size"); prg[i].orig.tex_size_f = cgGetNamedParameter(prg[i].fprg, "ORIG.texture_size"); - prg[i].orig.pix_size_v = cgGetNamedParameter(prg[i].vprg, "ORIG.pixel_size"); - prg[i].orig.pix_size_f = cgGetNamedParameter(prg[i].fprg, "ORIG.pixel_size"); prg[i].orig.coord = cgGetNamedParameter(prg[i].vprg, "ORIG.tex_coord"); for (unsigned j = 0; j < i - 1; j++) @@ -877,10 +852,6 @@ bool gl_cg_init(const char *path) prg[i].fbo[j].tex_size_v = cgGetNamedParameter(prg[i].vprg, attr_buf); prg[i].fbo[j].tex_size_f = cgGetNamedParameter(prg[i].fprg, attr_buf); - snprintf(attr_buf, sizeof(attr_buf), "PASS%u.pixel_size", j + 1); - prg[i].fbo[j].pix_size_v = cgGetNamedParameter(prg[i].vprg, attr_buf); - prg[i].fbo[j].pix_size_f = cgGetNamedParameter(prg[i].fprg, attr_buf); - snprintf(attr_buf, sizeof(attr_buf), "PASS%u.tex_coord", j + 1); prg[i].fbo[j].coord = cgGetNamedParameter(prg[i].vprg, attr_buf); } diff --git a/gfx/shader_glsl.c b/gfx/shader_glsl.c index c1f5b33441..900e03920f 100644 --- a/gfx/shader_glsl.c +++ b/gfx/shader_glsl.c @@ -884,11 +884,6 @@ void gl_glsl_set_params(unsigned width, unsigned height, location = pglGetUniformLocation(gl_program[active_index], "rubyTextureSize"); pglUniform2fv(location, 1, textureSize); - // FBO textures are normal, regular textures are "flipped". - float pixelSize[2] = {1.0f / tex_width, ((active_index == 1) ? -1.0f : 1.0f) / tex_height}; - location = pglGetUniformLocation(gl_program[active_index], "rubyPixelSize"); - pglUniform2fv(location, 1, pixelSize); - location = pglGetUniformLocation(gl_program[active_index], "rubyFrameCount"); pglUniform1i(location, frame_count); @@ -913,10 +908,6 @@ void gl_glsl_set_params(unsigned width, unsigned height, location = pglGetUniformLocation(gl_program[active_index], "rubyOrigInputSize"); pglUniform2fv(location, 1, info->input_size); - float pixelSize[2] = {1.0f / info->tex_size[0], -1.0f / info->tex_size[1]}; - location = pglGetUniformLocation(gl_program[active_index], "rubyOrigPixelSize"); - pglUniform2fv(location, 1, pixelSize); - // Pass texture coordinates. location = pglGetAttribLocation(gl_program[active_index], "rubyOrigTexCoord"); if (location >= 0) @@ -951,11 +942,6 @@ void gl_glsl_set_params(unsigned width, unsigned height, location = pglGetUniformLocation(gl_program[active_index], attrib_buf); pglUniform2fv(location, 1, fbo_info[i].input_size); - snprintf(attrib_buf, sizeof(attrib_buf), "rubyPass%uPixelSize", i + 1); - float pixelSize[2] = {1.0f / fbo_info[i].tex_size[0], 1.0f / fbo_info[i].tex_size[1]}; - location = pglGetUniformLocation(gl_program[active_index], attrib_buf); - pglUniform2fv(location, 1, pixelSize); - snprintf(attrib_buf, sizeof(attrib_buf), "rubyPass%uTexCoord", i + 1); location = pglGetAttribLocation(gl_program[active_index], attrib_buf); if (location >= 0)