Skip to content

Commit

Permalink
Fixed typedef redefinition errors when including both SDL_vulkan.h an…
Browse files Browse the repository at this point in the history
…d vulkan.h

You should always include vulkan/vulkan.h first, then include SDL_vulkan.h
  • Loading branch information
slouken committed Aug 28, 2017
1 parent 9da4717 commit 37ce9f2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 36 deletions.
4 changes: 2 additions & 2 deletions include/SDL.h
Expand Up @@ -40,23 +40,23 @@
#include "SDL_error.h"
#include "SDL_events.h"
#include "SDL_filesystem.h"
#include "SDL_joystick.h"
#include "SDL_gamecontroller.h"
#include "SDL_haptic.h"
#include "SDL_hints.h"
#include "SDL_joystick.h"
#include "SDL_loadso.h"
#include "SDL_log.h"
#include "SDL_messagebox.h"
#include "SDL_mutex.h"
#include "SDL_power.h"
#include "SDL_render.h"
#include "SDL_rwops.h"
#include "SDL_shape.h"
#include "SDL_system.h"
#include "SDL_thread.h"
#include "SDL_timer.h"
#include "SDL_version.h"
#include "SDL_video.h"
#include "SDL_vulkan.h"

#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
Expand Down
47 changes: 25 additions & 22 deletions include/SDL_vulkan.h
@@ -1,23 +1,23 @@
/*
Simple DirectMedia Layer
Copyright (C) 2017, Mark Callow.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
Simple DirectMedia Layer
Copyright (C) 2017, Mark Callow
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

/**
* \file SDL_vulkan.h
Expand All @@ -36,8 +36,11 @@
extern "C" {
#endif

/* Avoid including vulkan.h */
#ifndef VULKAN_H_
/* Avoid including vulkan.h, don't define VkInstance if it's already included */
#ifdef VULKAN_H_
#define NO_SDL_VULKAN_TYPEDEFS
#endif
#ifndef NO_SDL_VULKAN_TYPEDEFS
#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;

#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
Expand All @@ -49,7 +52,7 @@ extern "C" {
VK_DEFINE_HANDLE(VkInstance)
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSurfaceKHR)

#endif /* !VULKAN_H_ */
#endif /* !NO_SDL_VULKAN_TYPEDEFS */

typedef VkInstance SDL_vulkanInstance;
typedef VkSurfaceKHR SDL_vulkanSurface; /* for compatibility with Tizen */
Expand Down
4 changes: 2 additions & 2 deletions src/dynapi/SDL_dynapi.c
Expand Up @@ -32,9 +32,9 @@

#include "SDL.h"

/* !!! FIXME: Shouldn't these be included in SDL.h? */
#include "SDL_shape.h"
/* These headers have system specific definitions, so aren't included above */
#include "SDL_syswm.h"
#include "SDL_vulkan.h"

/* This is the version of the dynamic API. This doesn't match the SDL version
and should not change until there's been a major revamp in API/ABI.
Expand Down
3 changes: 2 additions & 1 deletion src/video/SDL_sysvideo.h
Expand Up @@ -26,7 +26,8 @@
#include "SDL_messagebox.h"
#include "SDL_shape.h"
#include "SDL_thread.h"
#include "SDL_vulkan.h"

#include "SDL_vulkan_internal.h"

/* The SDL video driver */

Expand Down
17 changes: 8 additions & 9 deletions src/video/SDL_vulkan_internal.h
Expand Up @@ -18,8 +18,8 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _SDL_vulkan_internal_h
#define _SDL_vulkan_internal_h
#ifndef SDL_vulkan_internal_h_
#define SDL_vulkan_internal_h_

#include "../SDL_internal.h"

Expand Down Expand Up @@ -53,14 +53,13 @@
#define VK_USE_PLATFORM_XCB_KHR
#endif

#if SDL_VIDEO_VULKAN_SURFACE

/* Need vulkan.h for the following declarations. Must ensure the first
* inclusion of vulkan has the appropriate USE_PLATFORM defined, hence
* the above. */
#define VK_NO_PROTOTYPES
#include "./khronos/vulkan/vulkan.h"

#include "SDL_vulkan.h"

#if SDL_VIDEO_VULKAN_SURFACE

extern const char *SDL_Vulkan_GetResultString(VkResult result);

extern VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList(
Expand All @@ -73,8 +72,8 @@ extern SDL_bool SDL_Vulkan_GetInstanceExtensions_Helper(unsigned *userCount,
const char **userNames,
unsigned nameCount,
const char *const *names);
#endif /* SDL_VIDEO_VULKAN_SURFACE */

#endif
#endif /* SDL_vulkan_internal_h_ */

#endif
/* vi: set ts=4 sw=4 expandtab: */
1 change: 1 addition & 0 deletions test/testvulkan.c
Expand Up @@ -33,6 +33,7 @@ int main(int argc, char *argv[])
/* SDL includes a copy for building on systems without the Vulkan SDK */
#include "../src/video/khronos/vulkan/vulkan.h"
#endif
#include "SDL_vulkan.h"

#ifndef UINT64_MAX /* VS2008 */
#define UINT64_MAX 18446744073709551615
Expand Down

0 comments on commit 37ce9f2

Please sign in to comment.