video: Add a hint to allow Vulkan surfaces on foreign windows
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
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 384320e..ec228fb 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -1454,6 +1454,17 @@ extern "C" {
#define SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT"
/**
+ * \brief When calling SDL_CreateWindowFrom(), make the window compatible with Vulkan.
+ *
+ * This variable can be set to the following values:
+ * "0" - Don't add any graphics flags to the SDL_WindowFlags
+ * "1" - Add SDL_WINDOW_VULKAN to the SDL_WindowFlags
+ *
+ * By default SDL will not make the foreign window compatible with Vulkan.
+ */
+#define SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN "SDL_VIDEO_FOREIGN_WINDOW_VULKAN"
+
+/**
* \brief A variable specifying which shader compiler to preload when using the Chrome ANGLE binaries
*
* SDL has EGL and OpenGL ES2 support on Windows via the ANGLE project. It
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 2648c44..6fd668c 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -1703,6 +1703,16 @@ SDL_CreateWindowFrom(const void *data)
}
_this->windows = window;
+#if SDL_VIDEO_VULKAN
+ if (SDL_GetHintBoolean(SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN, SDL_FALSE)) {
+ window->flags |= SDL_WINDOW_VULKAN;
+ if (SDL_Vulkan_LoadLibrary(NULL) < 0) {
+ SDL_DestroyWindow(window);
+ return NULL;
+ }
+ }
+#endif
+
if (_this->CreateSDLWindowFrom(_this, window, data) < 0) {
SDL_DestroyWindow(window);
return NULL;