From 7f14138e1baa2c40fb30d90ebcd45ad17b12e0a3 Mon Sep 17 00:00:00 2001 From: Chuyan Zhang Date: Mon, 9 Sep 2024 00:30:29 -0700 Subject: Fixing swapchain --- src/app.cpp | 84 +++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 30 deletions(-) (limited to 'src/app.cpp') diff --git a/src/app.cpp b/src/app.cpp index a5b3247..6148e04 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -1,37 +1,20 @@ +#include "imgui.h" #include "vulkan_swapchain.h" #include "imgui_impl_vulkan.h" #include "argparse/argparse.hpp" #include #include +#include +#include #define GLFW_INCLUDE_VULKAN #include #include #include -#include #include -std::unique_ptr start_up(int width, int height) { - auto glfw_extensions = get_glfw_instance_extensions(); - iris::Device device({}, glfw_extensions); - - auto window = glfwCreateWindow(width, height, "IrisRenderer", nullptr, nullptr); - if (window == nullptr) { - std::cerr << "Failed to create GLFW window" << std::endl; - abort(); - } - return std::make_unique(window, device); -} - -void shut_down(std::unique_ptr& swapchain) { - ImGui_ImplVulkan_Shutdown(); - - glfwDestroyWindow(swapchain->window); - glfwTerminate(); -} - int main(int argc, char** argv) { argparse::ArgumentParser program("IrisRenderer"); program.add_argument("width") @@ -64,28 +47,69 @@ int main(int argc, char** argv) { glfwTerminate(); return -1; } + auto glfw_extensions = get_glfw_instance_extensions(); + for (const auto& extension : glfw_extensions) { + std::cerr << "GLFW extension: " << extension << std::endl; + } + + std::vector layers; + iris::Device device({}, glfw_extensions); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + auto window = glfwCreateWindow(window_width, window_height, "IrisRenderer", nullptr, nullptr); + if (window == nullptr) { + std::cerr << "Failed to create GLFW window" << std::endl; + abort(); + } - auto swapchain = start_up(window_width, window_height); - while (!glfwWindowShouldClose(swapchain->window)) { + // load debug image + iris::Texture2D debug_texture = device.create_texture_from_image( + "assets/debug.png", + VK_FORMAT_R8G8B8A8_UNORM, + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, + VmaAllocationCreateInfo { + .flags = VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT, + .usage = VMA_MEMORY_USAGE_AUTO, + }); + // end load debug image + + auto swapchain = iris::Swapchain(window, device, window_width, window_height); + std::cerr << "Swapchain created" << std::endl; + while (!glfwWindowShouldClose(swapchain.window)) { glfwPollEvents(); int display_w, display_h; - glfwGetFramebufferSize(swapchain->window, &display_w, &display_h); + glfwGetFramebufferSize(swapchain.window, &display_w, &display_h); if (display_w == 0 || display_h == 0) { break; } - swapchain->needs_recreate |= - (uint32_t) display_w != swapchain->width || - (uint32_t) display_h != swapchain->height; - if (swapchain->needs_recreate) { - swapchain->resize(display_w, display_h); - swapchain->needs_recreate = false; + swapchain.needs_recreate |= + (uint32_t) display_w != swapchain.width || + (uint32_t) display_h != swapchain.height; + if (swapchain.needs_recreate) { + swapchain.resize(display_w, display_h); + swapchain.needs_recreate = false; } + std::cerr << "Rendering frame" << std::endl; ImGui_ImplVulkan_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + swapchain.start_frame(); + std::cerr << "Frame started" << std::endl; + ImGui::NewFrame(); + ImGui::ShowDemoWindow(); + ImGui::Render(); + std::cerr << "ImGui rendered" << std::endl; + swapchain.display(debug_texture); + std::cerr << "Frame displayed" << std::endl; } - shut_down(swapchain); + ImGui_ImplVulkan_Shutdown(); + + glfwDestroyWindow(swapchain.window); + glfwTerminate(); + device.destroy(); + return 0; } \ No newline at end of file -- cgit v1.2.3-70-g09d2