diff --git a/Makefile.common b/Makefile.common
index 839fd46cc8..de2df1ab3d 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -1258,7 +1258,10 @@ endif
ifeq ($(HAVE_D3D9), 1)
HAVE_D3D_COMMON = 1
DEFINES += -DHAVE_D3D9
- LIBS += -ld3d9 -ld3dx9 -ldxguid
+ifneq ($(HAVE_DYLIB), 1)
+ LIBS += -ld3d9
+endif
+ LIBS += -ld3dx9 -ldxguid
OBJ += gfx/drivers_font/d3d_w32_font.o
ifeq ($(HAVE_CG), 1)
LIBS += -lcgD3D9
@@ -1274,7 +1277,10 @@ endif
ifeq ($(HAVE_D3D8), 1)
HAVE_D3D_COMMON = 1
DEFINES += -DHAVE_D3D8
- LIBS += -ld3d8 -ld3dx8 -ldxguid
+ifneq ($(HAVE_DYLIB), 1)
+ LIBS += -ld3d8
+endif
+ LIBS += -ld3dx8 -ldxguid
OBJ += gfx/drivers_renderchain/d3d8_renderchain.o
endif
diff --git a/gfx/common/d3d_common.c b/gfx/common/d3d_common.c
index e6c3434013..401f198f0a 100644
--- a/gfx/common/d3d_common.c
+++ b/gfx/common/d3d_common.c
@@ -13,6 +13,17 @@
* If not, see .
*/
+/* 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
+#endif
+
#include "../../configuration.h"
#include "../../verbosity.h"
@@ -30,6 +41,10 @@
static UINT SDKVersion = 0;
+#ifdef HAVE_DYNAMIC_D3D
+static dylib_t g_d3d_dll;
+#endif
+
#if defined(HAVE_D3D9)
typedef IDirect3D9 *(__stdcall *D3DCreate_t)(UINT);
#elif defined(HAVE_D3D8)
@@ -45,25 +60,51 @@ void *d3d_create(void)
bool d3d_initialize_symbols(void)
{
- /* For Xbox we will just link statically
- * to Direct3D libraries. */
+#ifdef HAVE_DYNAMIC_D3D
+#if defined(HAVE_D3D9)
+ g_d3d_dll = dylib_load("d3d9.dll");
+#elif defined(HAVE_D3D8)
+ g_d3d_dll = dylib_load("d3d8.dll");
+#endif
+ if (!g_d3d_dll)
+ return false;
+#endif
+
#if defined(HAVE_D3D9)
SDKVersion = 31;
+#ifdef HAVE_DYNAMIC_D3D
+ D3DCreate = (D3DCreate_t)dylib_proc(g_d3d_dll, "Direct3DCreate9");
+#else
D3DCreate = Direct3DCreate9;
+#endif
#elif defined(HAVE_D3D8)
SDKVersion = 220;
+#ifdef HAVE_DYNAMIC_D3D
+ D3DCreate = (D3DCreate_t)dylib_proc(g_d3d_dll, "Direct3DCreate8");
+#else
D3DCreate = Direct3DCreate8;
#endif
+#endif
+
+ if (!D3DCreate)
+ goto error;
#ifdef _XBOX
SDKVersion = 0;
#endif
return true;
+
+error:
+ if (g_d3d_dll)
+ d3d_deinitialize_symbols();
+ return false;
}
void d3d_deinitialize_symbols(void)
{
+ dylib_close(g_d3d_dll);
+ g_d3d_dll = NULL;
}
bool d3d_swap(void *data, LPDIRECT3DDEVICE dev)