video: check graphics flags the same way as the type flags

This commit is contained in:
pionere 2022-11-13 08:00:03 +01:00 committed by Sam Lantinga
parent 22354b4142
commit 5f2a1231dd
1 changed files with 8 additions and 15 deletions

View File

@ -1597,7 +1597,7 @@ SDL_Window *
SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
{ {
SDL_Window *window; SDL_Window *window;
Uint32 type_flags, graphics_flags = flags & (SDL_WINDOW_OPENGL | SDL_WINDOW_METAL | SDL_WINDOW_VULKAN); Uint32 type_flags, graphics_flags;
if (!_this) { if (!_this) {
/* Initialize the video system if needed */ /* Initialize the video system if needed */
@ -1627,6 +1627,13 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
return NULL; return NULL;
} }
/* ensure no more than one of these flags is set */
graphics_flags = flags & (SDL_WINDOW_OPENGL | SDL_WINDOW_METAL | SDL_WINDOW_VULKAN);
if ((graphics_flags & (graphics_flags - 1)) != 0) {
SDL_SetError("Conflicting window flags specified");
return NULL;
}
/* Some platforms have certain graphics backends enabled by default */ /* Some platforms have certain graphics backends enabled by default */
if (!graphics_flags && !SDL_IsVideoContextExternal()) { if (!graphics_flags && !SDL_IsVideoContextExternal()) {
#if (SDL_VIDEO_OPENGL && __MACOSX__) || (__IPHONEOS__ && !TARGET_OS_MACCATALYST) || __ANDROID__ || __NACL__ #if (SDL_VIDEO_OPENGL && __MACOSX__) || (__IPHONEOS__ && !TARGET_OS_MACCATALYST) || __ANDROID__ || __NACL__
@ -1656,10 +1663,6 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
SDL_ContextNotSupported("Vulkan"); SDL_ContextNotSupported("Vulkan");
return NULL; return NULL;
} }
if (graphics_flags & SDL_WINDOW_OPENGL) {
SDL_SetError("Vulkan and OpenGL not supported on same window");
return NULL;
}
if (SDL_Vulkan_LoadLibrary(NULL) < 0) { if (SDL_Vulkan_LoadLibrary(NULL) < 0) {
return NULL; return NULL;
} }
@ -1670,16 +1673,6 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
SDL_ContextNotSupported("Metal"); SDL_ContextNotSupported("Metal");
return NULL; return NULL;
} }
/* 'flags' may have default flags appended, don't check against that. */
if (graphics_flags & SDL_WINDOW_OPENGL) {
SDL_SetError("Metal and OpenGL not supported on same window");
return NULL;
}
if (graphics_flags & SDL_WINDOW_VULKAN) {
SDL_SetError("Metal and Vulkan not supported on same window. "
"To use MoltenVK, set SDL_WINDOW_VULKAN only.");
return NULL;
}
} }
/* Unless the user has specified the high-DPI disabling hint, respect the /* Unless the user has specified the high-DPI disabling hint, respect the