This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository direct3d.

View the commit online.

commit efc03daba66552e36f5b865db1c4d45eaabc50a2
Author: Vincent Torri <vto...@outlook.fr>
AuthorDate: Wed Aug 7 09:01:09 2024 +0200

    fix debug system
---
 src/d3d_0.c | 14 ++------------
 src/d3d_1.c | 39 ++++++++++++++++++++-------------------
 src/d3d_2.c | 39 ++++++++++++++++++++-------------------
 src/d3d_3.c | 39 ++++++++++++++++++++-------------------
 src/d3d_4.c | 39 ++++++++++++++++++++-------------------
 src/d3d_5.c | 39 ++++++++++++++++++++-------------------
 src/d3d_6.c | 39 ++++++++++++++++++++-------------------
 src/d3d_7.c | 39 ++++++++++++++++++++-------------------
 src/win.h   | 20 +++++++++++++++++++-
 9 files changed, 161 insertions(+), 146 deletions(-)

diff --git a/src/d3d_0.c b/src/d3d_0.c
index be3069c..74ad40e 100644
--- a/src/d3d_0.c
+++ b/src/d3d_0.c
@@ -5,16 +5,14 @@
  *
  * Compilation:
  *
- * gcc -g -O2 -Wall -Wextra -o d3d_0 d3d_0.c win.c -ld3d11 -ld3dcompiler -ldxgi /c/Windows/system32/DXGIDebug.dll -ldxguid -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o src/d3d_0 src/d3d_0.c src/win.c -ld3d11 -ld3dcompiler -ldxgi -ldxguid -luuid -D_WIN32_WINNT=0x0A00
  */
 
 #include <stdlib.h>  /* calloc() free() */
 #include <stdio.h>   /* printf() fflush() */
 #include <string.h>  /* strlen() */
 
-#define _DEBUG
-
-/* C API for d3d11 */
+/* C API for dxgi / d3d11 */
 #define COBJMACROS
 
 #include <dxgi1_3.h>     /* DXGI interface */
@@ -24,14 +22,6 @@
 
 #include "win.h"
 
-#ifdef _DEBUG
-# define DBG_FCT \
-do { printf(" * %s\n", __FUNCTION__); fflush(stdout); } while (0)
-#else
-# define DBG_FCT \
-do { } while (0)
-#endif
-
 struct D3d
 {
     unsigned int vsync : 1;
diff --git a/src/d3d_1.c b/src/d3d_1.c
index 1e895cf..c8c5dc3 100644
--- a/src/d3d_1.c
+++ b/src/d3d_1.c
@@ -7,16 +7,14 @@
  *
  * Compilation:
  *
- * gcc -g -O2 -Wall -Wextra -o d3d_1 d3d_1.c win.c -ld3d11 -ld3dcompiler -ldxgi /c/Windows/system32/DXGIDebug.dll -ldxguid -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o src/d3d_1 src/d3d_1.c src/win.c -ld3d11 -ld3dcompiler -ldxgi -ldxguid -luuid -D_WIN32_WINNT=0x0A00
  */
 
 #include <stdlib.h>  /* calloc() free() malloc() */
 #include <stdio.h>   /* printf() fflush() */
 #include <string.h>  /* strlen() */
 
-#define _DEBUG
-
-/* C API for d3d11 */
+/* C API for dxgi / d3d11 */
 #define COBJMACROS
 
 #include <dxgi1_3.h>     /* DXGI interface */
@@ -26,17 +24,6 @@
 
 #include "win.h"
 
-#ifdef _DEBUG
-# define DBG_FCT \
-do { printf(" * %s\n", __FUNCTION__); fflush(stdout); } while (0)
-# define DBG_NAME(interface_, child_, name_) interface_ ## _SetPrivateData(child_, &WKPDID_D3DDebugObjectName, strlen(name_), name_)
-#else
-# define DBG_FCT \
-do { } while (0)
-# define DBG_NAME(interface_, child_, name_) \
-do { } while (0)
-#endif
-
 struct D3d
 {
     /* DXGI */
@@ -156,6 +143,20 @@ D3d *d3d_init(Window *win, int vsync)
     UINT num;
     UINT den;
     D3D_FEATURE_LEVEL feature_level[4];
+#ifdef _DEBUG
+    typedef HRESULT (*DXGIGetDebugInterface_t)(REFIID, void **);
+    DXGIGetDebugInterface_t DXGIGetDebugInterface_f;
+    HMODULE mod;
+
+    mod = LoadLibrary("DXGIDebug.dll");
+    if (!mod)
+        return NULL;
+
+    DXGIGetDebugInterface_f = (DXGIGetDebugInterface_t)(void *)GetProcAddress(mod, "DXGIGetDebugInterface");
+    FreeLibrary(mod);
+    if (!DXGIGetDebugInterface_f)
+        return NULL;
+#endif
 
     d3d = (D3d *)calloc(1, sizeof(D3d));
     if (!d3d)
@@ -176,9 +177,9 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     IDXGIFactory2_SetPrivateData(d3d->dxgi_factory,
                                  &WKPDID_D3DDebugObjectName,
-                                 strlen("Factory2"), "Factory2");
-    res = DXGIGetDebugInterface(&IID_IDXGIDebug,
-                                (void **)&d3d->dxgi_debug);
+                                 (UINT)strlen("Factory2"), "Factory2");
+    res = DXGIGetDebugInterface_f(&IID_IDXGIDebug,
+                                  (void **)&d3d->dxgi_debug);
     if (FAILED(res))
         goto release_dxgi_factory2;
 #endif
@@ -212,7 +213,7 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     ID3D11Device_SetPrivateData(d3d->d3d_device,
                                 &WKPDID_D3DDebugObjectName,
-                                strlen("Device"), "Device");
+                                (UINT)strlen("Device"), "Device");
     res = ID3D11Debug_QueryInterface(d3d->d3d_device, &IID_ID3D11Debug,
                                      (void **)&d3d->d3d_debug);
     if (FAILED(res))
diff --git a/src/d3d_2.c b/src/d3d_2.c
index ed4aadd..fb93830 100644
--- a/src/d3d_2.c
+++ b/src/d3d_2.c
@@ -7,16 +7,14 @@
  *
  * Compilation:
  *
- * gcc -g -O2 -Wall -Wextra -o d3d_2 d3d_2.c win.c -ld3d11 -ld3dcompiler -ldxgi /c/Windows/system32/DXGIDebug.dll -ldxguid -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o src/d3d_2 src/d3d_2.c src/win.c -ld3d11 -ld3dcompiler -ldxgi -ldxguid -luuid -D_WIN32_WINNT=0x0A00
  */
 
 #include <stdlib.h>  /* calloc() free() malloc() */
 #include <stdio.h>   /* printf() fflush() */
 #include <string.h>  /* strlen() */
 
-#define _DEBUG
-
-/* C API for d3d11 */
+/* C API for dxgi / d3d11 */
 #define COBJMACROS
 
 #include <dxgi1_3.h>     /* DXGI interface */
@@ -26,17 +24,6 @@
 
 #include "win.h"
 
-#ifdef _DEBUG
-# define DBG_FCT \
-do { printf(" * %s\n", __FUNCTION__); fflush(stdout); } while (0)
-# define DBG_NAME(interface_, child_, name_) interface_ ## _SetPrivateData(child_, &WKPDID_D3DDebugObjectName, strlen(name_), name_)
-#else
-# define DBG_FCT \
-do { } while (0)
-# define DBG_NAME(interface_, child_, name_) \
-do { } while (0)
-#endif
-
 #define XF(w,x) ((float)(2 * (x) - (w)) / (float)(w))
 #define YF(h,y) ((float)((h) - 2 * (y)) / (float)(h))
 
@@ -183,6 +170,20 @@ D3d *d3d_init(Window *win, int vsync)
     ID3DBlob *vs_blob; /* vertex shader blob ptr */
     ID3DBlob *ps_blob; /* pixel shader blob ptr */
     ID3DBlob *err_blob; /* error blob ptr */
+#ifdef _DEBUG
+    typedef HRESULT (*DXGIGetDebugInterface_t)(REFIID, void **);
+    DXGIGetDebugInterface_t DXGIGetDebugInterface_f;
+    HMODULE mod;
+
+    mod = LoadLibrary("DXGIDebug.dll");
+    if (!mod)
+        return NULL;
+
+    DXGIGetDebugInterface_f = (DXGIGetDebugInterface_t)(void *)GetProcAddress(mod, "DXGIGetDebugInterface");
+    FreeLibrary(mod);
+    if (!DXGIGetDebugInterface_f)
+        return NULL;
+#endif
 
     d3d = (D3d *)calloc(1, sizeof(D3d));
     if (!d3d)
@@ -203,9 +204,9 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     IDXGIFactory2_SetPrivateData(d3d->dxgi_factory,
                                  &WKPDID_D3DDebugObjectName,
-                                 strlen("Factory2"), "Factory2");
-    res = DXGIGetDebugInterface(&IID_IDXGIDebug,
-                                (void **)&d3d->dxgi_debug);
+                                 (UINT)strlen("Factory2"), "Factory2");
+    res = DXGIGetDebugInterface_f(&IID_IDXGIDebug,
+                                  (void **)&d3d->dxgi_debug);
     if (FAILED(res))
         goto release_dxgi_factory2;
 #endif
@@ -239,7 +240,7 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     ID3D11Device_SetPrivateData(d3d->d3d_device,
                                 &WKPDID_D3DDebugObjectName,
-                                strlen("Device"), "Device");
+                                (UINT)strlen("Device"), "Device");
     res = ID3D11Debug_QueryInterface(d3d->d3d_device, &IID_ID3D11Debug,
                                      (void **)&d3d->d3d_debug);
     if (FAILED(res))
diff --git a/src/d3d_3.c b/src/d3d_3.c
index 486a376..8240d50 100644
--- a/src/d3d_3.c
+++ b/src/d3d_3.c
@@ -7,16 +7,14 @@
  *
  * Compilation:
  *
- * gcc -g -O2 -Wall -Wextra -o d3d_3 d3d_3.c win.c -ld3d11 -ld3dcompiler -ldxgi /c/Windows/system32/DXGIDebug.dll -ldxguid -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o src/d3d_3 src/d3d_3.c src/win.c -ld3d11 -ld3dcompiler -ldxgi -ldxguid -luuid -D_WIN32_WINNT=0x0A00
  */
 
 #include <stdlib.h>  /* calloc() free() malloc() */
 #include <stdio.h>   /* printf() fflush() */
 #include <string.h>  /* strlen() */
 
-#define _DEBUG
-
-/* C API for d3d11 */
+/* C API for dxgi / d3d11 */
 #define COBJMACROS
 
 #include <dxgi1_3.h>     /* DXGI interface */
@@ -26,17 +24,6 @@
 
 #include "win.h"
 
-#ifdef _DEBUG
-# define DBG_FCT \
-do { printf(" * %s\n", __FUNCTION__); fflush(stdout); } while (0)
-# define DBG_NAME(interface_, child_, name_) interface_ ## _SetPrivateData(child_, &WKPDID_D3DDebugObjectName, strlen(name_), name_)
-#else
-# define DBG_FCT \
-do { } while (0)
-# define DBG_NAME(interface_, child_, name_) \
-do { } while (0)
-#endif
-
 struct D3d
 {
     /* DXGI */
@@ -188,6 +175,20 @@ D3d *d3d_init(Window *win, int vsync)
     ID3DBlob *vs_blob; /* vertex shader blob ptr */
     ID3DBlob *ps_blob; /* pixel shader blob ptr */
     ID3DBlob *err_blob; /* error blob ptr */
+#ifdef _DEBUG
+    typedef HRESULT (*DXGIGetDebugInterface_t)(REFIID, void **);
+    DXGIGetDebugInterface_t DXGIGetDebugInterface_f;
+    HMODULE mod;
+
+    mod = LoadLibrary("DXGIDebug.dll");
+    if (!mod)
+        return NULL;
+
+    DXGIGetDebugInterface_f = (DXGIGetDebugInterface_t)(void *)GetProcAddress(mod, "DXGIGetDebugInterface");
+    FreeLibrary(mod);
+    if (!DXGIGetDebugInterface_f)
+        return NULL;
+#endif
 
     d3d = (D3d *)calloc(1, sizeof(D3d));
     if (!d3d)
@@ -208,9 +209,9 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     IDXGIFactory2_SetPrivateData(d3d->dxgi_factory,
                                  &WKPDID_D3DDebugObjectName,
-                                 strlen("Factory2"), "Factory2");
-    res = DXGIGetDebugInterface(&IID_IDXGIDebug,
-                                (void **)&d3d->dxgi_debug);
+                                 (UINT)strlen("Factory2"), "Factory2");
+    res = DXGIGetDebugInterface_f(&IID_IDXGIDebug,
+                                  (void **)&d3d->dxgi_debug);
     if (FAILED(res))
         goto release_dxgi_factory2;
 #endif
@@ -244,7 +245,7 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     ID3D11Device_SetPrivateData(d3d->d3d_device,
                                 &WKPDID_D3DDebugObjectName,
-                                strlen("Device"), "Device");
+                                (UINT)strlen("Device"), "Device");
     res = ID3D11Debug_QueryInterface(d3d->d3d_device, &IID_ID3D11Debug,
                                      (void **)&d3d->d3d_debug);
     if (FAILED(res))
diff --git a/src/d3d_4.c b/src/d3d_4.c
index 10df823..5aab225 100644
--- a/src/d3d_4.c
+++ b/src/d3d_4.c
@@ -5,16 +5,14 @@
  *
  * Compilation:
  *
- * gcc -g -O2 -Wall -Wextra -o d3d_4 d3d_4.c win.c -ld3d11 -ld3dcompiler -ldxgi /c/Windows/system32/DXGIDebug.dll -ldxguid -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o src/d3d_4 stc/d3d_4.c src/win.c -ld3d11 -ld3dcompiler -ldxgi -ldxguid -luuid -D_WIN32_WINNT=0x0A00
  */
 
 #include <stdlib.h>  /* calloc() free() malloc() */
 #include <stdio.h>   /* printf() fflush() */
 #include <string.h>  /* strlen() */
 
-#define _DEBUG
-
-/* C API for d3d11 */
+/* C API for dxgi / d3d11 */
 #define COBJMACROS
 
 #include <dxgi1_3.h>     /* DXGI interface */
@@ -24,17 +22,6 @@
 
 #include "win.h"
 
-#ifdef _DEBUG
-# define DBG_FCT \
-do { printf(" * %s\n", __FUNCTION__); fflush(stdout); } while (0)
-# define DBG_NAME(interface_, child_, name_) interface_ ## _SetPrivateData(child_, &WKPDID_D3DDebugObjectName, strlen(name_), name_)
-#else
-# define DBG_FCT \
-do { } while (0)
-# define DBG_NAME(interface_, child_, name_) \
-do { } while (0)
-#endif
-
 struct D3d
 {
     /* DXGI */
@@ -191,6 +178,20 @@ D3d *d3d_init(Window *win, int vsync)
     ID3DBlob *vs_blob; /* vertex shader blob ptr */
     ID3DBlob *ps_blob; /* pixel shader blob ptr */
     ID3DBlob *err_blob; /* error blob ptr */
+#ifdef _DEBUG
+    typedef HRESULT (*DXGIGetDebugInterface_t)(REFIID, void **);
+    DXGIGetDebugInterface_t DXGIGetDebugInterface_f;
+    HMODULE mod;
+
+    mod = LoadLibrary("DXGIDebug.dll");
+    if (!mod)
+        return NULL;
+
+    DXGIGetDebugInterface_f = (DXGIGetDebugInterface_t)(void *)GetProcAddress(mod, "DXGIGetDebugInterface");
+    FreeLibrary(mod);
+    if (!DXGIGetDebugInterface_f)
+        return NULL;
+#endif
 
     d3d = (D3d *)calloc(1, sizeof(D3d));
     if (!d3d)
@@ -211,9 +212,9 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     IDXGIFactory2_SetPrivateData(d3d->dxgi_factory,
                                  &WKPDID_D3DDebugObjectName,
-                                 strlen("Factory2"), "Factory2");
-    res = DXGIGetDebugInterface(&IID_IDXGIDebug,
-                                (void **)&d3d->dxgi_debug);
+                                 (UINT)strlen("Factory2"), "Factory2");
+    res = DXGIGetDebugInterface_f(&IID_IDXGIDebug,
+                                  (void **)&d3d->dxgi_debug);
     if (FAILED(res))
         goto release_dxgi_factory2;
 #endif
@@ -247,7 +248,7 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     ID3D11Device_SetPrivateData(d3d->d3d_device,
                                 &WKPDID_D3DDebugObjectName,
-                                strlen("Device"), "Device");
+                                (UINT)strlen("Device"), "Device");
     res = ID3D11Debug_QueryInterface(d3d->d3d_device, &IID_ID3D11Debug,
                                      (void **)&d3d->d3d_debug);
     if (FAILED(res))
diff --git a/src/d3d_5.c b/src/d3d_5.c
index 416d79b..a9d4b28 100644
--- a/src/d3d_5.c
+++ b/src/d3d_5.c
@@ -5,16 +5,14 @@
  *
  * Compilation:
  *
- * gcc -g -O2 -Wall -Wextra -o d3d_5 d3d_5.c win.c -ld3d11 -ld3dcompiler -ldxgi /c/Windows/system32/DXGIDebug.dll -ldxguid -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o src/d3d_5 src/d3d_5.c src/win.c -ld3d11 -ld3dcompiler -ldxgi -ldxguid -luuid -D_WIN32_WINNT=0x0A00
  */
 
 #include <stdlib.h>  /* calloc() free() malloc() */
 #include <stdio.h>   /* printf() fflush() */
 #include <string.h>  /* strlen() */
 
-#define _DEBUG
-
-/* C API for d3d11 */
+/* C API for dxgi / d3d11 */
 #define COBJMACROS
 
 #include <dxgi1_3.h>     /* DXGI interface */
@@ -24,17 +22,6 @@
 
 #include "win.h"
 
-#ifdef _DEBUG
-# define DBG_FCT \
-do { printf(" * %s\n", __FUNCTION__); fflush(stdout); } while (0)
-# define DBG_NAME(interface_, child_, name_) interface_ ## _SetPrivateData(child_, &WKPDID_D3DDebugObjectName, strlen(name_), name_)
-#else
-# define DBG_FCT \
-do { } while (0)
-# define DBG_NAME(interface_, child_, name_) \
-do { } while (0)
-#endif
-
 struct D3d
 {
     /* DXGI */
@@ -191,6 +178,20 @@ D3d *d3d_init(Window *win, int vsync)
     ID3DBlob *vs_blob; /* vertex shader blob ptr */
     ID3DBlob *ps_blob; /* pixel shader blob ptr */
     ID3DBlob *err_blob; /* error blob ptr */
+#ifdef _DEBUG
+    typedef HRESULT (*DXGIGetDebugInterface_t)(REFIID, void **);
+    DXGIGetDebugInterface_t DXGIGetDebugInterface_f;
+    HMODULE mod;
+
+    mod = LoadLibrary("DXGIDebug.dll");
+    if (!mod)
+        return NULL;
+
+    DXGIGetDebugInterface_f = (DXGIGetDebugInterface_t)(void *)GetProcAddress(mod, "DXGIGetDebugInterface");
+    FreeLibrary(mod);
+    if (!DXGIGetDebugInterface_f)
+        return NULL;
+#endif
 
     d3d = (D3d *)calloc(1, sizeof(D3d));
     if (!d3d)
@@ -211,9 +212,9 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     IDXGIFactory2_SetPrivateData(d3d->dxgi_factory,
                                  &WKPDID_D3DDebugObjectName,
-                                 strlen("Factory2"), "Factory2");
-    res = DXGIGetDebugInterface(&IID_IDXGIDebug,
-                                (void **)&d3d->dxgi_debug);
+                                 (UINT)strlen("Factory2"), "Factory2");
+    res = DXGIGetDebugInterface_f(&IID_IDXGIDebug,
+                                  (void **)&d3d->dxgi_debug);
     if (FAILED(res))
         goto release_dxgi_factory2;
 #endif
@@ -247,7 +248,7 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     ID3D11Device_SetPrivateData(d3d->d3d_device,
                                 &WKPDID_D3DDebugObjectName,
-                                strlen("Device"), "Device");
+                                (UINT)strlen("Device"), "Device");
     res = ID3D11Debug_QueryInterface(d3d->d3d_device, &IID_ID3D11Debug,
                                      (void **)&d3d->d3d_debug);
     if (FAILED(res))
diff --git a/src/d3d_6.c b/src/d3d_6.c
index 92f82f3..aff4d9e 100644
--- a/src/d3d_6.c
+++ b/src/d3d_6.c
@@ -5,16 +5,14 @@
  *
  * Compilation:
  *
- * gcc -g -O2 -Wall -Wextra -o d3d_6 d3d_6.c win.c -ld3d11 -ld3dcompiler -ldxgi /c/Windows/system32/DXGIDebug.dll -ldxguid -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o src/d3d_6 src/d3d_6.c src/win.c -ld3d11 -ld3dcompiler -ldxgi -ldxguid -luuid -D_WIN32_WINNT=0x0A00
  */
 
 #include <stdlib.h>  /* calloc() free() malloc() */
 #include <stdio.h>   /* printf() fflush() */
 #include <string.h>  /* strlen() */
 
-#define _DEBUG
-
-/* C API for d3d11 */
+/* C API for dxgi / d3d11 */
 #define COBJMACROS
 
 #include <dxgi1_3.h>     /* DXGI interface */
@@ -24,17 +22,6 @@
 
 #include "win.h"
 
-#ifdef _DEBUG
-# define DBG_FCT \
-do { printf(" * %s\n", __FUNCTION__); fflush(stdout); } while (0)
-# define DBG_NAME(interface_, child_, name_) interface_ ## _SetPrivateData(child_, &WKPDID_D3DDebugObjectName, strlen(name_), name_)
-#else
-# define DBG_FCT \
-do { } while (0)
-# define DBG_NAME(interface_, child_, name_) \
-do { } while (0)
-#endif
-
 struct D3d
 {
     /* DXGI */
@@ -192,6 +179,20 @@ D3d *d3d_init(Window *win, int vsync)
     ID3DBlob *vs_blob; /* vertex shader blob ptr */
     ID3DBlob *ps_blob; /* pixel shader blob ptr */
     ID3DBlob *err_blob; /* error blob ptr */
+#ifdef _DEBUG
+    typedef HRESULT (*DXGIGetDebugInterface_t)(REFIID, void **);
+    DXGIGetDebugInterface_t DXGIGetDebugInterface_f;
+    HMODULE mod;
+
+    mod = LoadLibrary("DXGIDebug.dll");
+    if (!mod)
+        return NULL;
+
+    DXGIGetDebugInterface_f = (DXGIGetDebugInterface_t)(void *)GetProcAddress(mod, "DXGIGetDebugInterface");
+    FreeLibrary(mod);
+    if (!DXGIGetDebugInterface_f)
+        return NULL;
+#endif
 
     d3d = (D3d *)calloc(1, sizeof(D3d));
     if (!d3d)
@@ -212,9 +213,9 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     IDXGIFactory2_SetPrivateData(d3d->dxgi_factory,
                                  &WKPDID_D3DDebugObjectName,
-                                 strlen("Factory2"), "Factory2");
-    res = DXGIGetDebugInterface(&IID_IDXGIDebug,
-                                (void **)&d3d->dxgi_debug);
+                                 (UINT)strlen("Factory2"), "Factory2");
+    res = DXGIGetDebugInterface_f(&IID_IDXGIDebug,
+                                  (void **)&d3d->dxgi_debug);
     if (FAILED(res))
         goto release_dxgi_factory2;
 #endif
@@ -248,7 +249,7 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     ID3D11Device_SetPrivateData(d3d->d3d_device,
                                 &WKPDID_D3DDebugObjectName,
-                                strlen("Device"), "Device");
+                                (UINT)strlen("Device"), "Device");
     res = ID3D11Debug_QueryInterface(d3d->d3d_device, &IID_ID3D11Debug,
                                      (void **)&d3d->d3d_debug);
     if (FAILED(res))
diff --git a/src/d3d_7.c b/src/d3d_7.c
index 4250a16..eb5bdc4 100644
--- a/src/d3d_7.c
+++ b/src/d3d_7.c
@@ -5,16 +5,14 @@
  *
  * Compilation:
  *
- * gcc -g -O2 -Wall -Wextra -o d3d_7 d3d_7.c win.c -ld3d11 -ld3dcompiler -ldxgi /c/Windows/system32/DXGIDebug.dll -ldxguid -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o src/d3d_7 src/d3d_7.c src/win.c -ld3d11 -ld3dcompiler -ldxgi -ldxguid -luuid -D_WIN32_WINNT=0x0A00
  */
 
 #include <stdlib.h>  /* calloc() free() malloc() */
 #include <stdio.h>   /* printf() fflush() */
 #include <string.h>  /* strlen() */
 
-#define _DEBUG
-
-/* C API for d3d11 */
+/* C API for dxgi / d3d11 */
 #define COBJMACROS
 
 #include <dxgi1_3.h>     /* DXGI interface */
@@ -24,17 +22,6 @@
 
 #include "win.h"
 
-#ifdef _DEBUG
-# define DBG_FCT \
-do { printf(" * %s\n", __FUNCTION__); fflush(stdout); } while (0)
-# define DBG_NAME(interface_, child_, name_) interface_ ## _SetPrivateData(child_, &WKPDID_D3DDebugObjectName, strlen(name_), name_)
-#else
-# define DBG_FCT \
-do { } while (0)
-# define DBG_NAME(interface_, child_, name_) \
-do { } while (0)
-#endif
-
 typedef enum
 {
     OBJECT_TYPE_RECTANGLE,
@@ -206,6 +193,20 @@ D3d *d3d_init(Window *win, int vsync)
     ID3DBlob *vs_blob; /* vertex shader blob ptr */
     ID3DBlob *ps_blob; /* pixel shader blob ptr */
     ID3DBlob *err_blob; /* error blob ptr */
+#ifdef _DEBUG
+    typedef HRESULT (*DXGIGetDebugInterface_t)(REFIID, void **);
+    DXGIGetDebugInterface_t DXGIGetDebugInterface_f;
+    HMODULE mod;
+
+    mod = LoadLibrary("DXGIDebug.dll");
+    if (!mod)
+        return NULL;
+
+    DXGIGetDebugInterface_f = (DXGIGetDebugInterface_t)(void *)GetProcAddress(mod, "DXGIGetDebugInterface");
+    FreeLibrary(mod);
+    if (!DXGIGetDebugInterface_f)
+        return NULL;
+#endif
 
     d3d = (D3d *)calloc(1, sizeof(D3d));
     if (!d3d)
@@ -226,9 +227,9 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     IDXGIFactory2_SetPrivateData(d3d->dxgi_factory,
                                  &WKPDID_D3DDebugObjectName,
-                                 strlen("Factory2"), "Factory2");
-    res = DXGIGetDebugInterface(&IID_IDXGIDebug,
-                                (void **)&d3d->dxgi_debug);
+                                 (UINT)strlen("Factory2"), "Factory2");
+    res = DXGIGetDebugInterface_f(&IID_IDXGIDebug,
+                                  (void **)&d3d->dxgi_debug);
     if (FAILED(res))
         goto release_dxgi_factory2;
 #endif
@@ -262,7 +263,7 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     ID3D11Device_SetPrivateData(d3d->d3d_device,
                                 &WKPDID_D3DDebugObjectName,
-                                strlen("Device"), "Device");
+                                (UINT)strlen("Device"), "Device");
     res = ID3D11Debug_QueryInterface(d3d->d3d_device, &IID_ID3D11Debug,
                                      (void **)&d3d->d3d_debug);
     if (FAILED(res))
diff --git a/src/win.h b/src/win.h
index 4c75ecf..97715e3 100644
--- a/src/win.h
+++ b/src/win.h
@@ -2,7 +2,25 @@
 #define WIN_H
 
 /* comment for no debug informations */
-#define _DEBUG
+#ifndef _DEBUG
+# define _DEBUG
+#endif
+
+#ifdef _DEBUG
+# define DBG_FCT \
+    do { \
+        printf(" * %s\n", __FUNCTION__); fflush(stdout); \
+    } while (0)
+# define DBG_NAME(interface_, child_, name_) \
+    do { \
+      interface_ ## _SetPrivateData(child_, &WKPDID_D3DDebugObjectName, (UINT)strlen(name_), name_); \
+    } while (0)
+#else
+# define DBG_FCT \
+    do { } while (0)
+# define DBG_NAME(interface_, child_, name_) \
+    do { } while (0)
+#endif
 
 typedef struct Window Window;
 typedef struct D3d D3d;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to