mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-25 00:49:47 +00:00
(D3D) Start implementing Xbox code in regular D3D driver
This commit is contained in:
parent
c8906bc016
commit
8714939ab7
@ -19,22 +19,24 @@
|
||||
#include "render_chain.hpp"
|
||||
|
||||
#include "../gfx_common.h"
|
||||
|
||||
#ifndef _XBOX
|
||||
#include "../context/win32_common.h"
|
||||
#define HAVE_MONITOR
|
||||
#define HAVE_WINDOW
|
||||
#endif
|
||||
|
||||
#include "../../compat/posix_string.h"
|
||||
#include "../../performance.h"
|
||||
|
||||
#ifndef _XBOX
|
||||
#define HAVE_MONITOR
|
||||
#define HAVE_WINDOW
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MONITOR
|
||||
#define IDI_ICON 1
|
||||
#define MAX_MONITORS 9
|
||||
|
||||
#ifdef HAVE_RMENU_XUI
|
||||
extern bool menu_iterate_xui(void);
|
||||
#endif
|
||||
|
||||
namespace Monitor
|
||||
{
|
||||
static HMONITOR last_hm;
|
||||
@ -211,6 +213,9 @@ static bool d3d_initialize(void *data, const video_info_t *info)
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(_XBOX360)
|
||||
strlcpy(g_settings.video.font_path, "game:\\media\\Arial_12.xpr", sizeof(g_settings.video.font_path));
|
||||
#endif
|
||||
d3d->font_ctx = d3d_font_init_first(d3d, g_settings.video.font_path, g_settings.video.font_size);
|
||||
if (!d3d->font_ctx)
|
||||
{
|
||||
@ -475,7 +480,22 @@ static bool d3d_frame(void *data, const void *frame,
|
||||
}
|
||||
|
||||
if (d3d->font_ctx && d3d->font_ctx->render_msg)
|
||||
d3d->font_ctx->render_msg(d3d, msg, NULL);
|
||||
{
|
||||
font_params_t font_parms = {0};
|
||||
#ifdef _XBOX
|
||||
#if defined(_XBOX1)
|
||||
float msg_width = 60;
|
||||
float msg_height = 365;
|
||||
#elif defined(_XBOX360)
|
||||
float msg_width = (g_extern.lifecycle_state & (1ULL << MODE_MENU_HD)) ? 160 : 100;
|
||||
float msg_height = 120;
|
||||
#endif
|
||||
font_parms.x = msg_width;
|
||||
font_parms.y = msg_height;
|
||||
font_parms.scale = 21;
|
||||
#endif
|
||||
d3d->font_ctx->render_msg(d3d, msg, &font_params);
|
||||
}
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
if (d3d->rgui && d3d->rgui->enabled)
|
||||
@ -492,6 +512,13 @@ static bool d3d_frame(void *data, const void *frame,
|
||||
|
||||
RARCH_PERFORMANCE_STOP(d3d_frame);
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
#ifdef HAVE_RMENU_XUI
|
||||
if (g_extern.lifecycle_state & (1ULL << MODE_MENU))
|
||||
menu_iterate_xui();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (d3d && d3d->ctx_driver && d3d->ctx_driver->update_window_title)
|
||||
d3d->ctx_driver->update_window_title();
|
||||
|
||||
@ -505,7 +532,12 @@ static void d3d_set_nonblock_state(void *data, bool state)
|
||||
{
|
||||
d3d_video_t *d3d = (d3d_video_t*)data;
|
||||
d3d->video_info.vsync = !state;
|
||||
|
||||
if (d3d->ctx_driver && d3d->ctx_driver->swap_interval)
|
||||
d3d->ctx_driver->swap_interval(state ? 0 : 1);
|
||||
#ifndef _XBOX
|
||||
d3d_restore(d3d);
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool d3d_alive(void *data)
|
||||
@ -1002,7 +1034,6 @@ static bool d3d_construct(void *data, const video_info_t *info, const input_driv
|
||||
|
||||
#ifdef HAVE_MONITOR
|
||||
RECT mon_rect = d3d_monitor_rect(d3d);
|
||||
#endif
|
||||
|
||||
bool windowed_full = g_settings.video.windowed_fullscreen;
|
||||
|
||||
@ -1012,6 +1043,15 @@ static bool d3d_construct(void *data, const video_info_t *info, const input_driv
|
||||
|
||||
d3d->screen_width = info->fullscreen ? full_x : info->width;
|
||||
d3d->screen_height = info->fullscreen ? full_y : info->height;
|
||||
#else
|
||||
unsigned full_x, full_y;
|
||||
|
||||
if (d3d->ctx_driver && d3d->ctx_driver->get_video_size)
|
||||
d3d->ctx_driver->get_video_size(&full_x, &full_y);
|
||||
|
||||
d3d->screen_width = info->fullscreen ? full_x : info->width;
|
||||
d3d->screen_height = info->fullscreen ? full_y : info->height;
|
||||
#endif
|
||||
|
||||
unsigned win_width = d3d->screen_width;
|
||||
unsigned win_height = d3d->screen_height;
|
||||
@ -1045,7 +1085,6 @@ static bool d3d_construct(void *data, const video_info_t *info, const input_driv
|
||||
driver.video_display = 0;
|
||||
driver.video_window = (uintptr_t)d3d->hWnd;
|
||||
|
||||
#ifdef HAVE_WINDOW
|
||||
if (d3d && d3d->ctx_driver && d3d->ctx_driver->show_mouse)
|
||||
d3d->ctx_driver->show_mouse(!info->fullscreen
|
||||
#ifdef HAVE_OVERLAY
|
||||
@ -1053,6 +1092,7 @@ static bool d3d_construct(void *data, const video_info_t *info, const input_driv
|
||||
#endif
|
||||
);
|
||||
|
||||
#ifdef HAVE_WINDOW
|
||||
ShowWindow(d3d->hWnd, SW_RESTORE);
|
||||
UpdateWindow(d3d->hWnd);
|
||||
SetForegroundWindow(d3d->hWnd);
|
||||
@ -1086,9 +1126,15 @@ static bool d3d_construct(void *data, const video_info_t *info, const input_driv
|
||||
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;
|
||||
enum gfx_ctx_api api;
|
||||
unsigned major, minor;
|
||||
#if defined(_XBOX1)
|
||||
api = GFX_CTX_DIRECT3D8_API;
|
||||
major = 8;
|
||||
#else
|
||||
api = GFX_CTX_DIRECT3D9_API;
|
||||
major = 9;
|
||||
#endif
|
||||
return gfx_ctx_init_first(api, major, minor);
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ bool renderchain_render(void *chain_data, const void *data,
|
||||
unsigned width, unsigned height, unsigned pitch, unsigned rotation)
|
||||
{
|
||||
renderchain_t *chain = (renderchain_t*)chain_data;
|
||||
LPDIRECT3DDEVICE d3dr = chain->dev;
|
||||
LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev;
|
||||
renderchain_start_render(chain);
|
||||
|
||||
unsigned current_width = width;
|
||||
@ -252,6 +252,10 @@ bool renderchain_render(void *chain_data, const void *data,
|
||||
unsigned out_height = 0;
|
||||
renderchain_convert_geometry(chain, &chain->passes[0].info, out_width, out_height,
|
||||
current_width, current_height, chain->final_viewport);
|
||||
#ifdef _XBOX1
|
||||
d3dr->SetFlickerFilter(g_extern.console.screen.flicker_filter_index);
|
||||
d3dr->SetSoftDisplayFilter(g_extern.lifecycle_state & (1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE));
|
||||
#endif
|
||||
renderchain_blit_to_texture(chain, data, width, height, pitch);
|
||||
|
||||
// Grab back buffer.
|
||||
@ -476,13 +480,17 @@ void renderchain_set_mvp(void *data, CGprogram &vPrg,
|
||||
|
||||
void renderchain_clear_texture(void *data, Pass &pass)
|
||||
{
|
||||
renderchain_t *chain = (renderchain_t*)data;
|
||||
D3DLOCKED_RECT d3dlr;
|
||||
#ifdef _XBOX
|
||||
D3DTexture_LockRect(pass.tex, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
|
||||
memset(d3dlr.pBits, 0, pass.info.tex_h * d3dlr.Pitch);
|
||||
#else
|
||||
if (SUCCEEDED(pass.tex->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK)))
|
||||
{
|
||||
memset(d3dlr.pBits, 0, pass.info.tex_h * d3dlr.Pitch);
|
||||
pass.tex->UnlockRect(0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void renderchain_convert_geometry(void *data, const LinkInfo *info,
|
||||
@ -532,17 +540,26 @@ void renderchain_blit_to_texture(void *data, const void *frame,
|
||||
renderchain_clear_texture(chain, first);
|
||||
|
||||
D3DLOCKED_RECT d3dlr;
|
||||
#ifdef _XBOX360
|
||||
D3DSURFACE_DESC desc;
|
||||
D3DTexture_LockRect(first.tex, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
|
||||
first.tex->GetLevelDesc(0, &desc);
|
||||
XGCopySurface(d3dlr.pBits, d3dlr.Pitch, width, height, desc.Format, NULL, frame,
|
||||
pitch, desc.Format, NULL, 0, 0);
|
||||
|
||||
#else
|
||||
if (SUCCEEDED(first.tex->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK)))
|
||||
{
|
||||
for (unsigned y = 0; y < height; y++)
|
||||
{
|
||||
const uint8_t *in = reinterpret_cast<const uint8_t*>(frame) + y * pitch;
|
||||
uint8_t *out = reinterpret_cast<uint8_t*>(d3dlr.pBits) + y * d3dlr.Pitch;
|
||||
const uint8_t *in = (const uint8_t*)frame + y * pitch;
|
||||
uint8_t *out =(uint8_t*)d3dlr.pBits + y * d3dlr.Pitch;
|
||||
memcpy(out, in, width * chain->pixel_size);
|
||||
}
|
||||
|
||||
first.tex->UnlockRect(0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void renderchain_render_pass(void *data, Pass &pass, unsigned pass_index)
|
||||
@ -550,13 +567,28 @@ void renderchain_render_pass(void *data, Pass &pass, unsigned pass_index)
|
||||
renderchain_t *chain = (renderchain_t*)data;
|
||||
LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev;
|
||||
renderchain_set_shaders(chain, pass.fPrg, pass.vPrg);
|
||||
#ifdef _XBOX
|
||||
if (g_extern.frame_count)
|
||||
{
|
||||
#if defined(_XBOX1)
|
||||
d3dr->SwitchTexture(0, pass.tex);
|
||||
#elif defined(_XBOX360)
|
||||
d3dr->SetTextureFetchConstant(0, pass.tex);
|
||||
#endif
|
||||
}
|
||||
else if(pass.tex)
|
||||
#endif
|
||||
d3dr->SetTexture(0, pass.tex);
|
||||
d3dr->SetSamplerState(0, D3DSAMP_MINFILTER,
|
||||
translate_filter(pass.info.pass->filter));
|
||||
d3dr->SetSamplerState(0, D3DSAMP_MAGFILTER,
|
||||
translate_filter(pass.info.pass->filter));
|
||||
|
||||
#ifdef _XBOX1
|
||||
d3dr->SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1);
|
||||
#else
|
||||
d3dr->SetVertexDeclaration(pass.vertex_decl);
|
||||
#endif
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
d3dr->SetStreamSource(i, pass.vertex_buf, 0, sizeof(Vertex));
|
||||
|
||||
@ -626,7 +658,7 @@ void renderchain_log_info(void *data, const LinkInfo *info)
|
||||
void renderchain_unbind_all(void *data)
|
||||
{
|
||||
renderchain_t *chain = (renderchain_t*)data;
|
||||
LPDIRECT3DDEVICE d3dr = chain->dev;
|
||||
LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev;
|
||||
// Have to be a bit anal about it.
|
||||
// Render targets hate it when they have filters apparently.
|
||||
for (unsigned i = 0; i < chain->bound_tex.size(); i++)
|
||||
@ -643,4 +675,4 @@ void renderchain_unbind_all(void *data)
|
||||
|
||||
chain->bound_tex.clear();
|
||||
chain->bound_vert.clear();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user