RetroArch/gfx/common/d3d_common.c

3045 lines
73 KiB
C
Raw Normal View History

2014-09-11 23:05:58 +02:00
/* RetroArch - A frontend for libretro.
2017-01-22 13:40:32 +01:00
* Copyright (C) 2011-2017 - Daniel De Matteis
*
2014-09-11 23:05:58 +02: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/>.
*/
/* For Xbox we will just link statically
* to Direct3D libraries instead. */
#if !defined(_XBOX) && defined(HAVE_DYLIB)
#define HAVE_DYNAMIC_D3D
#endif
#ifdef HAVE_DYNAMIC_D3D
#include <dynamic/dylib.h>
#endif
2016-01-09 07:14:46 +01:00
#include "../../configuration.h"
2015-11-23 12:03:38 +01:00
#include "../../verbosity.h"
2015-11-09 01:06:35 +01:00
2015-11-18 13:00:13 +01:00
#include "d3d_common.h"
2014-09-11 23:05:58 +02:00
2017-09-05 00:57:58 +02:00
#if defined(HAVE_D3D9)
2018-01-25 15:30:48 +01:00
#include <d3d9.h>
2018-01-20 07:04:21 +01:00
2018-01-25 15:30:48 +01:00
#ifdef HAVE_D3DX
2018-01-20 07:04:21 +01:00
#ifdef _XBOX
#include <d3dx9core.h>
#include <d3dx9tex.h>
#else
#include "../include/d3d9/d3dx9tex.h"
2018-01-20 07:04:21 +01:00
#endif
2018-01-25 15:30:48 +01:00
#endif
#endif
2018-01-20 07:04:21 +01:00
2018-01-25 15:30:48 +01:00
#if defined(HAVE_D3D8)
#include <d3d8.h>
#ifdef HAVE_D3DX
2018-01-20 07:04:21 +01:00
#ifdef _XBOX
#include <d3dx8core.h>
#include <d3dx8tex.h>
#else
2017-09-05 00:57:58 +02:00
#include "../include/d3d8/d3dx8tex.h"
2016-12-07 06:59:24 +01:00
#endif
2018-01-20 07:04:21 +01:00
#endif
#endif
2018-01-23 04:25:37 +01:00
static enum gfx_ctx_api d3d_common_api = GFX_CTX_NONE;
2018-01-23 02:55:33 +01:00
2017-10-16 01:33:17 +02:00
#ifdef _XBOX
#include <xgraphics.h>
#endif
2018-01-03 18:38:13 +01:00
static UINT SDKVersion = 0;
#ifdef HAVE_DYNAMIC_D3D
static dylib_t g_d3d_dll;
2018-01-04 14:42:13 +01:00
#ifdef HAVE_D3DX
2018-01-03 19:55:00 +01:00
static dylib_t g_d3dx_dll;
2018-01-04 14:42:13 +01:00
#endif
2018-01-03 19:55:00 +01:00
static bool dylib_initialized = false;
#endif
2018-01-03 18:38:13 +01:00
#if defined(HAVE_D3D9)
typedef IDirect3D9 *(__stdcall *D3DCreate_t)(UINT);
2018-01-04 14:42:13 +01:00
#ifdef HAVE_D3DX
2018-01-07 20:32:43 +01:00
typedef HRESULT (__stdcall
*D3DCompileShader_t)(
LPCSTR pSrcData,
UINT srcDataLen,
const D3DXMACRO *pDefines,
LPD3DXINCLUDE pInclude,
LPCSTR pFunctionName,
LPCSTR pProfile,
DWORD Flags,
LPD3DXBUFFER *ppShader,
LPD3DXBUFFER *ppErrorMsgs,
LPD3DXCONSTANTTABLE *ppConstantTable);
2018-01-07 11:52:32 +01:00
typedef HRESULT (__stdcall
*D3DCompileShaderFromFile_t)(
LPCTSTR pSrcFile,
const D3DXMACRO *pDefines,
LPD3DXINCLUDE pInclude,
LPCSTR pFunctionName,
LPCSTR pProfile,
DWORD Flags,
LPD3DXBUFFER *ppShader,
LPD3DXBUFFER *ppErrorMsgs,
LPD3DXCONSTANTTABLE *ppConstantTable);
2018-01-03 19:55:00 +01:00
typedef HRESULT (__stdcall
*D3DCreateTextureFromFile_t)(
LPDIRECT3DDEVICE9 pDevice,
LPCSTR pSrcFile,
UINT Width,
UINT Height,
UINT MipLevels,
DWORD Usage,
D3DFORMAT Format,
D3DPOOL Pool,
DWORD Filter,
DWORD MipFilter,
D3DCOLOR ColorKey,
D3DXIMAGE_INFO* pSrcInfo,
PALETTEENTRY* pPalette,
LPDIRECT3DTEXTURE9* ppTexture);
2018-01-03 20:26:13 +01:00
typedef HRESULT (__stdcall
*D3DXCreateFontIndirect_t)(
LPDIRECT3DDEVICE9 pDevice,
D3DXFONT_DESC* pDesc,
LPD3DXFONT* ppFont);
2018-01-04 14:42:13 +01:00
#endif
2018-01-03 18:38:13 +01:00
#elif defined(HAVE_D3D8)
typedef IDirect3D8 *(__stdcall *D3DCreate_t)(UINT);
2018-01-04 14:42:13 +01:00
#ifdef HAVE_D3DX
typedef HRESULT (__stdcall
*D3DCreateTextureFromFile_t)(
LPDIRECT3DDEVICE8 pDevice,
LPCSTR pSrcFile,
UINT Width,
UINT Height,
UINT MipLevels,
DWORD Usage,
D3DFORMAT Format,
D3DPOOL Pool,
DWORD Filter,
DWORD MipFilter,
D3DCOLOR ColorKey,
D3DXIMAGE_INFO* pSrcInfo,
PALETTEENTRY* pPalette,
2018-01-03 19:55:00 +01:00
LPDIRECT3DTEXTURE8* ppTexture);
typedef HRESULT (__stdcall
*D3DXCreateFontIndirect_t)(
2018-01-03 20:16:19 +01:00
LPDIRECT3DDEVICE8 pDevice,
CONST LOGFONT* pDesc,
2018-01-03 19:55:00 +01:00
LPD3DXFONT* ppFont);
2018-01-03 20:26:13 +01:00
#endif
2018-01-04 14:42:13 +01:00
#endif
2018-01-03 20:26:13 +01:00
2018-01-03 18:38:13 +01:00
2018-01-04 14:42:13 +01:00
#ifdef HAVE_D3DX
static D3DXCreateFontIndirect_t D3DCreateFontIndirect;
2018-01-03 19:55:00 +01:00
static D3DCreateTextureFromFile_t D3DCreateTextureFromFile;
2018-01-07 11:52:32 +01:00
#ifdef HAVE_D3D9
static D3DCompileShaderFromFile_t D3DCompileShaderFromFile;
2018-01-07 20:32:43 +01:00
static D3DCompileShader_t D3DCompileShader;
2018-01-07 11:52:32 +01:00
#endif
2018-01-04 14:42:13 +01:00
#endif
2018-01-03 18:38:13 +01:00
static D3DCreate_t D3DCreate;
2018-01-03 18:09:31 +01:00
void *d3d_create(void)
{
2018-01-03 18:38:13 +01:00
return D3DCreate(SDKVersion);
}
2018-01-03 19:55:00 +01:00
#ifdef HAVE_DYNAMIC_D3D
2018-01-21 06:41:54 +01:00
#ifdef HAVE_D3DX
static const char *d3dx9_dll_list[] =
{
"d3dx9_24.dll",
"d3dx9_25.dll",
"d3dx9_26.dll",
"d3dx9_27.dll",
"d3dx9_28.dll",
"d3dx9_29.dll",
"d3dx9_30.dll",
"d3dx9_31.dll",
"d3dx9_32.dll",
"d3dx9_33.dll",
"d3dx9_34.dll",
"d3dx9_35.dll",
"d3dx9_36.dll",
"d3dx9_37.dll",
"d3dx9_38.dll",
"d3dx9_39.dll",
"d3dx9_40.dll",
"d3dx9_41.dll",
"d3dx9_42.dll",
"d3dx9_43.dll",
NULL
};
static dylib_t dylib_load_d3dx(void)
2018-01-03 19:55:00 +01:00
{
2018-01-21 06:41:54 +01:00
dylib_t dll = NULL;
2018-01-03 19:55:00 +01:00
#if defined(HAVE_D3D9)
2018-01-21 06:41:54 +01:00
const char **dll_name = d3dx9_dll_list;
while (!dll && *dll_name)
dll = dylib_load(*dll_name++);
2018-01-03 19:55:00 +01:00
#endif
return dll;
}
#endif
2018-01-21 06:41:54 +01:00
#endif
2018-01-23 04:25:37 +01:00
bool d3d_initialize_symbols(enum gfx_ctx_api api)
2018-01-03 18:38:13 +01:00
{
2018-01-04 17:00:21 +01:00
#ifdef HAVE_DYNAMIC_D3D
2018-01-03 19:55:00 +01:00
if (dylib_initialized)
return true;
2018-01-23 02:55:33 +01:00
switch (api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
#if defined(HAVE_D3D9)
2018-01-07 10:46:30 +01:00
#if defined(DEBUG) || defined(_DEBUG)
2018-01-23 02:55:33 +01:00
g_d3d_dll = dylib_load("d3d9d.dll");
if(!g_d3d_dll)
2018-01-07 10:46:30 +01:00
#endif
2018-01-23 02:55:33 +01:00
g_d3d_dll = dylib_load("d3d9.dll");
2018-01-04 14:42:13 +01:00
#ifdef HAVE_D3DX
2018-01-23 02:55:33 +01:00
g_d3dx_dll = dylib_load_d3dx();
2018-01-23 02:55:33 +01:00
if (!g_d3dx_dll)
return false;
2018-01-23 03:20:14 +01:00
#endif
2018-01-04 14:42:13 +01:00
#endif
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-23 03:20:14 +01:00
#if defined(HAVE_D3D8)
2018-01-07 10:46:30 +01:00
#if defined(DEBUG) || defined(_DEBUG)
2018-01-23 02:55:33 +01:00
g_d3d_dll = dylib_load("d3d8d.dll");
if(!g_d3d_dll)
#endif
g_d3d_dll = dylib_load("d3d8.dll");
2018-01-07 10:46:30 +01:00
#endif
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
if (!g_d3d_dll)
return false;
#endif
2018-01-23 02:55:33 +01:00
d3d_common_api = api;
#ifdef HAVE_DYNAMIC_D3D
2018-01-04 14:42:13 +01:00
#ifdef HAVE_D3DX
2018-01-03 19:55:00 +01:00
#ifdef UNICODE
D3DCreateFontIndirect = (D3DXCreateFontIndirect_t)dylib_proc(g_d3dx_dll, "D3DXCreateFontIndirectW");
#else
D3DCreateFontIndirect = (D3DXCreateFontIndirect_t)dylib_proc(g_d3dx_dll, "D3DXCreateFontIndirectA");
#endif
D3DCreateTextureFromFile = (D3DCreateTextureFromFile_t)dylib_proc(g_d3dx_dll, "D3DXCreateTextureFromFileExA");
2018-01-07 11:52:32 +01:00
D3DCompileShaderFromFile = (D3DCompileShaderFromFile_t)dylib_proc(g_d3dx_dll, "D3DXCompileShaderFromFile");
2018-01-07 20:32:43 +01:00
D3DCompileShader = (D3DCompileShader_t)dylib_proc(g_d3dx_dll, "D3DXCompileShader");
2018-01-04 14:42:13 +01:00
#endif
#else
2018-01-04 14:42:13 +01:00
#ifdef HAVE_D3DX
2018-01-03 19:55:00 +01:00
D3DCreateFontIndirect = D3DXCreateFontIndirect;
D3DCreateTextureFromFile = D3DXCreateTextureFromFileExA;
2018-01-07 11:52:32 +01:00
D3DCompileShaderFromFile = D3DXCompileShaderFromFile;
2018-01-07 20:32:43 +01:00
D3DCompileShader = D3DXCompileShader;
#endif
2018-01-04 14:42:13 +01:00
#endif
2018-01-23 02:55:33 +01:00
switch (api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-23 02:55:33 +01:00
SDKVersion = 31;
#ifdef HAVE_D3D9
#ifdef HAVE_DYNAMIC_D3D
2018-01-23 02:55:33 +01:00
D3DCreate = (D3DCreate_t)dylib_proc(g_d3d_dll, "Direct3DCreate9");
#else
2018-01-23 02:55:33 +01:00
D3DCreate = Direct3DCreate9;
#endif
#endif
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-23 02:55:33 +01:00
SDKVersion = 220;
#ifdef HAVE_D3D8
#ifdef HAVE_DYNAMIC_D3D
D3DCreate = (D3DCreate_t)dylib_proc(g_d3d_dll, "Direct3DCreate8");
2018-01-04 14:42:13 +01:00
#ifdef HAVE_D3DX
2018-01-23 02:55:33 +01:00
D3DCreateFontIndirect = D3DXCreateFontIndirect;
D3DCreateTextureFromFile = D3DXCreateTextureFromFileExA;
#endif
2018-01-23 02:55:33 +01:00
#else
D3DCreate = Direct3DCreate8;
2018-01-04 14:42:13 +01:00
#endif
2018-01-03 18:14:54 +01:00
#endif
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2018-01-03 18:38:13 +01:00
if (!D3DCreate)
goto error;
2018-01-03 18:38:13 +01:00
#ifdef _XBOX
2018-01-23 02:55:33 +01:00
SDKVersion = 0;
2018-01-03 18:09:31 +01:00
#endif
2018-01-04 17:00:21 +01:00
#ifdef HAVE_DYNAMIC_D3D
2018-01-03 19:55:00 +01:00
dylib_initialized = true;
2018-01-04 17:00:21 +01:00
#endif
2018-01-03 18:38:13 +01:00
return true;
error:
2018-01-03 19:55:00 +01:00
d3d_deinitialize_symbols();
return false;
2018-01-03 18:38:13 +01:00
}
void d3d_deinitialize_symbols(void)
{
2018-01-04 17:00:21 +01:00
#ifdef HAVE_DYNAMIC_D3D
2018-01-03 19:55:00 +01:00
if (g_d3d_dll)
dylib_close(g_d3d_dll);
2018-01-04 14:42:13 +01:00
#ifdef HAVE_D3DX
2018-01-03 19:55:00 +01:00
if (g_d3dx_dll)
dylib_close(g_d3dx_dll);
2018-01-23 02:55:33 +01:00
g_d3dx_dll = NULL;
2018-01-04 14:42:13 +01:00
#endif
2018-01-23 02:55:33 +01:00
g_d3d_dll = NULL;
2018-01-03 19:55:00 +01:00
dylib_initialized = false;
2018-01-04 17:00:21 +01:00
#endif
2018-01-23 04:25:37 +01:00
d3d_common_api = GFX_CTX_NONE;
2018-01-03 18:09:31 +01:00
}
2018-01-25 04:12:16 +01:00
bool d3d_check_device_type(void *_d3d,
2018-01-06 19:41:55 +01:00
unsigned idx,
2018-01-25 15:30:48 +01:00
INT32 disp_format,
INT32 backbuffer_format,
2018-01-06 19:41:55 +01:00
bool windowed_mode)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 04:12:16 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 04:12:16 +01:00
LPDIRECT3D9 d3d = (LPDIRECT3D9)_d3d;
if (!d3d)
return false;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 04:12:16 +01:00
if (FAILED(d3d->CheckDeviceType(
0,
D3DDEVTYPE_HAL,
2018-01-25 15:30:48 +01:00
(D3DFORMAT)disp_format,
(D3DFORMAT)backbuffer_format,
2018-01-25 04:12:16 +01:00
windowed_mode)))
return false;
2018-01-23 02:55:33 +01:00
#else
2018-01-25 04:12:16 +01:00
if (FAILED(IDirect3D9_CheckDeviceType(d3d,
0,
D3DDEVTYPE_HAL,
2018-01-25 15:30:48 +01:00
(D3DFORMAT)disp_format,
(D3DFORMAT)backbuffer_format,
2018-01-25 04:12:16 +01:00
windowed_mode)))
return false;
2018-01-06 19:41:55 +01:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 04:12:16 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 04:12:16 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 04:12:16 +01:00
LPDIRECT3D8 d3d = (LPDIRECT3D8)_d3d;
if (!d3d)
return false;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 04:12:16 +01:00
if (FAILED(d3d->CheckDeviceType(
0,
D3DDEVTYPE_HAL,
2018-01-25 15:54:37 +01:00
(D3DFORMAT)disp_format,
(D3DFORMAT)backbuffer_format,
2018-01-25 04:12:16 +01:00
windowed_mode)))
return false;
2018-01-23 02:55:33 +01:00
#else
2018-01-25 04:12:16 +01:00
if (FAILED(IDirect3D8_CheckDeviceType(d3d,
0,
D3DDEVTYPE_HAL,
disp_format,
backbuffer_format,
windowed_mode)))
return false;
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 04:12:16 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
return false;
}
2018-01-06 19:41:55 +01:00
return true;
}
2018-01-25 04:12:16 +01:00
bool d3d_get_adapter_display_mode(
void *_d3d,
2018-01-06 16:10:05 +01:00
unsigned idx,
2018-01-25 15:30:48 +01:00
void *display_mode)
2018-01-06 16:10:05 +01:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 04:12:16 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 04:12:16 +01:00
LPDIRECT3D9 d3d = (LPDIRECT3D9)_d3d;
if (!d3d)
return false;
2018-01-06 21:10:30 +01:00
#ifdef _XBOX
2018-01-25 04:12:16 +01:00
return true;
2018-01-23 02:55:33 +01:00
#elif defined(__cplusplus)
2018-01-25 15:30:48 +01:00
if (FAILED(d3d->GetAdapterDisplayMode(idx, (D3DDISPLAYMODE*)display_mode)))
2018-01-25 04:12:16 +01:00
return false;
2018-01-06 21:10:30 +01:00
#else
2018-01-25 15:30:48 +01:00
if (FAILED(IDirect3D9_GetAdapterDisplayMode(d3d, idx, (D3DDISPLAYMODE*)display_mode)))
2018-01-25 04:12:16 +01:00
return false;
2018-01-06 21:10:30 +01:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 04:12:16 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 04:12:16 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 04:12:16 +01:00
LPDIRECT3D8 d3d = (LPDIRECT3D8)_d3d;
if (!d3d)
return false;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 15:30:48 +01:00
if (FAILED(d3d->GetAdapterDisplayMode(idx, (D3DDISPLAYMODE*)display_mode)))
2018-01-25 04:12:16 +01:00
return false;
2018-01-06 16:10:05 +01:00
#else
2018-01-25 15:30:48 +01:00
if (FAILED(IDirect3D8_GetAdapterDisplayMode(d3d, idx, (D3DDISPLAYMODE*)display_mode)))
2018-01-25 04:12:16 +01:00
return false;
2018-01-23 02:55:33 +01:00
#endif
2018-01-06 16:10:05 +01:00
#endif
2018-01-25 04:12:16 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
return false;
}
2018-01-06 16:10:05 +01:00
return true;
}
2018-01-25 01:45:03 +01:00
bool d3d_swap(void *data, void *_dev)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
#ifdef _XBOX
2018-01-25 01:45:03 +01:00
dev->Present(NULL, NULL, NULL, NULL);
#else
2018-01-25 01:45:03 +01:00
if (dev->Present(NULL, NULL, NULL, NULL) != D3D_OK)
return false;
#endif
2014-09-11 23:05:58 +02:00
#else
2018-01-23 02:55:33 +01:00
#ifdef _XBOX
2018-01-25 01:45:03 +01:00
IDirect3DDevice9_Present(dev, NULL, NULL, NULL, NULL);
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
if (IDirect3DDevice9_Present(dev, NULL, NULL, NULL, NULL)
== D3DERR_DEVICELOST)
return false;
2014-09-11 23:05:58 +02:00
#endif
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if (dev->Present(NULL, NULL, NULL, NULL) != D3D_OK)
return false;
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
if (IDirect3DDevice8_Present(dev, NULL, NULL, NULL, NULL)
== D3DERR_DEVICELOST)
return false;
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
return true;
2014-09-11 23:05:58 +02:00
}
2018-01-25 01:45:03 +01:00
void d3d_set_transform(void *_dev,
2018-01-25 15:30:48 +01:00
INT32 state, const void *_matrix)
2014-09-13 21:50:07 +02:00
{
2018-01-25 15:30:48 +01:00
CONST D3DMATRIX *matrix = (CONST D3DMATRIX*)_matrix;
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
/* XBox 360 D3D9 does not support fixed-function pipeline. */
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
#ifndef _XBOX
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 15:30:48 +01:00
dev->SetTransform((D3DTRANSFORMSTATETYPE)state, matrix);
#else
2018-01-25 15:30:48 +01:00
IDirect3DDevice9_SetTransform(dev, (D3DTRANSFORMSTATETYPE)state, matrix);
2014-09-13 21:50:07 +02:00
#endif
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 15:30:48 +01:00
dev->SetTransform((D3DTRANSFORMSTATETYPE)state, matrix);
2018-01-23 02:55:33 +01:00
#else
2018-01-25 15:30:48 +01:00
IDirect3DDevice8_SetTransform(dev, (D3DTRANSFORMSTATETYPE)state, matrix);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2014-09-13 21:50:07 +02:00
}
2018-01-25 04:28:50 +01:00
bool d3d_texture_get_level_desc(void *_tex,
2017-10-03 04:18:27 +02:00
unsigned idx, void *_ppsurface_level)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 04:28:50 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 04:28:50 +01:00
LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)_tex;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 04:28:50 +01:00
if (SUCCEEDED(tex->GetLevelDesc(idx, (D3DSURFACE_DESC*)_ppsurface_level)))
return true;
2018-01-23 02:55:33 +01:00
#else
2017-10-03 04:21:08 +02:00
#if defined(_XBOX)
2018-01-25 04:28:50 +01:00
D3DTexture_GetLevelDesc(tex, idx, (D3DSURFACE_DESC*)_ppsurface_level);
2018-01-23 02:55:33 +01:00
return true;
2018-01-25 04:28:50 +01:00
#else
if (SUCCEEDED(IDirect3DTexture9_GetLevelDesc(tex, idx, (D3DSURFACE_DESC*)_ppsurface_level)))
return true;
2017-10-03 04:21:08 +02:00
#endif
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 04:28:50 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 04:28:50 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 04:28:50 +01:00
LPDIRECT3DTEXTURE8 tex = (LPDIRECT3DTEXTURE8)_tex;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 04:28:50 +01:00
if (SUCCEEDED(tex->GetLevelDesc(idx, (D3DSURFACE_DESC*)_ppsurface_level)))
return true;
2017-10-03 04:18:27 +02:00
#else
2018-01-25 04:28:50 +01:00
if (SUCCEEDED(IDirect3DTexture8_GetLevelDesc(tex, idx, (D3DSURFACE_DESC*)_ppsurface_level)))
return true;
2017-10-03 04:18:27 +02:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 04:28:50 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2017-10-03 04:18:27 +02:00
return false;
}
2018-01-25 04:28:50 +01:00
bool d3d_texture_get_surface_level(void *_tex,
2017-10-03 02:45:06 +02:00
unsigned idx, void **_ppsurface_level)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 04:28:50 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 04:28:50 +01:00
LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)_tex;
if (!tex)
return false;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
if (SUCCEEDED(tex->GetSurfaceLevel(idx, (IDirect3DSurface9**)_ppsurface_level)))
2018-01-25 04:28:50 +01:00
return true;
2017-10-03 02:45:06 +02:00
#else
2018-01-25 04:28:50 +01:00
if (SUCCEEDED(IDirect3DTexture9_GetSurfaceLevel(tex, idx, (IDirect3DSurface9**)_ppsurface_level)))
return true;
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 04:28:50 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 04:28:50 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 04:28:50 +01:00
LPDIRECT3DTEXTURE8 tex = (LPDIRECT3DTEXTURE8)_tex;
if (!tex)
return false;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
if (SUCCEEDED(tex->GetSurfaceLevel(idx, (IDirect3DSurface8**)_ppsurface_level)))
2018-01-25 04:28:50 +01:00
return true;
2018-01-23 02:55:33 +01:00
#else
2018-01-25 04:28:50 +01:00
if (SUCCEEDED(IDirect3DTexture8_GetSurfaceLevel(tex, idx, (IDirect3DSurface8**)_ppsurface_level)))
return true;
2018-01-23 02:55:33 +01:00
#endif
2017-10-03 02:45:06 +02:00
#endif
2018-01-25 04:28:50 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2017-10-03 02:45:06 +02:00
return false;
}
2018-01-04 14:42:13 +01:00
#ifdef HAVE_D3DX
2018-01-25 04:28:50 +01:00
static void *d3d_texture_new_from_file(
2018-01-25 01:45:03 +01:00
void *dev,
2018-01-04 14:42:13 +01:00
const char *path, unsigned width, unsigned height,
unsigned miplevels, unsigned usage, D3DFORMAT format,
2018-01-25 15:30:48 +01:00
INT32 pool, unsigned filter, unsigned mipfilter,
INT32 color_key, void *src_info_data,
2018-01-04 14:42:13 +01:00
PALETTEENTRY *palette)
{
2018-01-25 04:28:50 +01:00
void *buf = NULL;
HRESULT hr = E_FAIL;
2018-01-04 14:42:13 +01:00
2018-01-25 04:28:50 +01:00
switch (d3d_common_api)
{
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
#if defined(HAVE_D3D9)
2018-01-25 04:28:50 +01:00
hr = D3DCreateTextureFromFile((LPDIRECT3DDEVICE9)dev,
path, width, height, miplevels, usage, format,
2018-01-25 16:33:28 +01:00
(D3DPOOL)pool, filter, mipfilter, color_key,
(D3DXIMAGE_INFO*)src_info_data,
2018-01-25 04:28:50 +01:00
palette, (struct IDirect3DTexture9**)&buf);
2018-01-25 01:45:03 +01:00
#endif
2018-01-25 04:28:50 +01:00
break;
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
#if defined(HAVE_D3D8)
2018-01-25 04:28:50 +01:00
hr = D3DCreateTextureFromFile((LPDIRECT3DDEVICE8)dev,
path, width, height, miplevels, usage, format,
2018-01-25 16:33:28 +01:00
(D3DPOOL)pool, filter, mipfilter, color_key, src_info_data,
2018-01-25 04:28:50 +01:00
palette, (struct IDirect3DTeture8**)&buf);
2018-01-25 01:45:03 +01:00
#endif
2018-01-25 04:28:50 +01:00
break;
default:
break;
2018-01-25 01:45:03 +01:00
}
2018-01-04 14:42:13 +01:00
2018-01-25 04:28:50 +01:00
if (FAILED(hr))
return NULL;
2018-01-04 14:42:13 +01:00
return buf;
}
#endif
2018-01-25 04:28:50 +01:00
void *d3d_texture_new(void *_dev,
const char *path, unsigned width, unsigned height,
2018-01-25 15:30:48 +01:00
unsigned miplevels, unsigned usage, INT32 format,
INT32 pool, unsigned filter, unsigned mipfilter,
INT32 color_key, void *src_info_data,
PALETTEENTRY *palette, bool want_mipmap)
{
2018-01-23 02:55:33 +01:00
HRESULT hr = S_OK;
2018-01-25 04:28:50 +01:00
void *buf = NULL;
2015-03-16 18:33:47 +01:00
if (path)
2018-01-23 02:55:33 +01:00
{
#ifdef HAVE_D3DX
2018-01-25 01:45:03 +01:00
return d3d_texture_new_from_file(_dev,
2018-01-04 14:42:13 +01:00
path, width, height, miplevels,
2018-01-25 16:33:28 +01:00
usage, (D3DFORMAT)format,
(D3DPOOL)pool, filter, mipfilter,
2018-01-04 14:42:13 +01:00
color_key, src_info_data, palette);
#else
return NULL;
#endif
2018-01-23 02:55:33 +01:00
}
2018-01-04 14:42:13 +01:00
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
2018-01-23 02:55:33 +01:00
#ifndef _XBOX
2018-01-25 01:45:03 +01:00
if (want_mipmap)
usage |= D3DUSAGE_AUTOGENMIPMAP;
2018-01-23 02:55:33 +01:00
#endif
2018-01-04 14:42:13 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
hr = dev->CreateTexture(
width, height, miplevels, usage,
2018-01-25 16:33:28 +01:00
(D3DFORMAT)format,
(D3DPOOL)pool,
(struct IDirect3DTexture9**)&buf, NULL);
2017-09-29 17:32:06 +02:00
#else
2018-01-25 01:45:03 +01:00
hr = IDirect3DDevice9_CreateTexture(dev,
width, height, miplevels, usage,
2018-01-25 16:33:28 +01:00
(D3DFORMAT)format,
(D3DPOOL)pool,
2018-01-25 15:30:48 +01:00
(struct IDirect3DTexture9**)&buf, NULL);
2018-01-04 14:42:13 +01:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
2018-01-04 14:42:13 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
hr = dev->CreateTexture(
width, height, miplevels, usage,
2018-01-25 15:54:37 +01:00
(D3DFORMAT)format, (D3DPOOL)pool, (IDirect3DTexture8**)&buf);
2018-01-04 14:42:13 +01:00
#else
2018-01-25 01:45:03 +01:00
hr = IDirect3DDevice8_CreateTexture(dev,
width, height, miplevels, usage,
2018-01-25 15:54:37 +01:00
(D3DFORMAT)format, (D3DPOOL)pool, (struct IDirect3DTexture8**)&buf);
2014-09-13 18:53:19 +02:00
#endif
2017-09-29 17:32:06 +02:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
if (FAILED(hr))
2018-01-04 14:42:13 +01:00
return NULL;
return buf;
}
2018-01-25 04:28:50 +01:00
void d3d_texture_free(void *_tex)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 04:28:50 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 04:28:50 +01:00
LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)_tex;
if (!tex)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 04:28:50 +01:00
tex->Release();
2018-01-23 02:55:33 +01:00
#else
2018-01-25 04:28:50 +01:00
IDirect3DTexture9_Release(tex);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 04:28:50 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 04:28:50 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 04:28:50 +01:00
LPDIRECT3DTEXTURE8 tex = (LPDIRECT3DTEXTURE8)_tex;
if (!tex)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 04:28:50 +01:00
tex->Release();
#else
2018-01-25 04:28:50 +01:00
IDirect3DTexture8_Release(tex);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 04:28:50 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
}
2017-10-02 00:45:33 +02:00
bool d3d_surface_lock_rect(void *data, void *data2)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 14:34:20 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 14:34:20 +01:00
LPDIRECT3DSURFACE9 surf = (LPDIRECT3DSURFACE9)data;
if (!surf)
return false;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 14:34:20 +01:00
if (FAILED(surf->LockRect((D3DLOCKED_RECT*)data2, NULL, D3DLOCK_READONLY)))
return false;
2018-01-23 02:55:33 +01:00
#else
#if defined(_XBOX)
2018-01-25 14:34:20 +01:00
IDirect3DSurface9_LockRect(surf, (D3DLOCKED_RECT*)data2, NULL, D3DLOCK_READONLY);
#else
2018-01-25 14:34:20 +01:00
if (FAILED(IDirect3DSurface9_LockRect(surf, (D3DLOCKED_RECT*)data2, NULL, D3DLOCK_READONLY)))
return false;
#endif
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 14:34:20 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 14:34:20 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 14:34:20 +01:00
LPDIRECT3DSURFACE8 surf = (LPDIRECT3DSURFACE8)data;
if (!surf)
return false;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 14:34:20 +01:00
if (FAILED(surf->LockRect((D3DLOCKED_RECT*)data2, NULL, D3DLOCK_READONLY)))
return false;
2017-10-02 00:45:33 +02:00
#else
2018-01-25 14:34:20 +01:00
if (FAILED(IDirect3DSurface8_LockRect(surf, (D3DLOCKED_RECT*)data2, NULL, D3DLOCK_READONLY)))
return false;
2018-01-23 02:55:33 +01:00
#endif
2017-10-02 00:45:33 +02:00
#endif
2018-01-25 14:34:20 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2017-10-02 00:45:33 +02:00
return true;
}
void d3d_surface_unlock_rect(void *data)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
2017-10-02 00:45:33 +02:00
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 14:34:20 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 14:34:20 +01:00
LPDIRECT3DSURFACE9 surf = (LPDIRECT3DSURFACE9)data;
if (!surf)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 14:34:20 +01:00
surf->UnlockRect();
2018-01-23 02:55:33 +01:00
#else
2018-01-25 14:34:20 +01:00
IDirect3DSurface9_UnlockRect(surf);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 14:34:20 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 14:34:20 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 14:34:20 +01:00
LPDIRECT3DSURFACE8 surf = (LPDIRECT3DSURFACE8)data;
if (!surf)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 14:34:20 +01:00
surf->UnlockRect();
2017-10-02 00:45:33 +02:00
#else
2018-01-25 14:34:20 +01:00
IDirect3DSurface8_UnlockRect(surf);
2017-10-02 00:45:33 +02:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 14:34:20 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
2017-10-02 00:45:33 +02:00
}
}
2017-10-01 22:28:48 +02:00
void d3d_surface_free(void *data)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 14:34:20 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 14:34:20 +01:00
LPDIRECT3DSURFACE9 surf = (LPDIRECT3DSURFACE9)data;
if (!surf)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 14:34:20 +01:00
surf->Release();
2018-01-23 02:55:33 +01:00
#else
2018-01-25 14:34:20 +01:00
IDirect3DSurface9_Release(surf);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 14:34:20 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 14:34:20 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 14:34:20 +01:00
LPDIRECT3DSURFACE8 surf = (LPDIRECT3DSURFACE8)data;
if (!surf)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 14:34:20 +01:00
surf->Release();
2017-10-01 22:28:48 +02:00
#else
2018-01-25 14:34:20 +01:00
IDirect3DSurface8_Release(surf);
2018-01-23 02:55:33 +01:00
#endif
2017-10-01 22:28:48 +02:00
#endif
2018-01-25 14:34:20 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2017-10-01 22:28:48 +02:00
}
void d3d_vertex_declaration_free(void *data)
{
2018-01-03 13:59:15 +01:00
if (!data)
return;
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
2018-01-03 13:59:42 +01:00
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
#ifdef __cplusplus
{
2018-01-25 14:34:20 +01:00
LPDIRECT3DVERTEXDECLARATION9 vertex_decl =
(LPDIRECT3DVERTEXDECLARATION9)data;
2018-01-23 02:55:33 +01:00
if (vertex_decl)
vertex_decl->Release();
}
#else
2018-01-25 14:34:20 +01:00
IDirect3DVertexDeclaration9_Release((LPDIRECT3DVERTEXDECLARATION9)data);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
}
2018-01-25 01:45:03 +01:00
bool d3d_vertex_declaration_new(void *_dev,
2015-11-12 01:38:13 +01:00
const void *vertex_data, void **decl_data)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2017-09-05 00:21:41 +02:00
#ifdef HAVE_D3D9
2018-01-23 02:55:33 +01:00
{
2018-01-25 14:34:20 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
const D3DVERTEXELEMENT9 *vertex_elements = (const D3DVERTEXELEMENT9*)vertex_data;
LPDIRECT3DVERTEXDECLARATION9 **vertex_decl = (LPDIRECT3DVERTEXDECLARATION9**)decl_data;
2017-09-29 17:40:27 +02:00
#if defined(__cplusplus)
2018-01-23 02:55:33 +01:00
if (SUCCEEDED(dev->CreateVertexDeclaration(vertex_elements, (IDirect3DVertexDeclaration9**)vertex_decl)))
return true;
2017-09-29 17:40:27 +02:00
#else
2018-01-23 02:55:33 +01:00
if (SUCCEEDED(IDirect3DDevice9_CreateVertexDeclaration(dev, vertex_elements, (IDirect3DVertexDeclaration9**)vertex_decl)))
return true;
2018-01-03 18:23:04 +01:00
#endif
2018-01-23 02:55:33 +01:00
}
2015-11-12 01:38:13 +01:00
#endif
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2015-11-12 01:38:13 +01:00
return false;
}
2018-01-25 14:34:20 +01:00
void *d3d_vertex_buffer_new(void *_dev,
unsigned length, unsigned usage,
2018-01-25 15:30:48 +01:00
unsigned fvf, INT32 pool, void *handle)
2014-09-11 23:05:58 +02:00
{
2018-01-25 14:34:20 +01:00
HRESULT hr = S_OK;
void *buf = NULL;
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
if (usage == 0)
{
2018-01-23 02:55:33 +01:00
#ifndef _XBOX
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if (dev->GetSoftwareVertexProcessing())
usage = D3DUSAGE_SOFTWAREPROCESSING;
#else
2018-01-25 01:45:03 +01:00
if (IDirect3DDevice9_GetSoftwareVertexProcessing(dev))
usage = D3DUSAGE_SOFTWAREPROCESSING;
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 16:33:28 +01:00
hr = dev->CreateVertexBuffer(length, usage, fvf,
(D3DPOOL)pool,
(LPDIRECT3DVERTEXBUFFER9*)&buf, NULL);
2018-01-23 02:55:33 +01:00
#else
2018-01-25 16:33:28 +01:00
hr = IDirect3DDevice9_CreateVertexBuffer(dev, length, usage, fvf,
(D3DPOOL)pool,
2018-01-25 14:34:20 +01:00
(LPDIRECT3DVERTEXBUFFER9*)&buf, NULL);
2015-04-07 03:32:10 +02:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 15:54:37 +01:00
hr = dev->CreateVertexBuffer(length, usage, fvf, (D3DPOOL)pool, (IDirect3DVertexBuffer8**)&buf);
2014-09-11 23:05:58 +02:00
#else
2018-01-25 16:33:28 +01:00
hr = IDirect3DDevice8_CreateVertexBuffer(dev, length, usage, fvf,
(D3DPOOL)pool,
2018-01-25 14:38:24 +01:00
(struct IDirect3DVertexBuffer8**)&buf);
2018-01-23 02:55:33 +01:00
#endif
2014-09-11 23:05:58 +02:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
if (FAILED(hr))
return NULL;
return buf;
2014-09-11 23:05:58 +02:00
}
2016-10-20 05:00:20 +02:00
void d3d_vertex_buffer_unlock(void *vertbuf_ptr)
2014-09-13 19:56:52 +02:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 14:34:20 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 14:34:20 +01:00
LPDIRECT3DVERTEXBUFFER9 vertbuf = (LPDIRECT3DVERTEXBUFFER9)vertbuf_ptr;
if (!vertbuf)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 14:34:20 +01:00
vertbuf->Unlock();
2017-09-29 17:32:06 +02:00
#else
2018-01-25 14:34:20 +01:00
IDirect3DVertexBuffer9_Unlock(vertbuf);
2014-09-13 19:56:52 +02:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 14:34:20 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 14:34:20 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 14:34:20 +01:00
LPDIRECT3DVERTEXBUFFER8 vertbuf = (LPDIRECT3DVERTEXBUFFER8)vertbuf_ptr;
if (!vertbuf)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 14:34:20 +01:00
vertbuf->Unlock();
2018-01-23 02:55:33 +01:00
#else
2018-01-25 14:34:20 +01:00
IDirect3DVertexBuffer8_Unlock(vertbuf);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 14:34:20 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
}
2016-10-20 05:00:20 +02:00
void *d3d_vertex_buffer_lock(void *vertbuf_ptr)
2014-09-13 19:33:06 +02:00
{
2018-01-25 14:34:20 +01:00
void *buf = NULL;
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 14:34:20 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 14:34:20 +01:00
LPDIRECT3DVERTEXBUFFER9 vertbuf = (LPDIRECT3DVERTEXBUFFER9)vertbuf_ptr;
if (!vertbuf)
return NULL;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 14:34:20 +01:00
vertbuf->Lock(0, 0, &buf, 0);
2017-09-29 17:32:06 +02:00
#else
2018-01-25 14:34:20 +01:00
IDirect3DVertexBuffer9_Lock(vertbuf, 0, 0, &buf, 0);
2014-09-13 19:33:06 +02:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 14:34:20 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 14:34:20 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 14:34:20 +01:00
LPDIRECT3DVERTEXBUFFER8 vertbuf = (LPDIRECT3DVERTEXBUFFER8)vertbuf_ptr;
if (!vertbuf)
return NULL;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 15:54:37 +01:00
vertbuf->Lock(0, 0, (BYTE**)&buf, 0);
2018-01-23 02:55:33 +01:00
#else
2018-01-25 14:34:20 +01:00
IDirect3DVertexBuffer8_Lock(vertbuf, 0, 0, (BYTE**)&buf, 0);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 14:34:20 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2014-09-13 19:33:06 +02:00
if (!buf)
return NULL;
return buf;
}
void d3d_vertex_buffer_free(void *vertex_data, void *vertex_declaration)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
if (vertex_data)
{
2018-01-25 14:34:20 +01:00
LPDIRECT3DVERTEXBUFFER9 buf = (LPDIRECT3DVERTEXBUFFER9)vertex_data;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
buf->Release();
2017-09-29 17:40:27 +02:00
#else
2018-01-23 02:55:33 +01:00
IDirect3DVertexBuffer9_Release(buf);
2017-09-29 17:40:27 +02:00
#endif
2018-01-23 02:55:33 +01:00
buf = NULL;
}
2018-01-23 02:55:33 +01:00
if (vertex_declaration)
{
2018-01-25 14:34:20 +01:00
LPDIRECT3DVERTEXDECLARATION9 vertex_decl = (LPDIRECT3DVERTEXDECLARATION9)vertex_declaration;
2018-01-23 02:55:33 +01:00
d3d_vertex_declaration_free(vertex_decl);
vertex_decl = NULL;
}
#endif
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
if (vertex_data)
{
2018-01-25 14:38:24 +01:00
LPDIRECT3DVERTEXBUFFER8 buf = (LPDIRECT3DVERTEXBUFFER8)vertex_data;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
buf->Release();
#else
IDirect3DVertexBuffer8_Release(buf);
#endif
buf = NULL;
}
#endif
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
}
2018-01-25 01:45:03 +01:00
void d3d_set_stream_source(void *_dev, unsigned stream_no,
2016-10-20 05:00:20 +02:00
void *stream_vertbuf_ptr, unsigned offset_bytes,
2014-09-11 23:05:58 +02:00
unsigned stride)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
2018-01-25 14:34:20 +01:00
LPDIRECT3DVERTEXBUFFER9 stream_vertbuf = (LPDIRECT3DVERTEXBUFFER9)stream_vertbuf_ptr;
if (!stream_vertbuf)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->SetStreamSource(stream_no, stream_vertbuf, offset_bytes, stride);
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice9_SetStreamSource(dev, stream_no, stream_vertbuf,
offset_bytes,
stride);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
2018-01-25 14:34:20 +01:00
LPDIRECT3DVERTEXBUFFER8 stream_vertbuf = (LPDIRECT3DVERTEXBUFFER8)stream_vertbuf_ptr;
if (!stream_vertbuf)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->SetStreamSource(stream_no, stream_vertbuf, offset_bytes, stride);
2014-09-11 23:05:58 +02:00
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice8_SetStreamSource(dev, stream_no, stream_vertbuf, stride);
2014-09-11 23:05:58 +02:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2014-09-11 23:05:58 +02:00
}
bool d3d_device_create_offscreen_plain_surface(
2018-01-25 01:45:03 +01:00
void *_dev,
unsigned width,
unsigned height,
unsigned format,
unsigned pool,
void **surf_data,
void *data)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifndef _XBOX
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(dev->CreateOffscreenPlainSurface(width, height,
(D3DFORMAT)format, (D3DPOOL)pool,
2018-01-25 14:34:20 +01:00
(LPDIRECT3DSURFACE9*)surf_data,
2018-01-25 01:45:03 +01:00
(HANDLE*)data)))
return true;
#else
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(IDirect3DDevice9_CreateOffscreenPlainSurface(dev,
width, height,
(D3DFORMAT)format, (D3DPOOL)pool,
2018-01-25 14:34:20 +01:00
(LPDIRECT3DSURFACE9*)surf_data,
2018-01-25 01:45:03 +01:00
(HANDLE*)data)))
return true;
#endif
2017-10-02 00:48:31 +02:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2017-10-02 00:48:31 +02:00
return false;
}
2018-01-25 01:45:03 +01:00
static void d3d_set_texture_stage_state(void *_dev,
unsigned sampler, unsigned type, unsigned value)
2017-10-02 00:30:14 +02:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
/* XBox 360 has no fixed-function pipeline. */
2018-01-23 02:55:33 +01:00
#ifndef _XBOX
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if (dev->SetTextureStageState(sampler, (D3DTEXTURESTAGESTATETYPE)type, value) != D3D_OK)
RARCH_ERR("SetTextureStageState call failed, sampler: %d, value: %d, type: %d\n", sampler, value, type);
2017-10-02 00:30:14 +02:00
#else
2018-01-25 01:45:03 +01:00
if (IDirect3DDevice9_SetTextureStageState(dev, sampler, (D3DTEXTURESTAGESTATETYPE)type, value) != D3D_OK)
RARCH_ERR("SetTextureStageState call failed, sampler: %d, value: %d, type: %d\n", sampler, value, type);
2018-01-23 02:55:33 +01:00
#endif
2017-10-02 00:30:14 +02:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if (dev->SetTextureStageState(sampler, (D3DTEXTURESTAGESTATETYPE)type, value) != D3D_OK)
RARCH_ERR("SetTextureStageState call failed, sampler: %d, value: %d, type: %d\n", sampler, value, type);
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
if (IDirect3DDevice8_SetTextureStageState(dev, sampler, (D3DTEXTURESTAGESTATETYPE)type, value) != D3D_OK)
RARCH_ERR("SetTextureStageState call failed, sampler: %d, value: %d, type: %d\n", sampler, value, type);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
}
2017-10-02 00:30:14 +02:00
2018-01-25 01:45:03 +01:00
void d3d_set_sampler_address_u(void *_dev,
unsigned sampler, unsigned value)
2014-09-11 23:05:58 +02:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->SetSamplerState(sampler, D3DSAMP_ADDRESSU, value);
2014-09-11 23:05:58 +02:00
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice9_SetSamplerState(dev, sampler, D3DSAMP_ADDRESSU, value);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
d3d_set_texture_stage_state(dev, sampler, D3DTSS_ADDRESSU, value);
2014-09-11 23:05:58 +02:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2014-09-11 23:05:58 +02:00
}
2018-01-25 01:45:03 +01:00
void d3d_set_sampler_address_v(void *_dev,
unsigned sampler, unsigned value)
2014-09-11 23:05:58 +02:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->SetSamplerState(sampler, D3DSAMP_ADDRESSV, value);
2014-09-11 23:05:58 +02:00
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice9_SetSamplerState(dev, sampler, D3DSAMP_ADDRESSV, value);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
d3d_set_texture_stage_state(dev, sampler, D3DTSS_ADDRESSV, value);
2014-09-11 23:05:58 +02:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2014-09-11 23:05:58 +02:00
}
2018-01-25 01:45:03 +01:00
void d3d_set_sampler_minfilter(void *_dev,
unsigned sampler, unsigned value)
2014-09-11 23:05:58 +02:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
if (!dev)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->SetSamplerState(sampler, D3DSAMP_MINFILTER, value);
2014-09-11 23:05:58 +02:00
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice9_SetSamplerState(dev, sampler, D3DSAMP_MINFILTER, value);
2018-01-23 02:55:33 +01:00
#endif
2014-09-11 23:05:58 +02:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:53:45 +01:00
d3d_set_texture_stage_state(_dev, sampler, D3DTSS_MINFILTER, value);
2018-01-23 02:55:33 +01:00
#endif
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2014-09-11 23:05:58 +02:00
}
2018-01-25 01:45:03 +01:00
void d3d_set_sampler_magfilter(void *_dev,
unsigned sampler, unsigned value)
2014-09-11 23:05:58 +02:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
if (!dev)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->SetSamplerState(sampler, D3DSAMP_MAGFILTER, value);
2014-09-11 23:05:58 +02:00
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice9_SetSamplerState(dev, sampler, D3DSAMP_MAGFILTER, value);
2014-09-11 23:05:58 +02:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:53:45 +01:00
d3d_set_texture_stage_state(_dev, sampler, D3DTSS_MAGFILTER, value);
2018-01-23 02:55:33 +01:00
#endif
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2014-09-11 23:05:58 +02:00
}
2018-01-25 01:45:03 +01:00
void d3d_set_sampler_mipfilter(void *_dev,
unsigned sampler, unsigned value)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
if (!dev)
return;
IDirect3DDevice9_SetSamplerState(dev, sampler,
D3DSAMP_MIPFILTER, value);
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
}
2018-01-25 01:45:03 +01:00
bool d3d_begin_scene(void *_dev)
2017-10-02 01:15:23 +02:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
if (!dev)
return false;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if (FAILED(dev->BeginScene()))
return false;
2018-01-23 02:55:33 +01:00
#else
#if defined(_XBOX)
2018-01-25 01:45:03 +01:00
IDirect3DDevice9_BeginScene(dev);
#else
2018-01-25 01:45:03 +01:00
if (FAILED(IDirect3DDevice9_BeginScene(dev)))
return false;
#endif
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
if (!dev)
return false;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
#ifdef _XBOX
2018-01-25 01:45:03 +01:00
dev->BeginScene();
2017-10-02 01:15:23 +02:00
#else
2018-01-25 01:45:03 +01:00
if (FAILED(dev->BeginScene()))
return false;
2018-01-23 02:55:33 +01:00
#endif
#else
#ifdef _XBOX
2018-01-25 01:45:03 +01:00
IDirect3DDevice8_BeginScene(dev);
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
if (FAILED(IDirect3DDevice8_BeginScene(dev)))
return false;
2018-01-23 02:55:33 +01:00
#endif
#endif
2017-10-02 01:15:23 +02:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
return true;
2017-10-02 01:15:23 +02:00
}
2018-01-25 01:45:03 +01:00
void d3d_end_scene(void *_dev)
2017-10-02 01:15:23 +02:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
if (!dev)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->EndScene();
2017-10-02 01:15:23 +02:00
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice9_EndScene(dev);
2018-01-23 02:55:33 +01:00
#endif
2017-10-02 01:15:23 +02:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
if (!dev)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->EndScene();
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice8_EndScene(dev);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2017-10-02 01:15:23 +02:00
}
2018-01-25 01:45:03 +01:00
static void d3d_draw_primitive_internal(void *_dev,
2017-10-02 01:15:23 +02:00
D3DPRIMITIVETYPE type, unsigned start, unsigned count)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
if (!dev)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->DrawPrimitive(type, start, count);
2017-10-02 01:15:23 +02:00
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice9_DrawPrimitive(dev, type, start, count);
2018-01-23 02:55:33 +01:00
#endif
2017-10-02 01:15:23 +02:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
if (!dev)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->DrawPrimitive(type, start, count);
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice8_DrawPrimitive(dev, type, start, count);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2017-10-02 01:15:23 +02:00
}
2018-01-25 01:45:03 +01:00
void d3d_draw_primitive(void *dev,
2018-01-25 15:30:48 +01:00
INT32 type, unsigned start, unsigned count)
2014-09-11 23:05:58 +02:00
{
if (!d3d_begin_scene(dev))
return;
2018-01-25 15:54:37 +01:00
d3d_draw_primitive_internal(dev, (D3DPRIMITIVETYPE)type, start, count);
d3d_end_scene(dev);
2014-09-11 23:05:58 +02:00
}
2018-01-25 01:45:03 +01:00
void d3d_clear(void *_dev,
2018-01-25 15:30:48 +01:00
unsigned count, const void *rects, unsigned flags,
INT32 color, float z, unsigned stencil)
2014-09-13 20:09:55 +02:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
if (!dev)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 15:30:48 +01:00
dev->Clear(count, (const D3DRECT*)rects, flags, color, z, stencil);
2014-09-13 20:09:55 +02:00
#else
2018-01-25 15:30:48 +01:00
IDirect3DDevice9_Clear(dev, count, (const D3DRECT*)rects, flags,
2018-01-25 01:45:03 +01:00
color, z, stencil);
2014-09-13 20:09:55 +02:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
if (!dev)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 15:30:48 +01:00
dev->Clear(count, (const D3DRECT*)rects, flags, color, z, stencil);
2018-01-23 02:55:33 +01:00
#else
2018-01-25 15:30:48 +01:00
IDirect3DDevice8_Clear(dev, count, (const D3DRECT*)rects, flags,
2018-01-25 01:45:03 +01:00
color, z, stencil);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2014-09-13 20:09:55 +02:00
}
2018-01-25 01:45:03 +01:00
bool d3d_device_get_render_target_data(void *_dev,
void *_src, void *_dst)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
#ifndef _XBOX
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 14:34:20 +01:00
LPDIRECT3DSURFACE9 src = (LPDIRECT3DSURFACE9)_src;
LPDIRECT3DSURFACE9 dst = (LPDIRECT3DSURFACE9)_dst;
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
2018-01-25 01:45:03 +01:00
if (!dev)
return false;
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(dev->GetRenderTargetData(src, dst)))
return true;
#else
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(IDirect3DDevice9_GetRenderTargetData(
dev, src, dst)))
return true;
#endif
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
return false;
}
2018-01-25 01:45:03 +01:00
bool d3d_device_get_render_target(void *_dev,
2017-10-01 22:38:30 +02:00
unsigned idx, void **data)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
if (!dev)
return false;
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(dev->GetRenderTarget(idx,
2018-01-25 14:34:20 +01:00
(LPDIRECT3DSURFACE9*)data)))
2018-01-25 01:45:03 +01:00
return true;
#else
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(IDirect3DDevice9_GetRenderTarget(dev,
2018-01-25 14:34:20 +01:00
idx, (LPDIRECT3DSURFACE9*)data)))
2018-01-25 01:45:03 +01:00
return true;
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
if (!dev)
return false;
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(dev->GetRenderTarget(
2018-01-25 14:34:20 +01:00
(LPDIRECT3DSURFACE8*)data)))
2018-01-25 01:45:03 +01:00
return true;
2017-10-01 22:38:30 +02:00
#else
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(IDirect3DDevice8_GetRenderTarget(dev,
2018-01-25 14:34:20 +01:00
(LPDIRECT3DSURFACE8*)data)))
2018-01-25 01:45:03 +01:00
return true;
2017-10-01 22:38:30 +02:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
return false;
2017-10-01 22:38:30 +02:00
}
2018-01-25 04:28:50 +01:00
bool d3d_lock_rectangle(void *_tex,
2018-01-25 15:30:48 +01:00
unsigned level, void *_lr, RECT *rect,
unsigned rectangle_height, unsigned flags)
2014-09-11 23:05:58 +02:00
{
2018-01-25 15:30:48 +01:00
D3DLOCKED_RECT *lr = (D3DLOCKED_RECT*)_lr;
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 04:28:50 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 04:28:50 +01:00
LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)_tex;
if (!tex)
return false;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 15:30:48 +01:00
if (FAILED(tex->LockRect(level, lr, rect, flags)))
2018-01-25 04:28:50 +01:00
return false;
2018-01-23 02:55:33 +01:00
#else
#ifdef _XBOX
2018-01-25 15:30:48 +01:00
IDirect3DTexture9_LockRect(tex, level, lr, (const RECT*)rect, flags);
#else
2018-01-25 15:30:48 +01:00
if (IDirect3DTexture9_LockRect(tex, level, lr, (const RECT*)rect, flags) != D3D_OK)
2018-01-25 04:28:50 +01:00
return false;
#endif
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 04:28:50 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 04:28:50 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 04:28:50 +01:00
LPDIRECT3DTEXTURE8 tex = (LPDIRECT3DTEXTURE8)_tex;
if (!tex)
return false;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 15:30:48 +01:00
if (FAILED(tex->LockRect(level, lr, rect, flags)))
2018-01-25 04:28:50 +01:00
return false;
2014-09-11 23:05:58 +02:00
#else
2018-01-25 15:30:48 +01:00
if (IDirect3DTexture8_LockRect(tex, level, lr, rect, flags) != D3D_OK)
2018-01-25 04:28:50 +01:00
return false;
2018-01-23 02:55:33 +01:00
#endif
2015-11-09 15:34:16 +01:00
#endif
2018-01-25 04:28:50 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
return true;
2015-11-09 15:34:16 +01:00
}
2018-01-25 04:28:50 +01:00
void d3d_unlock_rectangle(void *_tex)
2015-11-09 15:34:16 +01:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 04:28:50 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 04:28:50 +01:00
LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)_tex;
if (!tex)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 04:28:50 +01:00
tex->UnlockRect(0);
#else
2018-01-25 04:28:50 +01:00
IDirect3DTexture9_UnlockRect(tex, 0);
2018-01-23 02:55:33 +01:00
#endif
2015-11-09 15:34:16 +01:00
#endif
2018-01-25 04:28:50 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 04:28:50 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 04:28:50 +01:00
LPDIRECT3DTEXTURE8 tex = (LPDIRECT3DTEXTURE8)_tex;
if (!tex)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 04:28:50 +01:00
tex->UnlockRect(0);
2018-01-23 02:55:33 +01:00
#else
2018-01-25 04:28:50 +01:00
IDirect3DTexture8_UnlockRect(tex, 0);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 04:28:50 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2015-11-09 15:34:16 +01:00
}
2018-01-25 04:28:50 +01:00
void d3d_lock_rectangle_clear(void *tex,
2018-01-25 15:30:48 +01:00
unsigned level, void *_lr, RECT *rect,
2015-11-09 15:34:16 +01:00
unsigned rectangle_height, unsigned flags)
{
2018-01-25 15:30:48 +01:00
D3DLOCKED_RECT *lr = (D3DLOCKED_RECT*)_lr;
2015-11-09 15:34:16 +01:00
#if defined(_XBOX)
level = 0;
2014-09-11 23:05:58 +02:00
#endif
2018-01-25 15:30:48 +01:00
memset(lr->pBits, level, rectangle_height * lr->Pitch);
2015-11-09 15:39:47 +01:00
d3d_unlock_rectangle(tex);
2014-09-11 23:05:58 +02:00
}
2018-01-25 10:03:34 +01:00
void d3d_set_viewports(void *_dev, void *_vp)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
2018-01-25 10:03:34 +01:00
D3DVIEWPORT9 *vp = (D3DVIEWPORT9*)_vp;
2018-01-25 01:45:03 +01:00
if (!dev)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->SetViewport(vp);
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice9_SetViewport(dev, vp);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
2018-01-25 10:03:34 +01:00
D3DVIEWPORT8 *vp = (D3DVIEWPORT8*)_vp;
2018-01-25 01:45:03 +01:00
if (!dev)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->SetViewport(vp);
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice8_SetViewport(dev, vp);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
}
2018-01-25 01:45:03 +01:00
void d3d_set_texture(void *_dev, unsigned sampler,
void *tex_data)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 04:28:50 +01:00
LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)tex_data;
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
if (!dev || !tex)
2018-01-25 01:45:03 +01:00
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->SetTexture(sampler, tex);
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice9_SetTexture(dev, sampler,
(IDirect3DBaseTexture9*)tex);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 04:28:50 +01:00
LPDIRECT3DTEXTURE8 tex = (LPDIRECT3DTEXTURE8)tex_data;
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
if (!dev || !tex)
2018-01-25 01:45:03 +01:00
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->SetTexture(sampler, tex);
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice8_SetTexture(dev, sampler,
(IDirect3DBaseTexture8*)tex);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
}
2018-01-25 01:45:03 +01:00
void d3d_free_vertex_shader(void *_dev, void *data)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
#ifdef HAVE_D3D9
2018-01-23 02:55:33 +01:00
{
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
2018-01-23 02:55:33 +01:00
IDirect3DVertexShader9 *vs = (IDirect3DVertexShader9*)data;
if (!dev || !vs)
return;
#ifdef __cplusplus
2018-01-23 02:55:33 +01:00
vs->Release();
#else
2018-01-23 02:55:33 +01:00
IDirect3DVertexShader9_Release(vs);
#endif
2018-01-23 02:55:33 +01:00
}
#endif
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
}
2018-01-25 01:45:03 +01:00
void d3d_free_pixel_shader(void *_dev, void *data)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
#ifdef HAVE_D3D9
2018-01-23 02:55:33 +01:00
{
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
IDirect3DPixelShader9 *ps = (IDirect3DPixelShader9*)data;
2018-01-23 02:55:33 +01:00
if (!dev || !ps)
return;
#ifdef __cplusplus
2018-01-23 02:55:33 +01:00
ps->Release();
#else
2018-01-23 02:55:33 +01:00
IDirect3DPixelShader9_Release(ps);
#endif
2018-01-23 02:55:33 +01:00
}
#endif
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
}
2018-01-25 01:45:03 +01:00
bool d3d_create_vertex_shader(void *_dev, const DWORD *a, void **b)
{
2018-01-25 01:45:03 +01:00
if (!_dev)
return false;
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
#if defined(__cplusplus)
2018-01-25 01:45:03 +01:00
if (dev->CreateVertexShader(a, (IDirect3DVertexShader9**)b) == D3D_OK)
return true;
#else
2018-01-25 01:45:03 +01:00
if (IDirect3DDevice9_CreateVertexShader(dev, a,
2018-01-25 14:34:20 +01:00
(LPDIRECT3DVERTEXSHADER9*)b) == D3D_OK)
2018-01-25 01:45:03 +01:00
return true;
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
return false;
}
2018-01-25 01:45:03 +01:00
bool d3d_create_pixel_shader(void *_dev, const DWORD *a, void **b)
{
2018-01-25 01:45:03 +01:00
if (!_dev)
return false;
2018-01-25 01:45:03 +01:00
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if (dev->CreatePixelShader(a, (IDirect3DPixelShader9**)b) == D3D_OK)
return true;
#else
2018-01-25 01:45:03 +01:00
if (IDirect3DDevice9_CreatePixelShader(dev, a,
2018-01-25 14:34:20 +01:00
(LPDIRECT3DPIXELSHADER9*)b) == D3D_OK)
2018-01-25 01:45:03 +01:00
return true;
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
return false;
}
2018-01-25 01:45:03 +01:00
bool d3d_set_pixel_shader(void *_dev, void *data)
2018-01-06 22:49:17 +01:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-06 22:49:17 +01:00
#ifdef HAVE_D3D9
2018-01-23 02:55:33 +01:00
{
2018-01-25 14:34:20 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
LPDIRECT3DPIXELSHADER9 d3dps = (LPDIRECT3DPIXELSHADER9)data;
2018-01-23 02:55:33 +01:00
if (!dev || !d3dps)
return false;
2018-01-06 22:49:17 +01:00
#if defined(__cplusplus)
2018-01-23 02:55:33 +01:00
if (dev->SetPixelShader(d3dps) == D3D_OK)
return true;
2018-01-06 22:49:17 +01:00
#else
2018-01-07 12:00:09 +01:00
#ifdef _XBOX
2018-01-23 02:55:33 +01:00
/* Returns void on Xbox */
IDirect3DDevice9_SetPixelShader(dev, d3dps);
return true;
2018-01-07 12:00:09 +01:00
#else
2018-01-23 02:55:33 +01:00
if (IDirect3DDevice9_SetPixelShader(dev, d3dps) == D3D_OK)
return true;
2018-01-06 22:49:17 +01:00
#endif
2018-01-07 12:00:09 +01:00
#endif
2018-01-23 02:55:33 +01:00
}
2018-01-06 22:49:17 +01:00
#endif
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2018-01-06 22:49:17 +01:00
return false;
}
2018-01-25 01:45:03 +01:00
bool d3d_set_vertex_shader(void *_dev, unsigned index,
void *data)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-23 02:55:33 +01:00
{
#ifdef HAVE_D3D9
2018-01-25 14:34:20 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
LPDIRECT3DVERTEXSHADER9 shader = (LPDIRECT3DVERTEXSHADER9)data;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
if (dev->SetVertexShader(shader) != D3D_OK)
return false;
#else
#ifdef _XBOX
2018-01-23 02:55:33 +01:00
IDirect3DDevice9_SetVertexShader(dev, shader);
#else
2018-01-23 02:55:33 +01:00
if (IDirect3DDevice9_SetVertexShader(dev, shader) != D3D_OK)
return false;
#endif
2018-01-23 02:55:33 +01:00
#endif
#endif
}
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
{
2018-01-25 14:34:20 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 14:34:20 +01:00
LPDIRECT3DVERTEXSHADER8 shader = (LPDIRECT3DVERTEXSHADER8)data;
2018-01-25 01:45:03 +01:00
2018-01-23 02:55:33 +01:00
if (dev->SetVertexShader(shader) != D3D_OK)
return false;
#else
2018-01-23 02:55:33 +01:00
if (IDirect3DDevice8_SetVertexShader(dev, index) != D3D_OK)
return false;
#endif
}
#endif
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2018-01-06 22:49:17 +01:00
return true;
}
2018-01-25 01:45:03 +01:00
bool d3d_set_vertex_shader_constantf(void *_dev,
UINT start_register,const float* constant_data,
unsigned vector4f_count)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
#if defined(HAVE_D3D9)
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
#ifdef __cplusplus
2018-01-23 02:55:33 +01:00
#ifdef _XBOX
2018-01-25 01:45:03 +01:00
dev->SetVertexShaderConstantF(
start_register, constant_data, vector4f_count);
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
if (dev->SetVertexShaderConstantF(
start_register, constant_data, vector4f_count) == D3D_OK)
return true;
2018-01-23 02:55:33 +01:00
#endif
2018-01-15 06:36:02 +01:00
#else
#ifdef _XBOX
2018-01-25 01:45:03 +01:00
IDirect3DDevice9_SetVertexShaderConstantF(dev,
start_register, constant_data, vector4f_count);
2018-01-23 02:55:33 +01:00
return true;
2018-01-25 01:45:03 +01:00
#else
if (IDirect3DDevice9_SetVertexShaderConstantF(dev,
start_register, constant_data, vector4f_count) == D3D_OK)
return true;
#endif
2018-01-15 06:36:02 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
return false;
}
2015-04-07 00:46:46 +02:00
void d3d_texture_blit(unsigned pixel_size,
2018-01-25 04:28:50 +01:00
void *tex,
2018-01-25 15:30:48 +01:00
void *_lr, const void *frame,
2014-09-11 23:05:58 +02:00
unsigned width, unsigned height, unsigned pitch)
{
2018-01-16 00:08:10 +01:00
unsigned y;
2018-01-25 15:30:48 +01:00
D3DLOCKED_RECT *lr = (D3DLOCKED_RECT*)_lr;
2018-01-16 00:08:10 +01:00
for (y = 0; y < height; y++)
{
const uint8_t *in = (const uint8_t*)frame + y * pitch;
uint8_t *out = (uint8_t*)lr->pBits + y * lr->Pitch;
memcpy(out, in, width * pixel_size);
2016-10-03 04:19:19 +02:00
}
2014-09-11 23:05:58 +02:00
}
2018-01-25 15:30:48 +01:00
bool d3d_get_render_state(void *data, INT32 state, DWORD *value)
2018-01-15 06:14:20 +01:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)data;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 15:30:48 +01:00
if (dev && dev->GetRenderState((D3DRENDERSTATETYPE)state, value) == D3D_OK)
2018-01-25 01:45:03 +01:00
return true;
2018-01-23 02:55:33 +01:00
#else
2018-01-15 06:36:02 +01:00
#ifdef _XBOX
2018-01-25 01:45:03 +01:00
if (!dev)
return false;
2018-01-25 15:30:48 +01:00
IDirect3DDevice9_GetRenderState(dev, (D3DRENDERSTATETYPE)state, value);
2018-01-23 02:55:33 +01:00
return true;
2018-01-25 01:45:03 +01:00
#else
2018-01-25 15:30:48 +01:00
if (dev && IDirect3DDevice9_GetRenderState(dev, (D3DRENDERSTATETYPE)state, value) == D3D_OK)
2018-01-25 01:45:03 +01:00
return true;
2018-01-15 06:36:02 +01:00
#endif
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)data;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 15:30:48 +01:00
if (dev && dev->GetRenderState((D3DRENDERSTATETYPE)state, value) == D3D_OK)
2018-01-25 01:45:03 +01:00
return true;
2018-01-15 06:14:20 +01:00
#else
2018-01-25 15:30:48 +01:00
if (dev && IDirect3DDevice8_GetRenderState(dev, (D3DRENDERSTATETYPE)state, value) == D3D_OK)
2018-01-25 01:45:03 +01:00
return true;
2018-01-15 06:14:20 +01:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2018-01-15 06:14:20 +01:00
return false;
}
2018-01-25 15:30:48 +01:00
void d3d_set_render_state(void *data, INT32 state, DWORD value)
2015-11-12 01:28:14 +01:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)data;
if (!dev)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 15:30:48 +01:00
dev->SetRenderState((D3DRENDERSTATETYPE)state, value);
2018-01-23 02:55:33 +01:00
#else
2018-01-25 15:30:48 +01:00
IDirect3DDevice9_SetRenderState(dev, (D3DRENDERSTATETYPE)state, value);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)data;
if (!dev)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 15:30:48 +01:00
dev->SetRenderState((D3DRENDERSTATETYPE)state, value);
#else
2018-01-25 15:30:48 +01:00
IDirect3DDevice8_SetRenderState(dev, (D3DRENDERSTATETYPE)state, value);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2015-11-12 01:28:14 +01:00
}
void d3d_enable_blend_func(void *data)
{
2018-01-25 01:45:03 +01:00
if (!data)
return;
2018-01-25 01:45:03 +01:00
d3d_set_render_state(data, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
d3d_set_render_state(data, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
d3d_set_render_state(data, D3DRS_ALPHABLENDENABLE, true);
}
2018-01-25 01:45:03 +01:00
void d3d_device_set_render_target(void *_dev, unsigned idx,
2017-10-01 23:19:44 +02:00
void *data)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 14:34:20 +01:00
LPDIRECT3DSURFACE9 surf = (LPDIRECT3DSURFACE9)data;
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
2018-01-25 01:45:03 +01:00
if (!dev)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->SetRenderTarget(idx, surf);
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice9_SetRenderTarget(dev, idx, surf);
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 14:34:20 +01:00
LPDIRECT3DSURFACE8 surf = (LPDIRECT3DSURFACE8)data;
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
if (!dev)
return;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->SetRenderTarget(idx, surf);
2017-10-01 23:19:44 +02:00
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice8_SetRenderTarget(dev, surf, NULL);
2017-10-01 23:19:44 +02:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2017-10-01 23:19:44 +02:00
}
void d3d_enable_alpha_blend_texture_func(void *data)
{
/* Also blend the texture with the set alpha value. */
2018-01-25 01:45:03 +01:00
d3d_set_texture_stage_state(data, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
d3d_set_texture_stage_state(data, 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
d3d_set_texture_stage_state(data, 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
}
void d3d_frame_postprocess(void *data)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
{
#if defined(_XBOX)
global_t *global = global_get_ptr();
2018-01-03 14:18:57 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)data;
2018-01-23 02:55:33 +01:00
if (!dev)
return;
2018-01-23 02:55:33 +01:00
dev->SetFlickerFilter(global->console.screen.flicker_filter_index);
dev->SetSoftDisplayFilter(global->console.softfilter_enable);
2018-01-03 14:18:57 +01:00
#else
2018-01-23 02:55:33 +01:00
D3DDevice_SetFlickerFilter(global->console.screen.flicker_filter_index);
D3DDevice_SetSoftDisplayFilter(global->console.softfilter_enable);
2018-01-03 14:18:57 +01:00
#endif
#endif
2018-01-23 02:55:33 +01:00
}
#endif
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
}
void d3d_disable_blend_func(void *data)
{
2018-01-25 01:45:03 +01:00
d3d_set_render_state(data, D3DRS_ALPHABLENDENABLE, false);
}
2015-04-07 02:44:12 +02:00
void d3d_set_vertex_declaration(void *data, void *vertex_data)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#if defined(HAVE_D3D9)
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)data;
if (!dev)
return;
2018-01-19 05:22:25 +01:00
#ifdef __cplusplus
2018-01-25 14:34:20 +01:00
dev->SetVertexDeclaration((LPDIRECT3DVERTEXDECLARATION9)vertex_data);
2018-01-19 05:22:25 +01:00
#else
2018-01-25 14:34:20 +01:00
IDirect3DDevice9_SetVertexDeclaration(dev, (LPDIRECT3DVERTEXDECLARATION9)vertex_data);
2018-01-19 05:22:25 +01:00
#endif
2015-04-07 02:44:12 +02:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2015-04-07 02:44:12 +02:00
}
2015-11-14 20:02:55 +01:00
2018-01-25 01:45:03 +01:00
static bool d3d_reset_internal(void *data,
2017-10-02 03:02:22 +02:00
D3DPRESENT_PARAMETERS *d3dpp
)
2015-11-14 20:02:55 +01:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)data;
if (!dev)
return false;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if ((dev->Reset(d3dpp) == D3D_OK))
return true;
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
if (IDirect3DDevice9_Reset(dev, d3dpp) == D3D_OK)
return true;
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)data;
if (!dev)
return false;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if ((dev->Reset(d3dpp) == D3D_OK))
return true;
2017-10-02 03:02:22 +02:00
#else
2018-01-25 01:45:03 +01:00
if (IDirect3DDevice8_Reset(dev, d3dpp) == D3D_OK)
return true;
2018-01-23 02:55:33 +01:00
#endif
2015-11-17 11:47:44 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
return false;
2017-10-02 03:02:22 +02:00
}
2015-11-14 20:02:55 +01:00
2018-01-25 01:45:03 +01:00
static HRESULT d3d_test_cooperative_level(void *data)
2017-10-02 03:02:22 +02:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifndef _XBOX
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)data;
if (!dev)
return E_FAIL;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
return dev->TestCooperativeLevel();
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
return IDirect3DDevice9_TestCooperativeLevel(dev);
2018-01-23 02:55:33 +01:00
#endif
#endif
#endif
2018-01-25 01:45:03 +01:00
}
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifndef _XBOX
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)data;
if (!dev)
return E_FAIL;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
return dev->TestCooperativeLevel();
2017-09-29 17:32:06 +02:00
#else
2018-01-25 01:45:03 +01:00
return IDirect3DDevice8_TestCooperativeLevel(dev);
2018-01-23 02:55:33 +01:00
#endif
#endif
2017-09-29 17:32:06 +02:00
#endif
2018-01-25 01:45:03 +01:00
}
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
return E_FAIL;
2017-10-02 03:02:22 +02:00
}
2018-01-25 01:45:03 +01:00
static bool d3d_create_device_internal(
void *data,
2017-10-02 03:15:49 +02:00
D3DPRESENT_PARAMETERS *d3dpp,
2018-01-25 04:12:16 +01:00
void *_d3d,
2017-10-02 03:15:49 +02:00
HWND focus_window,
unsigned cur_mon_id,
DWORD behavior_flags)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 04:12:16 +01:00
LPDIRECT3D9 d3d = (LPDIRECT3D9)_d3d;
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)data;
if (!dev)
return false;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(d3d->CreateDevice(
cur_mon_id,
D3DDEVTYPE_HAL,
focus_window,
behavior_flags,
d3dpp,
2018-01-25 16:33:28 +01:00
(IDirect3DDevice9**)dev)))
2018-01-25 01:45:03 +01:00
return true;
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(IDirect3D9_CreateDevice(d3d,
cur_mon_id,
D3DDEVTYPE_HAL,
focus_window,
behavior_flags,
d3dpp,
(IDirect3DDevice9**)dev)))
return true;
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 04:12:16 +01:00
LPDIRECT3D8 d3d = (LPDIRECT3D8)_d3d;
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)data;
if (!dev)
return false;
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(d3d->CreateDevice(
cur_mon_id,
D3DDEVTYPE_HAL,
focus_window,
behavior_flags,
d3dpp,
2018-01-25 15:54:37 +01:00
(IDirect3DDevice8**)dev)))
2018-01-25 01:45:03 +01:00
return true;
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(IDirect3D8_CreateDevice(d3d,
cur_mon_id,
D3DDEVTYPE_HAL,
focus_window,
behavior_flags,
d3dpp,
2018-01-25 14:38:24 +01:00
(IDirect3DDevice8**)dev)))
2018-01-25 01:45:03 +01:00
return true;
2017-10-02 03:52:53 +02:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2017-10-03 03:57:28 +02:00
return false;
2017-10-02 03:15:49 +02:00
}
2018-01-25 01:45:03 +01:00
bool d3d_create_device(void *dev,
2018-01-25 15:30:48 +01:00
void *d3dpp,
2018-01-25 04:12:16 +01:00
void *d3d,
2017-10-02 03:15:49 +02:00
HWND focus_window,
unsigned cur_mon_id)
{
if (!d3d_create_device_internal(dev,
2018-01-25 15:54:37 +01:00
(D3DPRESENT_PARAMETERS*)d3dpp,
2017-10-02 03:15:49 +02:00
d3d,
focus_window,
cur_mon_id,
D3DCREATE_HARDWARE_VERTEXPROCESSING))
if (!d3d_create_device_internal(
2018-01-25 15:54:37 +01:00
dev,
(D3DPRESENT_PARAMETERS*)d3dpp, d3d, focus_window,
2017-10-02 03:15:49 +02:00
cur_mon_id,
D3DCREATE_SOFTWARE_VERTEXPROCESSING))
return false;
return true;
}
2018-01-25 15:30:48 +01:00
bool d3d_reset(void *dev, void *d3dpp)
2017-10-02 03:02:22 +02:00
{
const char *err = NULL;
2015-11-14 20:02:55 +01:00
2018-01-25 15:54:37 +01:00
if (d3d_reset_internal(dev, (D3DPRESENT_PARAMETERS*)d3dpp))
2017-10-02 03:02:22 +02:00
return true;
RARCH_WARN("[D3D]: Attempting to recover from dead state...\n");
#ifndef _XBOX
/* Try to recreate the device completely. */
switch (d3d_test_cooperative_level(dev))
2015-11-14 20:02:55 +01:00
{
case D3DERR_DEVICELOST:
err = "DEVICELOST";
break;
case D3DERR_DEVICENOTRESET:
err = "DEVICENOTRESET";
break;
case D3DERR_DRIVERINTERNALERROR:
err = "DRIVERINTERNALERROR";
break;
default:
err = "Unknown";
}
2017-10-02 03:02:22 +02:00
RARCH_WARN("[D3D]: recovering from dead state: (%s).\n", err);
2015-11-14 20:02:55 +01:00
#endif
return false;
}
2016-01-07 00:19:27 +01:00
2018-01-25 01:45:03 +01:00
bool d3d_device_get_backbuffer(void *_dev,
2018-01-03 15:21:48 +01:00
unsigned idx, unsigned swapchain_idx,
unsigned backbuffer_type, void **data)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
if (!dev)
return false;
2018-01-03 15:21:48 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(dev->GetBackBuffer(
swapchain_idx, idx,
(D3DBACKBUFFER_TYPE)backbuffer_type,
2018-01-25 14:34:20 +01:00
(LPDIRECT3DSURFACE9*)data)))
2018-01-25 01:45:03 +01:00
return true;
2018-01-03 15:21:48 +01:00
#else
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(IDirect3DDevice9_GetBackBuffer(dev,
swapchain_idx, idx,
(D3DBACKBUFFER_TYPE)backbuffer_type,
2018-01-25 14:34:20 +01:00
(LPDIRECT3DSURFACE9*)data)))
2018-01-25 01:45:03 +01:00
return true;
2018-01-03 15:21:48 +01:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
if (!dev)
return false;
2018-01-03 15:21:48 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(dev->GetBackBuffer(idx,
(D3DBACKBUFFER_TYPE)backbuffer_type,
2018-01-25 14:34:20 +01:00
(LPDIRECT3DSURFACE8*)data)))
2018-01-25 01:45:03 +01:00
return true;
2018-01-03 15:21:48 +01:00
#else
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(IDirect3DDevice8_GetBackBuffer(dev, idx,
(D3DBACKBUFFER_TYPE)backbuffer_type,
2018-01-25 14:34:20 +01:00
(LPDIRECT3DSURFACE8*)data)))
2018-01-25 01:45:03 +01:00
return true;
2018-01-03 15:21:48 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2018-01-03 15:21:48 +01:00
return false;
}
2018-01-25 04:12:16 +01:00
void d3d_device_free(void *_dev, void *_pd3d)
2016-01-07 00:19:27 +01:00
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-23 02:55:33 +01:00
{
2018-01-25 01:45:03 +01:00
#ifdef HAVE_D3D9
2018-01-25 04:12:16 +01:00
LPDIRECT3D9 pd3d = (LPDIRECT3D9)_pd3d;
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
if (dev)
{
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->Release();
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice9_Release(dev);
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
2018-01-25 01:45:03 +01:00
if (pd3d)
{
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
pd3d->Release();
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
IDirect3D9_Release(pd3d);
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-23 02:55:33 +01:00
{
2018-01-25 01:45:03 +01:00
#ifdef HAVE_D3D8
2018-01-25 04:12:16 +01:00
LPDIRECT3D8 pd3d = (LPDIRECT3D8)_pd3d;
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
if (dev)
{
2018-01-23 02:55:33 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
dev->Release();
2018-01-23 02:55:33 +01:00
#else
2018-01-25 01:45:03 +01:00
IDirect3DDevice8_Release(dev);
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
2018-01-25 01:45:03 +01:00
if (pd3d)
{
2018-01-23 02:55:33 +01:00
#if defined(__cplusplus)
2018-01-25 01:45:03 +01:00
pd3d->Release();
#else
2018-01-25 01:45:03 +01:00
IDirect3D8_Release(pd3d);
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2018-01-23 02:55:33 +01:00
2016-01-07 00:19:27 +01:00
}
2018-01-25 15:30:48 +01:00
INT32 d3d_translate_filter(unsigned type)
{
switch (type)
{
case RARCH_FILTER_UNSPEC:
2017-04-25 15:31:32 +02:00
{
settings_t *settings = config_get_ptr();
2017-04-28 00:53:06 +02:00
if (!settings->bools.video_smooth)
2017-04-25 15:31:32 +02:00
break;
}
/* fall-through */
case RARCH_FILTER_LINEAR:
return D3DTEXF_LINEAR;
case RARCH_FILTER_NEAREST:
break;
}
return D3DTEXF_POINT;
}
void *d3d_matrix_transpose(void *_pout, const void *_pm)
{
unsigned i,j;
D3DMATRIX *pout = (D3DMATRIX*)_pout;
CONST D3DMATRIX *pm = (D3DMATRIX*)_pm;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
pout->m[i][j] = pm->m[j][i];
}
return pout;
}
void *d3d_matrix_identity(void *_pout)
{
D3DMATRIX *pout = (D3DMATRIX*)_pout;
if ( !pout )
return NULL;
pout->m[0][1] = 0.0f;
pout->m[0][2] = 0.0f;
pout->m[0][3] = 0.0f;
pout->m[1][0] = 0.0f;
pout->m[1][2] = 0.0f;
pout->m[1][3] = 0.0f;
pout->m[2][0] = 0.0f;
pout->m[2][1] = 0.0f;
pout->m[2][3] = 0.0f;
pout->m[3][0] = 0.0f;
pout->m[3][1] = 0.0f;
pout->m[3][2] = 0.0f;
pout->m[0][0] = 1.0f;
pout->m[1][1] = 1.0f;
pout->m[2][2] = 1.0f;
pout->m[3][3] = 1.0f;
return pout;
}
void *d3d_matrix_ortho_off_center_lh(void *_pout, float l, float r, float b, float t, float zn, float zf)
{
D3DMATRIX *pout = (D3DMATRIX*)_pout;
d3d_matrix_identity(pout);
pout->m[0][0] = 2.0f / (r - l);
pout->m[1][1] = 2.0f / (t - b);
pout->m[2][2] = 1.0f / (zf -zn);
pout->m[3][0] = -1.0f -2.0f *l / (r - l);
pout->m[3][1] = 1.0f + 2.0f * t / (b - t);
pout->m[3][2] = zn / (zn -zf);
return pout;
}
void *d3d_matrix_multiply(void *_pout, const void *_pm1, const void *_pm2)
{
unsigned i,j;
D3DMATRIX *pout = (D3DMATRIX*)_pout;
CONST D3DMATRIX *pm1 = (CONST D3DMATRIX*)_pm1;
CONST D3DMATRIX *pm2 = (CONST D3DMATRIX*)_pm2;
for (i=0; i<4; i++)
{
for (j=0; j<4; j++)
pout->m[i][j] = pm1->m[i][0] * pm2->m[0][j] + pm1->m[i][1] * pm2->m[1][j] + pm1->m[i][2] * pm2->m[2][j] + pm1->m[i][3] * pm2->m[3][j];
}
return pout;
}
void *d3d_matrix_rotation_z(void *_pout, float angle)
{
D3DMATRIX *pout = (D3DMATRIX*)_pout;
d3d_matrix_identity(pout);
pout->m[0][0] = cos(angle);
pout->m[1][1] = cos(angle);
pout->m[0][1] = sin(angle);
pout->m[1][0] = -sin(angle);
return pout;
}
2018-01-03 19:03:19 +01:00
2018-01-25 01:45:03 +01:00
bool d3dx_create_font_indirect(void *_dev,
2018-01-03 19:03:19 +01:00
void *desc, void **font_data)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-25 01:45:03 +01:00
{
2018-01-04 14:42:13 +01:00
#ifdef HAVE_D3DX
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3D9
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev;
2018-01-03 19:03:19 +01:00
#ifdef __cplusplus
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(D3DCreateFontIndirect(
2018-01-25 16:33:28 +01:00
dev, (D3DXFONT_DESC*)desc,
(struct ID3DXFont**)font_data)))
2018-01-25 01:45:03 +01:00
return true;
2018-01-03 19:03:19 +01:00
#else
2018-01-25 01:45:03 +01:00
if (SUCCEEDED(D3DCreateFontIndirect(
dev, (D3DXFONT_DESC*)desc,
(struct ID3DXFont**)font_data)))
return true;
2018-01-03 19:03:19 +01:00
#endif
2018-01-03 20:16:19 +01:00
#endif
2018-01-23 02:55:33 +01:00
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
2018-01-25 01:45:03 +01:00
{
2018-01-23 02:55:33 +01:00
#ifdef HAVE_D3DX
#ifdef HAVE_D3D8
2018-01-25 01:45:03 +01:00
LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev;
if (SUCCEEDED(D3DCreateFontIndirect(
dev, (CONST LOGFONT*)desc,
(struct ID3DXFont**)font_data)))
return true;
2018-01-23 02:55:33 +01:00
#endif
#endif
2018-01-25 01:45:03 +01:00
}
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2018-01-04 14:42:13 +01:00
return false;
2018-01-03 19:03:19 +01:00
}
2018-01-06 21:30:50 +01:00
void d3dxbuffer_release(void *data)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-23 02:55:33 +01:00
{
2018-01-06 21:30:50 +01:00
#ifdef HAVE_D3D9
#ifdef HAVE_D3DX
#ifdef __cplusplus
2018-01-23 02:55:33 +01:00
ID3DXBuffer *p = (ID3DXBuffer*)data;
2018-01-06 21:30:50 +01:00
#else
2018-01-23 02:55:33 +01:00
LPD3DXBUFFER p = (LPD3DXBUFFER)data;
2018-01-06 21:30:50 +01:00
#endif
2018-01-23 02:55:33 +01:00
if (!p)
return;
2018-01-06 21:30:50 +01:00
#ifdef __cplusplus
2018-01-23 02:55:33 +01:00
p->Release();
2018-01-06 21:30:50 +01:00
#else
2018-01-23 02:55:33 +01:00
p->lpVtbl->Release(p);
2018-01-06 21:30:50 +01:00
#endif
#endif
#endif
2018-01-23 02:55:33 +01:00
}
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2018-01-06 21:30:50 +01:00
}
2018-01-07 11:52:32 +01:00
2018-01-07 20:32:43 +01:00
bool d3dx_compile_shader(
const char *src,
unsigned src_data_len,
const void *pdefines,
void *pinclude,
const char *pfunctionname,
const char *pprofile,
unsigned flags,
void *ppshader,
void *pperrormsgs,
void *ppconstanttable)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-20 16:40:26 +01:00
#if defined(HAVE_D3DX) && defined(HAVE_D3D9)
2018-01-23 02:55:33 +01:00
if (D3DCompileShader)
if (D3DCompileShader(
(LPCTSTR)src,
(UINT)src_data_len,
(const D3DXMACRO*)pdefines,
(LPD3DXINCLUDE)pinclude,
(LPCSTR)pfunctionname,
(LPCSTR)pprofile,
(DWORD)flags,
(LPD3DXBUFFER*)ppshader,
(LPD3DXBUFFER*)pperrormsgs,
(LPD3DXCONSTANTTABLE*)ppconstanttable) >= 0)
return true;
2018-01-07 20:32:43 +01:00
#endif
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2018-01-07 20:32:43 +01:00
return false;
}
void d3dx_font_draw_text(void *data, void *sprite_data, void *string_data,
unsigned count, void *rect_data, unsigned format, unsigned color)
{
#ifdef HAVE_D3DX
#if !defined(__cplusplus) || defined(CINTERFACE)
ID3DXFont *font = (ID3DXFont*)data;
if (!font)
return;
2018-01-25 14:34:20 +01:00
font->lpVtbl->DrawText(font, (LPD3DXSPRITE)sprite_data,
(LPCTSTR)string_data, count, (LPRECT)rect_data,
(DWORD)format, (D3DCOLOR)color);
#else
LPD3DXFONT font = (LPD3DXFONT)data;
if (!font)
return;
font->DrawText((LPD3DXSPRITE)sprite_data,
(LPCTSTR)string_data, count, (LPRECT)rect_data,
(DWORD)format, (D3DCOLOR)color);
#endif
#endif
}
2018-01-25 12:16:57 +01:00
void d3dx_font_release(void *data)
{
#ifdef HAVE_D3DX
#if !defined(__cplusplus) || defined(CINTERFACE)
ID3DXFont *font = (ID3DXFont*)data;
if (!font)
return;
font->lpVtbl->Release(font);
#else
LPD3DXFONT font = (LPD3DXFONT)data;
if (!font)
return;
font->Release();
#endif
#endif
}
void d3dx_font_get_text_metrics(void *data, void *metrics)
{
#ifdef HAVE_D3DX
#if !defined(__cplusplus) || defined(CINTERFACE)
ID3DXFont *font = (ID3DXFont*)data;
if (!font)
return;
font->lpVtbl->GetTextMetrics(font, (TEXTMETRICA*)metrics);
#else
LPD3DXFONT font = (LPD3DXFONT)data;
if (!font)
return;
font->GetTextMetricsA((TEXTMETRICA*)metrics);
#endif
#endif
}
2018-01-07 11:52:32 +01:00
bool d3dx_compile_shader_from_file(
const char *src,
const void *pdefines,
void *pinclude,
const char *pfunctionname,
const char *pprofile,
unsigned flags,
void *ppshader,
void *pperrormsgs,
void *ppconstanttable)
{
2018-01-23 02:55:33 +01:00
switch (d3d_common_api)
{
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D9_API:
2018-01-20 16:40:26 +01:00
#if defined(HAVE_D3DX) && defined(HAVE_D3D9)
2018-01-23 02:55:33 +01:00
if (D3DCompileShaderFromFile)
if (D3DCompileShaderFromFile(
(LPCTSTR)src,
(const D3DXMACRO*)pdefines,
(LPD3DXINCLUDE)pinclude,
(LPCSTR)pfunctionname,
(LPCSTR)pprofile,
(DWORD)flags,
(LPD3DXBUFFER*)ppshader,
(LPD3DXBUFFER*)pperrormsgs,
(LPD3DXCONSTANTTABLE*)ppconstanttable) >= 0)
return true;
2018-01-07 11:52:32 +01:00
#endif
2018-01-23 02:55:33 +01:00
break;
2018-01-23 04:25:37 +01:00
case GFX_CTX_DIRECT3D8_API:
case GFX_CTX_NONE:
default:
2018-01-23 02:55:33 +01:00
break;
}
2018-01-07 11:52:32 +01:00
return false;
}
2018-01-20 16:45:45 +01:00
2018-01-25 15:30:48 +01:00
INT32 d3d_get_rgb565_format(void)
2018-01-20 16:45:45 +01:00
{
#ifdef _XBOX
return D3DFMT_LIN_R5G6B5;
#else
return D3DFMT_R5G6B5;
#endif
}
2018-01-25 15:30:48 +01:00
INT32 d3d_get_argb8888_format(void)
2018-01-20 16:45:45 +01:00
{
#ifdef _XBOX
return D3DFMT_LIN_A8R8G8B8;
#else
return D3DFMT_A8R8G8B8;
#endif
}
2018-01-25 15:30:48 +01:00
INT32 d3d_get_xrgb8888_format(void)
2018-01-20 16:45:45 +01:00
{
#ifdef _XBOX
return D3DFMT_LIN_X8R8G8B8;
#else
return D3DFMT_X8R8G8B8;
#endif
}