static void gl_cg_set_texture_info(void *data, const struct cg_fbo_params *params, const struct gfx_tex_info *info) { cg_shader_data_t *cg_data = (cg_shader_data_t*)data; CGparameter param = params->tex; if (param) { cgGLSetTextureParameter(param, info->tex); cgGLEnableTextureParameter(param); } set_param_2f(params->vid_size_v, info->input_size[0], info->input_size[1]); set_param_2f(params->vid_size_f, info->input_size[0], info->input_size[1]); set_param_2f(params->tex_size_v, info->tex_size[0], info->tex_size[1]); set_param_2f(params->tex_size_f, info->tex_size[0], info->tex_size[1]); if (params->coord) { cgGLSetParameterPointer(params->coord, 2, GL_FLOAT, 0, info->coord); cgGLEnableClientState(params->coord); cg_data->cg_attribs[cg_data->cg_attrib_idx++] = params->coord; } }
void IOGLBaseShader::BindParameter(const CString& strParam, GLenum uType, const uint32 uNumber, const uint32 uStride, const uint32 uOffset){ auto uParam = this->GetParameter(strParam); cgGLEnableClientState(uParam); cgGLSetParameterPointer(uParam, uNumber, uType, uStride, reinterpret_cast<const GLvoid*>(uOffset)); this->m_uVaryingParams.Add(uParam); }
void Cluster::draw () { glColor3fv(d->color); cgGLEnableClientState(d->shader.v0); cgGLSetParameter1f(d->shader.t, d->age); cgGLSetParameter1f(d->shader.nt, d->age/d->lifetime); cgGLSetParameterPointer(d->shader.v0, 3, GL_FLOAT, sizeof(btVector3), d->initialVelocities[0]); cgGLSetParameter3fv(d->shader.origin, d->origin); cgGLSetParameter3fv(d->shader.eye, scene->camera()->position()); glDrawArrays(GL_POINTS, 0, d->starCount); cgGLDisableClientState(d->shader.v0); }
static void gl_cg_set_params(unsigned width, unsigned height, unsigned tex_width, unsigned tex_height, unsigned out_width, unsigned out_height, unsigned frame_count, const struct gl_tex_info *info, const struct gl_tex_info *prev_info, const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt) { unsigned i; if (!cg_active || (active_index == 0) || (active_index == GL_SHADER_STOCK_BLEND)) return; // Set frame. set_param_2f(prg[active_index].vid_size_f, width, 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_dir_f, g_extern.frame_is_reverse ? -1.0 : 1.0); 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_dir_v, g_extern.frame_is_reverse ? -1.0 : 1.0); if (prg[active_index].frame_cnt_f || prg[active_index].frame_cnt_v) { unsigned modulo = cg_shader->pass[active_index - 1].frame_count_mod; if (modulo) frame_count %= modulo; set_param_1f(prg[active_index].frame_cnt_f, (float)frame_count); set_param_1f(prg[active_index].frame_cnt_v, (float)frame_count); } // Set orig texture. CGparameter param = prg[active_index].orig.tex; if (param) { cgGLSetTextureParameter(param, info->tex); cgGLEnableTextureParameter(param); } set_param_2f(prg[active_index].orig.vid_size_v, info->input_size[0], info->input_size[1]); 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]); if (prg[active_index].orig.coord) { cgGLSetParameterPointer(prg[active_index].orig.coord, 2, GL_FLOAT, 0, info->coord); cgGLEnableClientState(prg[active_index].orig.coord); cg_attribs[cg_attrib_index++] = prg[active_index].orig.coord; } // Set prev textures. for (i = 0; i < PREV_TEXTURES; i++) { param = prg[active_index].prev[i].tex; if (param) { cgGLSetTextureParameter(param, prev_info[i].tex); cgGLEnableTextureParameter(param); } set_param_2f(prg[active_index].prev[i].vid_size_v, prev_info[i].input_size[0], prev_info[i].input_size[1]); set_param_2f(prg[active_index].prev[i].vid_size_f, prev_info[i].input_size[0], prev_info[i].input_size[1]); set_param_2f(prg[active_index].prev[i].tex_size_v, prev_info[i].tex_size[0], prev_info[i].tex_size[1]); set_param_2f(prg[active_index].prev[i].tex_size_f, prev_info[i].tex_size[0], prev_info[i].tex_size[1]); if (prg[active_index].prev[i].coord) { cgGLSetParameterPointer(prg[active_index].prev[i].coord, 2, GL_FLOAT, 0, prev_info[i].coord); cgGLEnableClientState(prg[active_index].prev[i].coord); cg_attribs[cg_attrib_index++] = prg[active_index].prev[i].coord; } } // Set lookup textures. for (i = 0; i < cg_shader->luts; i++) { CGparameter fparam = cgGetNamedParameter(prg[active_index].fprg, cg_shader->lut[i].id); if (fparam) { cgGLSetTextureParameter(fparam, lut_textures[i]); cgGLEnableTextureParameter(fparam); } CGparameter vparam = cgGetNamedParameter(prg[active_index].vprg, cg_shader->lut[i].id); if (vparam) { cgGLSetTextureParameter(vparam, lut_textures[i]); cgGLEnableTextureParameter(vparam); } } // Set FBO textures. if (active_index > 2) { for (i = 0; i < fbo_info_cnt; i++) { if (prg[active_index].fbo[i].tex) { cgGLSetTextureParameter(prg[active_index].fbo[i].tex, fbo_info[i].tex); cgGLEnableTextureParameter(prg[active_index].fbo[i].tex); } set_param_2f(prg[active_index].fbo[i].vid_size_v, fbo_info[i].input_size[0], fbo_info[i].input_size[1]); set_param_2f(prg[active_index].fbo[i].vid_size_f, fbo_info[i].input_size[0], fbo_info[i].input_size[1]); set_param_2f(prg[active_index].fbo[i].tex_size_v, fbo_info[i].tex_size[0], fbo_info[i].tex_size[1]); set_param_2f(prg[active_index].fbo[i].tex_size_f, fbo_info[i].tex_size[0], fbo_info[i].tex_size[1]); if (prg[active_index].fbo[i].coord) { cgGLSetParameterPointer(prg[active_index].fbo[i].coord, 2, GL_FLOAT, 0, fbo_info[i].coord); cgGLEnableClientState(prg[active_index].fbo[i].coord); cg_attribs[cg_attrib_index++] = prg[active_index].fbo[i].coord; } } } // Set state parameters if (state_tracker) { // Only query uniforms in first pass. static struct state_tracker_uniform info[MAX_VARIABLES]; static unsigned cnt = 0; if (active_index == 1) cnt = state_get_uniform(state_tracker, info, MAX_VARIABLES, frame_count); for (i = 0; i < cnt; i++) { CGparameter param_v = cgGetNamedParameter(prg[active_index].vprg, info[i].id); CGparameter param_f = cgGetNamedParameter(prg[active_index].fprg, info[i].id); set_param_1f(param_v, info[i].value); set_param_1f(param_f, info[i].value); } } }
static void gl_cg_set_params(void *data, unsigned width, unsigned height, unsigned tex_width, unsigned tex_height, unsigned out_width, unsigned out_height, unsigned frame_count, const void *_info, const void *_prev_info, const void *_fbo_info, unsigned fbo_info_cnt) { unsigned i; const struct gl_tex_info *info = (const struct gl_tex_info*)_info; const struct gl_tex_info *prev_info = (const struct gl_tex_info*)_prev_info; const struct gl_tex_info *fbo_info = (const struct gl_tex_info*)_fbo_info; cg_shader_data_t *cg = (cg_shader_data_t*)driver.video_shader_data; (void)data; if (!cg || (cg->active_idx == 0) || (cg->active_idx == GL_SHADER_STOCK_BLEND)) return; /* Set frame. */ set_param_2f(cg->prg[cg->active_idx].vid_size_f, width, height); set_param_2f(cg->prg[cg->active_idx].tex_size_f, tex_width, tex_height); set_param_2f(cg->prg[cg->active_idx].out_size_f, out_width, out_height); set_param_1f(cg->prg[cg->active_idx].frame_dir_f, g_extern.frame_is_reverse ? -1.0 : 1.0); set_param_2f(cg->prg[cg->active_idx].vid_size_v, width, height); set_param_2f(cg->prg[cg->active_idx].tex_size_v, tex_width, tex_height); set_param_2f(cg->prg[cg->active_idx].out_size_v, out_width, out_height); set_param_1f(cg->prg[cg->active_idx].frame_dir_v, g_extern.frame_is_reverse ? -1.0 : 1.0); if (cg->prg[cg->active_idx].frame_cnt_f || cg->prg[cg->active_idx].frame_cnt_v) { unsigned modulo = cg->cg_shader->pass[cg->active_idx - 1].frame_count_mod; if (modulo) frame_count %= modulo; set_param_1f(cg->prg[cg->active_idx].frame_cnt_f, (float)frame_count); set_param_1f(cg->prg[cg->active_idx].frame_cnt_v, (float)frame_count); } /* Set orig texture. */ CGparameter param = cg->prg[cg->active_idx].orig.tex; if (param) { cgGLSetTextureParameter(param, info->tex); cgGLEnableTextureParameter(param); } set_param_2f(cg->prg[cg->active_idx].orig.vid_size_v, info->input_size[0], info->input_size[1]); set_param_2f(cg->prg[cg->active_idx].orig.vid_size_f, info->input_size[0], info->input_size[1]); set_param_2f(cg->prg[cg->active_idx].orig.tex_size_v, info->tex_size[0], info->tex_size[1]); set_param_2f(cg->prg[cg->active_idx].orig.tex_size_f, info->tex_size[0], info->tex_size[1]); if (cg->prg[cg->active_idx].orig.coord) { cgGLSetParameterPointer(cg->prg[cg->active_idx].orig.coord, 2, GL_FLOAT, 0, info->coord); cgGLEnableClientState(cg->prg[cg->active_idx].orig.coord); cg->cg_attribs[cg->cg_attrib_idx++] = cg->prg[cg->active_idx].orig.coord; } /* Set prev textures. */ for (i = 0; i < PREV_TEXTURES; i++) { param = cg->prg[cg->active_idx].prev[i].tex; if (param) { cgGLSetTextureParameter(param, prev_info[i].tex); cgGLEnableTextureParameter(param); } set_param_2f(cg->prg[cg->active_idx].prev[i].vid_size_v, prev_info[i].input_size[0], prev_info[i].input_size[1]); set_param_2f(cg->prg[cg->active_idx].prev[i].vid_size_f, prev_info[i].input_size[0], prev_info[i].input_size[1]); set_param_2f(cg->prg[cg->active_idx].prev[i].tex_size_v, prev_info[i].tex_size[0], prev_info[i].tex_size[1]); set_param_2f(cg->prg[cg->active_idx].prev[i].tex_size_f, prev_info[i].tex_size[0], prev_info[i].tex_size[1]); if (cg->prg[cg->active_idx].prev[i].coord) { cgGLSetParameterPointer(cg->prg[cg->active_idx].prev[i].coord, 2, GL_FLOAT, 0, prev_info[i].coord); cgGLEnableClientState(cg->prg[cg->active_idx].prev[i].coord); cg->cg_attribs[cg->cg_attrib_idx++] = cg->prg[cg->active_idx].prev[i].coord; } } /* Set lookup textures. */ for (i = 0; i < cg->cg_shader->luts; i++) { CGparameter fparam = cgGetNamedParameter( cg->prg[cg->active_idx].fprg, cg->cg_shader->lut[i].id); if (fparam) { cgGLSetTextureParameter(fparam, cg->lut_textures[i]); cgGLEnableTextureParameter(fparam); } CGparameter vparam = cgGetNamedParameter( cg->prg[cg->active_idx].vprg, cg->cg_shader->lut[i].id); if (vparam) { cgGLSetTextureParameter(vparam, cg->lut_textures[i]); cgGLEnableTextureParameter(vparam); } } /* Set FBO textures. */ if (cg->active_idx) { for (i = 0; i < fbo_info_cnt; i++) { if (cg->prg[cg->active_idx].fbo[i].tex) { cgGLSetTextureParameter( cg->prg[cg->active_idx].fbo[i].tex, fbo_info[i].tex); cgGLEnableTextureParameter(cg->prg[cg->active_idx].fbo[i].tex); } set_param_2f(cg->prg[cg->active_idx].fbo[i].vid_size_v, fbo_info[i].input_size[0], fbo_info[i].input_size[1]); set_param_2f(cg->prg[cg->active_idx].fbo[i].vid_size_f, fbo_info[i].input_size[0], fbo_info[i].input_size[1]); set_param_2f(cg->prg[cg->active_idx].fbo[i].tex_size_v, fbo_info[i].tex_size[0], fbo_info[i].tex_size[1]); set_param_2f(cg->prg[cg->active_idx].fbo[i].tex_size_f, fbo_info[i].tex_size[0], fbo_info[i].tex_size[1]); if (cg->prg[cg->active_idx].fbo[i].coord) { cgGLSetParameterPointer(cg->prg[cg->active_idx].fbo[i].coord, 2, GL_FLOAT, 0, fbo_info[i].coord); cgGLEnableClientState(cg->prg[cg->active_idx].fbo[i].coord); cg->cg_attribs[cg->cg_attrib_idx++] = cg->prg[cg->active_idx].fbo[i].coord; } } } /* #pragma parameters. */ for (i = 0; i < cg->cg_shader->num_parameters; i++) { CGparameter param_v = cgGetNamedParameter( cg->prg[cg->active_idx].vprg, cg->cg_shader->parameters[i].id); CGparameter param_f = cgGetNamedParameter( cg->prg[cg->active_idx].fprg, cg->cg_shader->parameters[i].id); set_param_1f(param_v, cg->cg_shader->parameters[i].current); set_param_1f(param_f, cg->cg_shader->parameters[i].current); } /* Set state parameters. */ if (cg->state_tracker) { /* Only query uniforms in first pass. */ static struct state_tracker_uniform tracker_info[MAX_VARIABLES]; static unsigned cnt = 0; if (cg->active_idx == 1) cnt = state_get_uniform(cg->state_tracker, tracker_info, MAX_VARIABLES, frame_count); for (i = 0; i < cnt; i++) { CGparameter param_v = cgGetNamedParameter( cg->prg[cg->active_idx].vprg, tracker_info[i].id); CGparameter param_f = cgGetNamedParameter( cg->prg[cg->active_idx].fprg, tracker_info[i].id); set_param_1f(param_v, tracker_info[i].value); set_param_1f(param_f, tracker_info[i].value); } } }