isloate sdl logic to window class
This commit is contained in:
@@ -34,6 +34,7 @@ add_executable(ouros
|
|||||||
target_include_directories(ouros PRIVATE
|
target_include_directories(ouros PRIVATE
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/"
|
"${CMAKE_CURRENT_SOURCE_DIR}/"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/src"
|
"${CMAKE_CURRENT_SOURCE_DIR}/src"
|
||||||
|
"${VULKAN_PATH}/Include"
|
||||||
)
|
)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
|||||||
@@ -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.
|
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
|
## 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
|
- Will add more as I use them
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
|
||||||
#include "App.hpp"
|
#include "App.hpp"
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#include "utils/utils.hpp"
|
#include "utils/utils.hpp"
|
||||||
|
|
||||||
App::App() {
|
App::App() {
|
||||||
@@ -24,22 +27,25 @@ int App::run() {
|
|||||||
|
|
||||||
utils::debugPrint(__FUNCTION__, __LINE__, "Run app.", utils::DebugLevel::Trace);
|
utils::debugPrint(__FUNCTION__, __LINE__, "Run app.", utils::DebugLevel::Trace);
|
||||||
|
|
||||||
bool quit = false;
|
|
||||||
while (!quit) {
|
|
||||||
// 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;
|
SDL_Event event;
|
||||||
while(SDL_PollEvent(&event)) { // TODO: pass event handling to window
|
while (window_->open()) {
|
||||||
if(event.type == SDL_EVENT_QUIT ) {
|
// app loop for as long as the window is open
|
||||||
quit = true;
|
|
||||||
}
|
// pass events to the window
|
||||||
|
while(SDL_PollEvent(&event) != 0) {
|
||||||
|
window_->handleEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pass vulkan handling to engine
|
// pass vulkan handling to engine
|
||||||
// call engine.render() or something
|
// call engine.render() or something
|
||||||
// engine has a pointer to window so can handle pushing to the screen
|
// 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
|
// SDL teardown handled in window destructor
|
||||||
|
|||||||
@@ -22,4 +22,6 @@ private:
|
|||||||
Window* window_;
|
Window* window_;
|
||||||
Engine* engine_;
|
Engine* engine_;
|
||||||
|
|
||||||
|
bool rendering_ = true;
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
#include "Window.hpp"
|
#include "Window.hpp"
|
||||||
|
|
||||||
|
#include <SDL3/SDL_events.h>
|
||||||
|
|
||||||
Window::Window() {
|
Window::Window() {
|
||||||
|
|
||||||
(void)init();
|
(void)init();
|
||||||
@@ -18,6 +20,25 @@ int Window::init() {
|
|||||||
|
|
||||||
sdlWindow_ = SDL_CreateWindow("Ouros: Vulkan", 1280u, 720u, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "SDL3/SDL.h"
|
#include "SDL3/SDL.h"
|
||||||
#include "SDL3/SDL_Vulkan.h"
|
#include "SDL3/SDL_vulkan.h"
|
||||||
|
|
||||||
// reference: https://wiki.libsdl.org/SDL3/SDL_CreateWindow
|
// reference: https://wiki.libsdl.org/SDL3/SDL_CreateWindow
|
||||||
|
|
||||||
@@ -13,6 +13,11 @@ public:
|
|||||||
Window();
|
Window();
|
||||||
~Window();
|
~Window();
|
||||||
|
|
||||||
|
void handleEvent(SDL_Event& event);
|
||||||
|
|
||||||
|
bool rendering() { return rendering_; }
|
||||||
|
bool open() { return open_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// launches window
|
// launches window
|
||||||
@@ -23,4 +28,7 @@ private:
|
|||||||
|
|
||||||
SDL_Window* sdlWindow_;
|
SDL_Window* sdlWindow_;
|
||||||
|
|
||||||
|
bool rendering_ = false;
|
||||||
|
bool open_ = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -36,8 +36,15 @@ void Engine::init() {
|
|||||||
utils::debugPrint(__FUNCTION__, __LINE__, "Error creating Vulkan instance", utils::DebugLevel::Error);
|
utils::debugPrint(__FUNCTION__, __LINE__, "Error creating Vulkan instance", utils::DebugLevel::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
// next steps:
|
||||||
|
// device selection and setup
|
||||||
void Engine::process() {
|
// queue creation
|
||||||
|
// vulkan memory allocator
|
||||||
|
// create vulkan surface
|
||||||
|
// attach surface to window
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::draw() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ public:
|
|||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
// process is called every render iteration in that while loop
|
// draw is called every render iteration in that while loop
|
||||||
void process();
|
void draw();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user