mirror of
https://github.com/libretro/RetroArch.git
synced 2025-02-25 20:32:22 +00:00
(D3D) Move more functions out of D3DVideo class
This commit is contained in:
parent
e48b7e7d8a
commit
eae35b9a50
@ -52,8 +52,9 @@ static BOOL CALLBACK monitor_enum_proc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT
|
||||
}
|
||||
|
||||
// Multi-monitor support.
|
||||
RECT D3DVideo::monitor_rect(void)
|
||||
RECT d3d_monitor_rect(void *data)
|
||||
{
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
||||
Monitor::num_mons = 0;
|
||||
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, 0);
|
||||
|
||||
@ -94,7 +95,7 @@ static void d3d_deinitialize(void *data)
|
||||
d3d->deinit_font();
|
||||
d3d->deinit_chain();
|
||||
#ifdef HAVE_CG
|
||||
d3d->deinit_cg();
|
||||
d3d_deinit_shader(d3d);
|
||||
#endif
|
||||
|
||||
d3d->needs_restore = false;
|
||||
@ -274,7 +275,7 @@ static bool d3d_initialize(void *data, const video_info_t *info)
|
||||
d3d_calculate_rect(d3d, d3d->screen_width, d3d->screen_height, info->force_aspect, g_extern.system.aspect_ratio);
|
||||
|
||||
#ifdef HAVE_CG
|
||||
if (!d3d->init_cg())
|
||||
if (!d3d_init_shader(d3d))
|
||||
{
|
||||
RARCH_ERR("Failed to initialize Cg.\n");
|
||||
return false;
|
||||
@ -460,7 +461,7 @@ static void d3d_set_viewport(void *data, int x, int y, unsigned width, unsigned
|
||||
|
||||
d3d->final_viewport = viewport;
|
||||
|
||||
d3d->set_font_rect(NULL);
|
||||
d3d_set_font_rect(d3d, NULL);
|
||||
}
|
||||
|
||||
static void d3d_calculate_rect(void *data, unsigned width, unsigned height,
|
||||
@ -527,7 +528,7 @@ static bool d3d_frame(void *data, const void *frame,
|
||||
{
|
||||
d3d_calculate_rect(d3d, d3d->screen_width, d3d->screen_height, d3d->video_info.force_aspect, g_extern.system.aspect_ratio);
|
||||
d3d->chain->set_final_viewport(d3d->final_viewport);
|
||||
d3d->recompute_pass_sizes();
|
||||
d3d_recompute_pass_sizes(d3d);
|
||||
|
||||
d3d->should_resize = false;
|
||||
}
|
||||
@ -585,7 +586,7 @@ static bool d3d_frame(void *data, const void *frame,
|
||||
return true;
|
||||
}
|
||||
|
||||
d3d->update_title();
|
||||
d3d_update_title(d3d);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -760,7 +761,7 @@ static bool d3d_set_shader(void *data, enum rarch_shader_type type, const char *
|
||||
bool restore_old = false;
|
||||
d3d->cg_shader = path;
|
||||
|
||||
if (!d3d->process_shader() || !d3d_restore(d3d))
|
||||
if (!d3d_process_shader(d3d) || !d3d_restore(d3d))
|
||||
{
|
||||
RARCH_ERR("[D3D9]: Setting shader failed.\n");
|
||||
restore_old = true;
|
||||
@ -769,7 +770,7 @@ static bool d3d_set_shader(void *data, enum rarch_shader_type type, const char *
|
||||
if (restore_old)
|
||||
{
|
||||
d3d->cg_shader = old_shader;
|
||||
d3d->process_shader();
|
||||
d3d_process_shader(d3d);
|
||||
d3d_restore(d3d);
|
||||
}
|
||||
|
||||
@ -950,7 +951,7 @@ static void d3d_render_msg(void *data, const char *msg, void *userdata)
|
||||
}
|
||||
|
||||
if (params)
|
||||
d3d->set_font_rect(NULL);
|
||||
d3d_set_font_rect(d3d, NULL);
|
||||
}
|
||||
|
||||
static void d3d_set_osd_msg(void *data, const char *msg, void *userdata)
|
||||
@ -959,7 +960,7 @@ static void d3d_set_osd_msg(void *data, const char *msg, void *userdata)
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
||||
|
||||
if (params)
|
||||
d3d->set_font_rect(params);
|
||||
d3d_set_font_rect(d3d, params);
|
||||
|
||||
d3d_render_msg(d3d, msg, params);
|
||||
}
|
||||
@ -1110,7 +1111,7 @@ bool d3d_construct(void *data, const video_info_t *info, const input_driver_t **
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MONITOR
|
||||
RECT mon_rect = d3d->monitor_rect();
|
||||
RECT mon_rect = d3d_monitor_rect(d3d);
|
||||
#endif
|
||||
|
||||
bool windowed_full = g_settings.video.windowed_fullscreen;
|
||||
@ -1177,7 +1178,7 @@ bool d3d_construct(void *data, const video_info_t *info, const input_driver_t **
|
||||
d3d->cg_shader = g_settings.video.shader_path;
|
||||
#endif
|
||||
|
||||
if (!d3d->process_shader())
|
||||
if (!d3d_process_shader(d3d))
|
||||
return false;
|
||||
|
||||
d3d->video_info = *info;
|
||||
|
@ -53,14 +53,17 @@ typedef struct
|
||||
LPDIRECT3DVERTEXBUFFER vert_buf;
|
||||
} overlay_t;
|
||||
|
||||
void d3d_set_font_rect(void *data, font_params_t *params);
|
||||
bool d3d_process_shader(void *data);
|
||||
void d3d_update_title(void *data);
|
||||
void d3d_recompute_pass_sizes(void *data);
|
||||
RECT d3d_monitor_rect(void *data);
|
||||
bool d3d_init_shader(void *data);
|
||||
void d3d_deinit_shader(void *data);
|
||||
|
||||
class D3DVideo
|
||||
{
|
||||
public:
|
||||
bool process_shader(void);
|
||||
|
||||
void set_filtering(unsigned index, bool smooth);
|
||||
void set_font_rect(font_params_t *params);
|
||||
|
||||
bool should_resize;
|
||||
|
||||
WNDCLASSEX windowClass;
|
||||
@ -69,7 +72,6 @@ public:
|
||||
LPDIRECT3DDEVICE dev;
|
||||
LPD3DXFONT font;
|
||||
|
||||
void recompute_pass_sizes();
|
||||
unsigned screen_width;
|
||||
unsigned screen_height;
|
||||
unsigned dev_rotation;
|
||||
@ -79,16 +81,12 @@ public:
|
||||
|
||||
struct gfx_shader shader;
|
||||
|
||||
RECT monitor_rect(void);
|
||||
|
||||
video_info_t video_info;
|
||||
|
||||
bool needs_restore;
|
||||
|
||||
#ifdef HAVE_CG
|
||||
CGcontext cgCtx;
|
||||
bool init_cg();
|
||||
void deinit_cg();
|
||||
#endif
|
||||
|
||||
bool init_imports(void);
|
||||
@ -104,8 +102,6 @@ public:
|
||||
RECT font_rect_shifted;
|
||||
uint32_t font_color;
|
||||
|
||||
void update_title(void);
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
bool overlays_enabled;
|
||||
std::vector<overlay_t> overlays;
|
||||
|
@ -34,8 +34,36 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void D3DVideo::set_font_rect(font_params_t *params)
|
||||
bool d3d_process_shader(void *data)
|
||||
{
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
||||
if (strcmp(path_get_extension(d3d->cg_shader.c_str()), "cgp") == 0)
|
||||
return d3d->init_multipass();
|
||||
|
||||
return d3d->init_singlepass();
|
||||
}
|
||||
|
||||
void d3d_update_title(void *data)
|
||||
{
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
||||
char buffer[128], buffer_fps[128];
|
||||
bool fps_draw = g_settings.fps_show;
|
||||
if (gfx_get_fps(buffer, sizeof(buffer), fps_draw ? buffer_fps : NULL, sizeof(buffer_fps)))
|
||||
{
|
||||
std::string title = buffer;
|
||||
title += " || Direct3D9";
|
||||
SetWindowText(d3d->hWnd, title.c_str());
|
||||
}
|
||||
|
||||
if (fps_draw)
|
||||
msg_queue_push(g_extern.msg_queue, buffer_fps, 1, 1);
|
||||
|
||||
g_extern.frame_count++;
|
||||
}
|
||||
|
||||
void d3d_set_font_rect(void *data, font_params_t *params)
|
||||
{
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
||||
float pos_x = g_settings.video.msg_pos_x;
|
||||
float pos_y = g_settings.video.msg_pos_y;
|
||||
float font_size = g_settings.video.font_size;
|
||||
@ -47,43 +75,85 @@ void D3DVideo::set_font_rect(font_params_t *params)
|
||||
font_size *= params->scale;
|
||||
}
|
||||
|
||||
font_rect.left = final_viewport.X + final_viewport.Width * pos_x;
|
||||
font_rect.right = final_viewport.X + final_viewport.Width;
|
||||
font_rect.top = final_viewport.Y + (1.0f - pos_y) * final_viewport.Height - font_size;
|
||||
font_rect.bottom = final_viewport.Height;
|
||||
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;
|
||||
|
||||
font_rect_shifted = font_rect;
|
||||
font_rect_shifted.left -= 2;
|
||||
font_rect_shifted.right -= 2;
|
||||
font_rect_shifted.top += 2;
|
||||
font_rect_shifted.bottom += 2;
|
||||
d3d->font_rect_shifted = d3d->font_rect;
|
||||
d3d->font_rect_shifted.left -= 2;
|
||||
d3d->font_rect_shifted.right -= 2;
|
||||
d3d->font_rect_shifted.top += 2;
|
||||
d3d->font_rect_shifted.bottom += 2;
|
||||
}
|
||||
|
||||
void d3d_recompute_pass_sizes(void *data)
|
||||
{
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
||||
LinkInfo link_info = {0};
|
||||
link_info.pass = &d3d->shader.pass[0];
|
||||
link_info.tex_w = link_info.tex_h = d3d->video_info.input_scale * RARCH_SCALE_BASE;
|
||||
|
||||
unsigned current_width = link_info.tex_w;
|
||||
unsigned current_height = link_info.tex_h;
|
||||
unsigned out_width = 0;
|
||||
unsigned out_height = 0;
|
||||
|
||||
if (!d3d->chain->set_pass_size(0, current_width, current_height))
|
||||
{
|
||||
RARCH_ERR("[D3D]: Failed to set pass size.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (unsigned i = 1; i < d3d->shader.passes; i++)
|
||||
{
|
||||
RenderChain::convert_geometry(link_info,
|
||||
out_width, out_height,
|
||||
current_width, current_height, d3d->final_viewport);
|
||||
|
||||
link_info.tex_w = next_pow2(out_width);
|
||||
link_info.tex_h = next_pow2(out_height);
|
||||
|
||||
if (!d3d->chain->set_pass_size(i, link_info.tex_w, link_info.tex_h))
|
||||
{
|
||||
RARCH_ERR("[D3D]: Failed to set pass size.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
current_width = out_width;
|
||||
current_height = out_height;
|
||||
|
||||
link_info.pass = &d3d->shader.pass[i];
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_CG
|
||||
bool D3DVideo::init_cg(void)
|
||||
bool d3d_init_shader(void *data)
|
||||
{
|
||||
cgCtx = cgCreateContext();
|
||||
if (cgCtx == NULL)
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
||||
d3d->cgCtx = cgCreateContext();
|
||||
if (d3d->cgCtx == NULL)
|
||||
return false;
|
||||
|
||||
RARCH_LOG("[D3D9 Cg]: Created context.\n");
|
||||
|
||||
HRESULT ret = cgD3D9SetDevice(dev);
|
||||
HRESULT ret = cgD3D9SetDevice(d3d->dev);
|
||||
if (FAILED(ret))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void D3DVideo::deinit_cg(void)
|
||||
void d3d_deinit_shader(void *data)
|
||||
{
|
||||
if (!cgCtx)
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
||||
if (!d3d->cgCtx)
|
||||
return;
|
||||
|
||||
cgD3D9UnloadAllPrograms();
|
||||
cgD3D9SetDevice(NULL);
|
||||
cgDestroyContext(cgCtx);
|
||||
cgCtx = NULL;
|
||||
cgDestroyContext(d3d->cgCtx);
|
||||
d3d->cgCtx = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -200,53 +270,6 @@ bool D3DVideo::init_multipass(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool D3DVideo::process_shader(void)
|
||||
{
|
||||
if (strcmp(path_get_extension(cg_shader.c_str()), "cgp") == 0)
|
||||
return init_multipass();
|
||||
|
||||
return init_singlepass();
|
||||
}
|
||||
|
||||
void D3DVideo::recompute_pass_sizes(void)
|
||||
{
|
||||
LinkInfo link_info = {0};
|
||||
link_info.pass = &shader.pass[0];
|
||||
link_info.tex_w = link_info.tex_h = video_info.input_scale * RARCH_SCALE_BASE;
|
||||
|
||||
unsigned current_width = link_info.tex_w;
|
||||
unsigned current_height = link_info.tex_h;
|
||||
unsigned out_width = 0;
|
||||
unsigned out_height = 0;
|
||||
|
||||
if (!chain->set_pass_size(0, current_width, current_height))
|
||||
{
|
||||
RARCH_ERR("[D3D]: Failed to set pass size.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (unsigned i = 1; i < shader.passes; i++)
|
||||
{
|
||||
RenderChain::convert_geometry(link_info,
|
||||
out_width, out_height,
|
||||
current_width, current_height, final_viewport);
|
||||
|
||||
link_info.tex_w = next_pow2(out_width);
|
||||
link_info.tex_h = next_pow2(out_height);
|
||||
|
||||
if (!chain->set_pass_size(i, link_info.tex_w, link_info.tex_h))
|
||||
{
|
||||
RARCH_ERR("[D3D]: Failed to set pass size.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
current_width = out_width;
|
||||
current_height = out_height;
|
||||
|
||||
link_info.pass = &shader.pass[i];
|
||||
}
|
||||
}
|
||||
|
||||
bool D3DVideo::init_chain(const video_info_t *video_info)
|
||||
{
|
||||
// Setup information for first pass.
|
||||
@ -338,21 +361,4 @@ void D3DVideo::deinit_font(void)
|
||||
if (font)
|
||||
font->Release();
|
||||
font = NULL;
|
||||
}
|
||||
|
||||
void D3DVideo::update_title(void)
|
||||
{
|
||||
char buffer[128], buffer_fps[128];
|
||||
bool fps_draw = g_settings.fps_show;
|
||||
if (gfx_get_fps(buffer, sizeof(buffer), fps_draw ? buffer_fps : NULL, sizeof(buffer_fps)))
|
||||
{
|
||||
std::string title = buffer;
|
||||
title += " || Direct3D9";
|
||||
SetWindowText(hWnd, title.c_str());
|
||||
}
|
||||
|
||||
if (fps_draw)
|
||||
msg_queue_push(g_extern.msg_queue, buffer_fps, 1, 1);
|
||||
|
||||
g_extern.frame_count++;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user