diff --git a/CMakeLists.txt b/CMakeLists.txt index 552b958..50d1e81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ add_executable(ouros target_include_directories(ouros PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/" "${CMAKE_CURRENT_SOURCE_DIR}/src" + "${VULKAN_PATH}/Include" ) if(WIN32) diff --git a/README.md b/README.md index 8f051ec..eb37617 100644 --- a/README.md +++ b/README.md @@ -74,5 +74,6 @@ $ ./build/ouros --debug=0b00111111 where each bit in the mask corresponds to a debug level, in order: unused, unused, fatal, trace, error, warning, notice, and info. `0b1111111` enables all debug messages. ## Additional Resources - - https://howtovulkan.com/ + - https://howtovulkan.com/, primary guide, most up-to-date (2026, Vulkan v1.4) + - https://vkguide.dev/, Vulkan v1.3, but provides a lot of guidance on a more robustly architectured Vulkan app - Will add more as I use them diff --git a/src/app/App.cpp b/src/app/App.cpp index b07014a..00eed65 100644 --- a/src/app/App.cpp +++ b/src/app/App.cpp @@ -1,6 +1,9 @@ #include "App.hpp" +#include +#include + #include "utils/utils.hpp" App::App() { @@ -24,22 +27,25 @@ int App::run() { utils::debugPrint(__FUNCTION__, __LINE__, "Run app.", utils::DebugLevel::Trace); - bool quit = false; - while (!quit) { + SDL_Event event; + while (window_->open()) { // app loop for as long as the window is open - // other threads might be able to change quit to true to auto close in the future - SDL_Event event; - while(SDL_PollEvent(&event)) { // TODO: pass event handling to window - if(event.type == SDL_EVENT_QUIT ) { - quit = true; - } + // pass events to the window + while(SDL_PollEvent(&event) != 0) { + window_->handleEvent(event); } // pass vulkan handling to engine // call engine.render() or something // engine has a pointer to window so can handle pushing to the screen + if(window_->rendering()) { + engine_->draw(); + } else { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); // wait until the window is visible again + } + } // SDL teardown handled in window destructor diff --git a/src/app/App.hpp b/src/app/App.hpp index d24b948..021d505 100644 --- a/src/app/App.hpp +++ b/src/app/App.hpp @@ -22,4 +22,6 @@ private: Window* window_; Engine* engine_; + bool rendering_ = true; + }; \ No newline at end of file diff --git a/src/app/Window.cpp b/src/app/Window.cpp index a127a05..87e79f1 100644 --- a/src/app/Window.cpp +++ b/src/app/Window.cpp @@ -1,6 +1,8 @@ #include "Window.hpp" +#include + Window::Window() { (void)init(); @@ -18,6 +20,25 @@ int Window::init() { sdlWindow_ = SDL_CreateWindow("Ouros: Vulkan", 1280u, 720u, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE); - return (sdlWindow_ == nullptr); + if(sdlWindow_ != nullptr) { + rendering_ = true; + open_ = true; + return 0; + } else { + return -1; + } } + +void Window::handleEvent(SDL_Event& event) { + + if(event.type == SDL_EVENT_QUIT ) { + open_ = false; + } + + if(event.type == SDL_EVENT_WINDOW_MINIMIZED) { + rendering_ = false; + } else if(event.type == SDL_EVENT_WINDOW_RESTORED) { + rendering_ = true; + } +} diff --git a/src/app/Window.hpp b/src/app/Window.hpp index 4b31295..b9f12ad 100644 --- a/src/app/Window.hpp +++ b/src/app/Window.hpp @@ -2,7 +2,7 @@ #pragma once #include "SDL3/SDL.h" -#include "SDL3/SDL_Vulkan.h" +#include "SDL3/SDL_vulkan.h" // reference: https://wiki.libsdl.org/SDL3/SDL_CreateWindow @@ -13,6 +13,11 @@ public: Window(); ~Window(); + void handleEvent(SDL_Event& event); + + bool rendering() { return rendering_; } + bool open() { return open_; } + private: // launches window @@ -23,4 +28,7 @@ private: SDL_Window* sdlWindow_; + bool rendering_ = false; + bool open_ = false; + }; \ No newline at end of file diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 798fe17..7f2b239 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -36,8 +36,15 @@ void Engine::init() { utils::debugPrint(__FUNCTION__, __LINE__, "Error creating Vulkan instance", utils::DebugLevel::Error); } + // next steps: + // device selection and setup + // queue creation + // vulkan memory allocator + // create vulkan surface + // attach surface to window + } -void Engine::process() { - +void Engine::draw() { + } diff --git a/src/engine/Engine.hpp b/src/engine/Engine.hpp index 9ff32bc..63ec5c2 100644 --- a/src/engine/Engine.hpp +++ b/src/engine/Engine.hpp @@ -14,8 +14,8 @@ public: void init(); - // process is called every render iteration in that while loop - void process(); + // draw is called every render iteration in that while loop + void draw(); private: