isloate sdl logic to window class

This commit is contained in:
2026-04-12 16:41:27 -05:00
parent 779c51c2f8
commit 2c240ad7e3
8 changed files with 61 additions and 15 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -1,6 +1,9 @@
#include "App.hpp"
#include <thread>
#include <chrono>
#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

View File

@@ -22,4 +22,6 @@ private:
Window* window_;
Engine* engine_;
bool rendering_ = true;
};

View File

@@ -1,6 +1,8 @@
#include "Window.hpp"
#include <SDL3/SDL_events.h>
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;
}
}

View File

@@ -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;
};

View File

@@ -36,8 +36,15 @@ void Engine::init() {
utils::debugPrint(__FUNCTION__, __LINE__, "Error creating Vulkan instance", utils::DebugLevel::Error);
}
}
void Engine::process() {
// next steps:
// device selection and setup
// queue creation
// vulkan memory allocator
// create vulkan surface
// attach surface to window
}
void Engine::draw() {
}

View File

@@ -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: