diff --git a/NothinFancy/CMakeLists.txt b/NothinFancy/CMakeLists.txt index 684bd6a..a530e96 100644 --- a/NothinFancy/CMakeLists.txt +++ b/NothinFancy/CMakeLists.txt @@ -1,5 +1,5 @@ # NF library CMakeLists.txt -add_library(NothinFancy STATIC "src/Engine.cpp" "src/include/nf.h" "src/pch.h" "src/util.h" "src/util/log.h" "src/util/log.cpp" "src/include/nf/config.h" "src/util/util.cpp" "src/util/file.h" "src/util/file.cpp" "src/client/Client.h" "src/client/Client.cpp" "src/client/Window.h" "src/client/Window.cpp") +add_library(NothinFancy STATIC "src/Engine.cpp" "src/include/nf.h" "src/pch.h" "src/util.h" "src/util/log.h" "src/util/log.cpp" "src/include/nf/config.h" "src/util/util.cpp" "src/util/file.h" "src/util/file.cpp" "src/client/Client.h" "src/client/Client.cpp" "src/client/Window.h" "src/client/Window.cpp" "src/client/render/RenderEngine.h" "src/client/render/RenderEngine.cpp") # Use C++20 set_property(TARGET NothinFancy PROPERTY CXX_STANDARD 20) @@ -10,6 +10,10 @@ target_include_directories(NothinFancy PUBLIC "src" "src/include") # Use precompiled header target_precompile_headers(NothinFancy PUBLIC "src/pch.h") +# Link libraries +target_link_libraries(NothinFancy "$ENV{VULKAN_SDK}/Lib/vulkan-1.lib") +target_include_directories(NothinFancy PUBLIC "$ENV{VULKAN_SDK}/Include") + # Generate version.h find_package(Git) execute_process(COMMAND ${GIT_EXECUTABLE} describe OUTPUT_VARIABLE NFVERSION OUTPUT_STRIP_TRAILING_WHITESPACE) diff --git a/NothinFancy/src/client/Client.cpp b/NothinFancy/src/client/Client.cpp index cdb06d3..9304e0f 100644 --- a/NothinFancy/src/client/Client.cpp +++ b/NothinFancy/src/client/Client.cpp @@ -7,6 +7,7 @@ namespace nf::cli { Client::Client(ClientConfig config) : m_config(config) , m_window(m_config.appName, m_config.display) + , m_renderEngine() { // Setup window and renderer } diff --git a/NothinFancy/src/client/Client.h b/NothinFancy/src/client/Client.h index 87a772e..625bec5 100644 --- a/NothinFancy/src/client/Client.h +++ b/NothinFancy/src/client/Client.h @@ -3,6 +3,7 @@ #include "nf/config.h" #include "Window.h" +#include "render/RenderEngine.h" namespace nf::cli { class Client { @@ -13,5 +14,6 @@ namespace nf::cli { private: ClientConfig m_config; Window m_window; + render::RenderEngine m_renderEngine; }; } diff --git a/NothinFancy/src/client/Window.cpp b/NothinFancy/src/client/Window.cpp index 6e6df25..e5ab8b4 100644 --- a/NothinFancy/src/client/Window.cpp +++ b/NothinFancy/src/client/Window.cpp @@ -17,12 +17,7 @@ namespace nf::cli { // Disable automatic DPI upscaling SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); - // Register window class - WNDCLASS wc = {}; - wc.lpszClassName = m_wndClassName; - wc.hCursor = LoadCursor(nullptr, IDC_ARROW); - wc.lpfnWndProc = wndProc; - RegisterClass(&wc); + registerWindowClass(); m_handle = CreateWindow(m_wndClassName, windowTitle, NULL, 0, 0, 0, 0, nullptr, nullptr, nullptr, this); setDisplay(config); @@ -34,7 +29,7 @@ namespace nf::cli { bool wasShown = IsWindowVisible(m_handle); show(false); - // Temporary monitor choice + // TODO: Only use "active" monitor when starting windowed POINT cursor = {}; GetCursorPos(&cursor); MONITORINFO mi = {}; @@ -80,6 +75,14 @@ namespace nf::cli { ShowWindow(m_handle, show ? SW_SHOW : SW_HIDE); } + void Window::registerWindowClass() { + WNDCLASS wc = {}; + wc.lpszClassName = m_wndClassName; + wc.hCursor = LoadCursor(nullptr, IDC_ARROW); + wc.lpfnWndProc = wndProc; + RegisterClass(&wc); + } + LRESULT CALLBACK Window::wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { static Window* wnd = nullptr; diff --git a/NothinFancy/src/client/Window.h b/NothinFancy/src/client/Window.h index 47b2ba1..361ea03 100644 --- a/NothinFancy/src/client/Window.h +++ b/NothinFancy/src/client/Window.h @@ -14,6 +14,7 @@ namespace nf::cli { void runLoop(); void show(bool show = true); private: + void registerWindowClass(); static LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); SIZE getWindowSize(); diff --git a/NothinFancy/src/client/render/RenderEngine.cpp b/NothinFancy/src/client/render/RenderEngine.cpp new file mode 100644 index 0000000..6746764 --- /dev/null +++ b/NothinFancy/src/client/render/RenderEngine.cpp @@ -0,0 +1,36 @@ +// RenderEngine class implementation +#include "pch.h" + +#include "RenderEngine.h" +#include "util.h" + +namespace nf::cli::render { + RenderEngine::RenderEngine() + : m_instance() + { + NFLog("Initializing render engine"); + createInstance(); + } + + void RenderEngine::createInstance() { + VkApplicationInfo appInfo = { VK_STRUCTURE_TYPE_APPLICATION_INFO }; + appInfo.apiVersion = VK_API_VERSION_1_0; + + VkInstanceCreateInfo instanceCI = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO }; + instanceCI.pApplicationInfo = &appInfo; +#ifdef _DEBUG + const char* validationLayerName = "VK_LAYER_KHRONOS_validation"; + instanceCI.ppEnabledLayerNames = &validationLayerName; + instanceCI.enabledLayerCount = 1; +#endif + std::vector instanceExtNames = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME }; + instanceCI.ppEnabledExtensionNames = instanceExtNames.data(); + instanceCI.enabledExtensionCount = instanceExtNames.size(); + if (vkCreateInstance(&instanceCI, nullptr, &m_instance) != VK_SUCCESS) + NFError("Could not create Vulkan instance."); + } + + RenderEngine::~RenderEngine() { + vkDestroyInstance(m_instance, nullptr); + } +} diff --git a/NothinFancy/src/client/render/RenderEngine.h b/NothinFancy/src/client/render/RenderEngine.h new file mode 100644 index 0000000..5922d23 --- /dev/null +++ b/NothinFancy/src/client/render/RenderEngine.h @@ -0,0 +1,15 @@ +// RenderEngine class header +#pragma once + +namespace nf::cli::render { + class RenderEngine { + public: + RenderEngine(); + + ~RenderEngine(); + private: + void createInstance(); + + VkInstance m_instance; + }; +} diff --git a/NothinFancy/src/pch.h b/NothinFancy/src/pch.h index 339b045..2d31879 100644 --- a/NothinFancy/src/pch.h +++ b/NothinFancy/src/pch.h @@ -37,3 +37,7 @@ // Windows #define WIN32_LEAN_AND_MEAN #include + +// Vulkan +#define VK_USE_PLATFORM_WIN32_KHR +#include