diff options
author | Chuyan Zhang <me@zcy.moe> | 2024-09-09 00:30:29 -0700 |
---|---|---|
committer | Chuyan Zhang <me@zcy.moe> | 2024-09-09 00:30:29 -0700 |
commit | 7f14138e1baa2c40fb30d90ebcd45ad17b12e0a3 (patch) | |
tree | d9ad5dbb2871e3999480e55ffa24bea6e50f8dd4 /src/app.cpp | |
parent | 2ead02037dc89e987fbc0a021fe470e29d226cfd (diff) | |
download | iris-7f14138e1baa2c40fb30d90ebcd45ad17b12e0a3.tar.gz iris-7f14138e1baa2c40fb30d90ebcd45ad17b12e0a3.zip |
Fixing swapchain
Diffstat (limited to 'src/app.cpp')
-rw-r--r-- | src/app.cpp | 84 |
1 files changed, 54 insertions, 30 deletions
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 <cstdint> #include <sys/types.h> +#include <vk_mem_alloc.h> +#include <vulkan/vulkan_core.h> #define GLFW_INCLUDE_VULKAN #include <GLFW/glfw3.h> #include <cstdlib> #include <iostream> -#include <memory> #include <vector> -std::unique_ptr<iris::Swapchain> 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<iris::Swapchain>(window, device); -} - -void shut_down(std::unique_ptr<iris::Swapchain>& 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<std::string> 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 |