mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-19 14:36:34 +00:00
Examples: Vulkan: Only resize swap chain and framebuffer once. (#1042)
This commit is contained in:
parent
1c18d65313
commit
37cb177745
@ -34,7 +34,9 @@ static VkPresentModeKHR g_PresentMode;
|
|||||||
static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
|
static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
|
||||||
static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
|
static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
|
||||||
|
|
||||||
static int fb_width, fb_height;
|
static int fb_width = 0, fb_height = 0;
|
||||||
|
static bool g_ResizeWanted = false;
|
||||||
|
static int g_ResizeWidth = 0, g_ResizeHeight = 0;
|
||||||
static uint32_t g_BackbufferIndices[IMGUI_VK_QUEUED_FRAMES]; // keep track of recently rendered swapchain frame indices
|
static uint32_t g_BackbufferIndices[IMGUI_VK_QUEUED_FRAMES]; // keep track of recently rendered swapchain frame indices
|
||||||
static uint32_t g_BackBufferCount = 0;
|
static uint32_t g_BackBufferCount = 0;
|
||||||
static VkImage g_BackBuffer[IMGUI_MAX_POSSIBLE_BACK_BUFFERS] = {};
|
static VkImage g_BackBuffer[IMGUI_MAX_POSSIBLE_BACK_BUFFERS] = {};
|
||||||
@ -58,7 +60,7 @@ static void check_vk_result(VkResult err)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resize_vulkan(GLFWwindow* /*window*/, int w, int h)
|
static void resize_vulkan(int w, int h)
|
||||||
{
|
{
|
||||||
VkResult err;
|
VkResult err;
|
||||||
VkSwapchainKHR old_swapchain = g_Swapchain;
|
VkSwapchainKHR old_swapchain = g_Swapchain;
|
||||||
@ -355,7 +357,7 @@ static void setup_vulkan(GLFWwindow* window)
|
|||||||
|
|
||||||
// Get Present Mode
|
// Get Present Mode
|
||||||
{
|
{
|
||||||
// Requst a certain mode and confirm that it is available. If not use VK_PRESENT_MODE_FIFO_KHR which is mandatory
|
// Request a certain mode and confirm that it is available. If not use VK_PRESENT_MODE_FIFO_KHR which is mandatory
|
||||||
#ifdef IMGUI_UNLIMITED_FRAME_RATE
|
#ifdef IMGUI_UNLIMITED_FRAME_RATE
|
||||||
g_PresentMode = VK_PRESENT_MODE_IMMEDIATE_KHR;
|
g_PresentMode = VK_PRESENT_MODE_IMMEDIATE_KHR;
|
||||||
#else
|
#else
|
||||||
@ -406,8 +408,7 @@ static void setup_vulkan(GLFWwindow* window)
|
|||||||
{
|
{
|
||||||
int w, h;
|
int w, h;
|
||||||
glfwGetFramebufferSize(window, &w, &h);
|
glfwGetFramebufferSize(window, &w, &h);
|
||||||
resize_vulkan(window, w, h);
|
resize_vulkan(w, h);
|
||||||
glfwSetFramebufferSizeCallback(window, resize_vulkan);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Command Buffers
|
// Create Command Buffers
|
||||||
@ -588,6 +589,13 @@ static void glfw_error_callback(int error, const char* description)
|
|||||||
fprintf(stderr, "Error %d: %s\n", error, description);
|
fprintf(stderr, "Error %d: %s\n", error, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void glfw_resize_callback(GLFWwindow*, int w, int h)
|
||||||
|
{
|
||||||
|
g_ResizeWanted = true;
|
||||||
|
g_ResizeWidth = w;
|
||||||
|
g_ResizeHeight = h;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
// Setup window
|
// Setup window
|
||||||
@ -605,6 +613,7 @@ int main(int, char**)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
setup_vulkan(window);
|
setup_vulkan(window);
|
||||||
|
glfwSetFramebufferSizeCallback(window, glfw_resize_callback);
|
||||||
|
|
||||||
// Setup ImGui binding
|
// Setup ImGui binding
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
@ -680,6 +689,11 @@ int main(int, char**)
|
|||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
|
if (g_ResizeWanted)
|
||||||
|
resize_vulkan(g_ResizeWidth, g_ResizeHeight);
|
||||||
|
g_ResizeWanted = false;
|
||||||
|
|
||||||
ImGui_ImplGlfwVulkan_NewFrame();
|
ImGui_ImplGlfwVulkan_NewFrame();
|
||||||
|
|
||||||
// 1. Show a simple window.
|
// 1. Show a simple window.
|
||||||
|
Loading…
Reference in New Issue
Block a user