Frame counter for shaders. Not in spec currently.

This commit is contained in:
Themaister 2011-05-11 13:24:59 +02:00
parent dc20c58189
commit 59c6de69b0
5 changed files with 28 additions and 10 deletions

View File

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

View File

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

View File

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

View File

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

View File

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