Commit 035f8f239197e167c11ee098fdab54dc499010ec

Sylvain Becker 2020-12-02T13:37:59

SDL_RecreateWindow: allow clearing VULKAN when recreating the window

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 65aafc6..9f5bbb2 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -1674,6 +1674,9 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
     SDL_bool loaded_opengl = SDL_FALSE;
     SDL_bool need_gl_unload = SDL_FALSE;
     SDL_bool need_gl_load = SDL_FALSE;
+    SDL_bool loaded_vulkan = SDL_FALSE;
+    SDL_bool need_vulkan_unload = SDL_FALSE;
+    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 "
@@ -1728,8 +1731,14 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
     }
 
     if ((window->flags & SDL_WINDOW_VULKAN) != (flags & SDL_WINDOW_VULKAN)) {
-        SDL_SetError("Can't change SDL_WINDOW_VULKAN window flag");
-        return -1;
+        if (flags & SDL_WINDOW_VULKAN) {
+            need_vulkan_load = SDL_TRUE;
+        } else {
+            need_vulkan_unload = SDL_TRUE;
+        }
+    } else if (window->flags & SDL_WINDOW_VULKAN) {
+        need_vulkan_unload = SDL_TRUE;
+        need_vulkan_load  = SDL_TRUE;
     }
 
     if ((flags & SDL_WINDOW_VULKAN) && (flags & SDL_WINDOW_OPENGL)) {
@@ -1751,6 +1760,10 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
         SDL_GL_UnloadLibrary();
     }
 
+    if (need_vulkan_unload) {
+        SDL_Vulkan_UnloadLibrary();
+    }
+
     if (need_gl_load) {
         if (SDL_GL_LoadLibrary(NULL) < 0) {
             return -1;
@@ -1758,6 +1771,13 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
         loaded_opengl = SDL_TRUE;
     }
 
+    if (need_vulkan_unload) {
+        if (SDL_Vulkan_LoadLibrary(NULL) < 0) {
+            return -1;
+        }
+        loaded_vulkan = SDL_TRUE;
+    }
+
     window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
     window->last_fullscreen_flags = window->flags;
     window->is_destroying = SDL_FALSE;
@@ -1768,6 +1788,10 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
                 SDL_GL_UnloadLibrary();
                 window->flags &= ~SDL_WINDOW_OPENGL;
             }
+            if (loaded_vulkan) {
+                SDL_Vulkan_UnloadLibrary();
+                window->flags &= ~SDL_WINDOW_VULKAN;
+            }
             return -1;
         }
     }