From e12ca33626bdadedc3158cb69f2a4d2f9bbeeeb0 Mon Sep 17 00:00:00 2001 From: Chuyan Zhang Date: Fri, 6 Sep 2024 01:50:30 -0700 Subject: setup swapchain --- src/app.cpp | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) (limited to 'src/app.cpp') diff --git a/src/app.cpp b/src/app.cpp index 7ef2310..b3df2a5 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -1,21 +1,45 @@ +#include "vulkan_swapchain.h" + #include "imgui.h" #include "imgui_impl_glfw.h" #include "imgui_impl_vulkan.h" #include "argparse/argparse.hpp" + +#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(); + // std::vector glfw_extensions = { + // "VK_KHR_surface", + // }; + // for (const auto& extension : glfw_extensions) { + // std::cerr << "GLFW extension: " << extension << std::endl; + // } + iris::Device device({}, glfw_extensions); -GLFWwindow *start_up(int width, int height) { - return nullptr; + 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 main_loop(GLFWwindow *window) { - + (void) window; } -void shut_down(GLFWwindow *window) { +void shut_down(std::unique_ptr& swapchain) { + ImGui_ImplVulkan_Shutdown(); + glfwDestroyWindow(swapchain->window); + glfwTerminate(); } int main(int argc, char** argv) { @@ -51,13 +75,11 @@ int main(int argc, char** argv) { return -1; } - auto window = start_up(window_width, window_height); - if (window == nullptr) { - return -2; + auto swapchain = start_up(window_width, window_height); + while (!glfwWindowShouldClose(swapchain->window)) { + main_loop(swapchain->window); } - while (!glfwWindowShouldClose(window)) { - main_loop(window); - } - shut_down(window); + + shut_down(swapchain); return 0; } \ No newline at end of file -- cgit v1.2.3-70-g09d2