2012-10-26 19:09:30 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2013-01-01 00:37:37 +00:00
|
|
|
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2013 - Daniel De Matteis
|
2012-11-14 00:13:08 +00:00
|
|
|
* Copyright (C) 2012 - OV2
|
2012-10-26 19:09:30 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This driver is merged from the external RetroArch-D3D9 driver.
|
|
|
|
// It is written in C++11 (should be compat with MSVC 2010).
|
|
|
|
// Might get rewritten in C99 if I have lots of time to burn.
|
|
|
|
|
2012-11-14 20:01:40 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma comment( lib, "d3d9" )
|
|
|
|
#pragma comment( lib, "d3dx9" )
|
|
|
|
#pragma comment( lib, "cgd3d9" )
|
|
|
|
#pragma comment( lib, "dxguid" )
|
|
|
|
#endif
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
#include "d3d9.hpp"
|
|
|
|
#include "render_chain.hpp"
|
2013-04-06 19:26:27 +00:00
|
|
|
#include "../../file.h"
|
2012-10-26 19:09:30 +00:00
|
|
|
#include "../gfx_common.h"
|
|
|
|
#include "../../compat/posix_string.h"
|
2012-11-03 23:14:43 +00:00
|
|
|
#include "../../performance.h"
|
2012-10-26 19:09:30 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <exception>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <cstring>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <cmath>
|
2013-04-21 10:07:57 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#undef min
|
|
|
|
#undef max
|
2012-10-26 19:09:30 +00:00
|
|
|
|
|
|
|
#define IDI_ICON 1
|
2012-10-30 10:47:37 +00:00
|
|
|
#define MAX_MONITORS 9
|
|
|
|
|
2012-11-14 00:13:08 +00:00
|
|
|
/* TODO: Make Cg optional - same as in the GL driver where we can either bake in
|
2012-11-19 23:06:51 +00:00
|
|
|
* Cg or HLSL shader support */
|
2012-11-14 00:13:08 +00:00
|
|
|
|
2012-10-30 10:47:37 +00:00
|
|
|
namespace Monitor
|
|
|
|
{
|
|
|
|
static HMONITOR last_hm;
|
|
|
|
static HMONITOR all_hms[MAX_MONITORS];
|
|
|
|
static unsigned num_mons;
|
2012-10-30 23:04:21 +00:00
|
|
|
static unsigned cur_mon_id;
|
2012-10-30 10:47:37 +00:00
|
|
|
}
|
2012-10-26 19:09:30 +00:00
|
|
|
|
2013-11-05 19:49:04 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
#endif
|
|
|
|
bool dinput_handle_message(void *dinput, UINT message, WPARAM wParam, LPARAM lParam);
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
namespace Callback
|
|
|
|
{
|
|
|
|
static bool quit = false;
|
2012-10-30 22:49:48 +00:00
|
|
|
static D3DVideo *curD3D = nullptr;
|
2012-11-19 23:06:51 +00:00
|
|
|
static HRESULT d3d_err;
|
2013-11-05 19:49:04 +00:00
|
|
|
static void *dinput;
|
2012-10-26 19:09:30 +00:00
|
|
|
|
|
|
|
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message,
|
|
|
|
WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (message)
|
|
|
|
{
|
2012-10-30 22:49:48 +00:00
|
|
|
case WM_CREATE:
|
|
|
|
LPCREATESTRUCT p_cs;
|
|
|
|
p_cs = (LPCREATESTRUCT)lParam;
|
2012-10-30 23:40:02 +00:00
|
|
|
curD3D = (D3DVideo*)p_cs->lpCreateParams;
|
2012-10-30 22:49:48 +00:00
|
|
|
break;
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case VK_F10:
|
|
|
|
case VK_RSHIFT:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_DESTROY:
|
|
|
|
quit = true;
|
|
|
|
return 0;
|
|
|
|
|
2012-10-30 22:49:48 +00:00
|
|
|
case WM_SIZE:
|
|
|
|
unsigned new_width, new_height;
|
|
|
|
new_width = LOWORD(lParam);
|
|
|
|
new_height = HIWORD(lParam);
|
2012-10-31 16:30:38 +00:00
|
|
|
|
|
|
|
if (new_width && new_height)
|
|
|
|
curD3D->resize(new_width, new_height);
|
|
|
|
return 0;
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
2013-11-05 19:49:04 +00:00
|
|
|
if (dinput_handle_message(dinput, message, wParam, lParam))
|
|
|
|
return 0;
|
2012-10-26 19:09:30 +00:00
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::init_base(const video_info_t &info)
|
|
|
|
{
|
|
|
|
D3DPRESENT_PARAMETERS d3dpp;
|
|
|
|
make_d3dpp(info, d3dpp);
|
|
|
|
|
|
|
|
g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
|
|
|
|
if (!g_pD3D)
|
|
|
|
throw std::runtime_error("Failed to create D3D9 interface!");
|
|
|
|
|
2012-11-19 23:06:51 +00:00
|
|
|
if (FAILED(Callback::d3d_err = g_pD3D->CreateDevice(
|
2012-10-30 23:04:21 +00:00
|
|
|
Monitor::cur_mon_id,
|
2012-10-26 19:09:30 +00:00
|
|
|
D3DDEVTYPE_HAL,
|
|
|
|
hWnd,
|
|
|
|
D3DCREATE_HARDWARE_VERTEXPROCESSING,
|
|
|
|
&d3dpp,
|
|
|
|
&dev)))
|
|
|
|
{
|
2012-12-18 20:17:08 +00:00
|
|
|
RARCH_WARN("[D3D9]: Failed to init device with hardware vertex processing (code: 0x%x). Trying to fall back to software vertex processing.\n",
|
|
|
|
(unsigned)Callback::d3d_err);
|
|
|
|
|
|
|
|
if (FAILED(Callback::d3d_err = g_pD3D->CreateDevice(
|
|
|
|
Monitor::cur_mon_id,
|
|
|
|
D3DDEVTYPE_HAL,
|
|
|
|
hWnd,
|
|
|
|
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
|
|
|
|
&d3dpp,
|
|
|
|
&dev)))
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Failed to init device");
|
|
|
|
}
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::make_d3dpp(const video_info_t &info, D3DPRESENT_PARAMETERS &d3dpp)
|
|
|
|
{
|
|
|
|
std::memset(&d3dpp, 0, sizeof(d3dpp));
|
|
|
|
|
2012-10-30 22:49:48 +00:00
|
|
|
d3dpp.Windowed = g_settings.video.windowed_fullscreen || !info.fullscreen;
|
2012-10-26 19:09:30 +00:00
|
|
|
|
2013-09-01 11:20:10 +00:00
|
|
|
if (info.vsync)
|
|
|
|
{
|
|
|
|
switch (g_settings.video.swap_interval)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 1: d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; break;
|
|
|
|
case 2: d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_TWO; break;
|
|
|
|
case 3: d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_THREE; break;
|
|
|
|
case 4: d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_FOUR; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
|
|
|
d3dpp.hDeviceWindow = hWnd;
|
|
|
|
d3dpp.BackBufferCount = 2;
|
2012-10-31 16:30:38 +00:00
|
|
|
d3dpp.BackBufferFormat = !d3dpp.Windowed ? D3DFMT_X8R8G8B8 : D3DFMT_UNKNOWN;
|
2012-10-26 19:09:30 +00:00
|
|
|
|
2012-10-31 16:30:38 +00:00
|
|
|
if (!d3dpp.Windowed)
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
|
|
|
d3dpp.BackBufferWidth = screen_width;
|
|
|
|
d3dpp.BackBufferHeight = screen_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::init(const video_info_t &info)
|
|
|
|
{
|
|
|
|
if (!g_pD3D)
|
|
|
|
init_base(info);
|
|
|
|
else if (needs_restore)
|
|
|
|
{
|
|
|
|
D3DPRESENT_PARAMETERS d3dpp;
|
|
|
|
make_d3dpp(info, d3dpp);
|
|
|
|
if (dev->Reset(&d3dpp) != D3D_OK)
|
2012-10-31 16:30:38 +00:00
|
|
|
{
|
|
|
|
HRESULT res = dev->TestCooperativeLevel();
|
|
|
|
const char *err;
|
|
|
|
switch (res)
|
|
|
|
{
|
|
|
|
case D3DERR_DEVICELOST:
|
|
|
|
err = "DEVICELOST";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DERR_DEVICENOTRESET:
|
|
|
|
err = "DEVICENOTRESET";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DERR_DRIVERINTERNALERROR:
|
|
|
|
err = "DRIVERINTERNALERROR";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err = "Unknown";
|
|
|
|
}
|
|
|
|
// Try to recreate the device completely ...
|
|
|
|
RARCH_WARN("[D3D9]: Attempting to recover from dead state (%s).\n", err);
|
|
|
|
deinit();
|
|
|
|
g_pD3D->Release();
|
|
|
|
g_pD3D = nullptr;
|
|
|
|
init_base(info);
|
|
|
|
RARCH_LOG("[D3D9]: Recovered from dead state.\n");
|
|
|
|
}
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
|
2013-03-17 21:05:15 +00:00
|
|
|
calculate_rect(screen_width, screen_height, info.force_aspect, g_extern.system.aspect_ratio);
|
2012-10-26 19:09:30 +00:00
|
|
|
|
2012-11-14 00:13:08 +00:00
|
|
|
#ifdef HAVE_CG
|
2012-10-26 19:09:30 +00:00
|
|
|
if (!init_cg())
|
|
|
|
throw std::runtime_error("Failed to init Cg");
|
2012-11-14 00:13:08 +00:00
|
|
|
#endif
|
2012-10-26 19:09:30 +00:00
|
|
|
if (!init_chain(info))
|
|
|
|
throw std::runtime_error("Failed to init render chain");
|
|
|
|
if (!init_font())
|
|
|
|
throw std::runtime_error("Failed to init Font");
|
|
|
|
}
|
|
|
|
|
2013-04-21 09:20:56 +00:00
|
|
|
void D3DVideo::set_viewport(int x, int y, unsigned width, unsigned height)
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
|
|
|
D3DVIEWPORT9 viewport;
|
2013-04-21 10:07:57 +00:00
|
|
|
viewport.X = std::max(x, 0); // D3D9 doesn't support negative X/Y viewports ...
|
|
|
|
viewport.Y = std::max(y, 0);
|
2012-10-26 19:09:30 +00:00
|
|
|
viewport.Width = width;
|
|
|
|
viewport.Height = height;
|
|
|
|
viewport.MinZ = 0.0f;
|
|
|
|
viewport.MaxZ = 1.0f;
|
|
|
|
|
2013-04-07 17:34:44 +00:00
|
|
|
final_viewport = viewport;
|
|
|
|
|
|
|
|
set_font_rect(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::set_font_rect(font_params_t *params)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (params)
|
|
|
|
{
|
|
|
|
pos_x = params->x;
|
|
|
|
pos_y = params->y;
|
|
|
|
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;
|
2012-10-26 19:09:30 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::set_rotation(unsigned rot)
|
|
|
|
{
|
|
|
|
rotation = rot;
|
|
|
|
}
|
|
|
|
|
2012-10-27 22:41:24 +00:00
|
|
|
void D3DVideo::viewport_info(rarch_viewport &vp)
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
2012-10-27 22:38:31 +00:00
|
|
|
vp.x = final_viewport.X;
|
|
|
|
vp.y = final_viewport.Y;
|
|
|
|
vp.width = final_viewport.Width;
|
|
|
|
vp.height = final_viewport.Height;
|
2013-01-11 15:23:04 +00:00
|
|
|
|
|
|
|
vp.full_width = screen_width;
|
|
|
|
vp.full_height = screen_height;
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool D3DVideo::read_viewport(uint8_t *buffer)
|
|
|
|
{
|
2012-11-20 17:06:52 +00:00
|
|
|
RARCH_PERFORMANCE_INIT(d3d_read_viewport);
|
|
|
|
RARCH_PERFORMANCE_START(d3d_read_viewport);
|
2012-10-26 19:09:30 +00:00
|
|
|
bool ret = true;
|
|
|
|
IDirect3DSurface9 *target = nullptr;
|
|
|
|
IDirect3DSurface9 *dest = nullptr;
|
|
|
|
|
2012-11-19 23:06:51 +00:00
|
|
|
if (FAILED(Callback::d3d_err = dev->GetRenderTarget(0, &target)))
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
|
|
|
ret = false;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2012-11-19 23:06:51 +00:00
|
|
|
if (FAILED(Callback::d3d_err = dev->CreateOffscreenPlainSurface(screen_width, screen_height,
|
2012-10-26 19:09:30 +00:00
|
|
|
D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM,
|
|
|
|
&dest, nullptr)))
|
|
|
|
{
|
|
|
|
ret = false;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2012-11-19 23:06:51 +00:00
|
|
|
if (FAILED(Callback::d3d_err = dev->GetRenderTargetData(target, dest)))
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
|
|
|
ret = false;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3DLOCKED_RECT rect;
|
|
|
|
if (SUCCEEDED(dest->LockRect(&rect, nullptr, D3DLOCK_READONLY)))
|
|
|
|
{
|
|
|
|
unsigned pitchpix = rect.Pitch / 4;
|
|
|
|
const uint32_t *pixels = (const uint32_t*)rect.pBits;
|
|
|
|
pixels += final_viewport.X;
|
|
|
|
pixels += (final_viewport.Height - 1) * pitchpix;
|
|
|
|
pixels -= final_viewport.Y * pitchpix;
|
|
|
|
|
|
|
|
for (unsigned y = 0; y < final_viewport.Height; y++, pixels -= pitchpix)
|
|
|
|
{
|
|
|
|
for (unsigned x = 0; x < final_viewport.Width; x++)
|
|
|
|
{
|
|
|
|
*buffer++ = (pixels[x] >> 0) & 0xff;
|
|
|
|
*buffer++ = (pixels[x] >> 8) & 0xff;
|
|
|
|
*buffer++ = (pixels[x] >> 16) & 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dest->UnlockRect();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = false;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
2012-11-20 17:06:52 +00:00
|
|
|
RARCH_PERFORMANCE_STOP(d3d_read_viewport);
|
2012-10-26 19:09:30 +00:00
|
|
|
if (target)
|
|
|
|
target->Release();
|
|
|
|
if (dest)
|
|
|
|
dest->Release();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::calculate_rect(unsigned width, unsigned height,
|
|
|
|
bool keep, float desired_aspect)
|
|
|
|
{
|
2013-02-17 14:42:33 +00:00
|
|
|
if (g_settings.video.scale_integer)
|
|
|
|
{
|
|
|
|
struct rarch_viewport vp = {0};
|
|
|
|
gfx_scale_integer(&vp, width, height, desired_aspect, keep);
|
|
|
|
set_viewport(vp.x, vp.y, vp.width, vp.height);
|
|
|
|
}
|
|
|
|
else if (!keep)
|
2012-10-26 19:09:30 +00:00
|
|
|
set_viewport(0, 0, width, height);
|
|
|
|
else
|
|
|
|
{
|
2013-04-21 09:20:56 +00:00
|
|
|
if (g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
2013-04-21 12:04:16 +00:00
|
|
|
const rarch_viewport_t &custom = g_extern.console.screen.viewports.custom_vp;
|
2013-04-21 09:20:56 +00:00
|
|
|
set_viewport(custom.x, custom.y, custom.width, custom.height);
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-21 09:20:56 +00:00
|
|
|
float device_aspect = static_cast<float>(width) / static_cast<float>(height);
|
2013-09-12 20:23:56 +00:00
|
|
|
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
2013-04-21 09:20:56 +00:00
|
|
|
set_viewport(0, 0, width, height);
|
|
|
|
else if (device_aspect > desired_aspect)
|
|
|
|
{
|
2013-09-12 20:23:56 +00:00
|
|
|
float delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
|
|
|
|
set_viewport(int(roundf(width * (0.5f - delta))), 0, unsigned(roundf(2.0f * width * delta)), height);
|
2013-04-21 09:20:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-12 20:23:56 +00:00
|
|
|
float delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
|
|
|
|
set_viewport(0, int(roundf(height * (0.5f - delta))), width, unsigned(roundf(2.0f * height * delta)));
|
2013-04-21 09:20:56 +00:00
|
|
|
}
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show_cursor(bool show)
|
|
|
|
{
|
|
|
|
if (show)
|
|
|
|
while (ShowCursor(TRUE) < 0);
|
|
|
|
else
|
|
|
|
while (ShowCursor(FALSE) >= 0);
|
|
|
|
}
|
|
|
|
|
2012-10-30 10:47:37 +00:00
|
|
|
static BOOL CALLBACK monitor_enum_proc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
|
|
|
|
{
|
|
|
|
Monitor::all_hms[Monitor::num_mons++] = hMonitor;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Multi-monitor support.
|
|
|
|
RECT D3DVideo::monitor_rect()
|
|
|
|
{
|
|
|
|
Monitor::num_mons = 0;
|
|
|
|
EnumDisplayMonitors(nullptr, nullptr, monitor_enum_proc, 0);
|
|
|
|
|
|
|
|
if (!Monitor::last_hm)
|
|
|
|
Monitor::last_hm = MonitorFromWindow(GetDesktopWindow(), MONITOR_DEFAULTTONEAREST);
|
|
|
|
HMONITOR hm_to_use = Monitor::last_hm;
|
|
|
|
|
|
|
|
unsigned fs_monitor = g_settings.video.monitor_index;
|
|
|
|
if (fs_monitor && fs_monitor <= Monitor::num_mons && Monitor::all_hms[fs_monitor - 1])
|
2012-10-30 23:04:21 +00:00
|
|
|
{
|
2012-10-30 10:47:37 +00:00
|
|
|
hm_to_use = Monitor::all_hms[fs_monitor - 1];
|
2012-10-30 23:04:21 +00:00
|
|
|
Monitor::cur_mon_id = fs_monitor - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-30 23:40:02 +00:00
|
|
|
for (unsigned i = 0; i < Monitor::num_mons; i++)
|
2012-10-30 23:04:21 +00:00
|
|
|
{
|
2012-10-30 23:40:02 +00:00
|
|
|
if (Monitor::all_hms[i] == hm_to_use)
|
2012-10-30 23:04:21 +00:00
|
|
|
{
|
|
|
|
Monitor::cur_mon_id = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-30 10:47:37 +00:00
|
|
|
|
|
|
|
MONITORINFOEX current_mon;
|
|
|
|
std::memset(¤t_mon, 0, sizeof(current_mon));
|
|
|
|
current_mon.cbSize = sizeof(MONITORINFOEX);
|
|
|
|
GetMonitorInfo(hm_to_use, (MONITORINFO*)¤t_mon);
|
|
|
|
|
|
|
|
return current_mon.rcMonitor;
|
|
|
|
}
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
D3DVideo::D3DVideo(const video_info_t *info) :
|
2012-11-19 23:06:51 +00:00
|
|
|
g_pD3D(nullptr), dev(nullptr), font(nullptr),
|
2013-10-21 11:26:23 +00:00
|
|
|
rotation(0), needs_restore(false), cgCtx(nullptr), overlays_enabled(false)
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
2013-04-21 12:04:16 +00:00
|
|
|
should_resize = false;
|
2012-10-26 19:09:30 +00:00
|
|
|
gfx_set_dwm();
|
|
|
|
|
2013-04-07 17:34:44 +00:00
|
|
|
#ifdef HAVE_RGUI
|
|
|
|
std::memset(&rgui, 0, sizeof(rgui));
|
|
|
|
rgui.tex_coords.x = 0;
|
|
|
|
rgui.tex_coords.y = 0;
|
|
|
|
rgui.tex_coords.w = 1;
|
|
|
|
rgui.tex_coords.h = 1;
|
|
|
|
rgui.vert_coords.x = 0;
|
|
|
|
rgui.vert_coords.y = 1;
|
|
|
|
rgui.vert_coords.w = 1;
|
|
|
|
rgui.vert_coords.h = -1;
|
|
|
|
#endif
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
std::memset(&windowClass, 0, sizeof(windowClass));
|
|
|
|
windowClass.cbSize = sizeof(windowClass);
|
|
|
|
windowClass.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
windowClass.lpfnWndProc = Callback::WindowProc;
|
|
|
|
windowClass.hInstance = nullptr;
|
|
|
|
windowClass.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
|
|
|
windowClass.lpszClassName = "RetroArch";
|
|
|
|
windowClass.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON));
|
|
|
|
windowClass.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, 0);
|
|
|
|
if (!info->fullscreen)
|
|
|
|
windowClass.hbrBackground = (HBRUSH)COLOR_WINDOW;
|
|
|
|
|
|
|
|
RegisterClassEx(&windowClass);
|
2012-10-30 10:47:37 +00:00
|
|
|
RECT mon_rect = monitor_rect();
|
2012-10-26 19:09:30 +00:00
|
|
|
|
2012-10-30 22:49:48 +00:00
|
|
|
bool windowed_full = g_settings.video.windowed_fullscreen;
|
|
|
|
|
|
|
|
unsigned full_x = (windowed_full || info->width == 0) ? (mon_rect.right - mon_rect.left) : info->width;
|
|
|
|
unsigned full_y = (windowed_full || info->height == 0) ? (mon_rect.bottom - mon_rect.top) : info->height;
|
|
|
|
RARCH_LOG("[D3D9]: Monitor size: %dx%d.\n", (int)(mon_rect.right - mon_rect.left), (int)(mon_rect.bottom - mon_rect.top));
|
2012-10-26 19:09:30 +00:00
|
|
|
|
|
|
|
screen_width = info->fullscreen ? full_x : info->width;
|
|
|
|
screen_height = info->fullscreen ? full_y : info->height;
|
|
|
|
|
|
|
|
unsigned win_width = screen_width;
|
|
|
|
unsigned win_height = screen_height;
|
|
|
|
|
|
|
|
if (!info->fullscreen)
|
|
|
|
{
|
2012-10-30 10:47:37 +00:00
|
|
|
RECT rect = {0};
|
|
|
|
rect.right = screen_width;
|
2012-10-26 19:09:30 +00:00
|
|
|
rect.bottom = screen_height;
|
2012-10-30 22:49:48 +00:00
|
|
|
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
|
2012-10-30 10:47:37 +00:00
|
|
|
win_width = rect.right - rect.left;
|
2012-10-26 19:09:30 +00:00
|
|
|
win_height = rect.bottom - rect.top;
|
|
|
|
}
|
|
|
|
|
2013-10-08 20:45:08 +00:00
|
|
|
char buffer[128];
|
|
|
|
gfx_get_fps(buffer, sizeof(buffer), nullptr, 0);
|
2012-10-26 19:09:30 +00:00
|
|
|
std::string title = buffer;
|
|
|
|
title += " || Direct3D9";
|
|
|
|
|
|
|
|
hWnd = CreateWindowEx(0, "RetroArch", title.c_str(),
|
|
|
|
info->fullscreen ?
|
2012-10-30 22:49:48 +00:00
|
|
|
(WS_EX_TOPMOST | WS_POPUP) : WS_OVERLAPPEDWINDOW,
|
2012-10-30 10:47:37 +00:00
|
|
|
info->fullscreen ? mon_rect.left : CW_USEDEFAULT,
|
|
|
|
info->fullscreen ? mon_rect.top : CW_USEDEFAULT,
|
|
|
|
win_width, win_height,
|
2012-10-30 22:49:48 +00:00
|
|
|
nullptr, nullptr, nullptr, this);
|
2012-10-26 19:09:30 +00:00
|
|
|
|
|
|
|
driver.display_type = RARCH_DISPLAY_WIN32;
|
|
|
|
driver.video_display = 0;
|
|
|
|
driver.video_window = (uintptr_t)hWnd;
|
|
|
|
|
2013-03-27 14:55:59 +00:00
|
|
|
show_cursor(!info->fullscreen
|
|
|
|
#ifdef HAVE_OVERLAY
|
2013-10-21 11:26:23 +00:00
|
|
|
|| overlays_enabled
|
2013-03-27 14:55:59 +00:00
|
|
|
#endif
|
|
|
|
);
|
2012-10-26 19:09:30 +00:00
|
|
|
Callback::quit = false;
|
|
|
|
|
|
|
|
ShowWindow(hWnd, SW_RESTORE);
|
|
|
|
UpdateWindow(hWnd);
|
|
|
|
SetForegroundWindow(hWnd);
|
|
|
|
SetFocus(hWnd);
|
|
|
|
|
2012-12-19 20:33:59 +00:00
|
|
|
// This should only be done once here
|
|
|
|
// to avoid set_shader() to be overridden
|
|
|
|
// later.
|
2012-12-19 20:33:10 +00:00
|
|
|
#ifdef HAVE_CG
|
2013-04-07 00:02:41 +00:00
|
|
|
enum rarch_shader_type type = gfx_shader_parse_type(g_settings.video.shader_path, RARCH_SHADER_NONE);
|
|
|
|
if (g_settings.video.shader_enable && type == RARCH_SHADER_CG)
|
|
|
|
cg_shader = g_settings.video.shader_path;
|
2012-12-19 20:33:10 +00:00
|
|
|
#endif
|
|
|
|
|
2013-04-06 19:26:27 +00:00
|
|
|
process_shader();
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
video_info = *info;
|
|
|
|
init(video_info);
|
|
|
|
|
|
|
|
RARCH_LOG("[D3D9]: Init complete.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::deinit()
|
|
|
|
{
|
|
|
|
deinit_font();
|
|
|
|
deinit_chain();
|
|
|
|
deinit_cg();
|
|
|
|
|
|
|
|
needs_restore = false;
|
|
|
|
}
|
|
|
|
|
2013-03-27 14:55:59 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2013-10-21 11:26:23 +00:00
|
|
|
void D3DVideo::free_overlays()
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < overlays.size(); i++)
|
|
|
|
free_overlay(overlays[i]);
|
|
|
|
overlays.clear();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void D3DVideo::free_overlay(overlay_t &overlay)
|
|
|
|
{
|
2013-03-29 10:50:05 +00:00
|
|
|
if (overlay.tex)
|
2013-03-27 14:55:59 +00:00
|
|
|
overlay.tex->Release();
|
2013-03-29 10:50:05 +00:00
|
|
|
if (overlay.vert_buf)
|
2013-03-27 14:55:59 +00:00
|
|
|
overlay.vert_buf->Release();
|
2013-10-21 11:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
D3DVideo::~D3DVideo()
|
|
|
|
{
|
|
|
|
deinit();
|
|
|
|
#ifdef HAVE_OVERLAY
|
|
|
|
free_overlays();
|
2013-04-07 17:34:44 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_RGUI
|
2013-10-21 11:26:23 +00:00
|
|
|
free_overlay(rgui);
|
2013-03-27 14:55:59 +00:00
|
|
|
#endif
|
2012-10-26 19:09:30 +00:00
|
|
|
if (dev)
|
|
|
|
dev->Release();
|
|
|
|
if (g_pD3D)
|
|
|
|
g_pD3D->Release();
|
|
|
|
|
2012-10-30 10:47:37 +00:00
|
|
|
Monitor::last_hm = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
|
2012-10-26 19:09:30 +00:00
|
|
|
DestroyWindow(hWnd);
|
2012-10-30 10:47:37 +00:00
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
UnregisterClass("RetroArch", GetModuleHandle(nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool D3DVideo::restore()
|
|
|
|
{
|
|
|
|
deinit();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
needs_restore = true;
|
|
|
|
init(video_info);
|
|
|
|
needs_restore = false;
|
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[D3D9]: Restore error: (%s).\n", e.what());
|
|
|
|
needs_restore = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !needs_restore;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool D3DVideo::frame(const void *frame,
|
|
|
|
unsigned width, unsigned height, unsigned pitch,
|
|
|
|
const char *msg)
|
|
|
|
{
|
2012-11-10 12:57:21 +00:00
|
|
|
if (!frame)
|
|
|
|
return true;
|
|
|
|
|
2012-11-03 23:14:43 +00:00
|
|
|
RARCH_PERFORMANCE_INIT(d3d_frame);
|
|
|
|
RARCH_PERFORMANCE_START(d3d_frame);
|
2012-10-31 16:30:38 +00:00
|
|
|
// We cannot recover in fullscreen.
|
|
|
|
if (needs_restore && IsIconic(hWnd))
|
|
|
|
return true;
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
if (needs_restore && !restore())
|
|
|
|
{
|
2012-10-31 16:30:38 +00:00
|
|
|
RARCH_ERR("[D3D9]: Failed to restore.\n");
|
2012-10-26 19:09:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-21 12:04:16 +00:00
|
|
|
if (should_resize)
|
|
|
|
{
|
|
|
|
calculate_rect(screen_width, screen_height, video_info.force_aspect, g_extern.system.aspect_ratio);
|
|
|
|
chain->set_final_viewport(final_viewport);
|
|
|
|
recompute_pass_sizes();
|
|
|
|
|
|
|
|
should_resize = false;
|
|
|
|
}
|
|
|
|
|
2013-04-21 12:09:48 +00:00
|
|
|
// render_chain() only clears out viewport, clear out everything.
|
2013-04-21 13:29:44 +00:00
|
|
|
D3DVIEWPORT9 screen_vp;
|
|
|
|
screen_vp.X = 0;
|
|
|
|
screen_vp.Y = 0;
|
|
|
|
screen_vp.MinZ = 0;
|
|
|
|
screen_vp.MaxZ = 1;
|
|
|
|
screen_vp.Width = screen_width;
|
|
|
|
screen_vp.Height = screen_height;
|
|
|
|
dev->SetViewport(&screen_vp);
|
|
|
|
dev->Clear(0, 0, D3DCLEAR_TARGET, 0, 1, 0);
|
2013-04-21 12:09:48 +00:00
|
|
|
|
2013-08-30 07:35:13 +00:00
|
|
|
// Insert black frame first, so we can screenshot, etc.
|
|
|
|
if (g_settings.video.black_frame_insertion)
|
|
|
|
{
|
|
|
|
if (dev->Present(nullptr, nullptr, nullptr, nullptr) != D3D_OK)
|
|
|
|
{
|
|
|
|
needs_restore = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
dev->Clear(0, 0, D3DCLEAR_TARGET, 0, 1, 0);
|
|
|
|
}
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
if (!chain->render(frame, width, height, pitch, rotation))
|
2012-10-31 16:30:38 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("[D3D9]: Failed to render scene.\n");
|
|
|
|
return false;
|
|
|
|
}
|
2012-10-26 19:09:30 +00:00
|
|
|
|
2013-04-07 17:34:44 +00:00
|
|
|
render_msg(msg);
|
|
|
|
|
|
|
|
#ifdef HAVE_RGUI
|
|
|
|
if (rgui.enabled)
|
|
|
|
overlay_render(rgui);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_OVERLAY
|
2013-10-21 11:26:23 +00:00
|
|
|
if (overlays_enabled)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < overlays.size(); i++)
|
|
|
|
overlay_render(overlays[i]);
|
|
|
|
}
|
2013-04-07 17:34:44 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
RARCH_PERFORMANCE_STOP(d3d_frame);
|
|
|
|
|
|
|
|
if (dev->Present(nullptr, nullptr, nullptr, nullptr) != D3D_OK)
|
|
|
|
{
|
|
|
|
needs_restore = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
update_title();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::render_msg(const char *msg, font_params_t *params)
|
|
|
|
{
|
|
|
|
if (params)
|
|
|
|
set_font_rect(params);
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
if (msg && SUCCEEDED(dev->BeginScene()))
|
|
|
|
{
|
|
|
|
font->DrawTextA(nullptr,
|
|
|
|
msg,
|
|
|
|
-1,
|
|
|
|
&font_rect_shifted,
|
|
|
|
DT_LEFT,
|
|
|
|
((font_color >> 2) & 0x3f3f3f) | 0xff000000);
|
|
|
|
|
|
|
|
font->DrawTextA(nullptr,
|
|
|
|
msg,
|
|
|
|
-1,
|
|
|
|
&font_rect,
|
|
|
|
DT_LEFT,
|
|
|
|
font_color | 0xff000000);
|
|
|
|
|
|
|
|
dev->EndScene();
|
|
|
|
}
|
|
|
|
|
2013-04-07 17:34:44 +00:00
|
|
|
if (params)
|
|
|
|
set_font_rect(NULL);
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::set_nonblock_state(bool state)
|
|
|
|
{
|
|
|
|
video_info.vsync = !state;
|
|
|
|
restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool D3DVideo::alive()
|
|
|
|
{
|
|
|
|
process();
|
|
|
|
return !Callback::quit;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool D3DVideo::focus() const
|
|
|
|
{
|
|
|
|
return GetFocus() == hWnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::process()
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-14 00:13:08 +00:00
|
|
|
#ifdef HAVE_CG
|
2012-10-26 19:09:30 +00:00
|
|
|
bool D3DVideo::init_cg()
|
|
|
|
{
|
|
|
|
cgCtx = cgCreateContext();
|
|
|
|
if (cgCtx == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
RARCH_LOG("[D3D9 Cg]: Created context.\n");
|
|
|
|
|
|
|
|
HRESULT ret = cgD3D9SetDevice(dev);
|
|
|
|
if (FAILED(ret))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::deinit_cg()
|
|
|
|
{
|
|
|
|
if (cgCtx)
|
|
|
|
{
|
|
|
|
cgD3D9UnloadAllPrograms();
|
|
|
|
cgD3D9SetDevice(nullptr);
|
|
|
|
cgDestroyContext(cgCtx);
|
|
|
|
cgCtx = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2012-11-14 00:13:08 +00:00
|
|
|
#endif
|
2012-10-26 19:09:30 +00:00
|
|
|
|
2013-04-06 19:26:27 +00:00
|
|
|
void D3DVideo::init_singlepass()
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
2013-04-07 17:34:44 +00:00
|
|
|
std::memset(&shader, 0, sizeof(shader));
|
2013-04-06 19:26:27 +00:00
|
|
|
shader.passes = 1;
|
|
|
|
gfx_shader_pass &pass = shader.pass[0];
|
2013-04-21 12:14:43 +00:00
|
|
|
pass.fbo.valid = true;
|
|
|
|
pass.fbo.scale_x = pass.fbo.scale_y = 1.0;
|
|
|
|
pass.fbo.type_x = pass.fbo.type_y = RARCH_SCALE_VIEWPORT;
|
2013-04-06 19:26:27 +00:00
|
|
|
strlcpy(pass.source.cg, cg_shader.c_str(), sizeof(pass.source.cg));
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
|
2013-04-06 19:26:27 +00:00
|
|
|
void D3DVideo::init_imports()
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
2013-04-07 00:02:41 +00:00
|
|
|
if (!shader.variables)
|
|
|
|
return;
|
|
|
|
|
2012-10-27 10:20:52 +00:00
|
|
|
state_tracker_info tracker_info = {0};
|
|
|
|
|
|
|
|
tracker_info.wram = (uint8_t*)pretro_get_memory_data(RETRO_MEMORY_SYSTEM_RAM);
|
2013-04-06 19:26:27 +00:00
|
|
|
tracker_info.info = shader.variable;
|
|
|
|
tracker_info.info_elem = shader.variables;
|
2012-10-27 10:20:52 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_PYTHON
|
2013-04-07 00:02:41 +00:00
|
|
|
if (*shader.script_path)
|
|
|
|
{
|
|
|
|
tracker_info.script = shader.script_path;
|
|
|
|
tracker_info.script_is_file = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
tracker_info.script_class = *shader.script_class ? shader.script_class : nullptr;
|
2012-10-27 10:20:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
state_tracker_t *state_tracker = state_tracker_init(&tracker_info);
|
|
|
|
if (!state_tracker)
|
|
|
|
throw std::runtime_error("Failed to initialize state tracker.");
|
2012-10-26 19:09:30 +00:00
|
|
|
|
2012-10-27 10:20:52 +00:00
|
|
|
std::shared_ptr<state_tracker_t> tracker(state_tracker, [](state_tracker_t *tracker) {
|
|
|
|
state_tracker_free(tracker);
|
|
|
|
});
|
|
|
|
|
|
|
|
chain->add_state_tracker(tracker);
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
|
2013-04-06 19:26:27 +00:00
|
|
|
void D3DVideo::init_luts()
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
2013-04-06 19:26:27 +00:00
|
|
|
for (unsigned i = 0; i < shader.luts; i++)
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
2013-04-21 09:18:55 +00:00
|
|
|
chain->add_lut(shader.lut[i].id, shader.lut[i].path,
|
|
|
|
shader.lut[i].filter == RARCH_FILTER_UNSPEC ?
|
|
|
|
g_settings.video.smooth :
|
|
|
|
(shader.lut[i].filter == RARCH_FILTER_LINEAR));
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-06 19:26:27 +00:00
|
|
|
void D3DVideo::init_multipass()
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
2013-04-06 19:26:27 +00:00
|
|
|
config_file_t *conf = config_file_new(cg_shader.c_str());
|
|
|
|
if (!conf)
|
|
|
|
throw std::runtime_error("Failed to load preset");
|
|
|
|
|
2013-04-07 17:34:44 +00:00
|
|
|
std::memset(&shader, 0, sizeof(shader));
|
2012-10-26 19:09:30 +00:00
|
|
|
|
2013-04-06 19:26:27 +00:00
|
|
|
if (!gfx_shader_read_conf_cgp(conf, &shader))
|
|
|
|
{
|
|
|
|
config_file_free(conf);
|
|
|
|
throw std::runtime_error("Failed to parse CGP file.");
|
|
|
|
}
|
2012-10-26 19:09:30 +00:00
|
|
|
|
2013-04-06 19:26:27 +00:00
|
|
|
config_file_free(conf);
|
2012-10-26 19:09:30 +00:00
|
|
|
|
2013-04-21 09:18:55 +00:00
|
|
|
gfx_shader_resolve_relative(&shader, cg_shader.c_str());
|
|
|
|
|
2013-04-06 19:26:27 +00:00
|
|
|
RARCH_LOG("[D3D9 Meta-Cg] Found %d shaders.\n", shader.passes);
|
2012-10-26 19:09:30 +00:00
|
|
|
|
2013-04-06 19:26:27 +00:00
|
|
|
for (unsigned i = 0; i < shader.passes; i++)
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
2013-04-06 19:26:27 +00:00
|
|
|
if (!shader.pass[i].fbo.valid)
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
2013-04-06 19:26:27 +00:00
|
|
|
shader.pass[i].fbo.scale_x = shader.pass[i].fbo.scale_y = 1.0f;
|
|
|
|
shader.pass[i].fbo.type_x = shader.pass[i].fbo.type_y = RARCH_SCALE_INPUT;
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-21 12:04:16 +00:00
|
|
|
|
|
|
|
bool use_extra_pass = shader.passes < GFX_MAX_SHADERS && shader.pass[shader.passes - 1].fbo.valid;
|
|
|
|
if (use_extra_pass)
|
|
|
|
{
|
|
|
|
shader.passes++;
|
|
|
|
gfx_shader_pass &dummy_pass = shader.pass[shader.passes - 1];
|
|
|
|
dummy_pass.fbo.scale_x = dummy_pass.fbo.scale_y = 1.0f;
|
|
|
|
dummy_pass.fbo.type_x = dummy_pass.fbo.type_y = RARCH_SCALE_VIEWPORT;
|
|
|
|
dummy_pass.filter = RARCH_FILTER_UNSPEC;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gfx_shader_pass &pass = shader.pass[shader.passes - 1];
|
|
|
|
pass.fbo.scale_x = pass.fbo.scale_y = 1.0f;
|
|
|
|
pass.fbo.type_x = pass.fbo.type_y = RARCH_SCALE_VIEWPORT;
|
|
|
|
}
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
|
2012-10-31 15:28:09 +00:00
|
|
|
bool D3DVideo::set_shader(const std::string &path)
|
|
|
|
{
|
|
|
|
auto old_shader = cg_shader;
|
|
|
|
bool restore_old = false;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
cg_shader = path;
|
2013-04-06 19:26:27 +00:00
|
|
|
process_shader();
|
2012-10-31 15:28:09 +00:00
|
|
|
restore();
|
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[D3D9]: Setting shader failed: (%s).\n", e.what());
|
|
|
|
restore_old = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (restore_old)
|
|
|
|
{
|
|
|
|
cg_shader = old_shader;
|
2013-04-06 19:26:27 +00:00
|
|
|
process_shader();
|
2012-10-31 15:28:09 +00:00
|
|
|
restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
return !restore_old;
|
|
|
|
}
|
|
|
|
|
2013-04-06 19:26:27 +00:00
|
|
|
void D3DVideo::process_shader()
|
|
|
|
{
|
2013-04-21 09:18:55 +00:00
|
|
|
if (strcmp(path_get_extension(cg_shader.c_str()), "cgp") == 0)
|
2013-04-06 19:26:27 +00:00
|
|
|
init_multipass();
|
|
|
|
else
|
|
|
|
init_singlepass();
|
|
|
|
}
|
|
|
|
|
2013-04-21 12:04:16 +00:00
|
|
|
void D3DVideo::recompute_pass_sizes()
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-04-06 19:26:27 +00:00
|
|
|
LinkInfo link_info = {0};
|
2013-04-21 12:04:16 +00:00
|
|
|
link_info.pass = &shader.pass[0];
|
|
|
|
link_info.tex_w = link_info.tex_h = video_info.input_scale * RARCH_SCALE_BASE;
|
2013-04-06 19:26:27 +00:00
|
|
|
|
2013-04-21 12:04:16 +00:00
|
|
|
unsigned current_width = link_info.tex_w;
|
|
|
|
unsigned current_height = link_info.tex_h;
|
|
|
|
unsigned out_width = 0;
|
|
|
|
unsigned out_height = 0;
|
|
|
|
|
|
|
|
chain->set_pass_size(0, current_width, current_height);
|
|
|
|
for (unsigned i = 1; i < shader.passes; i++)
|
2013-04-06 19:26:27 +00:00
|
|
|
{
|
2013-04-21 12:04:16 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
chain->set_pass_size(i, link_info.tex_w, link_info.tex_h);
|
|
|
|
|
|
|
|
current_width = out_width;
|
|
|
|
current_height = out_height;
|
|
|
|
|
|
|
|
link_info.pass = &shader.pass[i];
|
2013-04-06 19:26:27 +00:00
|
|
|
}
|
2013-04-21 12:04:16 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[D3D9]: Render chain error: (%s).\n", e.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool D3DVideo::init_chain(const video_info_t &video_info)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Setup information for first pass.
|
|
|
|
LinkInfo link_info = {0};
|
2013-04-06 19:26:27 +00:00
|
|
|
|
|
|
|
link_info.pass = &shader.pass[0];
|
|
|
|
link_info.tex_w = link_info.tex_h = video_info.input_scale * RARCH_SCALE_BASE;
|
|
|
|
|
|
|
|
chain = std::unique_ptr<RenderChain>(
|
|
|
|
new RenderChain(
|
|
|
|
video_info,
|
|
|
|
dev, cgCtx,
|
|
|
|
link_info,
|
|
|
|
video_info.rgb32 ? RenderChain::ARGB : RenderChain::RGB565,
|
|
|
|
final_viewport));
|
|
|
|
|
|
|
|
unsigned current_width = link_info.tex_w;
|
|
|
|
unsigned current_height = link_info.tex_h;
|
|
|
|
unsigned out_width = 0;
|
|
|
|
unsigned out_height = 0;
|
|
|
|
|
2013-04-07 00:02:41 +00:00
|
|
|
for (unsigned i = 1; i < shader.passes; i++)
|
2013-04-06 19:26:27 +00:00
|
|
|
{
|
|
|
|
RenderChain::convert_geometry(link_info,
|
|
|
|
out_width, out_height,
|
|
|
|
current_width, current_height, final_viewport);
|
|
|
|
|
|
|
|
link_info.pass = &shader.pass[i];
|
|
|
|
link_info.tex_w = next_pow2(out_width);
|
|
|
|
link_info.tex_h = next_pow2(out_height);
|
|
|
|
|
|
|
|
current_width = out_width;
|
|
|
|
current_height = out_height;
|
|
|
|
|
|
|
|
chain->add_pass(link_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
init_luts();
|
|
|
|
init_imports();
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
2012-10-31 15:28:09 +00:00
|
|
|
RARCH_ERR("[D3D9]: Render chain error: (%s).\n", e.what());
|
2012-10-26 19:09:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::deinit_chain()
|
|
|
|
{
|
|
|
|
chain.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool D3DVideo::init_font()
|
|
|
|
{
|
|
|
|
D3DXFONT_DESC desc = {
|
|
|
|
static_cast<int>(g_settings.video.font_size), 0, 400, 0,
|
|
|
|
false, DEFAULT_CHARSET,
|
|
|
|
OUT_TT_PRECIS,
|
|
|
|
CLIP_DEFAULT_PRECIS,
|
|
|
|
DEFAULT_PITCH,
|
|
|
|
"Verdana" // Hardcode ftl :(
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t r = static_cast<uint32_t>(g_settings.video.msg_color_r * 255) & 0xff;
|
|
|
|
uint32_t g = static_cast<uint32_t>(g_settings.video.msg_color_g * 255) & 0xff;
|
|
|
|
uint32_t b = static_cast<uint32_t>(g_settings.video.msg_color_b * 255) & 0xff;
|
|
|
|
font_color = D3DCOLOR_XRGB(r, g, b);
|
|
|
|
|
|
|
|
return SUCCEEDED(D3DXCreateFontIndirect(dev, &desc, &font));
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::deinit_font()
|
|
|
|
{
|
|
|
|
if (font)
|
|
|
|
font->Release();
|
2012-10-31 16:30:38 +00:00
|
|
|
font = nullptr;
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::update_title()
|
|
|
|
{
|
2013-10-07 18:17:07 +00:00
|
|
|
char buffer[128], buffer_fps[128];
|
2013-10-10 23:19:54 +00:00
|
|
|
bool fps_draw = g_settings.fps_show;
|
2013-10-08 20:45:08 +00:00
|
|
|
if (gfx_get_fps(buffer, sizeof(buffer), fps_draw ? buffer_fps : NULL, sizeof(buffer_fps)))
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
|
|
|
std::string title = buffer;
|
|
|
|
title += " || Direct3D9";
|
|
|
|
SetWindowText(hWnd, title.c_str());
|
|
|
|
}
|
2013-04-13 12:28:12 +00:00
|
|
|
|
2013-10-08 20:45:08 +00:00
|
|
|
if (fps_draw)
|
|
|
|
msg_queue_push(g_extern.msg_queue, buffer_fps, 1, 1);
|
|
|
|
|
2013-04-13 12:28:12 +00:00
|
|
|
g_extern.frame_count++;
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
|
2012-10-30 22:49:48 +00:00
|
|
|
void D3DVideo::resize(unsigned new_width, unsigned new_height)
|
|
|
|
{
|
2012-10-30 23:40:02 +00:00
|
|
|
if (!dev)
|
2012-10-30 22:49:48 +00:00
|
|
|
return;
|
|
|
|
|
2012-10-31 16:30:38 +00:00
|
|
|
RARCH_LOG("[D3D9]: Resize %ux%u.\n", new_width, new_height);
|
|
|
|
|
2012-10-30 23:40:02 +00:00
|
|
|
if (new_width != video_info.width || new_height != video_info.height)
|
2012-10-30 22:49:48 +00:00
|
|
|
{
|
|
|
|
video_info.width = screen_width = new_width;
|
|
|
|
video_info.height = screen_height = new_height;
|
|
|
|
restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-27 14:55:59 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2013-10-21 11:26:23 +00:00
|
|
|
bool D3DVideo::overlay_load(const video_overlay_image *images, unsigned num_images)
|
2013-03-27 14:55:59 +00:00
|
|
|
{
|
2013-10-21 11:26:23 +00:00
|
|
|
free_overlays();
|
|
|
|
overlays.resize(num_images);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < num_images; i++)
|
2013-03-27 14:55:59 +00:00
|
|
|
{
|
2013-10-21 11:26:23 +00:00
|
|
|
unsigned width = images[i].width;
|
|
|
|
unsigned height = images[i].height;
|
|
|
|
overlay_t &overlay = overlays[i];
|
|
|
|
if (FAILED(dev->CreateTexture(width, height, 1,
|
|
|
|
0,
|
|
|
|
D3DFMT_A8R8G8B8,
|
|
|
|
D3DPOOL_MANAGED,
|
|
|
|
&overlay.tex, nullptr)))
|
|
|
|
{
|
|
|
|
RARCH_ERR("[D3D9]: Failed to create overlay texture\n");
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-27 14:55:59 +00:00
|
|
|
|
2013-10-21 11:26:23 +00:00
|
|
|
D3DLOCKED_RECT d3dlr;
|
|
|
|
if (SUCCEEDED(overlay.tex->LockRect(0, &d3dlr, nullptr, D3DLOCK_NOSYSLOCK)))
|
|
|
|
{
|
|
|
|
uint32_t *dst = static_cast<uint32_t*>(d3dlr.pBits);
|
|
|
|
const uint32_t *src = images[i].image;
|
|
|
|
unsigned pitch = d3dlr.Pitch >> 2;
|
|
|
|
for (unsigned y = 0; y < height; y++, dst += pitch, src += width)
|
|
|
|
std::memcpy(dst, src, width << 2);
|
|
|
|
overlay.tex->UnlockRect(0);
|
|
|
|
}
|
2013-04-07 17:34:44 +00:00
|
|
|
|
2013-10-21 11:26:23 +00:00
|
|
|
overlay.tex_w = width;
|
|
|
|
overlay.tex_h = height;
|
|
|
|
overlay_tex_geom(i, 0, 0, 1, 1); // Default. Stretch to whole screen.
|
|
|
|
overlay_vertex_geom(i, 0, 0, 1, 1);
|
|
|
|
}
|
2013-03-27 14:55:59 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-21 11:26:23 +00:00
|
|
|
void D3DVideo::overlay_tex_geom(unsigned index, float x, float y, float w, float h)
|
2013-03-27 14:55:59 +00:00
|
|
|
{
|
2013-10-21 11:26:23 +00:00
|
|
|
overlays[index].tex_coords.x = x;
|
|
|
|
overlays[index].tex_coords.y = y;
|
|
|
|
overlays[index].tex_coords.w = w;
|
|
|
|
overlays[index].tex_coords.h = h;
|
2013-03-27 14:55:59 +00:00
|
|
|
}
|
|
|
|
|
2013-10-21 11:26:23 +00:00
|
|
|
void D3DVideo::overlay_vertex_geom(unsigned index, float x, float y, float w, float h)
|
2013-03-27 14:55:59 +00:00
|
|
|
{
|
|
|
|
y = 1.0f - y;
|
|
|
|
h = -h;
|
2013-10-21 11:26:23 +00:00
|
|
|
overlays[index].vert_coords.x = x;
|
|
|
|
overlays[index].vert_coords.y = y;
|
|
|
|
overlays[index].vert_coords.w = w;
|
|
|
|
overlays[index].vert_coords.h = h;
|
2013-03-27 14:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::overlay_enable(bool state)
|
|
|
|
{
|
2013-10-21 11:26:23 +00:00
|
|
|
for (unsigned i = 0; i < overlays.size(); i++)
|
|
|
|
overlays_enabled = state;
|
2013-03-27 14:55:59 +00:00
|
|
|
show_cursor(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3DVideo::overlay_full_screen(bool enable)
|
|
|
|
{
|
2013-10-21 11:26:23 +00:00
|
|
|
for (unsigned i = 0; i < overlays.size(); i++)
|
|
|
|
overlays[i].fullscreen = enable;
|
2013-03-27 14:55:59 +00:00
|
|
|
}
|
|
|
|
|
2013-10-21 11:26:23 +00:00
|
|
|
void D3DVideo::overlay_set_alpha(unsigned index, float mod)
|
2013-03-27 14:55:59 +00:00
|
|
|
{
|
2013-10-21 11:26:23 +00:00
|
|
|
overlays[index].alpha_mod = mod;
|
2013-03-27 14:55:59 +00:00
|
|
|
}
|
2013-04-07 17:34:44 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void D3DVideo::overlay_render(overlay_t &overlay)
|
2013-03-27 17:19:36 +00:00
|
|
|
{
|
2013-04-21 10:07:57 +00:00
|
|
|
if (!overlay.tex)
|
|
|
|
return;
|
|
|
|
|
2013-03-27 17:19:36 +00:00
|
|
|
struct overlay_vertex
|
|
|
|
{
|
2013-03-28 13:29:04 +00:00
|
|
|
float x, y, z;
|
|
|
|
float u, v;
|
2013-03-29 10:48:33 +00:00
|
|
|
float r, g, b, a;
|
2013-03-27 17:19:36 +00:00
|
|
|
} vert[4];
|
|
|
|
|
2013-03-29 10:50:05 +00:00
|
|
|
if (!overlay.vert_buf)
|
2013-03-28 14:33:15 +00:00
|
|
|
{
|
2013-03-27 14:55:59 +00:00
|
|
|
dev->CreateVertexBuffer(
|
2013-03-27 17:19:36 +00:00
|
|
|
sizeof(vert),
|
2013-03-27 14:55:59 +00:00
|
|
|
dev->GetSoftwareVertexProcessing() ? D3DUSAGE_SOFTWAREPROCESSING : 0,
|
|
|
|
0,
|
|
|
|
D3DPOOL_MANAGED,
|
|
|
|
&overlay.vert_buf,
|
|
|
|
nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 4; i++)
|
2013-03-29 10:48:33 +00:00
|
|
|
{
|
2013-03-27 14:55:59 +00:00
|
|
|
vert[i].z = 0.5f;
|
2013-03-29 10:48:33 +00:00
|
|
|
vert[i].r = vert[i].g = vert[i].b = 1.0f;
|
2013-04-07 17:34:44 +00:00
|
|
|
vert[i].a = overlay.alpha_mod;
|
2013-03-29 10:48:33 +00:00
|
|
|
}
|
2013-03-27 14:55:59 +00:00
|
|
|
|
|
|
|
float overlay_width = final_viewport.Width;
|
|
|
|
float overlay_height = final_viewport.Height;
|
|
|
|
|
|
|
|
vert[0].x = overlay.vert_coords.x * overlay_width;
|
|
|
|
vert[1].x = (overlay.vert_coords.x + overlay.vert_coords.w) * overlay_width;
|
|
|
|
vert[2].x = overlay.vert_coords.x * overlay_width;
|
|
|
|
vert[3].x = (overlay.vert_coords.x + overlay.vert_coords.w) * overlay_width;
|
|
|
|
vert[0].y = overlay.vert_coords.y * overlay_height;
|
|
|
|
vert[1].y = overlay.vert_coords.y * overlay_height;
|
|
|
|
vert[2].y = (overlay.vert_coords.y + overlay.vert_coords.h) * overlay_height;
|
|
|
|
vert[3].y = (overlay.vert_coords.y + overlay.vert_coords.h) * overlay_height;
|
|
|
|
|
|
|
|
vert[0].u = overlay.tex_coords.x;
|
|
|
|
vert[1].u = overlay.tex_coords.x + overlay.tex_coords.w;
|
|
|
|
vert[2].u = overlay.tex_coords.x;
|
|
|
|
vert[3].u = overlay.tex_coords.x + overlay.tex_coords.w;
|
|
|
|
vert[0].v = overlay.tex_coords.y;
|
|
|
|
vert[1].v = overlay.tex_coords.y;
|
|
|
|
vert[2].v = overlay.tex_coords.y + overlay.tex_coords.h;
|
|
|
|
vert[3].v = overlay.tex_coords.y + overlay.tex_coords.h;
|
|
|
|
|
|
|
|
// Align texels and vertices.
|
|
|
|
for (unsigned i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
vert[i].x -= 0.5f;
|
|
|
|
vert[i].y += 0.5f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *verts;
|
|
|
|
overlay.vert_buf->Lock(0, sizeof(vert), &verts, 0);
|
|
|
|
std::memcpy(verts, vert, sizeof(vert));
|
|
|
|
overlay.vert_buf->Unlock();
|
|
|
|
|
2013-03-28 13:29:04 +00:00
|
|
|
// enable alpha
|
2013-04-11 11:13:37 +00:00
|
|
|
dev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
|
|
|
|
dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
|
|
|
dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
2013-03-27 14:55:59 +00:00
|
|
|
|
2013-03-28 13:29:04 +00:00
|
|
|
// set vertex decl for overlay
|
|
|
|
D3DVERTEXELEMENT9 vElems[4] = {
|
2013-03-27 17:19:36 +00:00
|
|
|
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
|
|
|
|
{0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
|
2013-03-29 10:48:33 +00:00
|
|
|
{0, 20, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
|
2013-03-27 17:19:36 +00:00
|
|
|
D3DDECL_END()
|
|
|
|
};
|
2013-10-21 11:26:23 +00:00
|
|
|
IDirect3DVertexDeclaration9 *vertex_decl;
|
2013-03-27 17:19:36 +00:00
|
|
|
dev->CreateVertexDeclaration(vElems, &vertex_decl);
|
|
|
|
dev->SetVertexDeclaration(vertex_decl);
|
2013-03-28 13:29:04 +00:00
|
|
|
vertex_decl->Release();
|
2013-03-27 17:19:36 +00:00
|
|
|
|
|
|
|
dev->SetStreamSource(0, overlay.vert_buf, 0, sizeof(overlay_vertex));
|
2013-03-27 14:55:59 +00:00
|
|
|
|
2013-04-07 17:34:44 +00:00
|
|
|
if (overlay.fullscreen)
|
2013-03-27 14:55:59 +00:00
|
|
|
{
|
|
|
|
// set viewport to full window
|
|
|
|
D3DVIEWPORT9 vp_full;
|
|
|
|
vp_full.X = 0;
|
|
|
|
vp_full.Y = 0;
|
|
|
|
vp_full.Width = screen_width;
|
|
|
|
vp_full.Height = screen_height;
|
|
|
|
vp_full.MinZ = 0.0f;
|
|
|
|
vp_full.MaxZ = 1.0f;
|
|
|
|
dev->SetViewport(&vp_full);
|
|
|
|
}
|
2013-03-28 13:29:04 +00:00
|
|
|
|
|
|
|
// render overlay
|
2013-03-27 14:55:59 +00:00
|
|
|
dev->SetTexture(0, overlay.tex);
|
|
|
|
dev->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
|
|
|
|
dev->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
|
|
|
|
dev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
|
|
|
dev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
|
|
|
if (SUCCEEDED(dev->BeginScene()))
|
|
|
|
{
|
|
|
|
dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
|
|
|
dev->EndScene();
|
|
|
|
}
|
2013-03-28 13:29:04 +00:00
|
|
|
|
2013-10-21 11:26:23 +00:00
|
|
|
// restore previous state
|
2013-04-11 11:13:37 +00:00
|
|
|
dev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
|
2013-03-27 14:55:59 +00:00
|
|
|
dev->SetViewport(&final_viewport);
|
|
|
|
}
|
|
|
|
|
2013-04-07 17:34:44 +00:00
|
|
|
#ifdef HAVE_RGUI
|
|
|
|
void D3DVideo::set_rgui_texture_frame(const void *frame,
|
|
|
|
bool rgb32, unsigned width, unsigned height,
|
|
|
|
float alpha)
|
|
|
|
{
|
|
|
|
if (!rgui.tex || rgui.tex_w != width || rgui.tex_h != height)
|
|
|
|
{
|
|
|
|
if (rgui.tex)
|
|
|
|
rgui.tex->Release();
|
|
|
|
if (FAILED(dev->CreateTexture(width, height, 1,
|
2013-04-21 10:07:57 +00:00
|
|
|
0, D3DFMT_A8R8G8B8,
|
2013-04-07 17:34:44 +00:00
|
|
|
D3DPOOL_MANAGED,
|
|
|
|
&rgui.tex, nullptr)))
|
|
|
|
{
|
|
|
|
RARCH_ERR("[D3D9]: Failed to create rgui texture\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rgui.tex_w = width;
|
|
|
|
rgui.tex_h = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
rgui.alpha_mod = alpha;
|
|
|
|
|
|
|
|
|
|
|
|
D3DLOCKED_RECT d3dlr;
|
|
|
|
if (SUCCEEDED(rgui.tex->LockRect(0, &d3dlr, nullptr, D3DLOCK_NOSYSLOCK)))
|
|
|
|
{
|
|
|
|
if (rgb32)
|
2013-04-21 10:07:57 +00:00
|
|
|
{
|
|
|
|
uint8_t *dst = (uint8_t*)d3dlr.pBits;
|
|
|
|
const uint32_t *src = (const uint32_t*)frame;
|
|
|
|
for (unsigned h = 0; h < height; h++, dst += d3dlr.Pitch, src += width)
|
|
|
|
{
|
|
|
|
std::memcpy(dst, src, width * sizeof(uint32_t));
|
|
|
|
std::memset(dst + width * sizeof(uint32_t), 0, d3dlr.Pitch - width * sizeof(uint32_t));
|
|
|
|
}
|
|
|
|
}
|
2013-04-07 17:34:44 +00:00
|
|
|
else
|
|
|
|
{
|
2013-04-21 10:07:57 +00:00
|
|
|
uint32_t *dst = (uint32_t*)d3dlr.pBits;
|
|
|
|
const uint16_t *src = (const uint16_t*)frame;
|
|
|
|
for (unsigned h = 0; h < height; h++, dst += d3dlr.Pitch >> 2, src += width)
|
2013-04-07 17:34:44 +00:00
|
|
|
{
|
|
|
|
for (unsigned w = 0; w < width; w++)
|
|
|
|
{
|
2013-04-21 10:07:57 +00:00
|
|
|
uint16_t c = src[w];
|
|
|
|
uint32_t r = (c >> 12) & 0xf;
|
|
|
|
uint32_t g = (c >> 8) & 0xf;
|
|
|
|
uint32_t b = (c >> 4) & 0xf;
|
|
|
|
uint32_t a = (c >> 0) & 0xf;
|
|
|
|
r = ((r << 4) | r) << 16;
|
|
|
|
g = ((g << 4) | g) << 8;
|
|
|
|
b = ((b << 4) | b) << 0;
|
|
|
|
a = ((a << 4) | a) << 24;
|
|
|
|
dst[w] = r | g | b | a;
|
2013-04-07 17:34:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-21 10:07:57 +00:00
|
|
|
|
2013-04-07 17:34:44 +00:00
|
|
|
rgui.tex->UnlockRect(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-13 14:58:05 +00:00
|
|
|
void D3DVideo::set_rgui_texture_enable(bool state, bool fullscreen)
|
2013-04-07 17:34:44 +00:00
|
|
|
{
|
|
|
|
rgui.enabled = state;
|
2013-04-13 14:58:05 +00:00
|
|
|
rgui.fullscreen = fullscreen;
|
2013-04-07 17:34:44 +00:00
|
|
|
}
|
2013-03-27 14:55:59 +00:00
|
|
|
#endif
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
static void *d3d9_init(const video_info_t *info, const input_driver_t **input,
|
|
|
|
void **input_data)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
D3DVideo *vid = new D3DVideo(info);
|
|
|
|
if (!vid)
|
|
|
|
return nullptr;
|
|
|
|
|
2013-02-16 01:21:43 +00:00
|
|
|
if (input && input_data)
|
|
|
|
{
|
2013-11-05 19:49:04 +00:00
|
|
|
Callback::dinput = input_dinput.init();
|
|
|
|
*input = Callback::dinput ? &input_dinput : nullptr;
|
|
|
|
*input_data = Callback::dinput;
|
2013-02-16 01:21:43 +00:00
|
|
|
}
|
2012-10-26 19:09:30 +00:00
|
|
|
|
|
|
|
return vid;
|
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
2012-11-19 23:06:51 +00:00
|
|
|
RARCH_ERR("[D3D9]: Failed to init D3D9 (%s, code: 0x%x).\n", e.what(), (unsigned)Callback::d3d_err);
|
2012-10-26 19:09:30 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool d3d9_frame(void *data, const void *frame,
|
|
|
|
unsigned width, unsigned height, unsigned pitch,
|
|
|
|
const char *msg)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<D3DVideo*>(data)->frame(frame,
|
|
|
|
width, height, pitch, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_set_nonblock_state(void *data, bool state)
|
|
|
|
{
|
|
|
|
reinterpret_cast<D3DVideo*>(data)->set_nonblock_state(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool d3d9_alive(void *data)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<D3DVideo*>(data)->alive();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool d3d9_focus(void *data)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<D3DVideo*>(data)->focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_set_rotation(void *data, unsigned rot)
|
|
|
|
{
|
|
|
|
reinterpret_cast<D3DVideo*>(data)->set_rotation(rot);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_free(void *data)
|
|
|
|
{
|
|
|
|
delete reinterpret_cast<D3DVideo*>(data);
|
|
|
|
}
|
|
|
|
|
2012-10-27 22:38:31 +00:00
|
|
|
static void d3d9_viewport_info(void *data, struct rarch_viewport *vp)
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
2012-10-27 22:38:31 +00:00
|
|
|
reinterpret_cast<D3DVideo*>(data)->viewport_info(*vp);
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool d3d9_read_viewport(void *data, uint8_t *buffer)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<D3DVideo*>(data)->read_viewport(buffer);
|
|
|
|
}
|
|
|
|
|
2013-04-07 11:00:21 +00:00
|
|
|
static bool d3d9_set_shader(void *data, enum rarch_shader_type type, const char *path)
|
2012-10-31 15:28:09 +00:00
|
|
|
{
|
2013-04-13 15:04:28 +00:00
|
|
|
std::string shader = "";
|
2013-04-21 12:14:43 +00:00
|
|
|
if (path && type == RARCH_SHADER_CG)
|
2013-04-13 15:04:28 +00:00
|
|
|
shader = path;
|
|
|
|
|
|
|
|
return reinterpret_cast<D3DVideo*>(data)->set_shader(shader);
|
2012-10-31 15:28:09 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 17:34:44 +00:00
|
|
|
#if defined(HAVE_RGUI)
|
|
|
|
static void d3d9_get_poke_interface(void *data, const video_poke_interface_t **iface);
|
|
|
|
#endif
|
|
|
|
|
2013-03-27 14:55:59 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2013-10-21 11:26:23 +00:00
|
|
|
static bool d3d9_overlay_load(void *data, const video_overlay_image *images, unsigned num_images)
|
2013-03-27 14:55:59 +00:00
|
|
|
{
|
2013-10-21 11:26:23 +00:00
|
|
|
return reinterpret_cast<D3DVideo*>(data)->overlay_load(images, num_images);
|
2013-03-27 14:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_overlay_tex_geom(void *data,
|
2013-10-21 11:26:23 +00:00
|
|
|
unsigned index,
|
2013-03-27 14:55:59 +00:00
|
|
|
float x, float y,
|
|
|
|
float w, float h)
|
|
|
|
{
|
2013-10-21 11:26:23 +00:00
|
|
|
return reinterpret_cast<D3DVideo*>(data)->overlay_tex_geom(index, x, y, w, h);
|
2013-03-27 14:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_overlay_vertex_geom(void *data,
|
2013-10-21 11:26:23 +00:00
|
|
|
unsigned index,
|
2013-03-27 14:55:59 +00:00
|
|
|
float x, float y,
|
|
|
|
float w, float h)
|
|
|
|
{
|
2013-10-21 11:26:23 +00:00
|
|
|
return reinterpret_cast<D3DVideo*>(data)->overlay_vertex_geom(index, x, y, w, h);
|
2013-03-27 14:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_overlay_enable(void *data, bool state)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<D3DVideo*>(data)->overlay_enable(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_overlay_full_screen(void *data, bool enable)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<D3DVideo*>(data)->overlay_full_screen(enable);
|
|
|
|
}
|
|
|
|
|
2013-10-21 11:26:23 +00:00
|
|
|
static void d3d9_overlay_set_alpha(void *data, unsigned index, float mod)
|
2013-03-27 14:55:59 +00:00
|
|
|
{
|
2013-10-21 11:26:23 +00:00
|
|
|
return reinterpret_cast<D3DVideo*>(data)->overlay_set_alpha(index, mod);
|
2013-03-27 14:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const video_overlay_interface_t d3d9_overlay_interface = {
|
|
|
|
d3d9_overlay_enable,
|
|
|
|
d3d9_overlay_load,
|
|
|
|
d3d9_overlay_tex_geom,
|
|
|
|
d3d9_overlay_vertex_geom,
|
|
|
|
d3d9_overlay_full_screen,
|
|
|
|
d3d9_overlay_set_alpha,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void d3d9_get_overlay_interface(void *data, const video_overlay_interface_t **iface)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
*iface = &d3d9_overlay_interface;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-21 09:20:56 +00:00
|
|
|
static void d3d9_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
|
2013-04-07 17:34:44 +00:00
|
|
|
{
|
2013-04-21 09:20:56 +00:00
|
|
|
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
|
|
|
|
|
|
|
switch (aspect_ratio_idx)
|
|
|
|
{
|
|
|
|
case ASPECT_RATIO_SQUARE:
|
2013-06-05 20:00:38 +00:00
|
|
|
gfx_set_square_pixel_viewport(g_extern.system.av_info.geometry.base_width, g_extern.system.av_info.geometry.base_height);
|
2013-04-21 09:20:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ASPECT_RATIO_CORE:
|
|
|
|
gfx_set_core_viewport();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASPECT_RATIO_CONFIG:
|
|
|
|
gfx_set_config_viewport();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_extern.system.aspect_ratio = aspectratio_lut[aspect_ratio_idx].value;
|
|
|
|
d3d->info().force_aspect = true;
|
2013-04-21 12:04:16 +00:00
|
|
|
d3d->should_resize = true;
|
2013-04-07 17:34:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_apply_state_changes(void *data)
|
|
|
|
{
|
2013-04-21 09:20:56 +00:00
|
|
|
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
2013-04-21 12:04:16 +00:00
|
|
|
d3d->should_resize = true;
|
2013-04-07 17:34:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_set_osd_msg(void *data, const char *msg, void *userdata)
|
|
|
|
{
|
|
|
|
font_params_t *params = (font_params_t*)userdata;
|
2013-04-21 09:20:56 +00:00
|
|
|
reinterpret_cast<D3DVideo*>(data)->render_msg(msg, params);
|
2013-04-07 17:34:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_show_mouse(void *data, bool state)
|
|
|
|
{
|
|
|
|
show_cursor(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_RGUI
|
|
|
|
static void d3d9_set_rgui_texture_frame(void *data,
|
|
|
|
const void *frame, bool rgb32, unsigned width, unsigned height,
|
|
|
|
float alpha)
|
|
|
|
{
|
|
|
|
reinterpret_cast<D3DVideo*>(data)->set_rgui_texture_frame(frame, rgb32, width, height, alpha);
|
|
|
|
}
|
|
|
|
|
2013-04-13 14:48:03 +00:00
|
|
|
static void d3d9_set_rgui_texture_enable(void *data, bool state, bool full_screen)
|
2013-04-07 17:34:44 +00:00
|
|
|
{
|
2013-04-13 14:58:05 +00:00
|
|
|
reinterpret_cast<D3DVideo*>(data)->set_rgui_texture_enable(state, full_screen);
|
2013-04-07 17:34:44 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const video_poke_interface_t d3d9_poke_interface = {
|
2013-04-20 22:54:25 +00:00
|
|
|
NULL,
|
2013-04-07 17:34:44 +00:00
|
|
|
#ifdef HAVE_FBO
|
2013-04-20 22:54:25 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2013-04-07 17:34:44 +00:00
|
|
|
#endif
|
|
|
|
d3d9_set_aspect_ratio,
|
|
|
|
d3d9_apply_state_changes,
|
|
|
|
#ifdef HAVE_RGUI
|
|
|
|
d3d9_set_rgui_texture_frame,
|
|
|
|
d3d9_set_rgui_texture_enable,
|
|
|
|
#endif
|
|
|
|
d3d9_set_osd_msg,
|
|
|
|
|
|
|
|
d3d9_show_mouse,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void d3d9_get_poke_interface(void *data, const video_poke_interface_t **iface)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
*iface = &d3d9_poke_interface;
|
|
|
|
}
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
const video_driver_t video_d3d9 = {
|
|
|
|
d3d9_init,
|
|
|
|
d3d9_frame,
|
|
|
|
d3d9_set_nonblock_state,
|
|
|
|
d3d9_alive,
|
|
|
|
d3d9_focus,
|
|
|
|
d3d9_set_shader,
|
|
|
|
d3d9_free,
|
|
|
|
"d3d9",
|
2013-03-24 01:24:53 +00:00
|
|
|
#ifdef HAVE_RGUI
|
2013-04-21 09:20:56 +00:00
|
|
|
nullptr,
|
2013-03-24 01:24:53 +00:00
|
|
|
#endif
|
2012-10-26 19:09:30 +00:00
|
|
|
d3d9_set_rotation,
|
2012-10-27 22:38:31 +00:00
|
|
|
d3d9_viewport_info,
|
2012-10-26 19:09:30 +00:00
|
|
|
d3d9_read_viewport,
|
2013-03-27 14:55:59 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
|
|
|
d3d9_get_overlay_interface,
|
|
|
|
#endif
|
2013-04-07 17:34:44 +00:00
|
|
|
d3d9_get_poke_interface
|
2012-10-26 19:09:30 +00:00
|
|
|
};
|