static void menu_display_d3d9_bind_texture(menu_display_ctx_draw_t *draw, d3d9_video_t *d3d) { LPDIRECT3DDEVICE9 dev = d3d->dev; d3d9_set_texture(dev, 0, (LPDIRECT3DTEXTURE9)draw->texture); d3d9_set_sampler_address_u(dev, 0, D3DTADDRESS_COMM_CLAMP); d3d9_set_sampler_address_v(dev, 0, D3DTADDRESS_COMM_CLAMP); d3d9_set_sampler_minfilter(dev, 0, D3DTEXF_COMM_LINEAR); d3d9_set_sampler_magfilter(dev, 0, D3DTEXF_COMM_LINEAR); d3d9_set_sampler_mipfilter(dev, 0, D3DTEXF_COMM_LINEAR); }
static void d3d9_cg_renderchain_bind_orig( d3d9_renderchain_t *chain, LPDIRECT3DDEVICE9 dev, struct shader_pass *pass) { CGparameter param; float video_size[2]; float texture_size[2]; struct shader_pass *first_pass = (struct shader_pass*)&chain->passes->data[0]; video_size[0] = first_pass->last_width; video_size[1] = first_pass->last_height; texture_size[0] = first_pass->info.tex_w; texture_size[1] = first_pass->info.tex_h; d3d9_cg_set_param_2f(pass->vprg, dev, "ORIG.video_size", &video_size); d3d9_cg_set_param_2f(pass->fprg, dev, "ORIG.video_size", &video_size); d3d9_cg_set_param_2f(pass->vprg, dev, "ORIG.texture_size", &texture_size); d3d9_cg_set_param_2f(pass->fprg, dev, "ORIG.texture_size", &texture_size); param = d3d9_cg_get_constant_by_name(pass->fprg, "ORIG.texture"); if (param) { unsigned index = cgGetParameterResourceIndex(param); d3d9_set_texture(chain->dev, index, first_pass->tex); d3d9_set_sampler_magfilter(chain->dev, index, d3d_translate_filter(first_pass->info.pass->filter)); d3d9_set_sampler_minfilter(chain->dev, index, d3d_translate_filter(first_pass->info.pass->filter)); d3d9_set_sampler_address_u(chain->dev, index, D3DTADDRESS_BORDER); d3d9_set_sampler_address_v(chain->dev, index, D3DTADDRESS_BORDER); unsigned_vector_list_append(chain->bound_tex, index); } param = d3d9_cg_get_constant_by_name(pass->vprg, "ORIG.tex_coord"); if (param) { LPDIRECT3DVERTEXBUFFER9 vert_buf = (LPDIRECT3DVERTEXBUFFER9)first_pass->vertex_buf; struct unsigned_vector_list *attrib_map = (struct unsigned_vector_list*) pass->attrib_map; unsigned index = attrib_map->data[cgGetParameterResourceIndex(param)]; d3d9_set_stream_source(chain->dev, index, vert_buf, 0, sizeof(struct D3D9Vertex)); unsigned_vector_list_append(chain->bound_vert, index); } }
static void d3d9_cg_renderchain_render_pass( d3d9_renderchain_t *chain, struct shader_pass *pass, state_tracker_t *tracker, unsigned pass_index) { unsigned i; d3d9_cg_bind_program(pass); d3d9_set_texture(chain->dev, 0, pass->tex); d3d9_set_sampler_minfilter(chain->dev, 0, d3d_translate_filter(pass->info.pass->filter)); d3d9_set_sampler_magfilter(chain->dev, 0, d3d_translate_filter(pass->info.pass->filter)); d3d9_set_vertex_declaration(chain->dev, pass->vertex_decl); for (i = 0; i < 4; i++) d3d9_set_stream_source(chain->dev, i, pass->vertex_buf, 0, sizeof(struct D3D9Vertex)); /* Set orig texture. */ d3d9_cg_renderchain_bind_orig(chain, chain->dev, pass); /* Set prev textures. */ d3d9_cg_renderchain_bind_prev(chain, chain->dev, pass); /* Set lookup textures */ for (i = 0; i < chain->luts->count; i++) { CGparameter vparam; CGparameter fparam = d3d9_cg_get_constant_by_name( pass->fprg, chain->luts->data[i].id); int bound_index = -1; if (fparam) { unsigned index = cgGetParameterResourceIndex(fparam); bound_index = index; d3d9_renderchain_add_lut_internal(chain, index, i); } vparam = d3d9_cg_get_constant_by_name(pass->vprg, chain->luts->data[i].id); if (vparam) { unsigned index = cgGetParameterResourceIndex(vparam); if (index != (unsigned)bound_index) d3d9_renderchain_add_lut_internal(chain, index, i); } } /* We only bother binding passes which are two indices behind. */ if (pass_index >= 3) d3d9_cg_renderchain_bind_pass(chain, chain->dev, pass, pass_index); if (tracker) d3d9_cg_renderchain_set_params(chain, chain->dev, pass, tracker, pass_index); d3d9_draw_primitive(chain->dev, D3DPT_TRIANGLESTRIP, 0, 2); /* So we don't render with linear filter into render targets, * which apparently looked odd (too blurry). */ d3d9_set_sampler_minfilter(chain->dev, 0, D3DTEXF_POINT); d3d9_set_sampler_magfilter(chain->dev, 0, D3DTEXF_POINT); d3d9_renderchain_unbind_all(chain); }
static bool d3d9_cg_renderchain_create_first_pass( LPDIRECT3DDEVICE9 dev, cg_renderchain_t *cg_chain, d3d9_renderchain_t *chain, const struct LinkInfo *info, unsigned _fmt) { unsigned i; struct shader_pass pass; struct d3d_matrix ident; unsigned fmt = (_fmt == RETRO_PIXEL_FORMAT_RGB565) ? d3d9_get_rgb565_format() : d3d9_get_xrgb8888_format(); d3d_matrix_identity(&ident); d3d9_set_transform(dev, D3DTS_WORLD, (D3DMATRIX*)&ident); d3d9_set_transform(dev, D3DTS_VIEW, (D3DMATRIX*)&ident); pass.info = *info; pass.last_width = 0; pass.last_height = 0; pass.attrib_map = (struct unsigned_vector_list*) unsigned_vector_list_new(); chain->prev.ptr = 0; for (i = 0; i < TEXTURES; i++) { chain->prev.last_width[i] = 0; chain->prev.last_height[i] = 0; chain->prev.vertex_buf[i] = (LPDIRECT3DVERTEXBUFFER9) d3d9_vertex_buffer_new( chain->dev, 4 * sizeof(struct D3D9Vertex), D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, NULL); if (!chain->prev.vertex_buf[i]) return false; chain->prev.tex[i] = (LPDIRECT3DTEXTURE9) d3d9_texture_new(chain->dev, NULL, info->tex_w, info->tex_h, 1, 0, fmt, D3DPOOL_MANAGED, 0, 0, 0, NULL, NULL, false); if (!chain->prev.tex[i]) return false; d3d9_set_texture(chain->dev, 0, chain->prev.tex[i]); d3d9_set_sampler_minfilter(dev, 0, d3d_translate_filter(info->pass->filter)); d3d9_set_sampler_magfilter(dev, 0, d3d_translate_filter(info->pass->filter)); d3d9_set_sampler_address_u(dev, 0, D3DTADDRESS_BORDER); d3d9_set_sampler_address_v(dev, 0, D3DTADDRESS_BORDER); d3d9_set_texture(chain->dev, 0, NULL); } d3d9_cg_load_program(cg_chain, &pass, info->pass->source.path, true); if (!d3d9_cg_renderchain_init_shader_fvf(chain, &pass)) return false; shader_pass_vector_list_append(chain->passes, pass); return true; }
static void d3d9_cg_renderchain_bind_pass( d3d9_renderchain_t *chain, LPDIRECT3DDEVICE9 dev, struct shader_pass *pass, unsigned pass_index) { unsigned i; for (i = 1; i < pass_index - 1; i++) { CGparameter param; float video_size[2]; float texture_size[2]; char pass_base[64] = {0}; char attr_texture[64] = {0}; char attr_input_size[64] = {0}; char attr_tex_size[64] = {0}; char attr_coord[64] = {0}; struct shader_pass *curr_pass = (struct shader_pass*)&chain->passes->data[i]; snprintf(pass_base, sizeof(pass_base), "PASS%u", i); snprintf(attr_texture, sizeof(attr_texture), "%s.texture", pass_base); snprintf(attr_input_size, sizeof(attr_input_size), "%s.video_size", pass_base); snprintf(attr_tex_size, sizeof(attr_tex_size), "%s.texture_size", pass_base); snprintf(attr_coord, sizeof(attr_coord), "%s.tex_coord", pass_base); video_size[0] = curr_pass->last_width; video_size[1] = curr_pass->last_height; texture_size[0] = curr_pass->info.tex_w; texture_size[1] = curr_pass->info.tex_h; d3d9_cg_set_param_2f(pass->vprg, dev, attr_input_size, &video_size); d3d9_cg_set_param_2f(pass->fprg, dev, attr_input_size, &video_size); d3d9_cg_set_param_2f(pass->vprg, dev, attr_tex_size, &texture_size); d3d9_cg_set_param_2f(pass->fprg, dev, attr_tex_size, &texture_size); param = d3d9_cg_get_constant_by_name(pass->fprg, attr_texture); if (param) { unsigned index = cgGetParameterResourceIndex(param); unsigned_vector_list_append(chain->bound_tex, index); d3d9_set_texture(chain->dev, index, curr_pass->tex); d3d9_set_sampler_magfilter(chain->dev, index, d3d_translate_filter(curr_pass->info.pass->filter)); d3d9_set_sampler_minfilter(chain->dev, index, d3d_translate_filter(curr_pass->info.pass->filter)); d3d9_set_sampler_address_u(chain->dev, index, D3DTADDRESS_BORDER); d3d9_set_sampler_address_v(chain->dev, index, D3DTADDRESS_BORDER); } param = d3d9_cg_get_constant_by_name(pass->vprg, attr_coord); if (param) { struct unsigned_vector_list *attrib_map = (struct unsigned_vector_list*)pass->attrib_map; unsigned index = attrib_map->data[cgGetParameterResourceIndex(param)]; d3d9_set_stream_source(chain->dev, index, curr_pass->vertex_buf, 0, sizeof(struct D3D9Vertex)); unsigned_vector_list_append(chain->bound_vert, index); } } }
static void d3d9_cg_renderchain_bind_prev(d3d9_renderchain_t *chain, LPDIRECT3DDEVICE9 dev, struct shader_pass *pass) { unsigned i; float texture_size[2]; char attr_texture[64] = {0}; char attr_input_size[64] = {0}; char attr_tex_size[64] = {0}; char attr_coord[64] = {0}; static const char *prev_names[] = { "PREV", "PREV1", "PREV2", "PREV3", "PREV4", "PREV5", "PREV6", }; texture_size[0] = chain->passes->data[0].info.tex_w; texture_size[1] = chain->passes->data[0].info.tex_h; for (i = 0; i < TEXTURES - 1; i++) { CGparameter param; float video_size[2]; snprintf(attr_texture, sizeof(attr_texture), "%s.texture", prev_names[i]); snprintf(attr_input_size, sizeof(attr_input_size), "%s.video_size", prev_names[i]); snprintf(attr_tex_size, sizeof(attr_tex_size), "%s.texture_size", prev_names[i]); snprintf(attr_coord, sizeof(attr_coord), "%s.tex_coord", prev_names[i]); video_size[0] = chain->prev.last_width[ (chain->prev.ptr - (i + 1)) & TEXTURESMASK]; video_size[1] = chain->prev.last_height[ (chain->prev.ptr - (i + 1)) & TEXTURESMASK]; d3d9_cg_set_param_2f(pass->vprg, dev, attr_input_size, &video_size); d3d9_cg_set_param_2f(pass->fprg, dev, attr_input_size, &video_size); d3d9_cg_set_param_2f(pass->vprg, dev, attr_tex_size, &texture_size); d3d9_cg_set_param_2f(pass->fprg, dev, attr_tex_size, &texture_size); param = d3d9_cg_get_constant_by_name(pass->fprg, attr_texture); if (param) { unsigned index = cgGetParameterResourceIndex(param); LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9) chain->prev.tex[ (chain->prev.ptr - (i + 1)) & TEXTURESMASK]; d3d9_set_texture(chain->dev, index, tex); unsigned_vector_list_append(chain->bound_tex, index); d3d9_set_sampler_magfilter(chain->dev, index, d3d_translate_filter(chain->passes->data[0].info.pass->filter)); d3d9_set_sampler_minfilter(chain->dev, index, d3d_translate_filter(chain->passes->data[0].info.pass->filter)); d3d9_set_sampler_address_u(chain->dev, index, D3DTADDRESS_BORDER); d3d9_set_sampler_address_v(chain->dev, index, D3DTADDRESS_BORDER); } param = d3d9_cg_get_constant_by_name(pass->vprg, attr_coord); if (param) { LPDIRECT3DVERTEXBUFFER9 vert_buf = (LPDIRECT3DVERTEXBUFFER9) chain->prev.vertex_buf[ (chain->prev.ptr - (i + 1)) & TEXTURESMASK]; struct unsigned_vector_list *attrib_map = (struct unsigned_vector_list*)pass->attrib_map; unsigned index = attrib_map->data[cgGetParameterResourceIndex(param)]; d3d9_set_stream_source(chain->dev, index, vert_buf, 0, sizeof(struct D3D9Vertex)); unsigned_vector_list_append(chain->bound_vert, index); } } }