mirror of
https://github.com/libretro/RetroArch
synced 2025-03-05 19:13:45 +00:00
(D3D) Create graphics context driver for D3D and move
state code over to it
This commit is contained in:
parent
8b8ebe0a06
commit
ab9d4440db
@ -548,14 +548,12 @@ static bool d3d_frame(void *data, const void *frame,
|
||||
|
||||
RARCH_PERFORMANCE_STOP(d3d_frame);
|
||||
|
||||
if (d3d->dev->Present(NULL, NULL, NULL, NULL) != D3D_OK)
|
||||
{
|
||||
d3d->needs_restore = true;
|
||||
RARCH_ERR("[D3D]: Present() failed.\n");
|
||||
return true;
|
||||
}
|
||||
if (d3d && d3d->ctx_driver && d3d->ctx_driver->update_window_title)
|
||||
d3d->ctx_driver->update_window_title();
|
||||
|
||||
if (d3d && d3d->ctx_driver && d3d->ctx_driver->swap_buffers)
|
||||
d3d->ctx_driver->swap_buffers();
|
||||
|
||||
d3d_update_title(d3d);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -569,18 +567,26 @@ static void d3d_set_nonblock_state(void *data, bool state)
|
||||
static bool d3d_alive(void *data)
|
||||
{
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
||||
bool ret = d3d_alive_func(d3d);
|
||||
return !d3d_quit && ret;
|
||||
bool quit = false, resize = false;
|
||||
|
||||
if (d3d->ctx_driver && d3d->ctx_driver->check_window)
|
||||
d3d->ctx_driver->check_window(&quit, &resize, &d3d->screen_width,
|
||||
&d3d->screen_height, g_extern.frame_count);
|
||||
|
||||
if (quit)
|
||||
d3d_quit = true;
|
||||
else if (resize)
|
||||
d3d->should_resize = true;
|
||||
|
||||
return !d3d_quit;
|
||||
}
|
||||
|
||||
static bool d3d_focus(void *data)
|
||||
{
|
||||
#ifdef _XBOX
|
||||
return true;
|
||||
#else
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
||||
return GetFocus() == d3d->hWnd;
|
||||
#endif
|
||||
if (d3d && d3d->ctx_driver && d3d->ctx_driver->has_focus)
|
||||
return d3d->ctx_driver->has_focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
static void d3d_set_rotation(void *data, unsigned rot)
|
||||
@ -811,15 +817,15 @@ static bool d3d_overlay_load(void *data, const texture_image *images, unsigned n
|
||||
return true;
|
||||
}
|
||||
|
||||
static void d3d_show_mouse(void *data, bool state);
|
||||
|
||||
static void d3d_overlay_enable(void *data, bool state)
|
||||
{
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
||||
|
||||
for (unsigned i = 0; i < d3d->overlays.size(); i++)
|
||||
d3d->overlays_enabled = state;
|
||||
d3d_show_mouse(d3d, state);
|
||||
|
||||
if (d3d && d3d->ctx_driver && d3d->ctx_driver->show_mouse)
|
||||
d3d->ctx_driver->show_mouse(state);
|
||||
}
|
||||
|
||||
static void d3d_overlay_full_screen(void *data, bool enable)
|
||||
@ -909,7 +915,9 @@ static void d3d_set_osd_msg(void *data, const char *msg, void *userdata)
|
||||
static void d3d_show_mouse(void *data, bool state)
|
||||
{
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
||||
d3d_show_cursor(d3d, state);
|
||||
|
||||
if (d3d && d3d->ctx_driver && d3d->ctx_driver->show_mouse)
|
||||
d3d->ctx_driver->show_mouse(state);
|
||||
}
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
@ -1092,7 +1100,8 @@ bool d3d_construct(void *data, const video_info_t *info, const input_driver_t **
|
||||
driver.video_window = (uintptr_t)d3d->hWnd;
|
||||
|
||||
#ifdef HAVE_WINDOW
|
||||
d3d_show_mouse(d3d, !info->fullscreen
|
||||
if (d3d && d3d->ctx_driver && d3d->ctx_driver->show_mouse)
|
||||
d3d->ctx_driver->show_mouse(!info->fullscreen
|
||||
#ifdef HAVE_OVERLAY
|
||||
|| d3d->overlays_enabled
|
||||
#endif
|
||||
@ -1134,6 +1143,15 @@ bool d3d_construct(void *data, const video_info_t *info, const input_driver_t **
|
||||
return true;
|
||||
}
|
||||
|
||||
static const gfx_ctx_driver_t *d3d_get_context(void)
|
||||
{
|
||||
// TODO: GL core contexts through ANGLE?
|
||||
enum gfx_ctx_api api = GFX_CTX_DIRECT3D9_API;
|
||||
unsigned major = 0;
|
||||
unsigned minor = 0;
|
||||
return gfx_ctx_init_first(api, major, minor);
|
||||
}
|
||||
|
||||
static void *d3d_init(const video_info_t *info, const input_driver_t **input,
|
||||
void **input_data)
|
||||
{
|
||||
@ -1141,6 +1159,13 @@ static void *d3d_init(const video_info_t *info, const input_driver_t **input,
|
||||
if (!vid)
|
||||
return NULL;
|
||||
|
||||
vid->ctx_driver = d3d_get_context();
|
||||
if (!vid->ctx_driver)
|
||||
{
|
||||
free(vid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//default values
|
||||
vid->g_pD3D = NULL;
|
||||
vid->dev = NULL;
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "../../driver.h"
|
||||
#include "../shader_parse.h"
|
||||
|
||||
#include "../gfx_context.h"
|
||||
#include "../gfx_common.h"
|
||||
|
||||
#ifdef HAVE_CG
|
||||
@ -89,6 +90,7 @@ bool d3d_alive_func(void *data);
|
||||
|
||||
struct D3DVideo
|
||||
{
|
||||
const gfx_ctx_driver_t *ctx_driver;
|
||||
bool should_resize;
|
||||
|
||||
#ifdef HAVE_WINDOW
|
||||
|
@ -38,9 +38,19 @@ bool d3d_process_shader(void *data)
|
||||
return d3d_init_singlepass(d3d);
|
||||
}
|
||||
|
||||
void d3d_update_title(void *data)
|
||||
static void gfx_ctx_d3d_swap_buffers(void)
|
||||
{
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(driver.video_data);
|
||||
if (d3d->dev->Present(NULL, NULL, NULL, NULL) != D3D_OK)
|
||||
{
|
||||
d3d->needs_restore = true;
|
||||
RARCH_ERR("[D3D]: Present() failed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void gfx_ctx_d3d_update_title(void)
|
||||
{
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(driver.video_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)))
|
||||
@ -374,7 +384,7 @@ void d3d_deinit_font(void *data)
|
||||
d3d->font = NULL;
|
||||
}
|
||||
|
||||
void d3d_show_cursor(void *data, bool state)
|
||||
static void gfx_ctx_d3d_show_mouse(bool state)
|
||||
{
|
||||
#ifdef HAVE_WINDOW
|
||||
if (state)
|
||||
@ -442,9 +452,12 @@ void d3d_make_d3dpp(void *data, const video_info_t *info, D3DPRESENT_PARAMETERS
|
||||
}
|
||||
}
|
||||
|
||||
bool d3d_alive_func(void *data)
|
||||
static void gfx_ctx_d3d_check_window(bool *quit,
|
||||
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
|
||||
{
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(driver.video_data);
|
||||
*quit = false;
|
||||
*resize = false;
|
||||
#ifndef _XBOX
|
||||
MSG msg;
|
||||
|
||||
@ -454,5 +467,50 @@ bool d3d_alive_func(void *data)
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool gfx_ctx_d3d_has_focus(void)
|
||||
{
|
||||
#ifdef _XBOX
|
||||
return true;
|
||||
#else
|
||||
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(driver.video_data);
|
||||
return GetFocus() == d3d->hWnd;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool gfx_ctx_d3d_bind_api(enum gfx_ctx_api api, unsigned major, unsigned minor)
|
||||
{
|
||||
(void)major;
|
||||
(void)minor;
|
||||
(void)api;
|
||||
#if defined(_XBOX1)
|
||||
return api == GFX_CTX_DIRECT3D8_API;
|
||||
#else
|
||||
return api == GFX_CTX_DIRECT3D9_API;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool gfx_ctx_d3d_init(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
const gfx_ctx_driver_t gfx_ctx_d3d9 = {
|
||||
gfx_ctx_d3d_init, // gfx_ctx_init
|
||||
NULL, // gfx_ctx_destroy
|
||||
gfx_ctx_d3d_bind_api, // gfx_ctx_bind_api
|
||||
NULL, // gfx_ctx_swap_interval
|
||||
NULL, // gfx_ctx_set_video_mode
|
||||
NULL, // gfx_ctx_get_video_size
|
||||
NULL,
|
||||
gfx_ctx_d3d_update_title, // gfx_ctx_update_window_title
|
||||
gfx_ctx_d3d_check_window, // gfx_ctx_check_window
|
||||
NULL, // gfx_ctx_set_resize
|
||||
gfx_ctx_d3d_has_focus, // gfx_ctx_has_focus
|
||||
gfx_ctx_d3d_swap_buffers, // gfx_ctx_swap_buffers
|
||||
NULL, // gfx_ctx_input_driver
|
||||
NULL, // gfx_ctx_get_proc_address
|
||||
gfx_ctx_d3d_show_mouse, // gfx_ctx_show_mouse
|
||||
"d3d9",
|
||||
};
|
||||
|
@ -29,6 +29,9 @@ static const gfx_ctx_driver_t *gfx_ctx_drivers[] = {
|
||||
#if defined(_XBOX)
|
||||
&gfx_ctx_xdk,
|
||||
#endif
|
||||
#if defined(HAVE_WIN32_D3D9)
|
||||
&gfx_ctx_d3d9,
|
||||
#endif
|
||||
#if defined(HAVE_VIDEOCORE)
|
||||
&gfx_ctx_videocore,
|
||||
#endif
|
||||
|
@ -100,6 +100,7 @@ typedef struct gfx_ctx_driver
|
||||
extern const gfx_ctx_driver_t gfx_ctx_sdl_gl;
|
||||
extern const gfx_ctx_driver_t gfx_ctx_x_egl;
|
||||
extern const gfx_ctx_driver_t gfx_ctx_glx;
|
||||
extern const gfx_ctx_driver_t gfx_ctx_d3d9;
|
||||
extern const gfx_ctx_driver_t gfx_ctx_drm_egl;
|
||||
extern const gfx_ctx_driver_t gfx_ctx_android;
|
||||
extern const gfx_ctx_driver_t gfx_ctx_ps3;
|
||||
|
Loading…
x
Reference in New Issue
Block a user