RetroArch/gfx/context/xdk_ctx.c

257 lines
6.3 KiB
C
Raw Normal View History

2012-05-28 00:29:51 +00:00
/* 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/>.
*/
#include "../../driver.h"
2012-09-30 15:51:48 +00:00
#ifdef _XBOX
#if defined(_XBOX1)
#include "../../xbox1/xdk_d3d8.h"
#elif defined(_XBOX360)
#include "../../360/xdk_d3d9.h"
#endif
#endif
2012-05-28 00:29:51 +00:00
#include <stdint.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2012-08-21 22:37:42 +00:00
#include <xgraphics.h>
#include "../../screenshot.h"
2012-05-28 00:29:51 +00:00
#if defined(_XBOX1)
// for Xbox 1
#define XBOX_PRESENTATIONINTERVAL D3DRS_PRESENTATIONINTERVAL
#else
// for Xbox 360
#define XBOX_PRESENTATIONINTERVAL D3DRS_PRESENTINTERVAL
#endif
static void gfx_ctx_xdk_set_blend(bool enable)
2012-08-03 16:10:00 +00:00
{
2012-08-04 03:59:30 +00:00
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
if(enable)
{
d3d->d3d_render_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
d3d->d3d_render_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
}
d3d->d3d_render_device->SetRenderState(D3DRS_ALPHABLENDENABLE, enable);
2012-08-03 16:10:00 +00:00
}
static void gfx_ctx_xdk_set_swap_interval(unsigned interval)
2012-05-28 00:29:51 +00:00
{
2012-07-07 17:15:06 +00:00
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
2012-05-28 00:29:51 +00:00
if (interval)
d3d->d3d_render_device->SetRenderState(XBOX_PRESENTATIONINTERVAL, D3DPRESENT_INTERVAL_ONE);
2012-05-28 00:29:51 +00:00
else
d3d->d3d_render_device->SetRenderState(XBOX_PRESENTATIONINTERVAL, D3DPRESENT_INTERVAL_IMMEDIATE);
2012-05-28 00:29:51 +00:00
}
static void gfx_ctx_xdk_get_available_resolutions (void)
{
}
static void gfx_ctx_xdk_check_window(bool *quit,
2012-05-28 00:29:51 +00:00
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
{
2012-07-07 17:15:06 +00:00
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
2012-05-28 00:29:51 +00:00
*quit = false;
*resize = false;
if (d3d->quitting)
2012-05-28 00:29:51 +00:00
*quit = true;
if (d3d->should_resize)
2012-05-28 00:29:51 +00:00
*resize = true;
}
static void gfx_ctx_xdk_set_resize(unsigned width, unsigned height) { }
2012-05-28 00:29:51 +00:00
static void gfx_ctx_xdk_swap_buffers(void)
2012-05-28 00:29:51 +00:00
{
2012-07-07 17:15:06 +00:00
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
#ifdef _XBOX1
d3d->d3d_render_device->EndScene();
#endif
d3d->d3d_render_device->Present(NULL, NULL, NULL, NULL);
2012-05-28 00:29:51 +00:00
}
2012-05-30 15:24:02 +00:00
static void gfx_ctx_xdk_clear(void)
{
xdk_d3d_video_t *device_ptr = (xdk_d3d_video_t*)driver.video_data;
2012-08-10 04:50:41 +00:00
#ifdef _XBOX1
unsigned flicker_filter = g_console.flicker_filter;
bool soft_filter_enable = g_console.soft_display_filter_enable;
2012-08-10 04:50:41 +00:00
#endif
device_ptr->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
#ifdef _XBOX1
device_ptr->d3d_render_device->BeginScene();
device_ptr->d3d_render_device->SetFlickerFilter(flicker_filter);
device_ptr->d3d_render_device->SetSoftDisplayFilter(soft_filter_enable);
#endif
}
static bool gfx_ctx_xdk_window_has_focus(void)
2012-05-30 15:24:02 +00:00
{
return true;
}
2012-05-28 00:29:51 +00:00
static bool gfx_ctx_xdk_menu_init(void)
2012-05-28 00:29:51 +00:00
{
return true;
}
static void gfx_ctx_xdk_update_window_title(bool reset) { }
2012-05-28 00:29:51 +00:00
static void gfx_ctx_xdk_get_video_size(unsigned *width, unsigned *height)
2012-05-28 00:29:51 +00:00
{
/* TODO: implement */
2012-05-28 00:29:51 +00:00
(void)width;
(void)height;
}
static bool gfx_ctx_xdk_init(void)
2012-05-28 00:29:51 +00:00
{
/* TODO: implement */
2012-05-28 00:29:51 +00:00
return true;
}
static bool gfx_ctx_xdk_set_video_mode(
2012-05-28 00:29:51 +00:00
unsigned width, unsigned height,
unsigned bits, bool fullscreen)
{
/* TODO: implement */
2012-05-28 00:29:51 +00:00
return true;
}
static void gfx_ctx_xdk_destroy(void)
2012-05-28 00:29:51 +00:00
{
/* TODO: implement */
2012-05-28 00:29:51 +00:00
}
static void gfx_ctx_xdk_input_driver(const input_driver_t **input, void **input_data) { }
2012-05-28 00:29:51 +00:00
static void gfx_ctx_xdk_set_filtering(unsigned index, bool set_smooth)
{
/* TODO: implement */
}
2012-05-28 00:29:51 +00:00
static void gfx_ctx_xdk_set_fbo(bool enable)
2012-05-28 00:29:51 +00:00
{
/* TODO: implement properly */
2012-07-07 17:15:06 +00:00
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
2012-05-28 00:29:51 +00:00
d3d->fbo_enabled = enable;
2012-05-28 00:29:51 +00:00
}
void gfx_ctx_xdk_apply_fbo_state_changes(unsigned mode)
{
}
void gfx_ctx_xdk_screenshot_dump(void *data)
{
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
HRESULT ret = S_OK;
char filename[PATH_MAX];
char shotname[PATH_MAX];
screenshot_generate_filename(shotname, sizeof(shotname));
snprintf(filename, sizeof(filename), "%s\\%s", default_paths.screenshots_dir, shotname);
#if defined(_XBOX1)
D3DSurface *surf = NULL;
d3d->d3d_render_device->GetBackBuffer(-1, D3DBACKBUFFER_TYPE_MONO, &surf);
ret = XGWriteSurfaceToFile(surf, filename);
surf->Release();
#elif defined(_XBOX360)
2012-08-21 22:37:42 +00:00
ret = 1; //false
//ret = D3DXSaveTextureToFile(filename, D3DXIFF_BMP, d3d->lpTexture, NULL);
#endif
if(ret == S_OK)
{
RARCH_LOG("Screenshot saved: %s.\n", filename);
msg_queue_push(g_extern.msg_queue, "Screenshot saved.", 1, 30);
}
}
2012-09-30 15:51:48 +00:00
static bool gfx_ctx_xdk_bind_api(enum gfx_ctx_api api)
{
#if defined(_XBOX1)
return api == GFX_CTX_DIRECT3D8_API;
#elif defined(_XBOX360)
return api == GFX_CTX_DIRECT3D9_API;
#endif
}
2012-05-28 00:29:51 +00:00
/*============================================================
MISC
TODO: Refactor
============================================================ */
void gfx_ctx_set_overscan(void)
{
/* TODO: implement */
2012-07-07 17:15:06 +00:00
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
if (!d3d)
2012-05-28 00:29:51 +00:00
return;
d3d->should_resize = true;
2012-05-28 00:29:51 +00:00
}
int gfx_ctx_xdk_check_resolution(unsigned resolution_id)
2012-05-30 14:30:25 +00:00
{
/* TODO: implement */
2012-05-30 14:30:25 +00:00
return 0;
}
const gfx_ctx_driver_t gfx_ctx_xdk = {
gfx_ctx_xdk_init,
gfx_ctx_xdk_destroy,
gfx_ctx_xdk_bind_api,
gfx_ctx_xdk_set_swap_interval,
gfx_ctx_xdk_set_video_mode,
gfx_ctx_xdk_get_video_size,
NULL,
gfx_ctx_xdk_update_window_title,
gfx_ctx_xdk_check_window,
gfx_ctx_xdk_set_resize,
gfx_ctx_xdk_window_has_focus,
gfx_ctx_xdk_swap_buffers,
gfx_ctx_xdk_input_driver,
NULL,
"xdk",
// RARCH_CONSOLE stuff.
gfx_ctx_xdk_set_filtering,
gfx_ctx_xdk_get_available_resolutions,
gfx_ctx_xdk_check_resolution,
gfx_ctx_xdk_menu_init,
gfx_ctx_xdk_set_fbo,
gfx_ctx_xdk_apply_fbo_state_changes,
};