Skip to content

Commit

Permalink
Fix build on Windows targets without dxgi.h, like MingW32.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed May 6, 2014
1 parent 7528f94 commit 2a7aa9b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions configure.in
Expand Up @@ -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"
Expand Down Expand Up @@ -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, [ ])
Expand Down
2 changes: 2 additions & 0 deletions include/SDL_config.h.cmake
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions include/SDL_config.h.in
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions include/SDL_config_windows.h
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions include/SDL_config_winrt.h
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions src/video/windows/SDL_windowsvideo.c
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -344,6 +352,7 @@ SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex)
} else {
return SDL_TRUE;
}
#endif
}

#endif /* SDL_VIDEO_DRIVER_WINDOWS */
Expand Down

0 comments on commit 2a7aa9b

Please sign in to comment.