diff --git a/Makefile.common b/Makefile.common index dcfbf6a894..26a2983e09 100644 --- a/Makefile.common +++ b/Makefile.common @@ -1259,7 +1259,8 @@ endif ifeq ($(HAVE_D3D9), 1) HAVE_D3D_COMMON = 1 - DEFINES += -DHAVE_D3D9 + HAVE_D3DX = 1 + DEFINES += -DHAVE_D3D9 -DHAVE_D3DX ifneq ($(HAVE_DYLIB), 1) LIBS += -ld3d9 -ld3dx9 endif diff --git a/gfx/common/d3d_common.c b/gfx/common/d3d_common.c index 9019e55f6c..b693c92b72 100644 --- a/gfx/common/d3d_common.c +++ b/gfx/common/d3d_common.c @@ -43,12 +43,15 @@ static UINT SDKVersion = 0; #ifdef HAVE_DYNAMIC_D3D static dylib_t g_d3d_dll; +#ifdef HAVE_D3DX static dylib_t g_d3dx_dll; +#endif static bool dylib_initialized = false; #endif #if defined(HAVE_D3D9) typedef IDirect3D9 *(__stdcall *D3DCreate_t)(UINT); +#ifdef HAVE_D3DX typedef HRESULT (__stdcall *D3DCreateTextureFromFile_t)( LPDIRECT3DDEVICE9 pDevice, @@ -71,23 +74,25 @@ typedef HRESULT (__stdcall LPDIRECT3DDEVICE9 pDevice, D3DXFONT_DESC* pDesc, LPD3DXFONT* ppFont); +#endif #elif defined(HAVE_D3D8) typedef IDirect3D8 *(__stdcall *D3DCreate_t)(UINT); -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, +#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, LPDIRECT3DTEXTURE8* ppTexture); typedef HRESULT (__stdcall @@ -96,10 +101,13 @@ typedef HRESULT (__stdcall CONST LOGFONT* pDesc, LPD3DXFONT* ppFont); #endif +#endif -static D3DXCreateFontIndirect_t D3DCreateFontIndirect; +#ifdef HAVE_D3DX +static D3DXCreateFontIndirect_t D3DCreateFontIndirect; static D3DCreateTextureFromFile_t D3DCreateTextureFromFile; +#endif static D3DCreate_t D3DCreate; void *d3d_create(void) @@ -167,10 +175,17 @@ bool d3d_initialize_symbols(void) #ifdef HAVE_DYNAMIC_D3D #if defined(HAVE_D3D9) g_d3d_dll = dylib_load("d3d9.dll"); +#ifdef HAVE_D3DX g_d3dx_dll = dylib_load_d3dx(); +#endif - if (!g_d3d_dll || !g_d3dx_dll) + if (!g_d3d_dll) return false; +#ifdef HAVE_D3DX + if (!g_d3dx_dll) + return false; +#endif + #elif defined(HAVE_D3D8) g_d3d_dll = dylib_load("d3d8.dll"); @@ -183,28 +198,36 @@ bool d3d_initialize_symbols(void) SDKVersion = 31; #ifdef HAVE_DYNAMIC_D3D D3DCreate = (D3DCreate_t)dylib_proc(g_d3d_dll, "Direct3DCreate9"); +#ifdef HAVE_D3DX #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"); +#endif #else D3DCreate = Direct3DCreate9; +#ifdef HAVE_D3DX D3DCreateFontIndirect = D3DXCreateFontIndirect; D3DCreateTextureFromFile = D3DXCreateTextureFromFileExA; #endif +#endif #elif defined(HAVE_D3D8) SDKVersion = 220; #ifdef HAVE_DYNAMIC_D3D D3DCreate = (D3DCreate_t)dylib_proc(g_d3d_dll, "Direct3DCreate8"); +#ifdef HAVE_D3DX D3DCreateFontIndirect = D3DXCreateFontIndirect; D3DCreateTextureFromFile = D3DXCreateTextureFromFileExA; +#endif #else D3DCreate = Direct3DCreate8; +#ifdef HAVE_D3DX D3DCreateFontIndirect = D3DXCreateFontIndirect; D3DCreateTextureFromFile = D3DXCreateTextureFromFileExA; #endif +#endif #endif if (!D3DCreate) @@ -226,10 +249,12 @@ void d3d_deinitialize_symbols(void) { if (g_d3d_dll) dylib_close(g_d3d_dll); +#ifdef HAVE_D3DX if (g_d3dx_dll) dylib_close(g_d3dx_dll); - g_d3d_dll = NULL; g_d3dx_dll = NULL; +#endif + g_d3d_dll = NULL; dylib_initialized = false; } @@ -313,6 +338,28 @@ bool d3d_texture_get_surface_level(LPDIRECT3DTEXTURE tex, return false; } +#ifdef HAVE_D3DX +static LPDIRECT3DTEXTURE d3d_texture_new_from_file( + LPDIRECT3DDEVICE dev, + const char *path, unsigned width, unsigned height, + unsigned miplevels, unsigned usage, D3DFORMAT format, + D3DPOOL pool, unsigned filter, unsigned mipfilter, + D3DCOLOR color_key, void *src_info_data, + PALETTEENTRY *palette) +{ + LPDIRECT3DTEXTURE buf; + HRESULT hr = D3DCreateTextureFromFile(dev, + path, width, height, miplevels, usage, format, + pool, filter, mipfilter, color_key, src_info_data, + palette, &buf); + + if (FAILED(hr)) + return NULL; + + return buf; +} +#endif + LPDIRECT3DTEXTURE d3d_texture_new(LPDIRECT3DDEVICE dev, const char *path, unsigned width, unsigned height, unsigned miplevels, unsigned usage, D3DFORMAT format, @@ -322,35 +369,42 @@ LPDIRECT3DTEXTURE d3d_texture_new(LPDIRECT3DDEVICE dev, { HRESULT hr; LPDIRECT3DTEXTURE buf; - D3DXIMAGE_INFO *src_info = (D3DXIMAGE_INFO*)src_info_data; +#ifdef HAVE_D3DX if (path) - { - hr = D3DCreateTextureFromFile(dev, - path, width, height, miplevels, usage, format, - pool, filter, mipfilter, color_key, src_info, - palette, &buf); - } - else - { -#if defined(HAVE_D3D9) && !defined(__cplusplus) - hr = IDirect3DDevice9_CreateTexture(dev, width, height, miplevels, usage, - format, pool, &buf, NULL); -#elif defined(HAVE_D3D8) && !defined(__cplusplus) - hr = IDirect3DDevice8_CreateTexture(dev, width, height, miplevels, usage, - format, pool, &buf); + return d3d_texture_new_from_file(dev, + path, width, height, miplevels, + usage, format, pool, filter, mipfilter, + color_key, src_info_data, palette); #else - hr = dev->CreateTexture(width, height, miplevels, usage, - format, pool, &buf -#ifndef HAVE_D3D8 - , NULL + if (path) + return NULL; +#endif + +#if defined(HAVE_D3D9) +#ifdef __cplusplus + hr = dev->CreateTexture( + width, height, miplevels, usage, + format, pool, &buf, NULL); +#else + hr = IDirect3DDevice9_CreateTexture(dev, + width, height, miplevels, usage, + format, pool, &buf, NULL); +#endif +#elif defined(HAVE_D3D8) +#ifdef __cplusplus + hr = dev->CreateTexture( + width, height, miplevels, usage, + format, pool, &buf); +#else + hr = IDirect3DDevice8_CreateTexture(dev, + width, height, miplevels, usage, + format, pool, &buf); #endif - ); #endif - } if (FAILED(hr)) - return NULL; + return NULL; return buf; } @@ -1332,10 +1386,11 @@ void *d3d_matrix_rotation_z(void *_pout, float angle) return pout; } -bool d3d_create_font_indirect(LPDIRECT3DDEVICE dev, +bool d3dx_create_font_indirect(LPDIRECT3DDEVICE dev, void *desc, void **font_data) { -#ifndef _XBOX +#ifdef HAVE_D3DX + #if defined(HAVE_D3D9) #ifdef __cplusplus if (FAILED(D3DCreateFontIndirect( @@ -1353,6 +1408,9 @@ bool d3d_create_font_indirect(LPDIRECT3DDEVICE dev, (struct ID3DXFont**)font_data))) return false; #endif -#endif + return true; +#else + return false; +#endif } diff --git a/gfx/common/d3d_common.h b/gfx/common/d3d_common.h index 6c61b4ef4e..ee623c8561 100644 --- a/gfx/common/d3d_common.h +++ b/gfx/common/d3d_common.h @@ -179,7 +179,7 @@ bool d3d_initialize_symbols(void); void d3d_deinitialize_symbols(void); -bool d3d_create_font_indirect(LPDIRECT3DDEVICE dev, +bool d3dx_create_font_indirect(LPDIRECT3DDEVICE dev, void *desc, void **font_data); D3DTEXTUREFILTERTYPE d3d_translate_filter(unsigned type); diff --git a/gfx/drivers_font/d3d_w32_font.c b/gfx/drivers_font/d3d_w32_font.c index fdb66d9399..0215a2afb8 100644 --- a/gfx/drivers_font/d3d_w32_font.c +++ b/gfx/drivers_font/d3d_w32_font.c @@ -77,7 +77,7 @@ static void *d3dfonts_w32_init_font(void *video_data, d3dfonts->d3d = (d3d_video_t*)video_data; d3dfonts->color = D3DCOLOR_XRGB(r, g, b); - if (!d3d_create_font_indirect(d3dfonts->d3d->dev, + if (!d3dx_create_font_indirect(d3dfonts->d3d->dev, &desc, (void**)&d3dfonts->font)) goto error; diff --git a/gfx/font_driver.c b/gfx/font_driver.c index 85f1bf43c3..5038d3e5bd 100644 --- a/gfx/font_driver.c +++ b/gfx/font_driver.c @@ -14,17 +14,17 @@ * If not, see . */ -#include "font_driver.h" -#include "video_thread_wrapper.h" - -#include "../configuration.h" -#include "../verbosity.h" +#include #ifdef HAVE_CONFIG_H #include "../config.h" #endif -#include +#include "font_driver.h" +#include "video_thread_wrapper.h" + +#include "../configuration.h" +#include "../verbosity.h" static const font_renderer_driver_t *font_backends[] = { #ifdef HAVE_FREETYPE @@ -88,7 +88,7 @@ static const font_renderer_t *d3d_font_backends[] = { &d3d_xdk1_font, #elif defined(_XBOX360) &d3d_xbox360_font, -#elif defined(_WIN32) && defined(HAVE_D3D9) +#elif defined(_WIN32) && defined(HAVE_D3DX) &d3d_win32_font, #endif NULL @@ -103,9 +103,9 @@ static bool d3d_font_init_first( for (i = 0; i < ARRAY_SIZE(d3d_font_backends); i++) { - void *data = d3d_font_backends[i]->init( + void *data = d3d_font_backends[i] ? d3d_font_backends[i]->init( video_data, font_path, font_size, - is_threaded); + is_threaded) : NULL; if (!data) continue; diff --git a/griffin/griffin.c b/griffin/griffin.c index a40792503e..6e76ca6865 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -431,7 +431,7 @@ FONTS #include "../gfx/drivers_font_renderer/bitmapfont.c" #include "../gfx/font_driver.c" -#if defined(HAVE_D3D9) && !defined(_XBOX) +#if defined(HAVE_D3D9) && defined(HAVE_D3DX) #include "../gfx/drivers_font/d3d_w32_font.c" #endif