add SDL_ContextNotSupported and validate flags in SDL_RecreateWindow similar to SDL_CreateWindow

This commit is contained in:
pionere 2022-11-10 08:23:16 +01:00 committed by Sam Lantinga
parent 1008cc8e5f
commit 29cafa9c94
1 changed files with 21 additions and 21 deletions

View File

@ -1579,6 +1579,14 @@ SDL_FinishWindowCreation(SDL_Window *window, Uint32 flags)
} }
} }
static int
SDL_ContextNotSupported(const char *name)
{
return SDL_SetError("%s support is either not configured in SDL "
"or not available in current SDL video driver "
"(%s) or platform", name, _this->name);
}
SDL_Window * 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)
{ {
@ -1627,9 +1635,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
if (flags & SDL_WINDOW_OPENGL) { if (flags & SDL_WINDOW_OPENGL) {
if (!_this->GL_CreateContext) { if (!_this->GL_CreateContext) {
SDL_SetError("OpenGL support is either not configured in SDL " SDL_ContextNotSupported("OpenGL");
"or not available in current SDL video driver "
"(%s) or platform", _this->name);
return NULL; return NULL;
} }
if (SDL_GL_LoadLibrary(NULL) < 0) { if (SDL_GL_LoadLibrary(NULL) < 0) {
@ -1639,9 +1645,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
if (flags & SDL_WINDOW_VULKAN) { if (flags & SDL_WINDOW_VULKAN) {
if (!_this->Vulkan_CreateSurface) { if (!_this->Vulkan_CreateSurface) {
SDL_SetError("Vulkan support is either not configured in SDL " SDL_ContextNotSupported("Vulkan");
"or not available in current SDL video driver "
"(%s) or platform", _this->name);
return NULL; return NULL;
} }
if (graphics_flags & SDL_WINDOW_OPENGL) { if (graphics_flags & SDL_WINDOW_OPENGL) {
@ -1655,9 +1659,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
if (flags & SDL_WINDOW_METAL) { if (flags & SDL_WINDOW_METAL) {
if (!_this->Metal_CreateView) { if (!_this->Metal_CreateView) {
SDL_SetError("Metal support is either not configured in SDL " SDL_ContextNotSupported("Metal");
"or not available in current SDL video driver "
"(%s) or platform", _this->name);
return NULL; return NULL;
} }
/* 'flags' may have default flags appended, don't check against that. */ /* 'flags' may have default flags appended, don't check against that. */
@ -1809,9 +1811,7 @@ SDL_CreateWindowFrom(const void *data)
if (SDL_GetHintBoolean(SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL, SDL_FALSE)) { if (SDL_GetHintBoolean(SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL, SDL_FALSE)) {
if (!_this->GL_CreateContext) { if (!_this->GL_CreateContext) {
SDL_SetError("OpenGL support is either not configured in SDL " SDL_ContextNotSupported("OpenGL");
"or not available in current SDL video driver "
"(%s) or platform", _this->name);
return NULL; return NULL;
} }
if (SDL_GL_LoadLibrary(NULL) < 0) { if (SDL_GL_LoadLibrary(NULL) < 0) {
@ -1822,9 +1822,7 @@ SDL_CreateWindowFrom(const void *data)
if (SDL_GetHintBoolean(SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN, SDL_FALSE)) { if (SDL_GetHintBoolean(SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN, SDL_FALSE)) {
if (!_this->Vulkan_CreateSurface) { if (!_this->Vulkan_CreateSurface) {
SDL_SetError("Vulkan support is either not configured in SDL " SDL_ContextNotSupported("Vulkan");
"or not available in current SDL video driver "
"(%s) or platform", _this->name);
return NULL; return NULL;
} }
if (flags & SDL_WINDOW_OPENGL) { if (flags & SDL_WINDOW_OPENGL) {
@ -1877,9 +1875,13 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
SDL_bool need_vulkan_load = SDL_FALSE; SDL_bool need_vulkan_load = SDL_FALSE;
if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
return SDL_SetError("OpenGL support is either not configured in SDL " return SDL_ContextNotSupported("OpenGL");
"or not available in current SDL video driver " }
"(%s) or platform", _this->name); if ((flags & SDL_WINDOW_VULKAN) && !_this->Vulkan_CreateSurface) {
return SDL_ContextNotSupported("Vulkan");
}
if ((flags & SDL_WINDOW_METAL) && !_this->Metal_CreateView) {
return SDL_ContextNotSupported("Metal");
} }
if (window->flags & SDL_WINDOW_FOREIGN) { if (window->flags & SDL_WINDOW_FOREIGN) {
@ -4753,9 +4755,7 @@ int SDL_Vulkan_LoadLibrary(const char *path)
retval = 0; retval = 0;
} else { } else {
if (!_this->Vulkan_LoadLibrary) { if (!_this->Vulkan_LoadLibrary) {
return SDL_SetError("Vulkan support is either not configured in SDL " return SDL_ContextNotSupported("Vulkan");
"or not available in current SDL video driver "
"(%s) or platform", _this->name);
} }
retval = _this->Vulkan_LoadLibrary(_this, path); retval = _this->Vulkan_LoadLibrary(_this, path);
} }