Compare commits
2 Commits
44a5e2cab9
...
6d34dfc58f
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d34dfc58f | |||
| b196c97cf0 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
|
|
||||||
|
.vscode/*
|
||||||
build/*
|
build/*
|
||||||
|
|||||||
@@ -15,6 +15,12 @@ endif()
|
|||||||
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
|
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
|
||||||
|
|
||||||
#add_subdirectory(src)
|
#add_subdirectory(src)
|
||||||
|
|
||||||
|
set(Vulkan_INCLUDE_DIR "${VULKAN_PATH}/Include")
|
||||||
|
set(Vulkan_LIBRARY "${VULKAN_PATH}/Lib/vulkan-1.lib")
|
||||||
|
find_package(Vulkan REQUIRED)
|
||||||
|
|
||||||
|
# TODO: use SDL in the vulkanSDK if available
|
||||||
set(SDL3_DIR "${SDL3_PATH}/cmake")
|
set(SDL3_DIR "${SDL3_PATH}/cmake")
|
||||||
find_package(SDL3 REQUIRED)
|
find_package(SDL3 REQUIRED)
|
||||||
|
|
||||||
@@ -23,6 +29,7 @@ add_executable(ouros
|
|||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/app/App.cpp
|
src/app/App.cpp
|
||||||
src/app/Window.cpp
|
src/app/Window.cpp
|
||||||
|
src/engine/Engine.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(ouros PRIVATE
|
target_include_directories(ouros PRIVATE
|
||||||
@@ -41,4 +48,5 @@ endif()
|
|||||||
|
|
||||||
target_link_libraries(ouros PRIVATE
|
target_link_libraries(ouros PRIVATE
|
||||||
SDL3::SDL3
|
SDL3::SDL3
|
||||||
|
Vulkan::Vulkan
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ Below is beyond Sascha's guide, but available elsewhere on his github. These are
|
|||||||
- CMake (im using 4.0.0)
|
- CMake (im using 4.0.0)
|
||||||
- C++20 compatible compiler (I use g++12 or MSVC++17) (probably works with mingw but I haven't tested it myself)
|
- C++20 compatible compiler (I use g++12 or MSVC++17) (probably works with mingw but I haven't tested it myself)
|
||||||
- Vulkan compatible gpu drivers (tested with an RTX3070 and an R9700)
|
- Vulkan compatible gpu drivers (tested with an RTX3070 and an R9700)
|
||||||
|
- Vulkan SDK (https://vulkan.lunarg.com/sdk/home) <- the installer provides the option to install SDL and VOC as well as verifies GPU drivers
|
||||||
- SDL3 (im using version 3.4.4)
|
- SDL3 (im using version 3.4.4)
|
||||||
- Will add more as the project grows
|
- Will add more as the project grows
|
||||||
|
|
||||||
@@ -52,7 +53,9 @@ $ git clone https://git.vxbard.net/homeburger/ouros.git --recursive
|
|||||||
```
|
```
|
||||||
### Configure and build project:
|
### Configure and build project:
|
||||||
```bash
|
```bash
|
||||||
$ cmake -S . -B build -DSDL3_PATH="${SDL3_INSTALL_PATH}" # either set this variable or substitute it in
|
$ cmake -S . -B build \
|
||||||
|
-VULKAN_PATH="${VULKAN_INSTALL_PATH}" \ # either set these variables or substitute them in
|
||||||
|
-DSDL3_PATH="${SDL3_INSTALL_PATH}" # optional, dont need if youre using the sdl in the vulkan sdk
|
||||||
$ cmake --build build -j
|
$ cmake --build build -j
|
||||||
```
|
```
|
||||||
### Execute application:
|
### Execute application:
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ void App::init() {
|
|||||||
utils::debugPrint(__FUNCTION__, __LINE__, "Init app.", utils::DebugLevel::Trace);
|
utils::debugPrint(__FUNCTION__, __LINE__, "Init app.", utils::DebugLevel::Trace);
|
||||||
|
|
||||||
window_ = new Window();
|
window_ = new Window();
|
||||||
|
engine_ = new Engine(window_);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,6 +24,8 @@ int App::run() {
|
|||||||
|
|
||||||
utils::debugPrint(__FUNCTION__, __LINE__, "Run app.", utils::DebugLevel::Trace);
|
utils::debugPrint(__FUNCTION__, __LINE__, "Run app.", utils::DebugLevel::Trace);
|
||||||
|
|
||||||
|
engine_->exec();
|
||||||
|
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
// app loop for as long as the window is open
|
// app loop for as long as the window is open
|
||||||
@@ -34,6 +37,11 @@ int App::run() {
|
|||||||
quit = true;
|
quit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pass vulkan handling to engine
|
||||||
|
// call engine.render() or something
|
||||||
|
// engine has a pointer to window so can handle pushing to the screen
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SDL teardown handled in window destructor
|
// SDL teardown handled in window destructor
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Window.hpp"
|
#include "Window.hpp"
|
||||||
|
#include "engine/Engine.hpp"
|
||||||
|
|
||||||
class App {
|
class App {
|
||||||
|
|
||||||
@@ -19,5 +20,6 @@ private:
|
|||||||
void init();
|
void init();
|
||||||
|
|
||||||
Window* window_;
|
Window* window_;
|
||||||
|
Engine* engine_;
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -9,15 +9,15 @@ Window::Window() {
|
|||||||
|
|
||||||
Window::~Window() {
|
Window::~Window() {
|
||||||
|
|
||||||
SDL_DestroyWindow(window_);
|
SDL_DestroyWindow(sdlWindow_);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Window::init() {
|
int Window::init() {
|
||||||
|
|
||||||
window_ = SDL_CreateWindow("How to Vulkan", 1280u, 720u, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
|
sdlWindow_ = SDL_CreateWindow("How to Vulkan", 1280u, 720u, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
|
||||||
|
|
||||||
return (window_ == nullptr);
|
return (sdlWindow_ == nullptr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ private:
|
|||||||
|
|
||||||
int init();
|
int init();
|
||||||
|
|
||||||
SDL_Window* window_;
|
SDL_Window* sdlWindow_;
|
||||||
|
|
||||||
};
|
};
|
||||||
44
src/engine/Engine.cpp
Normal file
44
src/engine/Engine.cpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
#include "Engine.hpp"
|
||||||
|
|
||||||
|
#include "vulkan/vulkan.h"
|
||||||
|
|
||||||
|
#include "utils/utils.hpp"
|
||||||
|
|
||||||
|
Engine::Engine(Window* window): window_(window) {
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::exec() {
|
||||||
|
|
||||||
|
VkApplicationInfo appInfo {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||||
|
.pApplicationName = "How to Vulkan",
|
||||||
|
.apiVersion = VK_API_VERSION_1_3
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t instanceExtensionsCount = 0;
|
||||||
|
char const* const* instanceExtensions{ SDL_Vulkan_GetInstanceExtensions(&instanceExtensionsCount) };
|
||||||
|
|
||||||
|
VkInstanceCreateInfo instanceCI {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
||||||
|
.pApplicationInfo = &appInfo,
|
||||||
|
.enabledExtensionCount = instanceExtensionsCount,
|
||||||
|
.ppEnabledExtensionNames = instanceExtensions,
|
||||||
|
};
|
||||||
|
|
||||||
|
VkInstance instance;
|
||||||
|
VkResult result = vkCreateInstance(&instanceCI, nullptr, &instance);
|
||||||
|
if(result == VK_SUCCESS) {
|
||||||
|
utils::debugPrint(__FUNCTION__, __LINE__, "Vulkan instance successfully created.", utils::DebugLevel::Info);
|
||||||
|
} else {
|
||||||
|
utils::debugPrint(__FUNCTION__, __LINE__, "Error creating Vulkan instance", utils::DebugLevel::Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
24
src/engine/Engine.hpp
Normal file
24
src/engine/Engine.hpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "app/Window.hpp"
|
||||||
|
|
||||||
|
#define VK_USE_PLATFORM_WIN32_KHR 1
|
||||||
|
|
||||||
|
class Engine {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Engine(Window* window);
|
||||||
|
~Engine() = default;
|
||||||
|
|
||||||
|
void exec();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
|
// TODO: smart pointers probably would be smart
|
||||||
|
Window* window_;
|
||||||
|
|
||||||
|
};
|
||||||
@@ -40,6 +40,7 @@ namespace utils {
|
|||||||
if(!(debugMask >> debugLevel)) return; // then ignore this debug level
|
if(!(debugMask >> debugLevel)) return; // then ignore this debug level
|
||||||
|
|
||||||
std::cout << "[ " << std::left << std::setw(16) << function << ": " << std::right << std::setw(4) << line << ", " << std::left << std::setw(8) << debugTypeStrings[debugLevel] << " ] " << message << std::endl;
|
std::cout << "[ " << std::left << std::setw(16) << function << ": " << std::right << std::setw(4) << line << ", " << std::left << std::setw(8) << debugTypeStrings[debugLevel] << " ] " << message << std::endl;
|
||||||
|
// TODO: add timestamps
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user