static void d3d9_cg_renderchain_calc_and_set_shader_mvp( void *data, /* stock vertex program */ unsigned vp_width, unsigned vp_height, unsigned rotation) { struct d3d_matrix proj, ortho, rot, matrix; d3d_matrix_ortho_off_center_lh(&ortho, 0, vp_width, 0, vp_height, 0, 1); d3d_matrix_identity(&rot); d3d_matrix_rotation_z(&rot, rotation * (D3D_PI / 2.0)); d3d_matrix_multiply(&proj, &ortho, &rot); d3d_matrix_transpose(&matrix, &proj); d3d9_cg_set_param_matrix(data, NULL, "modelViewProj", (const void*)&matrix); }
static void menu_display_d3d_draw(void *data, video_frame_info_t *video_info) { unsigned i; video_shader_ctx_mvp_t mvp; math_matrix_4x4 mop, m1, m2; unsigned width, height; d3d_video_t *d3d = video_info ? (d3d_video_t*)video_info->userdata : NULL; menu_display_ctx_draw_t *draw = (menu_display_ctx_draw_t*)data; Vertex * pv = NULL; const float *vertex = NULL; const float *tex_coord = NULL; const float *color = NULL; if (!d3d || !draw || draw->pipeline.id) return; if((d3d->menu_display.offset + draw->coords->vertices ) > (unsigned)d3d->menu_display.size) return; pv = (Vertex*) d3d_vertex_buffer_lock(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_d3d_get_default_vertices(); if (!tex_coord) tex_coord = menu_display_d3d_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++; #ifdef HAVE_D3D8 if ((void*)draw->texture) { D3DSURFACE_DESC desc; if (d3d_texture_get_level_desc((void*)draw->texture, 0, &desc)) { pv[i].u *= desc.Width; pv[i].v *= desc.Height; } } #endif pv[i].color = D3DCOLOR_ARGB( colors[3], /* A */ colors[0], /* R */ colors[1], /* G */ colors[2] /* B */ ); } d3d_vertex_buffer_unlock(d3d->menu_display.buffer); if(!draw->matrix_data) draw->matrix_data = menu_display_d3d_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); menu_display_d3d_bind_texture(draw, (d3d_video_t*)video_info->userdata); d3d_draw_primitive(d3d->dev, menu_display_prim_to_d3d_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; }
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; }