#include "vulkan_swapchain.h" #include "imgui_impl_vulkan.h" #include "argparse/argparse.hpp" #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") .help("display width of the window") .scan<'i', int>(); program.add_argument("height") .help("display height of the window") .scan<'i', int>(); try { program.parse_args(argc, argv); } catch (const std::exception& err) { std::cerr << err.what() << std::endl; std::cerr << program; return 1; } int window_width = program.get("width"); int window_height = program.get("height"); if (!glfwInit()) { const char* description = nullptr; glfwGetError(&description); if (description != nullptr) { std::cerr << "Error: " << description << std::endl; } else { std::cerr << "Failed to initialize GLFW" << std::endl; } glfwTerminate(); return -1; } auto swapchain = start_up(window_width, window_height); while (!glfwWindowShouldClose(swapchain->window)) { glfwPollEvents(); int 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; } ImGui_ImplVulkan_NewFrame(); } shut_down(swapchain); return 0; }