From 29cafa9c94e4db6dadfae43aece9fb2edcac121b Mon Sep 17 00:00:00 2001 From: pionere Date: Thu, 10 Nov 2022 08:23:16 +0100 Subject: [PATCH] add SDL_ContextNotSupported and validate flags in SDL_RecreateWindow similar to SDL_CreateWindow --- src/video/SDL_video.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index dde4912ad..7994c1943 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -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_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 (!_this->GL_CreateContext) { - SDL_SetError("OpenGL support is either not configured in SDL " - "or not available in current SDL video driver " - "(%s) or platform", _this->name); + SDL_ContextNotSupported("OpenGL"); return NULL; } 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 (!_this->Vulkan_CreateSurface) { - SDL_SetError("Vulkan support is either not configured in SDL " - "or not available in current SDL video driver " - "(%s) or platform", _this->name); + SDL_ContextNotSupported("Vulkan"); return NULL; } 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 (!_this->Metal_CreateView) { - SDL_SetError("Metal support is either not configured in SDL " - "or not available in current SDL video driver " - "(%s) or platform", _this->name); + SDL_ContextNotSupported("Metal"); return NULL; } /* '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 (!_this->GL_CreateContext) { - SDL_SetError("OpenGL support is either not configured in SDL " - "or not available in current SDL video driver " - "(%s) or platform", _this->name); + SDL_ContextNotSupported("OpenGL"); return NULL; } 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 (!_this->Vulkan_CreateSurface) { - SDL_SetError("Vulkan support is either not configured in SDL " - "or not available in current SDL video driver " - "(%s) or platform", _this->name); + SDL_ContextNotSupported("Vulkan"); return NULL; } if (flags & SDL_WINDOW_OPENGL) { @@ -1877,9 +1875,13 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags) SDL_bool need_vulkan_load = SDL_FALSE; if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { - return SDL_SetError("OpenGL support is either not configured in SDL " - "or not available in current SDL video driver " - "(%s) or platform", _this->name); + return SDL_ContextNotSupported("OpenGL"); + } + 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) { @@ -4753,9 +4755,7 @@ int SDL_Vulkan_LoadLibrary(const char *path) retval = 0; } else { if (!_this->Vulkan_LoadLibrary) { - return SDL_SetError("Vulkan support is either not configured in SDL " - "or not available in current SDL video driver " - "(%s) or platform", _this->name); + return SDL_ContextNotSupported("Vulkan"); } retval = _this->Vulkan_LoadLibrary(_this, path); }