mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-14 06:18:34 +00:00
(XDK) 360 and Xbox 1 now both use the same Direct3D driver
This commit is contained in:
parent
a457257164
commit
6c5d6515ce
@ -27,7 +27,7 @@
|
||||
#include "../../console/rmenu/rmenu.h"
|
||||
#include "../../gfx/gfx_context.h"
|
||||
|
||||
#include "../xdk_d3d9.h"
|
||||
#include "../../xdk/xdk_d3d.h"
|
||||
#include "menu.h"
|
||||
#include "../../message.h"
|
||||
|
||||
|
@ -149,11 +149,7 @@ VIDEO DRIVER
|
||||
|
||||
#ifdef _XBOX
|
||||
#include "../../xdk/xdk_resources.cpp"
|
||||
#if defined(HAVE_D3D9)
|
||||
#include "../../360/xdk_d3d9.cpp"
|
||||
#elif defined(HAVE_D3D8)
|
||||
#include "../../xbox1/xdk_d3d8.cpp"
|
||||
#endif
|
||||
#include "../../xdk/xdk_d3d.cpp"
|
||||
#endif
|
||||
|
||||
#include "../../gfx/null.c"
|
||||
|
@ -18,11 +18,7 @@
|
||||
#include "../../screenshot.h"
|
||||
|
||||
#ifdef _XBOX
|
||||
#if defined(_XBOX1)
|
||||
#include "../../xbox1/xdk_d3d8.h"
|
||||
#elif defined(_XBOX360)
|
||||
#include "../../360/xdk_d3d9.h"
|
||||
#endif
|
||||
#include "../../xdk/xdk_d3d.h"
|
||||
#endif
|
||||
|
||||
#include "../../gfx/gfx_context.h"
|
||||
|
@ -17,11 +17,7 @@
|
||||
#include "../../driver.h"
|
||||
|
||||
#ifdef _XBOX
|
||||
#if defined(_XBOX1)
|
||||
#include "../../xbox1/xdk_d3d8.h"
|
||||
#elif defined(_XBOX360)
|
||||
#include "../../360/xdk_d3d9.h"
|
||||
#endif
|
||||
#include "../../xdk/xdk_d3d.h"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
@ -460,10 +456,12 @@ static void gfx_ctx_xdk_set_filtering(unsigned index, bool set_smooth)
|
||||
|
||||
static void gfx_ctx_xdk_set_fbo(bool enable)
|
||||
{
|
||||
#ifdef HAVE_FBO
|
||||
/* TODO: implement properly */
|
||||
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
|
||||
|
||||
d3d->fbo_enabled = enable;
|
||||
#endif
|
||||
}
|
||||
|
||||
void gfx_ctx_xdk_apply_fbo_state_changes(unsigned mode)
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "../gfx/image.h"
|
||||
#include "xdk_d3d8.h"
|
||||
#include "../xdk/xdk_d3d.h"
|
||||
|
||||
bool texture_image_load(const char *path, struct texture_image *out_img)
|
||||
{
|
||||
|
@ -1,422 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2012 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef _XBOX
|
||||
#include <xtl.h>
|
||||
#include <xgraphics.h>
|
||||
#endif
|
||||
|
||||
#include "../driver.h"
|
||||
#include "xdk_d3d8.h"
|
||||
|
||||
#include "./../gfx/fonts/xdk1_xfonts.h"
|
||||
#include "./../gfx/gfx_context.h"
|
||||
#include "../general.h"
|
||||
#include "../message.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
wchar_t strw_buffer[128];
|
||||
unsigned font_x, font_y;
|
||||
FLOAT angle;
|
||||
|
||||
static void check_window(xdk_d3d_video_t *d3d)
|
||||
{
|
||||
bool quit, resize;
|
||||
|
||||
gfx_ctx_xdk_check_window(&quit,
|
||||
&resize, NULL, NULL,
|
||||
d3d->frame_count);
|
||||
|
||||
if (quit)
|
||||
d3d->quitting = true;
|
||||
else if (resize)
|
||||
d3d->should_resize = true;
|
||||
}
|
||||
|
||||
static void xdk_d3d_free(void * data)
|
||||
{
|
||||
#ifdef RARCH_CONSOLE
|
||||
if (driver.video_data)
|
||||
return;
|
||||
#endif
|
||||
|
||||
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data;
|
||||
|
||||
if (!d3d)
|
||||
return;
|
||||
|
||||
d3d->driver->destroy();
|
||||
|
||||
free(d3d);
|
||||
}
|
||||
|
||||
static void xdk_d3d_set_viewport(bool force_full)
|
||||
{
|
||||
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
|
||||
|
||||
d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0);
|
||||
|
||||
// Get the "video mode"
|
||||
d3d->video_mode = XGetVideoFlags();
|
||||
|
||||
// Set the viewport based on the current resolution
|
||||
int width, height;
|
||||
|
||||
width = d3d->d3dpp.BackBufferWidth;
|
||||
height = d3d->d3dpp.BackBufferHeight;
|
||||
|
||||
int m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp;
|
||||
float m_zNear, m_zFar;
|
||||
|
||||
m_viewport_x_temp = 0;
|
||||
m_viewport_y_temp = 0;
|
||||
m_viewport_width_temp = width;
|
||||
m_viewport_height_temp = height;
|
||||
|
||||
m_zNear = 0.0f;
|
||||
m_zFar = 1.0f;
|
||||
|
||||
if (!force_full)
|
||||
{
|
||||
float desired_aspect = g_settings.video.aspect_ratio;
|
||||
float device_aspect = (float)width / height;
|
||||
float delta;
|
||||
|
||||
// If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff),
|
||||
if(g_console.aspect_ratio_index == ASPECT_RATIO_CUSTOM)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
|
||||
m_viewport_x_temp = g_console.viewports.custom_vp.x;
|
||||
m_viewport_y_temp = g_console.viewports.custom_vp.y;
|
||||
m_viewport_width_temp = g_console.viewports.custom_vp.width;
|
||||
m_viewport_height_temp = g_console.viewports.custom_vp.height;
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
|
||||
m_viewport_x_temp = (int)(width * (0.5 - delta));
|
||||
m_viewport_width_temp = (int)(2.0 * width * delta);
|
||||
width = (unsigned)(2.0 * width * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5;
|
||||
m_viewport_y_temp = (int)(height * (0.5 - delta));
|
||||
m_viewport_height_temp = (int)(2.0 * height * delta);
|
||||
height = (unsigned)(2.0 * height * delta);
|
||||
}
|
||||
}
|
||||
|
||||
D3DVIEWPORT vp = {0};
|
||||
vp.Width = m_viewport_width_temp;
|
||||
vp.Height = m_viewport_height_temp;
|
||||
vp.X = m_viewport_x_temp;
|
||||
vp.Y = m_viewport_y_temp;
|
||||
vp.MinZ = m_zNear;
|
||||
vp.MaxZ = m_zFar;
|
||||
d3d->d3d_render_device->SetViewport(&vp);
|
||||
|
||||
font_x = vp.X;
|
||||
font_y = vp.Y;
|
||||
|
||||
//if(gl->overscan_enable && !force_full)
|
||||
//{
|
||||
// m_left = -gl->overscan_amount/2;
|
||||
// m_right = 1 + gl->overscan_amount/2;
|
||||
// m_bottom = -gl->overscan_amount/2;
|
||||
//}
|
||||
}
|
||||
|
||||
static void xdk_d3d_set_rotation(void * data, unsigned orientation)
|
||||
{
|
||||
(void)data;
|
||||
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data;
|
||||
|
||||
switch(orientation)
|
||||
{
|
||||
case ORIENTATION_NORMAL:
|
||||
angle = M_PI * 0 / 180;
|
||||
break;
|
||||
case ORIENTATION_VERTICAL:
|
||||
angle = M_PI * 270 / 180;
|
||||
break;
|
||||
case ORIENTATION_FLIPPED:
|
||||
angle = M_PI * 180 / 180;
|
||||
break;
|
||||
case ORIENTATION_FLIPPED_ROTATED:
|
||||
angle = M_PI * 90 / 180;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void *xdk_d3d_init(const video_info_t *video, const input_driver_t **input, void **input_data)
|
||||
{
|
||||
#ifdef RARCH_CONSOLE
|
||||
if (driver.video_data)
|
||||
return driver.video_data;
|
||||
#endif
|
||||
|
||||
driver.video_data = (xdk_d3d_video_t*)calloc(1, sizeof(xdk_d3d_video_t));
|
||||
if (!driver.video_data)
|
||||
return NULL;
|
||||
|
||||
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
|
||||
|
||||
d3d->vsync = video->vsync;
|
||||
|
||||
d3d->driver = gfx_ctx_init_first(GFX_CTX_DIRECT3D8_API);
|
||||
if (!d3d->driver)
|
||||
{
|
||||
free(d3d);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RARCH_LOG("Found D3D context: %s\n", d3d->driver->ident);
|
||||
|
||||
d3d->driver->get_video_size(&d3d->full_x, &d3d->full_y);
|
||||
RARCH_LOG("Detecting screen resolution: %ux%u.\n", d3d->full_x, d3d->full_y);
|
||||
|
||||
gfx_ctx_xdk_set_swap_interval(d3d->vsync ? 1 : 0);
|
||||
|
||||
xdk_d3d_set_rotation(d3d, g_console.screen_orientation);
|
||||
|
||||
// load debug font (toggle option in later revisions ?)
|
||||
XFONT_OpenDefaultFont(&d3d->debug_font);
|
||||
d3d->debug_font->SetBkMode(XFONT_TRANSPARENT);
|
||||
d3d->debug_font->SetBkColor(D3DCOLOR_ARGB(100,0,0,0));
|
||||
d3d->debug_font->SetTextHeight(14);
|
||||
d3d->debug_font->SetTextAntialiasLevel(d3d->debug_font->GetTextAntialiasLevel());
|
||||
|
||||
font_x = 0;
|
||||
font_y = 0;
|
||||
|
||||
return d3d;
|
||||
}
|
||||
|
||||
static bool xdk_d3d_frame(void *data, const void *frame,
|
||||
unsigned width, unsigned height, unsigned pitch, const char *msg)
|
||||
{
|
||||
if (!frame)
|
||||
return true;
|
||||
|
||||
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data;
|
||||
bool menu_enabled = g_console.menu_enable;
|
||||
bool fps_enable = g_console.fps_info_msg_enable;
|
||||
unsigned flicker_filter = g_console.flicker_filter;
|
||||
bool soft_filter_enable = g_console.soft_display_filter_enable;
|
||||
|
||||
if (d3d->last_width != width || d3d->last_height != height) //240*160
|
||||
{
|
||||
|
||||
D3DLOCKED_RECT d3dlr;
|
||||
|
||||
d3d->lpTexture->LockRect(0, &d3dlr, NULL, 0);
|
||||
memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch);
|
||||
d3d->lpTexture->UnlockRect(0);
|
||||
|
||||
float tex_w = width; // / 512.0f;
|
||||
float tex_h = height; // / 512.0f;
|
||||
|
||||
DrawVerticeFormats verts[] = {
|
||||
{ -1.0f, -1.0f, 1.0f, 0.0f, tex_h },
|
||||
{ 1.0f, -1.0f, 1.0f, tex_w, tex_h },
|
||||
{ -1.0f, 1.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ 1.0f, 1.0f, 1.0f, tex_w, 0.0f },
|
||||
};
|
||||
|
||||
// Align texels and vertices (D3D9 quirk).
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
{
|
||||
verts[i].x -= 0.5f / 512.0f;
|
||||
verts[i].y += 0.5f / 512.0f;
|
||||
}
|
||||
|
||||
BYTE *verts_ptr;
|
||||
d3d->vertex_buf->Lock(0, 0, &verts_ptr, 0);
|
||||
memcpy(verts_ptr, verts, sizeof(verts));
|
||||
d3d->vertex_buf->Unlock();
|
||||
|
||||
d3d->last_width = width;
|
||||
d3d->last_height = height;
|
||||
}
|
||||
|
||||
if (d3d->should_resize)
|
||||
xdk_d3d_set_viewport(false);
|
||||
|
||||
d3d->frame_count++;
|
||||
|
||||
d3d->d3d_render_device->SetTexture(0, d3d->lpTexture);
|
||||
|
||||
D3DLOCKED_RECT d3dlr;
|
||||
|
||||
d3d->lpTexture->LockRect(0, &d3dlr, NULL, 0);
|
||||
for (unsigned y = 0; y < height; y++)
|
||||
{
|
||||
const uint8_t *in = (const uint8_t*)frame + y * pitch;
|
||||
uint8_t *out = (uint8_t*)d3dlr.pBits + y * d3dlr.Pitch;
|
||||
memcpy(out, in, width * sizeof(uint16_t));
|
||||
}
|
||||
d3d->lpTexture->UnlockRect(0);
|
||||
|
||||
|
||||
d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
|
||||
d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
|
||||
d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
|
||||
d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
|
||||
|
||||
d3d->d3d_render_device->SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1);
|
||||
|
||||
D3DXMATRIX p_out, p_rotate;
|
||||
D3DXMatrixIdentity(&p_out);
|
||||
D3DXMatrixRotationZ(&p_rotate, angle);
|
||||
|
||||
d3d->d3d_render_device->SetTransform(D3DTS_WORLD, &p_rotate);
|
||||
d3d->d3d_render_device->SetTransform(D3DTS_VIEW, &p_out);
|
||||
d3d->d3d_render_device->SetTransform(D3DTS_PROJECTION, &p_out);
|
||||
|
||||
d3d->d3d_render_device->SetStreamSource(0, d3d->vertex_buf, sizeof(DrawVerticeFormats));
|
||||
d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0);
|
||||
|
||||
d3d->d3d_render_device->BeginScene();
|
||||
d3d->d3d_render_device->SetFlickerFilter(flicker_filter);
|
||||
d3d->d3d_render_device->SetSoftDisplayFilter(soft_filter_enable);
|
||||
d3d->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
||||
d3d->d3d_render_device->EndScene();
|
||||
|
||||
if(fps_enable)
|
||||
{
|
||||
MEMORYSTATUS stat;
|
||||
GlobalMemoryStatus(&stat);
|
||||
|
||||
//Output memory usage
|
||||
|
||||
char buf[128], buf2[128], buf_fps_last[128];
|
||||
bool ret = false;
|
||||
snprintf(buf, sizeof(buf), "%.2f MB free / %.2f MB total", stat.dwAvailPhys/(1024.0f*1024.0f), stat.dwTotalPhys/(1024.0f*1024.0f));
|
||||
xfonts_render_msg_place(d3d, font_x + 30, font_y + 50, 0 /* scale */, buf);
|
||||
|
||||
if(ret = gfx_window_title(buf2, sizeof(buf2)) || sizeof(buf_fps_last))
|
||||
{
|
||||
if(ret)
|
||||
{
|
||||
snprintf(buf_fps_last, sizeof(buf_fps_last), buf2);
|
||||
xfonts_render_msg_place(d3d, font_x + 30, font_y + 70, 0 /* scale */, buf_fps_last);
|
||||
convert_char_to_wchar(strw_buffer, buf2, sizeof(strw_buffer));
|
||||
}
|
||||
else if(buf_fps_last)
|
||||
xfonts_render_msg_place(d3d, font_x + 30, font_y + 70, 0 /* scale */, buf2);
|
||||
}
|
||||
}
|
||||
|
||||
if (msg)
|
||||
xfonts_render_msg_place(d3d, 60, 365, 0, msg); //TODO: dehardcode x/y here for HD (720p) mode
|
||||
|
||||
if(!d3d->block_swap)
|
||||
gfx_ctx_xdk_swap_buffers();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void xdk_d3d_set_nonblock_state(void *data, bool state)
|
||||
{
|
||||
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data;
|
||||
|
||||
if(d3d->vsync)
|
||||
{
|
||||
RARCH_LOG("D3D8: Vsync => %s\n", state ? "off" : "on");
|
||||
gfx_ctx_xdk_set_swap_interval(state ? 0 : 1);
|
||||
}
|
||||
}
|
||||
|
||||
static bool xdk_d3d_alive(void *data)
|
||||
{
|
||||
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data;
|
||||
check_window(d3d);
|
||||
return !d3d->quitting;
|
||||
}
|
||||
|
||||
static bool xdk_d3d_focus(void *data)
|
||||
{
|
||||
(void)data;
|
||||
return gfx_ctx_window_has_focus();
|
||||
}
|
||||
|
||||
static void xdk_d3d_start(void)
|
||||
{
|
||||
video_info_t video_info = {0};
|
||||
|
||||
video_info.vsync = g_settings.video.vsync;
|
||||
video_info.force_aspect = false;
|
||||
video_info.fullscreen = true;
|
||||
video_info.smooth = g_settings.video.smooth;
|
||||
video_info.input_scale = 2;
|
||||
|
||||
driver.video_data = xdk_d3d_init(&video_info, NULL, NULL);
|
||||
}
|
||||
|
||||
static void xdk_d3d_restart(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void xdk_d3d_stop(void)
|
||||
{
|
||||
void *data = driver.video_data;
|
||||
|
||||
xdk_d3d_free(data);
|
||||
|
||||
driver.video_data = NULL;
|
||||
}
|
||||
|
||||
static void xdk_d3d_apply_state_changes(void)
|
||||
{
|
||||
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
|
||||
d3d->should_resize = true;
|
||||
}
|
||||
|
||||
static void xdk_d3d_set_aspect_ratio(void *data, unsigned aspectratio_index)
|
||||
{
|
||||
(void)data;
|
||||
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
|
||||
|
||||
if(g_console.aspect_ratio_index == ASPECT_RATIO_AUTO)
|
||||
rarch_set_auto_viewport(g_extern.frame_cache.width, g_extern.frame_cache.height);
|
||||
else if(g_console.aspect_ratio_index == ASPECT_RATIO_CORE)
|
||||
rarch_set_core_viewport();
|
||||
|
||||
g_settings.video.aspect_ratio = aspectratio_lut[g_console.aspect_ratio_index].value;
|
||||
g_settings.video.force_aspect = false;
|
||||
d3d->should_resize = true;
|
||||
}
|
||||
|
||||
const video_driver_t video_xdk_d3d = {
|
||||
xdk_d3d_init,
|
||||
xdk_d3d_frame,
|
||||
xdk_d3d_set_nonblock_state,
|
||||
xdk_d3d_alive,
|
||||
xdk_d3d_focus,
|
||||
NULL,
|
||||
xdk_d3d_free,
|
||||
"xdk_d3d",
|
||||
xdk_d3d_start,
|
||||
xdk_d3d_stop,
|
||||
xdk_d3d_restart,
|
||||
xdk_d3d_apply_state_changes,
|
||||
xdk_d3d_set_aspect_ratio,
|
||||
xdk_d3d_set_rotation,
|
||||
};
|
@ -1,72 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2012 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _XDK_VIDEO_H
|
||||
#define _XDK_VIDEO_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <xfont.h>
|
||||
|
||||
#include "../xdk/xdk_defines.h"
|
||||
|
||||
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW | D3DFVF_TEX1)
|
||||
|
||||
#define MIN_SCALING_FACTOR (1.0f)
|
||||
#define MAX_SCALING_FACTOR (2.0f)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float rhw;
|
||||
float u;
|
||||
float v;
|
||||
} primitive_t;
|
||||
|
||||
typedef struct DrawVerticeFormats
|
||||
{
|
||||
float x, y, z;
|
||||
float rhw;
|
||||
float u, v;
|
||||
} DrawVerticeFormats;
|
||||
|
||||
typedef struct xdk_d3d_video
|
||||
{
|
||||
const gfx_ctx_driver_t *driver;
|
||||
bool block_swap;
|
||||
bool fbo_enabled;
|
||||
bool should_resize;
|
||||
bool quitting;
|
||||
bool vsync;
|
||||
unsigned frame_count;
|
||||
unsigned last_width;
|
||||
unsigned last_height;
|
||||
unsigned win_width;
|
||||
unsigned win_height;
|
||||
unsigned full_x;
|
||||
unsigned full_y;
|
||||
LPDIRECT3D d3d_device;
|
||||
LPDIRECT3DDEVICE d3d_render_device;
|
||||
LPDIRECT3DVERTEXBUFFER vertex_buf;
|
||||
LPDIRECT3DTEXTURE lpTexture;
|
||||
DWORD video_mode;
|
||||
D3DPRESENT_PARAMETERS d3dpp;
|
||||
XFONT *debug_font;
|
||||
D3DSurface *pBackBuffer, *pFrontBuffer;
|
||||
} xdk_d3d_video_t;
|
||||
|
||||
#endif
|
@ -32,11 +32,7 @@
|
||||
#include <xbdm.h>
|
||||
|
||||
#ifdef _XBOX
|
||||
#if defined(_XBOX1)
|
||||
#include "../../xbox1/xdk_d3d8.h"
|
||||
#elif defined(_XBOX360)
|
||||
#include "../../360/xdk_d3d9.h"
|
||||
#endif
|
||||
#include "../../xdk/xdk_d3d.h"
|
||||
#endif
|
||||
|
||||
#include "../../console/rarch_console.h"
|
||||
|
@ -16,15 +16,20 @@
|
||||
|
||||
#ifdef _XBOX
|
||||
#include <xtl.h>
|
||||
#include <xgraphics.h>
|
||||
#endif
|
||||
|
||||
#include "../driver.h"
|
||||
#include "xdk_d3d9.h"
|
||||
#include "xdk_d3d.h"
|
||||
|
||||
#ifdef HAVE_HLSL
|
||||
#include "../gfx/shader_hlsl.h"
|
||||
#endif
|
||||
|
||||
#ifdef _XBOX1
|
||||
#include "./../gfx/fonts/xdk1_xfonts.h"
|
||||
#endif
|
||||
|
||||
#include "./../gfx/gfx_context.h"
|
||||
#include "../general.h"
|
||||
#include "../message.h"
|
||||
@ -39,6 +44,11 @@
|
||||
|
||||
#include "../xdk/xdk_resources.h"
|
||||
|
||||
#if defined(_XBOX1)
|
||||
wchar_t strw_buffer[128];
|
||||
unsigned font_x, font_y;
|
||||
FLOAT angle;
|
||||
#elif defined(_XBOX360)
|
||||
extern video_console_t video_console;
|
||||
extern xdk360_video_font_t m_Font;
|
||||
|
||||
@ -109,12 +119,13 @@ const DWORD g_MapLinearToSrgbGpuFormat[] =
|
||||
GPUTEXTUREFORMAT_8_8_8_8_GAMMA_EDRAM,
|
||||
GPUTEXTUREFORMAT_2_10_10_10_FLOAT_EDRAM,
|
||||
};
|
||||
#endif
|
||||
|
||||
static void check_window(xdk_d3d_video_t *d3d)
|
||||
{
|
||||
bool quit, resize;
|
||||
|
||||
gfx_ctx_xdk_check_window(&quit,
|
||||
d3d->driver->check_window(&quit,
|
||||
&resize, NULL, NULL,
|
||||
d3d->frame_count);
|
||||
|
||||
@ -149,13 +160,16 @@ static void xdk_d3d_free(void * data)
|
||||
#ifdef HAVE_HLSL
|
||||
hlsl_deinit();
|
||||
#endif
|
||||
#ifdef HAVE_D3D9
|
||||
d3d9_deinit_font();
|
||||
#endif
|
||||
|
||||
d3d->driver->destroy();
|
||||
|
||||
free(d3d);
|
||||
}
|
||||
|
||||
#ifdef _XBOX360
|
||||
void xdk_video_font_draw_text(xdk360_video_font_t *font,
|
||||
float fOriginX, float fOriginY, const wchar_t * strText, float fMaxPixelWidth )
|
||||
{
|
||||
@ -349,24 +363,30 @@ static void xdk_convert_texture_to_as16_srgb( D3DTexture *pTexture )
|
||||
//convert to AS_16_16_16_16 format
|
||||
pTexture->Format.DataFormat = g_MapLinearToSrgbGpuFormat[ (desc.Format & D3DFORMAT_TEXTUREFORMAT_MASK) >> D3DFORMAT_TEXTUREFORMAT_SHIFT ];
|
||||
}
|
||||
#endif
|
||||
|
||||
static void xdk_d3d_set_viewport(bool force_full)
|
||||
{
|
||||
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
|
||||
|
||||
d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET,
|
||||
0xff000000, 1.0f, 0);
|
||||
|
||||
int width = d3d->video_mode.fIsHiDef ? 1280 : 640;
|
||||
int height = d3d->video_mode.fIsHiDef ? 720 : 480;
|
||||
int width, height; // Set the viewport based on the current resolution
|
||||
int m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp;
|
||||
float m_zNear, m_zFar;
|
||||
|
||||
d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0);
|
||||
#if defined(_XBOX1)
|
||||
// Get the "video mode"
|
||||
d3d->video_mode = XGetVideoFlags();
|
||||
|
||||
width = d3d->d3dpp.BackBufferWidth;
|
||||
height = d3d->d3dpp.BackBufferHeight;
|
||||
#elif defined(_XBOX360)
|
||||
width = d3d->video_mode.fIsHiDef ? 1280 : 640;
|
||||
height = d3d->video_mode.fIsHiDef ? 720 : 480;
|
||||
#endif
|
||||
m_viewport_x_temp = 0;
|
||||
m_viewport_y_temp = 0;
|
||||
m_viewport_width_temp = width;
|
||||
m_viewport_height_temp = height;
|
||||
|
||||
m_zNear = 0.0f;
|
||||
m_zFar = 1.0f;
|
||||
|
||||
@ -410,6 +430,11 @@ static void xdk_d3d_set_viewport(bool force_full)
|
||||
vp.MaxZ = m_zFar;
|
||||
d3d->d3d_render_device->SetViewport(&vp);
|
||||
|
||||
#ifdef _XBOX1
|
||||
font_x = vp.X;
|
||||
font_y = vp.Y;
|
||||
#endif
|
||||
|
||||
//if(gl->overscan_enable && !force_full)
|
||||
//{
|
||||
// m_left = -gl->overscan_amount/2;
|
||||
@ -498,7 +523,11 @@ static void *xdk_d3d_init(const video_info_t *video, const input_driver_t **inpu
|
||||
|
||||
d3d->vsync = video->vsync;
|
||||
|
||||
#if defined(_XBOX1)
|
||||
d3d->driver = gfx_ctx_init_first(GFX_CTX_DIRECT3D8_API);
|
||||
#elif defined(_XBOX360)
|
||||
d3d->driver = gfx_ctx_init_first(GFX_CTX_DIRECT3D9_API);
|
||||
#endif
|
||||
if (!d3d->driver)
|
||||
{
|
||||
free(d3d);
|
||||
@ -530,12 +559,24 @@ static void *xdk_d3d_init(const video_info_t *video, const input_driver_t **inpu
|
||||
|
||||
xdk_d3d_set_rotation(d3d, g_console.screen_orientation);
|
||||
|
||||
#if defined(_XBOX1)
|
||||
/* load debug fonts */
|
||||
XFONT_OpenDefaultFont(&d3d->debug_font);
|
||||
d3d->debug_font->SetBkMode(XFONT_TRANSPARENT);
|
||||
d3d->debug_font->SetBkColor(D3DCOLOR_ARGB(100,0,0,0));
|
||||
d3d->debug_font->SetTextHeight(14);
|
||||
d3d->debug_font->SetTextAntialiasLevel(d3d->debug_font->GetTextAntialiasLevel());
|
||||
|
||||
font_x = 0;
|
||||
font_y = 0;
|
||||
#elif defined(_XBOX360)
|
||||
HRESULT hr = d3d9_init_font("game:\\media\\Arial_12.xpr");
|
||||
|
||||
if(hr < 0)
|
||||
{
|
||||
RARCH_ERR("Couldn't initialize HLSL shader fonts.\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
//really returns driver.video_data to driver.video_data - see comment above
|
||||
return d3d;
|
||||
@ -552,6 +593,11 @@ static bool xdk_d3d_frame(void *data, const void *frame,
|
||||
D3DSurface* pRenderTarget0;
|
||||
#endif
|
||||
bool menu_enabled = g_console.menu_enable;
|
||||
#ifdef _XBOX1
|
||||
bool fps_enable = g_console.fps_info_msg_enable;
|
||||
unsigned flicker_filter = g_console.flicker_filter;
|
||||
bool soft_filter_enable = g_console.soft_display_filter_enable;
|
||||
#endif
|
||||
|
||||
if (d3d->last_width != width || d3d->last_height != height)
|
||||
{
|
||||
@ -561,6 +607,17 @@ static bool xdk_d3d_frame(void *data, const void *frame,
|
||||
memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch);
|
||||
d3d->lpTexture->UnlockRect(0);
|
||||
|
||||
#if defined(_XBOX1)
|
||||
float tex_w = width; // / 512.0f;
|
||||
float tex_h = height; // / 512.0f;
|
||||
|
||||
DrawVerticeFormats verts[] = {
|
||||
{ -1.0f, -1.0f, 1.0f, 0.0f, tex_h },
|
||||
{ 1.0f, -1.0f, 1.0f, tex_w, tex_h },
|
||||
{ -1.0f, 1.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ 1.0f, 1.0f, 1.0f, tex_w, 0.0f },
|
||||
};
|
||||
#elif defined(_XBOX360)
|
||||
float tex_w = width / 512.0f;
|
||||
float tex_h = height / 512.0f;
|
||||
|
||||
@ -570,6 +627,7 @@ static bool xdk_d3d_frame(void *data, const void *frame,
|
||||
{ -1.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ 1.0f, 1.0f, tex_w, 0.0f },
|
||||
};
|
||||
#endif
|
||||
|
||||
// Align texels and vertices (D3D9 quirk).
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
@ -578,7 +636,11 @@ static bool xdk_d3d_frame(void *data, const void *frame,
|
||||
verts[i].y += 0.5f / 512.0f;
|
||||
}
|
||||
|
||||
#if defined(_XBOX1)
|
||||
BYTE *verts_ptr;
|
||||
#elif defined(_XBOX360)
|
||||
void *verts_ptr;
|
||||
#endif
|
||||
d3d->vertex_buf->Lock(0, 0, &verts_ptr, 0);
|
||||
memcpy(verts_ptr, verts, sizeof(verts));
|
||||
d3d->vertex_buf->Unlock();
|
||||
@ -598,9 +660,11 @@ static bool xdk_d3d_frame(void *data, const void *frame,
|
||||
if (d3d->should_resize)
|
||||
xdk_d3d_set_viewport(false);
|
||||
|
||||
d3d->frame_count++;
|
||||
#ifdef _XBOX360
|
||||
d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET,
|
||||
0xff000000, 1.0f, 0);
|
||||
d3d->frame_count++;
|
||||
#endif
|
||||
|
||||
d3d->d3d_render_device->SetTexture(0, d3d->lpTexture);
|
||||
|
||||
@ -648,12 +712,34 @@ static bool xdk_d3d_frame(void *data, const void *frame,
|
||||
d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
|
||||
d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
|
||||
|
||||
#if defined(_XBOX1)
|
||||
d3d->d3d_render_device->SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1);
|
||||
|
||||
D3DXMATRIX p_out, p_rotate;
|
||||
D3DXMatrixIdentity(&p_out);
|
||||
D3DXMatrixRotationZ(&p_rotate, angle);
|
||||
|
||||
d3d->d3d_render_device->SetTransform(D3DTS_WORLD, &p_rotate);
|
||||
d3d->d3d_render_device->SetTransform(D3DTS_VIEW, &p_out);
|
||||
d3d->d3d_render_device->SetTransform(D3DTS_PROJECTION, &p_out);
|
||||
|
||||
d3d->d3d_render_device->SetStreamSource(0, d3d->vertex_buf, sizeof(DrawVerticeFormats));
|
||||
d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0);
|
||||
|
||||
d3d->d3d_render_device->BeginScene();
|
||||
d3d->d3d_render_device->SetFlickerFilter(flicker_filter);
|
||||
d3d->d3d_render_device->SetSoftDisplayFilter(soft_filter_enable);
|
||||
d3d->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
||||
d3d->d3d_render_device->EndScene();
|
||||
#elif defined(_XBOX360)
|
||||
|
||||
d3d->d3d_render_device->SetVertexDeclaration(d3d->v_decl);
|
||||
d3d->d3d_render_device->SetStreamSource(0, d3d->vertex_buf,
|
||||
0,
|
||||
sizeof(DrawVerticeFormats));
|
||||
|
||||
d3d->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FBO
|
||||
if(d3d->fbo_enabled)
|
||||
@ -684,13 +770,41 @@ static bool xdk_d3d_frame(void *data, const void *frame,
|
||||
}
|
||||
#endif
|
||||
|
||||
/* XBox 360 specific font code */
|
||||
#if defined(_XBOX1)
|
||||
if(fps_enable)
|
||||
{
|
||||
MEMORYSTATUS stat;
|
||||
GlobalMemoryStatus(&stat);
|
||||
|
||||
//Output memory usage
|
||||
|
||||
char buf[128], buf2[128], buf_fps_last[128];
|
||||
bool ret = false;
|
||||
snprintf(buf, sizeof(buf), "%.2f MB free / %.2f MB total", stat.dwAvailPhys/(1024.0f*1024.0f), stat.dwTotalPhys/(1024.0f*1024.0f));
|
||||
xfonts_render_msg_place(d3d, font_x + 30, font_y + 50, 0 /* scale */, buf);
|
||||
|
||||
if(ret = gfx_window_title(buf2, sizeof(buf2)) || sizeof(buf_fps_last))
|
||||
{
|
||||
if(ret)
|
||||
{
|
||||
snprintf(buf_fps_last, sizeof(buf_fps_last), buf2);
|
||||
xfonts_render_msg_place(d3d, font_x + 30, font_y + 70, 0 /* scale */, buf_fps_last);
|
||||
convert_char_to_wchar(strw_buffer, buf2, sizeof(strw_buffer));
|
||||
}
|
||||
else if(buf_fps_last)
|
||||
xfonts_render_msg_place(d3d, font_x + 30, font_y + 70, 0 /* scale */, buf2);
|
||||
}
|
||||
}
|
||||
|
||||
if (msg)
|
||||
xfonts_render_msg_place(d3d, 60, 365, 0, msg); //TODO: dehardcode x/y here for HD (720p) mode
|
||||
#elif defined(_XBOX360)
|
||||
if (msg && !menu_enabled)
|
||||
{
|
||||
xdk360_console_format(msg);
|
||||
|
||||
xdk360_console_draw();
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!d3d->block_swap)
|
||||
gfx_ctx_xdk_swap_buffers();
|
@ -14,15 +14,19 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _XDK360_VIDEO_H
|
||||
#define _XDK360_VIDEO_H
|
||||
#ifndef _XDK_D3D_VIDEO_H
|
||||
#define _XDK_D3D_VIDEO_H
|
||||
|
||||
#include <stdint.h>
|
||||
#ifdef _XBOX1
|
||||
#include <xfont.h>
|
||||
#endif
|
||||
|
||||
#include "../gfx/gfx_context.h"
|
||||
#include "../xdk/xdk_defines.h"
|
||||
|
||||
#define DFONT_MAX 4096
|
||||
#define PRIM_FVF (D3DFVF_XYZRHW | D3DFVF_TEX1)
|
||||
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW | D3DFVF_TEX1)
|
||||
|
||||
#define MIN_SCALING_FACTOR (1.0f)
|
||||
#define MAX_SCALING_FACTOR (2.0f)
|
||||
@ -39,7 +43,12 @@ typedef struct
|
||||
|
||||
typedef struct DrawVerticeFormats
|
||||
{
|
||||
#if defined(_XBOX1)
|
||||
float x, y, z;
|
||||
float rhw;
|
||||
#elif defined(_XBOX360)
|
||||
float x, y;
|
||||
#endif
|
||||
float u, v;
|
||||
} DrawVerticeFormats;
|
||||
|
||||
@ -47,7 +56,9 @@ typedef struct xdk_d3d_video
|
||||
{
|
||||
const gfx_ctx_driver_t *driver;
|
||||
bool block_swap;
|
||||
#ifdef HAVE_FBO
|
||||
bool fbo_enabled;
|
||||
#endif
|
||||
bool should_resize;
|
||||
bool quitting;
|
||||
bool vsync;
|
||||
@ -56,14 +67,24 @@ typedef struct xdk_d3d_video
|
||||
unsigned last_height;
|
||||
unsigned full_x;
|
||||
unsigned full_y;
|
||||
unsigned win_width;
|
||||
unsigned win_height;
|
||||
LPDIRECT3D d3d_device;
|
||||
LPDIRECT3DDEVICE d3d_render_device;
|
||||
LPDIRECT3DVERTEXBUFFER vertex_buf;
|
||||
LPDIRECT3DTEXTURE lpTexture;
|
||||
#ifdef HAVE_D3D9
|
||||
D3DTexture lpTexture_ot_as16srgb;
|
||||
LPDIRECT3DTEXTURE lpTexture_ot;
|
||||
IDirect3DVertexDeclaration9* v_decl;
|
||||
#endif
|
||||
#if defined(_XBOX1)
|
||||
DWORD video_mode;
|
||||
XFONT *debug_font;
|
||||
D3DSurface *pBackBuffer, *pFrontBuffer;
|
||||
#elif defined(_XBOX360)
|
||||
XVIDEO_MODE video_mode;
|
||||
#endif
|
||||
D3DPRESENT_PARAMETERS d3dpp;
|
||||
LPDIRECT3DSURFACE lpSurface;
|
||||
} xdk_d3d_video_t;
|
Loading…
Reference in New Issue
Block a user