
.. _program_listing_file_Src_GraphicsEngineVulkan_app_App.cpp:

Program Listing for File App.cpp
================================

|exhale_lsh| :ref:`Return to documentation for file <file_Src_GraphicsEngineVulkan_app_App.cpp>` (``Src/GraphicsEngineVulkan/app/App.cpp``)

.. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS

.. code-block:: cpp

   module;
   
   #include <cstdlib>
   #define GLFW_INCLUDE_NONE
   #include <GLFW/glfw3.h>
   
   #define GLM_FORCE_RADIANS
   #define GLM_FORCE_DEPTH_ZERO_TO_ONE
   
   #include <format>
   #include <memory>
   
   #include "spdlog/spdlog.h"
   
   module kataglyphis.vulkan.app;
   
   import kataglyphis.shared.frontend.frame_input;
   
   import kataglyphis.vulkan.camera;
   import kataglyphis.vulkan.gui;
   import kataglyphis.vulkan.renderer;
   import kataglyphis.vulkan.scene;
   import kataglyphis.vulkan.window;
   
   Kataglyphis::App::App() = default;
   
   auto Kataglyphis::App::run() -> int
   {
       int const window_width = 1280;
       int const window_height = 720;
   
       float delta_time = 0.0F;
       float last_time = 0.0F;
   
       std::unique_ptr<Kataglyphis::Frontend::Window> const window =
         std::make_unique<Kataglyphis::Frontend::Window>(window_width, window_height);
       std::unique_ptr<Scene> const scene = std::make_unique<Scene>();
       std::unique_ptr<Kataglyphis::Frontend::GUI> const gui = std::make_unique<Kataglyphis::Frontend::GUI>(window.get());
       std::unique_ptr<Camera> const camera = std::make_unique<Camera>();
   
       Kataglyphis::VulkanRenderer vulkan_renderer{ window.get(), scene.get(), gui.get(), camera.get() };
   
       while (!window->get_should_close()) {
           // poll all events incoming from user
           glfwPollEvents();
   
           Kataglyphis::Frontend::update_frame_timing(delta_time, last_time);
   
           // handle events for the camera
           Kataglyphis::Frontend::process_camera_input(window.get(), camera.get(), delta_time);
   
           gui->render();
   
           // Then update Scene/Renderer state with the NEW GUI values
           scene->update_user_input(gui.get());
           vulkan_renderer.updateStateDueToUserInput(gui.get());
           vulkan_renderer.updateUniforms(scene.get(), camera.get(), window.get());
   
           // Finally draw the frame with the updated state
           vulkan_renderer.drawFrame();
       }
   
       if (!vulkan_renderer.hasDeviceLost()) { vulkan_renderer.finishAllRenderCommands(); }
   
       if (!vulkan_renderer.hasDeviceLost()) {
           scene->cleanUp();
           gui->cleanUp();
       } else {
           spdlog::warn("Skipping scene/gui Vulkan teardown because device is lost.");
       }
   
       vulkan_renderer.cleanUp();
       window->cleanUp();
   
       return EXIT_SUCCESS;
   }
   
   Kataglyphis::App::~App() = default;
