test vulkan instance creation

This commit is contained in:
2026-04-12 00:19:38 -05:00
parent b196c97cf0
commit 6d34dfc58f
6 changed files with 81 additions and 1 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.vscode/*
build/*

View File

@@ -15,6 +15,12 @@ endif()
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
#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")
find_package(SDL3 REQUIRED)
@@ -42,4 +48,5 @@ endif()
target_link_libraries(ouros PRIVATE
SDL3::SDL3
Vulkan::Vulkan
)

View File

@@ -53,7 +53,9 @@ $ git clone https://git.vxbard.net/homeburger/ouros.git --recursive
```
### Configure and build project:
```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
```
### Execute application:

View File

@@ -24,6 +24,8 @@ int App::run() {
utils::debugPrint(__FUNCTION__, __LINE__, "Run app.", utils::DebugLevel::Trace);
engine_->exec();
bool quit = false;
while (!quit) {
// app loop for as long as the window is open

44
src/engine/Engine.cpp Normal file
View 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
View 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_;
};