Fix build on Windows targets without dxgi.h, like MingW32.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4d3544a..9ecad3a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -804,6 +804,7 @@ elseif(WINDOWS)
check_include_file(dsound.h HAVE_DSOUND_H)
check_include_file(dinput.h HAVE_DINPUT_H)
check_include_file(xaudio2.h HAVE_XAUDIO2_H)
+ check_include_file(dxgi.h HAVE_DXGI_H)
if(HAVE_D3D_H OR HAVE_D3D11_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H OR HAVE_XAUDIO2_H)
set(HAVE_DIRECTX TRUE)
# TODO: change $ENV{DXSDL_DIR} to get the path from the include checks
diff --git a/configure.in b/configure.in
index 97b57f3..be4ac9f 100644
--- a/configure.in
+++ b/configure.in
@@ -2404,6 +2404,7 @@ AC_HELP_STRING([--enable-directx], [use DirectX for Windows audio/video [[defaul
AC_CHECK_HEADER(dsound.h, have_dsound=yes)
AC_CHECK_HEADER(dinput.h, have_dinput=yes)
AC_CHECK_HEADER(xaudio2.h, have_xaudio2=yes)
+ AC_CHECK_HEADER(dxgi.h, have_dxgi=yes)
SUMMARY_video="${SUMMARY_video} directx"
SUMMARY_audio="${SUMMARY_audio} directx"
@@ -2830,6 +2831,9 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
AC_DEFINE(SDL_VIDEO_RENDER_D3D11, 1, [ ])
fi
fi
+ if test x$have_dxgi = xyes; then
+ AC_DEFINE(HAVE_DXGI_H, 1, [ ])
+ fi
# Set up files for the audio library
if test x$enable_audio = xyes; then
AC_DEFINE(SDL_AUDIO_DRIVER_WINMM, 1, [ ])
diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake
index b6fb53a..9b39422 100644
--- a/include/SDL_config.h.cmake
+++ b/include/SDL_config.h.cmake
@@ -48,6 +48,8 @@
#cmakedefine HAVE_GCC_SYNC_LOCK_TEST_AND_SET @HAVE_GCC_SYNC_LOCK_TEST_AND_SET@
#cmakedefine HAVE_PTHREAD_SPINLOCK @HAVE_PTHREAD_SPINLOCK@
+#cmakedefine HAVE_DXGI_H @HAVE_DXGI_H@
+
/* Comment this if you want to build without any C library requirements */
#cmakedefine HAVE_LIBC 1
#if HAVE_LIBC
diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in
index a152329..884fd9b 100644
--- a/include/SDL_config.h.in
+++ b/include/SDL_config.h.in
@@ -51,6 +51,8 @@
#undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET
#undef HAVE_PTHREAD_SPINLOCK
+#undef HAVE_DXGI_H
+
/* Comment this if you want to build without any C library requirements */
#undef HAVE_LIBC
#if HAVE_LIBC
diff --git a/include/SDL_config_windows.h b/include/SDL_config_windows.h
index 35eda46..1157270 100644
--- a/include/SDL_config_windows.h
+++ b/include/SDL_config_windows.h
@@ -76,6 +76,8 @@ typedef unsigned int uintptr_t;
# define SIZEOF_VOIDP 4
#endif
+#define HAVE_DXGI_H 1
+
/* This is disabled by default to avoid C runtime dependencies and manifest requirements */
#ifdef HAVE_LIBC
/* Useful headers */
diff --git a/include/SDL_config_winrt.h b/include/SDL_config_winrt.h
index 78b43ab..48d44ee 100644
--- a/include/SDL_config_winrt.h
+++ b/include/SDL_config_winrt.h
@@ -77,6 +77,7 @@ typedef unsigned int uintptr_t;
#endif
/* Useful headers */
+#define HAVE_DXGI_H 1
#define HAVE_LIBC 1
#define HAVE_STDIO_H 1
#define STDC_HEADERS 1
diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c
index ea15957..9ab1f4c 100644
--- a/src/video/windows/SDL_windowsvideo.c
+++ b/src/video/windows/SDL_windowsvideo.c
@@ -245,11 +245,12 @@ SDL_Direct3D9GetAdapterIndex( int displayIndex )
}
}
+#if HAVE_DXGI_H
#define CINTERFACE
#define COBJMACROS
#include <dxgi.h>
-SDL_bool
+static SDL_bool
DXGI_LoadDLL(void **pDXGIDLL, IDXGIFactory **pDXGIFactory)
{
*pDXGIDLL = SDL_LoadObject("DXGI.DLL");
@@ -277,18 +278,25 @@ DXGI_LoadDLL(void **pDXGIDLL, IDXGIFactory **pDXGIFactory)
return SDL_FALSE;
}
}
+#endif
SDL_bool
SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex)
{
+#if !HAVE_DXGI_H
+ if (adapterIndex) *adapterIndex = -1;
+ if (outputIndex) *outputIndex = -1;
+ SDL_SetError("SDL was compiled without DXGI support due to missing dxgi.h header");
+ return SDL_FALSE;
+#else
SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
void *pDXGIDLL;
+ char *displayName;
+ int nAdapter, nOutput;
IDXGIFactory *pDXGIFactory;
IDXGIAdapter *pDXGIAdapter;
IDXGIOutput* pDXGIOutput;
- char *displayName;
- int nAdapter, nOutput;
if (!adapterIndex) {
SDL_InvalidParamError("adapterIndex");
@@ -344,6 +352,7 @@ SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex)
} else {
return SDL_TRUE;
}
+#endif
}
#endif /* SDL_VIDEO_DRIVER_WINDOWS */