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 void menu_display_d3d9_draw(menu_display_ctx_draw_t *draw, video_frame_info_t *video_info) { unsigned i; video_shader_ctx_mvp_t mvp; math_matrix_4x4 mop, m1, m2; unsigned width, height; LPDIRECT3DDEVICE9 dev; d3d9_video_t *d3d = video_info ? (d3d9_video_t*)video_info->userdata : NULL; Vertex * pv = NULL; const float *vertex = NULL; const float *tex_coord = NULL; const float *color = NULL; if (!d3d || !draw || draw->pipeline.id) return; dev = d3d->dev; if((d3d->menu_display.offset + draw->coords->vertices ) > (unsigned)d3d->menu_display.size) return; pv = (Vertex*) d3d9_vertex_buffer_lock((LPDIRECT3DVERTEXBUFFER9)d3d->menu_display.buffer); if (!pv) return; pv += d3d->menu_display.offset; vertex = draw->coords->vertex; tex_coord = draw->coords->tex_coord; color = draw->coords->color; if (!vertex) vertex = menu_display_d3d9_get_default_vertices(); if (!tex_coord) tex_coord = menu_display_d3d9_get_default_tex_coords(); for (i = 0; i < draw->coords->vertices; i++) { int colors[4]; colors[0] = *color++ * 0xFF; colors[1] = *color++ * 0xFF; colors[2] = *color++ * 0xFF; colors[3] = *color++ * 0xFF; pv[i].x = *vertex++; pv[i].y = *vertex++; pv[i].z = 0.5f; pv[i].u = *tex_coord++; pv[i].v = *tex_coord++; pv[i].color = D3DCOLOR_ARGB( colors[3], /* A */ colors[0], /* R */ colors[1], /* G */ colors[2] /* B */ ); } d3d9_vertex_buffer_unlock((LPDIRECT3DVERTEXBUFFER9)d3d->menu_display.buffer); if(!draw->matrix_data) draw->matrix_data = menu_display_d3d9_get_default_mvp(video_info); /* ugh */ video_driver_get_size(&width, &height); matrix_4x4_scale(m1, 2.0, 2.0, 0); matrix_4x4_translate(mop, -1.0, -1.0, 0); matrix_4x4_multiply(m2, mop, m1); matrix_4x4_multiply(m1, *((math_matrix_4x4*)draw->matrix_data), m2); matrix_4x4_scale(mop, (draw->width / 2.0) / width, (draw->height / 2.0) / height, 0); matrix_4x4_multiply(m2, mop, m1); matrix_4x4_translate(mop, (draw->x + (draw->width / 2.0)) / width, (draw->y + (draw->height / 2.0)) / height, 0); matrix_4x4_multiply(m1, mop, m2); matrix_4x4_multiply(m2, d3d->mvp_transposed, m1); d3d_matrix_transpose(&m1, &m2); mvp.data = d3d; mvp.matrix = &m1; video_driver_set_mvp(&mvp); if (draw && draw->texture) menu_display_d3d9_bind_texture(draw, d3d); d3d9_draw_primitive(dev, (D3DPRIMITIVETYPE)menu_display_prim_to_d3d9_enum(draw->prim_type), d3d->menu_display.offset, draw->coords->vertices - ((draw->prim_type == MENU_DISPLAY_PRIM_TRIANGLESTRIP) ? 2 : 0)); d3d->menu_display.offset += draw->coords->vertices; }