Created Vulkan Instance (VkInstance)
This commit is contained in:
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||||
|
</state>
|
||||||
|
</component>
|
||||||
8
.idea/editor.xml
generated
8
.idea/editor.xml
generated
@@ -244,5 +244,13 @@
|
|||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IfStdIsConstantEvaluatedCanBeReplaced/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IfStdIsConstantEvaluatedCanBeReplaced/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StdIsConstantEvaluatedWillAlwaysEvaluateToConstant/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StdIsConstantEvaluatedWillAlwaysEvaluateToConstant/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLiteralTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLiteralTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||||
|
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/BracesInForStatement/@EntryValue" value="Required" type="string" />
|
||||||
|
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/BracesInIfStatement/@EntryValue" value="Required" type="string" />
|
||||||
|
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/BracesInWhileStatement/@EntryValue" value="Required" type="string" />
|
||||||
|
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/BracesRedundant/@EntryValue" value="true" type="bool" />
|
||||||
|
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/OverridingDestructorStyle/@EntryValue" value="VirtualAndOverride" type="string" />
|
||||||
|
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/OverridingFunctionStyle/@EntryValue" value="VirtualAndOverride" type="string" />
|
||||||
|
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/UseAutoCommonCase/@EntryValue" value="Never" type="string" />
|
||||||
|
<option name="/Default/CodeStyle/CppIncludeDirective/SortIncludeDirectives/@EntryValue" value="true" type="bool" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -31,8 +31,10 @@ FetchContent_MakeAvailable(glfw)
|
|||||||
project(VulkanRenderer LANGUAGES CXX)
|
project(VulkanRenderer LANGUAGES CXX)
|
||||||
add_executable(VulkanRenderer
|
add_executable(VulkanRenderer
|
||||||
main.cpp
|
main.cpp
|
||||||
src/GLFWManager.h
|
src/managers/GLFWManager.h
|
||||||
src/GLFWManager.cpp
|
src/managers/GLFWManager.cpp
|
||||||
|
src/managers/VulkanManager.cpp
|
||||||
|
src/managers/VulkanManager.h
|
||||||
)
|
)
|
||||||
|
|
||||||
# Links the libraries to the binary #
|
# Links the libraries to the binary #
|
||||||
|
|||||||
14
main.cpp
14
main.cpp
@@ -1,4 +1,5 @@
|
|||||||
#include "src/GLFWManager.h"
|
#include "src/managers/GLFWManager.h"
|
||||||
|
#include "src/managers/VulkanManager.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@@ -12,13 +13,20 @@ int main()
|
|||||||
if (!window)
|
if (!window)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
/* Creates the Vulkan instance */
|
||||||
|
if (std::optional<VkInstance> instance = VulkanManager::Init(); !instance)
|
||||||
|
{
|
||||||
|
GLFWManager::Cleanup();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Polls window events whilst it is still open */
|
/* Polls window events whilst it is still open */
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cleans up GLFW */
|
/* Cleans up GLFW and Vulkan */
|
||||||
if (!GLFWManager::Cleanup())
|
if (!GLFWManager::Cleanup() || !VulkanManager::Cleanup())
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ namespace PB::Renderer
|
|||||||
|
|
||||||
/* Stops GLFW from creating openGL contexts */
|
/* Stops GLFW from creating openGL contexts */
|
||||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
59
src/managers/VulkanManager.cpp
Normal file
59
src/managers/VulkanManager.cpp
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
#include "VulkanManager.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "GLFW/glfw3.h"
|
||||||
|
|
||||||
|
namespace PB::Renderer
|
||||||
|
{
|
||||||
|
std::optional<VkInstance> VulkanManager::s_Instance = std::nullopt;
|
||||||
|
|
||||||
|
std::optional<VkInstance> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/managers/VulkanManager.h
Normal file
17
src/managers/VulkanManager.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
|
namespace PB::Renderer
|
||||||
|
{
|
||||||
|
class VulkanManager
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static std::optional<VkInstance> s_Instance;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static std::optional<VkInstance> Init();
|
||||||
|
static bool Cleanup();
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user