Quellcode durchsuchen

Examples: Vulkan: SDL: Fixed missing resize handler (not properly merged from #1367) + tweaks.

omar vor 7 Jahren
Ursprung
Commit
68e9ef9885
2 geänderte Dateien mit 12 neuen und 5 gelöschten Zeilen
  1. 4 2
      examples/sdl_vulkan_example/main.cpp
  2. 8 3
      examples/vulkan_example/main.cpp

+ 4 - 2
examples/sdl_vulkan_example/main.cpp

@@ -57,7 +57,7 @@ static void check_vk_result(VkResult err)
         abort();
         abort();
 }
 }
 
 
-static void resize_vulkan(SDL_Window*, int w, int h)
+static void CreateOrResizeSwapChainAndFrameBuffer(int w, int h)
 {
 {
     VkResult err;
     VkResult err;
     VkSwapchainKHR old_swapchain = g_Swapchain;
     VkSwapchainKHR old_swapchain = g_Swapchain;
@@ -340,7 +340,7 @@ static void setup_vulkan(SDL_Window* window, const char** extensions, uint32_t e
     {
     {
         int w, h;
         int w, h;
         SDL_GetWindowSize(window, &w, &h);
         SDL_GetWindowSize(window, &w, &h);
-        resize_vulkan(window, w, h);
+        CreateOrResizeSwapChainAndFrameBuffer(w, h);
     }
     }
 
 
 
 
@@ -639,6 +639,8 @@ int main(int, char**)
             ImGui_ImplSDL2_ProcessEvent(&event);
             ImGui_ImplSDL2_ProcessEvent(&event);
             if (event.type == SDL_QUIT)
             if (event.type == SDL_QUIT)
                 done = true;
                 done = true;
+            if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED && event.window.windowID == SDL_GetWindowID(window)) 
+                CreateOrResizeSwapChainAndFrameBuffer((int)event.window.data1, (int)event.window.data2);
         }
         }
         ImGui_ImplVulkan_NewFrame();
         ImGui_ImplVulkan_NewFrame();
         ImGui_ImplSDL2_NewFrame(window);
         ImGui_ImplSDL2_NewFrame(window);

+ 8 - 3
examples/vulkan_example/main.cpp

@@ -60,7 +60,7 @@ static void check_vk_result(VkResult err)
         abort();
         abort();
 }
 }
 
 
-static void resize_vulkan(GLFWwindow*, int w, int h)
+static void CreateOrResizeSwapChainAndFrameBuffer(int w, int h)
 {
 {
     VkResult err;
     VkResult err;
     VkSwapchainKHR old_swapchain = g_Swapchain;
     VkSwapchainKHR old_swapchain = g_Swapchain;
@@ -189,6 +189,11 @@ static void resize_vulkan(GLFWwindow*, int w, int h)
     }
     }
 }
 }
 
 
+static void GlfwResizeCallback(GLFWwindow*, int w, int h)
+{
+    CreateOrResizeSwapChainAndFrameBuffer(w, h);
+}
+
 #ifdef IMGUI_VULKAN_DEBUG_REPORT
 #ifdef IMGUI_VULKAN_DEBUG_REPORT
 static VKAPI_ATTR VkBool32 VKAPI_CALL debug_report(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object, size_t location, int32_t messageCode, const char* pLayerPrefix, const char* pMessage, void* pUserData)
 static VKAPI_ATTR VkBool32 VKAPI_CALL debug_report(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object, size_t location, int32_t messageCode, const char* pLayerPrefix, const char* pMessage, void* pUserData)
 {
 {
@@ -340,8 +345,8 @@ static void setup_vulkan(GLFWwindow* window, const char** extensions, uint32_t e
     {
     {
         int w, h;
         int w, h;
         glfwGetFramebufferSize(window, &w, &h);
         glfwGetFramebufferSize(window, &w, &h);
-        resize_vulkan(window, w, h);
-        glfwSetFramebufferSizeCallback(window, resize_vulkan);
+        CreateOrResizeSwapChainAndFrameBuffer(w, h);
+        glfwSetFramebufferSizeCallback(window, GlfwResizeCallback);
     }
     }