diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..a55e7a1
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/editor.xml b/.idea/editor.xml
index ead1d8a..b768b3a 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -244,5 +244,13 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0526612..8780340 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,8 +31,10 @@ FetchContent_MakeAvailable(glfw)
project(VulkanRenderer LANGUAGES CXX)
add_executable(VulkanRenderer
main.cpp
- src/GLFWManager.h
- src/GLFWManager.cpp
+ src/managers/GLFWManager.h
+ src/managers/GLFWManager.cpp
+ src/managers/VulkanManager.cpp
+ src/managers/VulkanManager.h
)
# Links the libraries to the binary #
diff --git a/main.cpp b/main.cpp
index fcd209d..98320a2 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,4 +1,5 @@
-#include "src/GLFWManager.h"
+#include "src/managers/GLFWManager.h"
+#include "src/managers/VulkanManager.h"
int main()
{
@@ -12,13 +13,20 @@ int main()
if (!window)
return -1;
+ /* Creates the Vulkan instance */
+ if (std::optional instance = VulkanManager::Init(); !instance)
+ {
+ GLFWManager::Cleanup();
+ return -1;
+ }
+
/* Polls window events whilst it is still open */
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
}
- /* Cleans up GLFW */
- if (!GLFWManager::Cleanup())
+ /* Cleans up GLFW and Vulkan */
+ if (!GLFWManager::Cleanup() || !VulkanManager::Cleanup())
return -1;
}
diff --git a/src/GLFWManager.cpp b/src/managers/GLFWManager.cpp
similarity index 99%
rename from src/GLFWManager.cpp
rename to src/managers/GLFWManager.cpp
index 6a0fa17..597fe2f 100644
--- a/src/GLFWManager.cpp
+++ b/src/managers/GLFWManager.cpp
@@ -14,7 +14,6 @@ namespace PB::Renderer
/* Stops GLFW from creating openGL contexts */
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
-
return success;
}
diff --git a/src/GLFWManager.h b/src/managers/GLFWManager.h
similarity index 100%
rename from src/GLFWManager.h
rename to src/managers/GLFWManager.h
diff --git a/src/managers/VulkanManager.cpp b/src/managers/VulkanManager.cpp
new file mode 100644
index 0000000..0719cca
--- /dev/null
+++ b/src/managers/VulkanManager.cpp
@@ -0,0 +1,59 @@
+#include "VulkanManager.h"
+
+#include
+
+#include "GLFW/glfw3.h"
+
+namespace PB::Renderer
+{
+ std::optional VulkanManager::s_Instance = std::nullopt;
+
+ std::optional VulkanManager::Init()
+ {
+ /* Stops multi initialisation */
+ if (s_Instance != std::nullopt)
+ return s_Instance;
+
+ VkApplicationInfo appInfo;
+ appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
+ appInfo.pNext = nullptr;
+ appInfo.pApplicationName = "VulkanRenderer";
+ appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
+ appInfo.pEngineName = "VulkanRendererEngine";
+ appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
+ appInfo.apiVersion = VK_API_VERSION_1_3;
+
+ VkInstanceCreateInfo createInfo;
+ createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
+ createInfo.pNext = nullptr;
+ createInfo.pApplicationInfo = &appInfo;
+ createInfo.enabledLayerCount = 0;
+ createInfo.ppEnabledLayerNames = nullptr;
+
+ /* Imports GLFW extensions */
+ uint32_t glfwExtensionCount = 0;
+ const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
+ createInfo.enabledExtensionCount = glfwExtensionCount;
+ createInfo.ppEnabledExtensionNames = glfwExtensions;
+
+ /* Creates the Vulkan instance */
+ VkInstance instance;
+ if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS)
+ {
+ std::cout << "PB::Renderer::VulkanManager::Init(): Could not create Vulkan instance" << std::endl;
+ return std::nullopt;
+ }
+
+ s_Instance = instance;
+ return instance;
+ }
+
+ bool VulkanManager::Cleanup()
+ {
+ if (s_Instance != std::nullopt)
+ vkDestroyInstance(s_Instance.value(), nullptr);
+
+ s_Instance = std::nullopt;
+ return true;
+ }
+}
diff --git a/src/managers/VulkanManager.h b/src/managers/VulkanManager.h
new file mode 100644
index 0000000..3f54532
--- /dev/null
+++ b/src/managers/VulkanManager.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include
+#include
+
+namespace PB::Renderer
+{
+ class VulkanManager
+ {
+ private:
+ static std::optional s_Instance;
+
+ public:
+ static std::optional Init();
+ static bool Cleanup();
+ };
+}