diff --git a/xo-imgui/example/ex4a/VulkanApp.cpp b/xo-imgui/example/ex4a/VulkanApp.cpp index bffe57cc..dcabcef7 100644 --- a/xo-imgui/example/ex4a/VulkanApp.cpp +++ b/xo-imgui/example/ex4a/VulkanApp.cpp @@ -2,13 +2,48 @@ #include "VulkanApp.hpp" -void MinimalImGuiVulkan::run() -{ - this->init_window(); +void +MinimalImGuiVulkan::run() { + this->init_sdl_window(); this->init_vulkan(); this->init_imgui(); this->main_loop(); this->cleanup(); } +void +MinimalImGuiVulkan::init_sdl_window() { + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + throw std::runtime_error("Failed to initialize SDL!"); + } + + this->window_ = SDL_CreateWindow( + "ImGui Vulkan SDL2 Example", + SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, + 1000, 800, + SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE + ); + + if (!window_) { + throw std::runtime_error("Failed to create SDL window!"); + } +} + +void +MinimalImGuiVulkan::init_vulkan() { + createInstance(); + createSurface(); + pickPhysicalDevice(); + createLogicalDevice(); + this->createSwapchain(); + this->createImageViews(); + this->createRenderPass(); // must come before createFrameBuffers + this->createFramebuffers(); + createCommandPool(); + createCommandBuffers(); + createSyncObjects(); + createDescriptorPool(); +} + /* end VulkanApp.cpp */ diff --git a/xo-imgui/example/ex4a/VulkanApp.hpp b/xo-imgui/example/ex4a/VulkanApp.hpp index 4458b84d..53657a2d 100644 --- a/xo-imgui/example/ex4a/VulkanApp.hpp +++ b/xo-imgui/example/ex4a/VulkanApp.hpp @@ -18,38 +18,13 @@ public: void run(); private: - void init_window() { - if (SDL_Init(SDL_INIT_VIDEO) != 0) { - throw std::runtime_error("Failed to initialize SDL!"); - } + /* create SDL window for application. + * populates @p window_ + */ + void init_sdl_window(); - this->window_ = SDL_CreateWindow( - "ImGui Vulkan SDL2 Example", - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, - 800, 600, - SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE - ); - - if (!window_) { - throw std::runtime_error("Failed to create SDL window!"); - } - } - - void init_vulkan() { - createInstance(); - createSurface(); - pickPhysicalDevice(); - createLogicalDevice(); - this->createSwapchain(); - this->createImageViews(); - this->createRenderPass(); // must come before createFrameBuffers - this->createFramebuffers(); - createCommandPool(); - createCommandBuffers(); - createSyncObjects(); - createDescriptorPool(); - } + /* setup vulkan state. swapchain, command buffers etc */ + void init_vulkan(); void createInstance() { VkApplicationInfo appInfo{};