add SDL_ContextNotSupported and validate flags in SDL_RecreateWindow similar to SDL_CreateWindow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index dde4912..7994c19 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);
}