Skip to content

Commit

Permalink
Examples: Vulkan: Reworked buffer resize handling, fix for Linux/X11. (
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut authored and RoryO committed Sep 4, 2020
1 parent e8001e1 commit 223392b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ Other Changes:
- Backends: OpenGL3: Added support for glad2 loader. (#3330) [@moritz-h]
- Backends: Allegro 5: Fixed horizontal scrolling direction with mouse wheel / touch pads (it seems
like Allegro 5 reports it differently from GLFW and SDL). (#3394, #2424, #1463) [@nobody-special666]
- Examples: Vulkan: Reworked buffer resize handling, fix for Linux/X11. (#3390, #2626) [@RoryO]
- Examples: Vulkan: Fixed GLFW+Vulkan and SDL+Vulkan clear color not being set. (#3390) [@RoryO]
- CI: Emscripten has stopped their support for their fastcomp backend, switching to latest sdk [@Xipiryon]

Expand Down
17 changes: 8 additions & 9 deletions examples/example_glfw_vulkan/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;

static ImGui_ImplVulkanH_Window g_MainWindowData;
static int g_MinImageCount = 2;
static GLFWwindow* g_Window;
static bool g_SwapChainRebuild = false;
static int g_SwapChainResizeWidth = 0;
static int g_SwapChainResizeHeight = 0;
Expand Down Expand Up @@ -345,7 +344,7 @@ int main(int, char**)
return 1;

glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
g_Window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+Vulkan example", NULL, NULL);
GLFWwindow *window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+Vulkan example", NULL, NULL);

// Setup Vulkan
if (!glfwVulkanSupported())
Expand All @@ -359,12 +358,12 @@ int main(int, char**)

// Create Window Surface
VkSurfaceKHR surface;
VkResult err = glfwCreateWindowSurface(g_Instance, g_Window, g_Allocator, &surface);
VkResult err = glfwCreateWindowSurface(g_Instance, window, g_Allocator, &surface);
check_vk_result(err);

// Create Framebuffers
int w, h;
glfwGetFramebufferSize(g_Window, &w, &h);
glfwGetFramebufferSize(window, &w, &h);
ImGui_ImplVulkanH_Window* wd = &g_MainWindowData;
SetupVulkanWindow(wd, surface, w, h);

Expand Down Expand Up @@ -392,7 +391,7 @@ int main(int, char**)
}

// Setup Platform/Renderer bindings
ImGui_ImplGlfw_InitForVulkan(g_Window, true);
ImGui_ImplGlfw_InitForVulkan(window, true);
ImGui_ImplVulkan_InitInfo init_info = {};
init_info.Instance = g_Instance;
init_info.PhysicalDevice = g_PhysicalDevice;
Expand Down Expand Up @@ -462,7 +461,7 @@ int main(int, char**)
wd->ClearValue.color.float32[3] = clear_color.w;

// Main loop
while (!glfwWindowShouldClose(g_Window))
while (!glfwWindowShouldClose(window))
{
// Poll and handle events (inputs, window resize, etc.)
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
Expand Down Expand Up @@ -545,9 +544,9 @@ int main(int, char**)

// Present Main Platform Window
if (!main_is_minimized)
FramePresent(wd);
}
FramePresent(wd, window);

}
// Cleanup
err = vkDeviceWaitIdle(g_Device);
check_vk_result(err);
Expand All @@ -558,7 +557,7 @@ int main(int, char**)
CleanupVulkanWindow();
CleanupVulkan();

glfwDestroyWindow(g_Window);
glfwDestroyWindow(window);
glfwTerminate();

return 0;
Expand Down
19 changes: 9 additions & 10 deletions examples/example_sdl_vulkan/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ static uint32_t g_MinImageCount = 2;
static bool g_SwapChainRebuild = false;
static int g_SwapChainResizeWidth = 0;
static int g_SwapChainResizeHeight = 0;
static SDL_Window* g_Window;

static void check_vk_result(VkResult err)
{
Expand Down Expand Up @@ -335,28 +334,28 @@ int main(int, char**)

// Setup window
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
g_Window = SDL_CreateWindow("Dear ImGui SDL2+Vulkan example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+Vulkan example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);

// Setup Vulkan
uint32_t extensions_count = 0;
SDL_Vulkan_GetInstanceExtensions(g_Window, &extensions_count, NULL);
SDL_Vulkan_GetInstanceExtensions(window, &extensions_count, NULL);
const char** extensions = new const char*[extensions_count];
SDL_Vulkan_GetInstanceExtensions(g_Window, &extensions_count, extensions);
SDL_Vulkan_GetInstanceExtensions(window, &extensions_count, extensions);
SetupVulkan(extensions, extensions_count);
delete[] extensions;

// Create Window Surface
VkSurfaceKHR surface;
VkResult err;
if (SDL_Vulkan_CreateSurface(g_Window, g_Instance, &surface) == 0)
if (SDL_Vulkan_CreateSurface(window, g_Instance, &surface) == 0)
{
printf("Failed to create Vulkan surface.\n");
return 1;
}

// Create Framebuffers
int w, h;
SDL_GetWindowSize(g_Window, &w, &h);
SDL_GetWindowSize(window, &w, &h);
ImGui_ImplVulkanH_Window* wd = &g_MainWindowData;
SetupVulkanWindow(wd, surface, w, h);

Expand Down Expand Up @@ -384,7 +383,7 @@ int main(int, char**)
}

// Setup Platform/Renderer bindings
ImGui_ImplSDL2_InitForVulkan(g_Window);
ImGui_ImplSDL2_InitForVulkan(window);
ImGui_ImplVulkan_InitInfo init_info = {};
init_info.Instance = g_Instance;
init_info.PhysicalDevice = g_PhysicalDevice;
Expand Down Expand Up @@ -481,7 +480,7 @@ int main(int, char**)

// Start the Dear ImGui frame
ImGui_ImplVulkan_NewFrame();
ImGui_ImplSDL2_NewFrame(g_Window);
ImGui_ImplSDL2_NewFrame(window);
ImGui::NewFrame();

// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
Expand Down Expand Up @@ -544,7 +543,7 @@ int main(int, char**)

// Present Main Platform Window
if (!main_is_minimized)
FramePresent(wd);
FramePresent(wd, window);
}

// Cleanup
Expand All @@ -557,7 +556,7 @@ int main(int, char**)
CleanupVulkanWindow();
CleanupVulkan();

SDL_DestroyWindow(g_Window);
SDL_DestroyWindow(window);
SDL_Quit();

return 0;
Expand Down

0 comments on commit 223392b

Please sign in to comment.