mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 03:32:46 +00:00
Merge pull request #6097 from aliaspider/master
(Direct3D) Menu display driver implementation.
This commit is contained in:
commit
332ccbf300
@ -764,7 +764,7 @@ bool d3d_device_create_offscreen_plain_surface(
|
||||
#ifndef _XBOX360
|
||||
/* XBox 360 has no fixed-function pipeline. */
|
||||
static void d3d_set_texture_stage_state(LPDIRECT3DDEVICE dev,
|
||||
unsigned sampler, unsigned value, unsigned type)
|
||||
unsigned sampler, unsigned type, unsigned value)
|
||||
{
|
||||
#if defined(HAVE_D3D9) && !defined(__cplusplus)
|
||||
if (IDirect3DDevice9_SetTextureStageState(dev, sampler, (D3DTEXTURESTAGESTATETYPE)type, value) != D3D_OK)
|
||||
@ -847,6 +847,14 @@ void d3d_set_sampler_magfilter(LPDIRECT3DDEVICE dev,
|
||||
#endif
|
||||
}
|
||||
|
||||
void d3d_set_sampler_mipfilter(LPDIRECT3DDEVICE dev,
|
||||
unsigned sampler, unsigned value)
|
||||
{
|
||||
#if defined(HAVE_D3D9)
|
||||
IDirect3DDevice9_SetSamplerState(dev, sampler, D3DSAMP_MIPFILTER, value);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool d3d_begin_scene(LPDIRECT3DDEVICE dev)
|
||||
{
|
||||
#if defined(HAVE_D3D9) && !defined(__cplusplus)
|
||||
|
@ -69,6 +69,9 @@ void d3d_set_sampler_minfilter(LPDIRECT3DDEVICE dev,
|
||||
void d3d_set_sampler_magfilter(LPDIRECT3DDEVICE dev,
|
||||
unsigned sampler, unsigned value);
|
||||
|
||||
void d3d_set_sampler_mipfilter(LPDIRECT3DDEVICE dev,
|
||||
unsigned sampler, unsigned value);
|
||||
|
||||
bool d3d_begin_scene(LPDIRECT3DDEVICE dev);
|
||||
|
||||
void d3d_end_scene(LPDIRECT3DDEVICE dev);
|
||||
|
@ -489,6 +489,9 @@ static void d3d_deinitialize(d3d_video_t *d3d)
|
||||
font_driver_free_osd();
|
||||
|
||||
d3d_deinit_chain(d3d);
|
||||
d3d_vertex_buffer_free(d3d->menu_display.buffer, d3d->menu_display.decl);
|
||||
d3d->menu_display.buffer = NULL;
|
||||
d3d->menu_display.decl = NULL;
|
||||
}
|
||||
|
||||
#if defined(HAVE_D3D8)
|
||||
@ -834,6 +837,12 @@ static bool d3d_initialize(d3d_video_t *d3d, const video_info_t *info)
|
||||
|
||||
d3d_make_d3dpp(d3d, info, &d3dpp);
|
||||
|
||||
/* the D3DX font driver uses POOL_DEFAULT resources
|
||||
* and will prevent a clean reset here
|
||||
* another approach would be to keep track of all created D3D
|
||||
* font objects and free/realloc them around the d3d_reset call */
|
||||
|
||||
menu_driver_ctl(RARCH_MENU_CTL_DEINIT, NULL);
|
||||
if (!d3d_reset(d3d->dev, &d3dpp))
|
||||
{
|
||||
d3d_deinitialize(d3d);
|
||||
@ -844,6 +853,7 @@ static bool d3d_initialize(d3d_video_t *d3d, const video_info_t *info)
|
||||
if (ret)
|
||||
RARCH_LOG("[D3D]: Recovered from dead state.\n");
|
||||
}
|
||||
menu_driver_init(info->is_threaded);
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
@ -867,6 +877,28 @@ static bool d3d_initialize(d3d_video_t *d3d, const video_info_t *info)
|
||||
info->is_threaded,
|
||||
FONT_DRIVER_RENDER_DIRECT3D_API);
|
||||
|
||||
static const D3DVERTEXELEMENT VertexElements[] =
|
||||
{
|
||||
{ 0, 0 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
|
||||
{ 0, 2 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
|
||||
{ 0, 4 * sizeof(float), D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
|
||||
D3DDECL_END()
|
||||
};
|
||||
|
||||
if (!d3d_vertex_declaration_new(d3d->dev,
|
||||
(void*)VertexElements, (void**)&d3d->menu_display.decl))
|
||||
return false;
|
||||
|
||||
d3d->menu_display.offset = 0;
|
||||
d3d->menu_display.size = 1024;
|
||||
d3d->menu_display.buffer = d3d_vertex_buffer_new(
|
||||
d3d->dev, d3d->menu_display.size * 10 * sizeof(float),
|
||||
D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT,
|
||||
NULL);
|
||||
|
||||
if (!d3d->menu_display.buffer)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1002,7 +1034,7 @@ static void d3d_set_osd_msg(void *data,
|
||||
if (d3d->renderchain_driver->set_font_rect && params)
|
||||
d3d->renderchain_driver->set_font_rect(d3d, params);
|
||||
|
||||
font_driver_render_msg(video_info, NULL, msg, params);
|
||||
font_driver_render_msg(video_info, font, msg, params);
|
||||
}
|
||||
|
||||
static bool d3d_init_internal(d3d_video_t *d3d,
|
||||
@ -1448,7 +1480,6 @@ static bool d3d_frame(void *data, const void *frame,
|
||||
HWND window = win32_get_window();
|
||||
unsigned width = video_info->width;
|
||||
unsigned height = video_info->height;
|
||||
|
||||
(void)i;
|
||||
|
||||
if (!frame)
|
||||
@ -1506,16 +1537,16 @@ static bool d3d_frame(void *data, const void *frame,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (msg)
|
||||
{
|
||||
struct font_params font_parms = {0};
|
||||
font_driver_render_msg(video_info, NULL, msg, &font_parms);
|
||||
}
|
||||
d3d->renderchain_driver->set_mvp(d3d->renderchain_data, d3d, screen_vp.Width, screen_vp.Height, 0);
|
||||
d3d_set_viewports(d3d->dev, &screen_vp);
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
if (d3d->menu && d3d->menu->enabled)
|
||||
{
|
||||
d3d_overlay_render(d3d, video_info, d3d->menu);
|
||||
d3d->menu_display.offset = 0;
|
||||
d3d_set_vertex_declaration(d3d->dev, d3d->menu_display.decl);
|
||||
d3d_set_stream_source(d3d->dev, 0, d3d->menu_display.buffer, 0, 8 * sizeof(float));
|
||||
menu_driver_frame(video_info);
|
||||
}
|
||||
#endif
|
||||
@ -1528,6 +1559,9 @@ static bool d3d_frame(void *data, const void *frame,
|
||||
}
|
||||
#endif
|
||||
|
||||
if (msg && *msg)
|
||||
font_driver_render_msg(video_info, NULL, msg, NULL);
|
||||
|
||||
video_info->cb_update_window_title(
|
||||
video_info->context_data, video_info);
|
||||
|
||||
@ -1686,10 +1720,39 @@ static void video_texture_load_d3d(d3d_video_t *d3d,
|
||||
enum texture_filter_type filter_type,
|
||||
uintptr_t *id)
|
||||
{
|
||||
*id = (uintptr_t)d3d_texture_new(d3d->dev, NULL,
|
||||
ti->width, ti->height, 1,
|
||||
0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, 0, 0, 0,
|
||||
NULL, NULL);
|
||||
D3DLOCKED_RECT d3dlr;
|
||||
LPDIRECT3DTEXTURE tex = NULL;
|
||||
unsigned usage = 0;
|
||||
|
||||
if((filter_type == TEXTURE_FILTER_MIPMAP_LINEAR) ||
|
||||
(filter_type == TEXTURE_FILTER_MIPMAP_NEAREST))
|
||||
usage |= D3DUSAGE_AUTOGENMIPMAP;
|
||||
|
||||
tex = d3d_texture_new(d3d->dev, NULL,
|
||||
ti->width, ti->height, 0,
|
||||
usage, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, 0, 0, 0,
|
||||
NULL, NULL);
|
||||
|
||||
if (!tex)
|
||||
{
|
||||
RARCH_ERR("[D3D]: Failed to create texture\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (d3d_lock_rectangle(tex, 0, &d3dlr,
|
||||
NULL, 0, D3DLOCK_NOSYSLOCK))
|
||||
{
|
||||
unsigned i;
|
||||
uint32_t *dst = (uint32_t*)(d3dlr.pBits);
|
||||
const uint32_t *src = ti->pixels;
|
||||
unsigned pitch = d3dlr.Pitch >> 2;
|
||||
|
||||
for (i = 0; i < ti->height; i++, dst += pitch, src += ti->width)
|
||||
memcpy(dst, src, ti->width << 2);
|
||||
d3d_unlock_rectangle(tex);
|
||||
}
|
||||
|
||||
*id = (uintptr_t)tex;
|
||||
}
|
||||
|
||||
static int video_texture_load_wrap_d3d_mipmap(void *data)
|
||||
|
@ -93,6 +93,14 @@ typedef struct d3d_video
|
||||
|
||||
char *shader_path;
|
||||
|
||||
struct
|
||||
{
|
||||
int size;
|
||||
int offset;
|
||||
LPDIRECT3DVERTEXBUFFER buffer;
|
||||
LPDIRECT3DVERTEXDECLARATION decl;
|
||||
}menu_display;
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
size_t overlays_size;
|
||||
overlay_t *overlays;
|
||||
|
@ -40,16 +40,26 @@ typedef struct
|
||||
ID3DXFont *font;
|
||||
#endif
|
||||
uint32_t color;
|
||||
uint32_t font_size;
|
||||
} d3dfonts_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#else
|
||||
#endif
|
||||
|
||||
#if !defined(__cplusplus) || defined(CINTERFACE)
|
||||
#define IDirect3DXFont_DrawTextA(p, a, b, c, d, e, f) (p)->lpVtbl->DrawTextA(p, a, b, c, d, e, f)
|
||||
#define IDirect3DXFont_Release(p) (p)->lpVtbl->Release(p)
|
||||
#else
|
||||
#define IDirect3DXFont_DrawTextA(p, a, b, c, d, e, f) (p)->DrawTextA(a, b, c, d, e, f)
|
||||
#define IDirect3DXFont_Release(p) (p)->Release()
|
||||
#endif
|
||||
|
||||
static void *d3dfonts_w32_init_font(void *video_data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
{
|
||||
TEXTMETRICA metrics;
|
||||
settings_t *settings = config_get_ptr();
|
||||
D3DXFONT_DESC desc = {
|
||||
(int)(font_size), 0, 400, 0,
|
||||
@ -74,8 +84,9 @@ static void *d3dfonts_w32_init_font(void *video_data,
|
||||
if (!d3dfonts)
|
||||
return NULL;
|
||||
|
||||
d3dfonts->d3d = (d3d_video_t*)video_data;
|
||||
d3dfonts->color = D3DCOLOR_XRGB(r, g, b);
|
||||
d3dfonts->font_size = font_size;
|
||||
d3dfonts->d3d = (d3d_video_t*)video_data;
|
||||
d3dfonts->color = D3DCOLOR_XRGB(r, g, b);
|
||||
|
||||
if (!d3dx_create_font_indirect(d3dfonts->d3d->dev,
|
||||
&desc, (void**)&d3dfonts->font))
|
||||
@ -95,66 +106,123 @@ static void d3dfonts_w32_free_font(void *data, bool is_threaded)
|
||||
if (!d3dfonts)
|
||||
return;
|
||||
|
||||
#ifdef __cplusplus
|
||||
if (d3dfonts->font)
|
||||
d3dfonts->font->Release();
|
||||
#else
|
||||
if (d3dfonts->font)
|
||||
d3dfonts->font->lpVtbl->Release(d3dfonts->font);
|
||||
#endif
|
||||
d3dfonts->font = NULL;
|
||||
IDirect3DXFont_Release(d3dfonts->font);
|
||||
|
||||
free(d3dfonts);
|
||||
d3dfonts = NULL;
|
||||
}
|
||||
|
||||
|
||||
static int d3dfonts_w32_get_message_width(void* data, const char* msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
RECT box = {0,0,0,0};
|
||||
d3dfonts_t *d3dfonts = (d3dfonts_t*)data;
|
||||
|
||||
if (!d3dfonts || !d3dfonts->d3d | !msg)
|
||||
return 0;
|
||||
|
||||
IDirect3DXFont_DrawTextA(d3dfonts->font, NULL, msg, msg_len? msg_len : -1, &box, DT_CALCRECT, 0);
|
||||
|
||||
return box.right - box.left;
|
||||
}
|
||||
|
||||
|
||||
static void d3dfonts_w32_render_msg(video_frame_info_t *video_info, void *data, const char *msg,
|
||||
const void *userdata)
|
||||
{
|
||||
unsigned color, format;
|
||||
RECT rect, *p_rect;
|
||||
RECT rect_shifted, *p_rect_shifted;
|
||||
settings_t *settings = config_get_ptr();
|
||||
const struct font_params *params = (const struct font_params*)userdata;
|
||||
d3dfonts_t *d3dfonts = (d3dfonts_t*)data;
|
||||
unsigned width = video_info->width;
|
||||
unsigned height = video_info->height;
|
||||
float drop_mod = 0.3f;
|
||||
float drop_alpha = 1.0f;
|
||||
int drop_x = -2;
|
||||
int drop_y = -2;
|
||||
|
||||
if (!d3dfonts || !d3dfonts->d3d)
|
||||
return;
|
||||
if (!msg)
|
||||
return;
|
||||
d3d_set_viewports(d3dfonts->d3d->dev, &d3dfonts->d3d->final_viewport);
|
||||
|
||||
if (!d3d_begin_scene(d3dfonts->d3d->dev))
|
||||
return;
|
||||
|
||||
#ifdef __cplusplus
|
||||
d3dfonts->font->DrawTextA(NULL,
|
||||
msg,
|
||||
-1,
|
||||
&d3dfonts->d3d->font_rect_shifted,
|
||||
DT_LEFT,
|
||||
((d3dfonts->color >> 2) & 0x3f3f3f) | 0xff000000);
|
||||
color = d3dfonts->color;
|
||||
format = DT_LEFT;
|
||||
p_rect = &d3dfonts->d3d->font_rect;
|
||||
p_rect_shifted = &d3dfonts->d3d->font_rect_shifted;
|
||||
|
||||
d3dfonts->font->DrawTextA(NULL,
|
||||
msg,
|
||||
-1,
|
||||
&d3dfonts->d3d->font_rect,
|
||||
DT_LEFT,
|
||||
d3dfonts->color | 0xff000000);
|
||||
#else
|
||||
d3dfonts->font->lpVtbl->DrawTextA(
|
||||
d3dfonts->font,
|
||||
NULL,
|
||||
msg,
|
||||
-1,
|
||||
&d3dfonts->d3d->font_rect_shifted,
|
||||
DT_LEFT,
|
||||
((d3dfonts->color >> 2) & 0x3f3f3f) | 0xff000000);
|
||||
if(params)
|
||||
{
|
||||
unsigned a, r, g, b;
|
||||
|
||||
d3dfonts->font->lpVtbl->DrawTextA(
|
||||
d3dfonts->font,
|
||||
NULL,
|
||||
msg,
|
||||
-1,
|
||||
&d3dfonts->d3d->font_rect,
|
||||
DT_LEFT,
|
||||
d3dfonts->color | 0xff000000);
|
||||
#endif
|
||||
a = FONT_COLOR_GET_ALPHA(params->color);
|
||||
r = FONT_COLOR_GET_RED(params->color);
|
||||
g = FONT_COLOR_GET_GREEN(params->color);
|
||||
b = FONT_COLOR_GET_BLUE(params->color);
|
||||
|
||||
color = D3DCOLOR_ARGB(a, r, g, b);
|
||||
|
||||
switch (params->text_align)
|
||||
{
|
||||
case TEXT_ALIGN_RIGHT:
|
||||
format = DT_RIGHT;
|
||||
rect.left = 0;
|
||||
rect.right = params->x * width;
|
||||
break;
|
||||
case TEXT_ALIGN_CENTER:
|
||||
format = DT_CENTER;
|
||||
rect.left = (params->x - 1.0) * width;
|
||||
rect.right = (params->x + 1.0) * width;
|
||||
break;
|
||||
case TEXT_ALIGN_LEFT:
|
||||
default:
|
||||
format = DT_LEFT;
|
||||
rect.left = params->x * width;
|
||||
rect.right = width;
|
||||
break;
|
||||
}
|
||||
|
||||
rect.top = (1.0 - params->y) * height - d3dfonts->font_size;
|
||||
rect.bottom = height;
|
||||
p_rect = ▭
|
||||
|
||||
drop_x = params->drop_x;
|
||||
drop_y = params->drop_y;
|
||||
|
||||
if(drop_x || drop_y)
|
||||
{
|
||||
drop_mod = params->drop_mod;
|
||||
drop_alpha = params->drop_alpha;
|
||||
rect_shifted = rect;
|
||||
rect_shifted.left += params->drop_x;
|
||||
rect_shifted.right += params->drop_x;
|
||||
rect_shifted.top -= params->drop_y;
|
||||
rect_shifted.bottom -= params->drop_y;
|
||||
p_rect_shifted = &rect_shifted;
|
||||
}
|
||||
}
|
||||
|
||||
if(drop_x || drop_y)
|
||||
{
|
||||
unsigned a, r, g, b;
|
||||
|
||||
a = FONT_COLOR_GET_ALPHA(color) * drop_alpha;
|
||||
r = FONT_COLOR_GET_RED(color) * drop_mod;
|
||||
g = FONT_COLOR_GET_GREEN(color) * drop_mod;
|
||||
b = FONT_COLOR_GET_BLUE(color) * drop_mod;
|
||||
|
||||
IDirect3DXFont_DrawTextA(d3dfonts->font, NULL, msg, -1,
|
||||
p_rect_shifted, format, D3DCOLOR_ARGB(a, r, g, b));
|
||||
}
|
||||
|
||||
IDirect3DXFont_DrawTextA(d3dfonts->font, NULL, msg, -1,
|
||||
p_rect, format, color);
|
||||
|
||||
d3d_end_scene(d3dfonts->d3d->dev);
|
||||
}
|
||||
@ -167,5 +235,5 @@ font_renderer_t d3d_win32_font = {
|
||||
NULL, /* get_glyph */
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush */
|
||||
NULL /* get_message_width */
|
||||
d3dfonts_w32_get_message_width
|
||||
};
|
||||
|
@ -239,15 +239,6 @@ error:
|
||||
return false;
|
||||
}
|
||||
|
||||
static void d3d9_cg_renderchain_set_shader_mvp(cg_renderchain_t *chain, void *shader_data, void *matrix_data)
|
||||
{
|
||||
CGprogram *vPrg = (CGprogram*)shader_data;
|
||||
const D3DMATRIX *matrix = (const D3DMATRIX*)matrix_data;
|
||||
CGparameter cgpModelViewProj = cgGetNamedParameter(*vPrg, "modelViewProj");
|
||||
if (cgpModelViewProj)
|
||||
cgD3D9SetUniformMatrix(cgpModelViewProj, matrix);
|
||||
}
|
||||
|
||||
static void d3d9_cg_renderchain_set_shader_params(
|
||||
cg_renderchain_t *chain,
|
||||
struct Pass *pass,
|
||||
@ -865,7 +856,7 @@ static bool d3d9_cg_renderchain_create_first_pass(
|
||||
chain->prev.last_height[i] = 0;
|
||||
chain->prev.vertex_buf[i] = d3d_vertex_buffer_new(
|
||||
chain->dev, 4 * sizeof(struct CGVertex),
|
||||
0, 0, D3DPOOL_DEFAULT, NULL);
|
||||
D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, NULL);
|
||||
|
||||
if (!chain->prev.vertex_buf[i])
|
||||
return false;
|
||||
@ -1096,7 +1087,7 @@ static bool d3d9_cg_renderchain_add_pass(
|
||||
|
||||
pass.vertex_buf = d3d_vertex_buffer_new(chain->dev,
|
||||
4 * sizeof(struct CGVertex),
|
||||
0, 0, D3DPOOL_DEFAULT, NULL);
|
||||
D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, NULL);
|
||||
|
||||
if (!pass.vertex_buf)
|
||||
return false;
|
||||
@ -1190,24 +1181,34 @@ static void d3d9_cg_renderchain_end_render(cg_renderchain_t *chain)
|
||||
chain->prev.ptr = (chain->prev.ptr + 1) & TEXTURESMASK;
|
||||
}
|
||||
|
||||
static void d3d9_cg_renderchain_set_mvp(
|
||||
void *chain_data,
|
||||
void *data,
|
||||
static void d3d9_cg_renderchain_set_shader_mvp(
|
||||
cg_renderchain_t *chain, CGprogram vPrg,
|
||||
unsigned vp_width, unsigned vp_height,
|
||||
unsigned rotation)
|
||||
{
|
||||
D3DMATRIX proj, ortho, rot, tmp;
|
||||
CGprogram vPrg = (CGprogram)data;
|
||||
cg_renderchain_t *chain = (cg_renderchain_t*)chain_data;
|
||||
D3DMATRIX 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(&tmp, &proj);
|
||||
d3d_matrix_transpose(&matrix, &proj);
|
||||
|
||||
d3d9_cg_renderchain_set_shader_mvp(chain, &vPrg, &tmp);
|
||||
CGparameter cgpModelViewProj = cgGetNamedParameter(vPrg, "modelViewProj");
|
||||
if (cgpModelViewProj)
|
||||
cgD3D9SetUniformMatrix(cgpModelViewProj, &matrix);
|
||||
}
|
||||
|
||||
static void d3d9_cg_renderchain_set_mvp(
|
||||
void *chain_data,
|
||||
void *data,
|
||||
unsigned vp_width, unsigned vp_height,
|
||||
unsigned rotation)
|
||||
{
|
||||
cg_renderchain_t *chain = (cg_renderchain_t*)chain_data;
|
||||
|
||||
d3d9_cg_renderchain_set_shader_mvp(chain, chain->vStock, vp_width, vp_height, rotation);
|
||||
}
|
||||
|
||||
static void cg_d3d9_renderchain_set_vertices(
|
||||
@ -1297,7 +1298,7 @@ static void cg_d3d9_renderchain_set_vertices(
|
||||
|
||||
if (chain)
|
||||
{
|
||||
d3d9_cg_renderchain_set_mvp(
|
||||
d3d9_cg_renderchain_set_shader_mvp(
|
||||
chain, pass->vPrg, vp_width, vp_height, rotation);
|
||||
if (pass)
|
||||
d3d9_cg_renderchain_set_shader_params(chain, pass,
|
||||
@ -1561,7 +1562,7 @@ static bool d3d9_cg_renderchain_render(
|
||||
d3d9_cg_renderchain_end_render(chain);
|
||||
cgD3D9BindProgram(chain->fStock);
|
||||
cgD3D9BindProgram(chain->vStock);
|
||||
d3d9_cg_renderchain_set_mvp(
|
||||
d3d9_cg_renderchain_set_shader_mvp(
|
||||
chain, chain->vStock, chain->final_viewport->Width,
|
||||
chain->final_viewport->Height, 0);
|
||||
}
|
||||
@ -1590,13 +1591,10 @@ static void d3d9_cg_renderchain_set_font_rect(
|
||||
if (!d3d)
|
||||
return;
|
||||
|
||||
d3d->font_rect.left = d3d->final_viewport.X +
|
||||
d3d->final_viewport.Width * pos_x;
|
||||
d3d->font_rect.right = d3d->final_viewport.X +
|
||||
d3d->final_viewport.Width;
|
||||
d3d->font_rect.top = d3d->final_viewport.Y +
|
||||
(1.0f - pos_y) * d3d->final_viewport.Height - font_size;
|
||||
d3d->font_rect.bottom = d3d->final_viewport.Height;
|
||||
d3d->font_rect.left = d3d->video_info.width * pos_x;
|
||||
d3d->font_rect.right = d3d->video_info.width;
|
||||
d3d->font_rect.top = (1.0f - pos_y) * d3d->video_info.height - font_size;
|
||||
d3d->font_rect.bottom = d3d->video_info.height;
|
||||
|
||||
d3d->font_rect_shifted = d3d->font_rect;
|
||||
d3d->font_rect_shifted.left -= 2;
|
||||
|
@ -64,7 +64,7 @@ static void *menu_display_d3d_get_default_mvp(void)
|
||||
if (!d3d)
|
||||
return NULL;
|
||||
d3d_matrix_ortho_off_center_lh(&ortho, 0,
|
||||
d3d->final_viewport.Width, 0, d3d->final_viewport.Height, 0, 1);
|
||||
1, 0, 1, 0, 1);
|
||||
d3d_matrix_transpose(&mvp, &ortho);
|
||||
memcpy(default_mvp.data, (float*)&mvp, sizeof(default_mvp.data));
|
||||
|
||||
@ -109,8 +109,8 @@ static void menu_display_d3d_blend_end(void)
|
||||
|
||||
static void menu_display_d3d_viewport(void *data)
|
||||
{
|
||||
#if 0
|
||||
D3DVIEWPORT vp = {0};
|
||||
d3d_video_t *d3d = (d3d_video_t*)video_driver_get_ptr(false);
|
||||
menu_display_ctx_draw_t *draw = (menu_display_ctx_draw_t*)data;
|
||||
|
||||
if (!d3d || !draw)
|
||||
@ -124,6 +124,7 @@ static void menu_display_d3d_viewport(void *data)
|
||||
vp.MaxZ = 1.0f;
|
||||
|
||||
d3d_set_viewports(d3d->dev, &vp);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void menu_display_d3d_bind_texture(void *data)
|
||||
@ -131,44 +132,64 @@ static void menu_display_d3d_bind_texture(void *data)
|
||||
d3d_video_t *d3d = (d3d_video_t*)video_driver_get_ptr(false);
|
||||
menu_display_ctx_draw_t *draw = (menu_display_ctx_draw_t*)data;
|
||||
|
||||
if (!d3d || !draw)
|
||||
if (!d3d || !draw || !draw->texture)
|
||||
return;
|
||||
|
||||
d3d_set_texture(d3d->dev, 0, (LPDIRECT3DTEXTURE)draw->texture);
|
||||
d3d_set_sampler_address_u(d3d->dev, 0, D3DTADDRESS_BORDER);
|
||||
d3d_set_sampler_address_v(d3d->dev, 0, D3DTADDRESS_BORDER);
|
||||
|
||||
d3d_set_texture(d3d->dev, 0, (void*)draw->texture);
|
||||
d3d_set_sampler_address_u(d3d->dev, 0, D3DTADDRESS_CLAMP);
|
||||
d3d_set_sampler_address_v(d3d->dev, 0, D3DTADDRESS_CLAMP);
|
||||
d3d_set_sampler_minfilter(d3d->dev, 0, D3DTEXF_LINEAR);
|
||||
d3d_set_sampler_magfilter(d3d->dev, 0, D3DTEXF_LINEAR);
|
||||
d3d_set_sampler_mipfilter(d3d->dev, 0, D3DTEXF_LINEAR);
|
||||
|
||||
}
|
||||
|
||||
static void menu_display_d3d_draw(void *data)
|
||||
{
|
||||
video_shader_ctx_mvp_t mvp;
|
||||
d3d_video_t *d3d = (d3d_video_t*)video_driver_get_ptr(false);
|
||||
unsigned i;
|
||||
d3d_video_t *d3d = (d3d_video_t*)video_driver_get_ptr(false);
|
||||
menu_display_ctx_draw_t *draw = (menu_display_ctx_draw_t*)data;
|
||||
float* pv = NULL;
|
||||
const float *vertex = NULL;
|
||||
const float *tex_coord = NULL;
|
||||
const float *color = NULL;
|
||||
|
||||
if (!d3d || !draw)
|
||||
return;
|
||||
|
||||
if (!draw->coords->vertex)
|
||||
if(d3d->menu_display.offset + draw->coords->vertices > d3d->menu_display.size)
|
||||
return;
|
||||
|
||||
if (!draw->coords->vertex)
|
||||
draw->coords->vertex = menu_display_d3d_get_default_vertices();
|
||||
if (!draw->coords->tex_coord)
|
||||
draw->coords->tex_coord = menu_display_d3d_get_default_tex_coords();
|
||||
if (!draw->coords->lut_tex_coord)
|
||||
draw->coords->lut_tex_coord = menu_display_d3d_get_default_tex_coords();
|
||||
|
||||
mvp.data = d3d;
|
||||
mvp.matrix = draw->matrix_data ? (math_matrix_4x4*)draw->matrix_data
|
||||
: (math_matrix_4x4*)menu_display_d3d_get_default_mvp();
|
||||
pv = (float*)d3d_vertex_buffer_lock(d3d->menu_display.buffer);
|
||||
pv += d3d->menu_display.offset * 8;
|
||||
vertex = draw->coords->vertex;
|
||||
tex_coord = draw->coords->tex_coord;
|
||||
color = draw->coords->color;
|
||||
|
||||
video_driver_set_mvp(&mvp);
|
||||
for (i = 0; i < draw->coords->vertices; i++)
|
||||
{
|
||||
*pv++ = (*vertex++ * draw->width) + draw->x;
|
||||
*pv++ = ((1.0 - *vertex++) * draw->height) + draw->y;
|
||||
*pv++ = *tex_coord++;
|
||||
*pv++ = 1.0f - *tex_coord++;
|
||||
*pv++ = *color++;
|
||||
*pv++ = *color++;
|
||||
*pv++ = *color++;
|
||||
*pv++ = *color++;
|
||||
}
|
||||
d3d_vertex_buffer_unlock(d3d->menu_display.buffer);
|
||||
|
||||
menu_display_d3d_viewport(draw);
|
||||
menu_display_d3d_bind_texture(draw);
|
||||
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_draw_primitive(d3d->dev, (D3DPRIMITIVETYPE)
|
||||
menu_display_prim_to_d3d_enum(draw->prim_type),
|
||||
0, draw->coords->vertices);
|
||||
d3d->menu_display.offset += draw->coords->vertices;
|
||||
}
|
||||
|
||||
static void menu_display_d3d_draw_pipeline(void *data)
|
||||
@ -210,10 +231,7 @@ static void menu_display_d3d_draw_pipeline(void *data)
|
||||
|
||||
static void menu_display_d3d_restore_clear_color(void)
|
||||
{
|
||||
d3d_video_t *d3d = (d3d_video_t*)video_driver_get_ptr(false);
|
||||
DWORD clear_color = 0x00000000;
|
||||
|
||||
d3d_clear(d3d->dev, 0, NULL, D3DCLEAR_TARGET, clear_color, 0, 0);
|
||||
/* not needed */
|
||||
}
|
||||
|
||||
static void menu_display_d3d_clear_color(menu_display_ctx_clearcolor_t *clearcolor)
|
||||
|
Loading…
x
Reference in New Issue
Block a user