From 59c6de69b0a77abe342b9adcb8a041be38fdf408 Mon Sep 17 00:00:00 2001 From: Themaister Date: Wed, 11 May 2011 13:24:59 +0200 Subject: [PATCH] Frame counter for shaders. Not in spec currently. --- gfx/gl.c | 17 +++++++++++------ gfx/shader_cg.c | 9 ++++++++- gfx/shader_cg.h | 3 ++- gfx/shader_glsl.c | 6 +++++- gfx/shader_glsl.h | 3 ++- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index 9603fece18..7038d392ec 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -111,6 +111,8 @@ typedef struct gl GLuint texture; GLuint tex_filter; + unsigned frame_count; + #ifdef HAVE_FBO // Render-to-texture, multipass shaders GLuint fbo[MAX_SHADERS]; @@ -231,14 +233,15 @@ static void gl_shader_set_proj_matrix(void) static void gl_shader_set_params(unsigned width, unsigned height, unsigned tex_width, unsigned tex_height, - unsigned out_width, unsigned out_height) + unsigned out_width, unsigned out_height, + unsigned frame_count) { #ifdef HAVE_CG - gl_cg_set_params(width, height, tex_width, tex_height, out_width, out_height); + gl_cg_set_params(width, height, tex_width, tex_height, out_width, out_height, frame_count); #endif #ifdef HAVE_XML - gl_glsl_set_params(width, height, tex_width, tex_height, out_width, out_height); + gl_glsl_set_params(width, height, tex_width, tex_height, out_width, out_height, frame_count); #endif } @@ -634,6 +637,8 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei gl_shader_use(1); + gl->frame_count++; + #ifdef HAVE_FBO // Render to texture in first pass. if (gl->fbo_inited) @@ -746,7 +751,7 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei } glClear(GL_COLOR_BUFFER_BIT); - gl_shader_set_params(width, height, gl->tex_w, gl->tex_h, gl->vp_width, gl->vp_height); + gl_shader_set_params(width, height, gl->tex_w, gl->tex_h, gl->vp_width, gl->vp_height, gl->frame_count); if (width != gl->last_width || height != gl->last_height) // Res change. need to clear out texture. { @@ -812,7 +817,7 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei // Render to FBO with certain size. set_viewport(gl, rect->img_width, rect->img_height, true); - gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, prev_rect->width, prev_rect->height, gl->vp_width, gl->vp_height); + gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, prev_rect->width, prev_rect->height, gl->vp_width, gl->vp_height, gl->frame_count); glDrawArrays(GL_QUADS, 0, 4); } @@ -833,7 +838,7 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei glClear(GL_COLOR_BUFFER_BIT); gl->render_to_tex = false; set_viewport(gl, gl->win_width, gl->win_height, false); - gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, prev_rect->width, prev_rect->height, gl->vp_width, gl->vp_height); + gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, prev_rect->width, prev_rect->height, gl->vp_width, gl->vp_height, gl->frame_count); glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]); glDrawArrays(GL_QUADS, 0, 4); diff --git a/gfx/shader_cg.c b/gfx/shader_cg.c index 6a357645cf..4bbdea5a69 100644 --- a/gfx/shader_cg.c +++ b/gfx/shader_cg.c @@ -63,9 +63,11 @@ struct cg_program CGparameter vid_size_f; CGparameter tex_size_f; CGparameter out_size_f; + CGparameter frame_cnt_f; CGparameter vid_size_v; CGparameter tex_size_v; CGparameter out_size_v; + CGparameter frame_cnt_v; CGparameter mvp; }; @@ -82,17 +84,20 @@ void gl_cg_set_proj_matrix(void) void gl_cg_set_params(unsigned width, unsigned height, unsigned tex_width, unsigned tex_height, - unsigned out_width, unsigned out_height) + unsigned out_width, unsigned out_height, + unsigned frame_count) { if (cg_active) { cgGLSetParameter2f(prg[active_index].vid_size_f, width, height); cgGLSetParameter2f(prg[active_index].tex_size_f, tex_width, tex_height); cgGLSetParameter2f(prg[active_index].out_size_f, out_width, out_height); + cgGLSetParameter1f(prg[active_index].frame_cnt_f, (float)frame_count); cgGLSetParameter2f(prg[active_index].vid_size_v, width, height); cgGLSetParameter2f(prg[active_index].tex_size_v, tex_width, tex_height); cgGLSetParameter2f(prg[active_index].out_size_v, out_width, out_height); + cgGLSetParameter1f(prg[active_index].frame_cnt_v, (float)frame_count); } } @@ -165,9 +170,11 @@ 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].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].frame_cnt_v = cgGetNamedParameter(prg[i].fprg, "IN.frame_count"); prg[i].mvp = cgGetNamedParameter(prg[i].vprg, "modelViewProj"); cgGLSetStateMatrixParameter(prg[i].mvp, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); } diff --git a/gfx/shader_cg.h b/gfx/shader_cg.h index 3e62d6d791..8f5ce2184b 100644 --- a/gfx/shader_cg.h +++ b/gfx/shader_cg.h @@ -30,7 +30,8 @@ void gl_cg_set_proj_matrix(void); void gl_cg_set_params(unsigned width, unsigned height, unsigned tex_width, unsigned tex_height, - unsigned out_width, unsigned out_height); + unsigned out_width, unsigned out_height, + unsigned frame_count); void gl_cg_use(unsigned index); diff --git a/gfx/shader_glsl.c b/gfx/shader_glsl.c index 3ca1916156..2576d4435e 100644 --- a/gfx/shader_glsl.c +++ b/gfx/shader_glsl.c @@ -596,7 +596,8 @@ void gl_glsl_deinit(void) void gl_glsl_set_params(unsigned width, unsigned height, unsigned tex_width, unsigned tex_height, - unsigned out_width, unsigned out_height) + unsigned out_width, unsigned out_height, + unsigned frame_count) { if (glsl_enable && gl_program[active_index] > 0) { @@ -613,6 +614,9 @@ void gl_glsl_set_params(unsigned width, unsigned height, float textureSize[2] = {tex_width, tex_height}; location = pglGetUniformLocation(gl_program[active_index], "rubyTextureSize"); pglUniform2fv(location, 1, textureSize); + + location = pglGetUniformLocation(gl_program[active_index], "rubyFrameCount"); + pglUniform1i(location, frame_count); } } diff --git a/gfx/shader_glsl.h b/gfx/shader_glsl.h index 080ef56c44..e46a2f21a5 100644 --- a/gfx/shader_glsl.h +++ b/gfx/shader_glsl.h @@ -30,7 +30,8 @@ void gl_glsl_set_proj_matrix(void); void gl_glsl_set_params(unsigned width, unsigned height, unsigned tex_width, unsigned tex_height, - unsigned out_width, unsigned out_height); + unsigned out_width, unsigned out_height, + unsigned frame_counter); void gl_glsl_use(unsigned index);