Made Vulkan Surface
This commit is contained in:
@@ -35,6 +35,7 @@ add_executable(VulkanRenderer
|
|||||||
src/managers/GLFWManager.cpp
|
src/managers/GLFWManager.cpp
|
||||||
src/managers/VulkanManager.cpp
|
src/managers/VulkanManager.cpp
|
||||||
src/managers/VulkanManager.h
|
src/managers/VulkanManager.h
|
||||||
|
src/VulkanRenderer.h
|
||||||
)
|
)
|
||||||
|
|
||||||
# Links the libraries to the binary #
|
# Links the libraries to the binary #
|
||||||
|
|||||||
27
main.cpp
27
main.cpp
@@ -1,6 +1,22 @@
|
|||||||
|
#include "src/VulkanRenderer.h"
|
||||||
|
|
||||||
#include "src/managers/GLFWManager.h"
|
#include "src/managers/GLFWManager.h"
|
||||||
#include "src/managers/VulkanManager.h"
|
#include "src/managers/VulkanManager.h"
|
||||||
|
|
||||||
|
namespace PB::Renderer
|
||||||
|
{
|
||||||
|
void CleanupAllAndExit()
|
||||||
|
{
|
||||||
|
if (!GLFWManager::Cleanup())
|
||||||
|
std::exit(EXIT_FAILURE);
|
||||||
|
|
||||||
|
if (VulkanManager::Cleanup())
|
||||||
|
std::exit(EXIT_FAILURE);
|
||||||
|
|
||||||
|
std::exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
using namespace PB::Renderer; // Project namespace
|
using namespace PB::Renderer; // Project namespace
|
||||||
@@ -13,13 +29,19 @@ int main()
|
|||||||
if (!window)
|
if (!window)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Creates the Vulkan instance */
|
/* Creates the Vulkan instance and surface */
|
||||||
if (std::optional<VkInstance> instance = VulkanManager::Init(); !instance)
|
if (std::optional<VkInstance> instance = VulkanManager::Init(); !instance)
|
||||||
{
|
{
|
||||||
GLFWManager::Cleanup();
|
GLFWManager::Cleanup();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (std::optional<VkSurfaceKHR> surface = VulkanManager::CreateSurface(window); !surface)
|
||||||
|
{
|
||||||
|
CleanupAllAndExit();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Polls window events whilst it is still open */
|
/* Polls window events whilst it is still open */
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
@@ -27,6 +49,5 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Cleans up GLFW and Vulkan */
|
/* Cleans up GLFW and Vulkan */
|
||||||
if (!GLFWManager::Cleanup() || !VulkanManager::Cleanup())
|
CleanupAllAndExit();
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/VulkanRenderer.h
Normal file
14
src/VulkanRenderer.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/* Includes dependencies */
|
||||||
|
|
||||||
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
|
#define GLFW_INCLUDE_VULKAN
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
/* Commonly used C++ STD files */
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <optional>
|
||||||
|
#include <vector>
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
#include "GLFWManager.h"
|
#include "GLFWManager.h"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace PB::Renderer
|
namespace PB::Renderer
|
||||||
{
|
{
|
||||||
std::vector<GLFWwindow*> GLFWManager::s_Windows;
|
std::vector<GLFWwindow*> GLFWManager::s_Windows;
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "GLFW/glfw3.h"
|
#include "../VulkanRenderer.h"
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace PB::Renderer
|
namespace PB::Renderer
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
#include "VulkanManager.h"
|
#include "VulkanManager.h"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "GLFW/glfw3.h"
|
|
||||||
|
|
||||||
namespace PB::Renderer
|
namespace PB::Renderer
|
||||||
{
|
{
|
||||||
std::optional<VkInstance> VulkanManager::s_Instance = std::nullopt;
|
std::optional<VkInstance> VulkanManager::s_Instance = std::nullopt;
|
||||||
|
std::optional<VkSurfaceKHR> VulkanManager::s_Surface = std::nullopt;
|
||||||
|
|
||||||
std::optional<VkInstance> VulkanManager::Init()
|
std::optional<VkInstance> VulkanManager::Init()
|
||||||
{
|
{
|
||||||
@@ -48,8 +45,23 @@ namespace PB::Renderer
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<VkSurfaceKHR> VulkanManager::CreateSurface(GLFWwindow* window)
|
||||||
|
{
|
||||||
|
VkSurfaceKHR surface;
|
||||||
|
if (glfwCreateWindowSurface(s_Instance.value(), window, nullptr, &surface) != VK_SUCCESS)
|
||||||
|
{
|
||||||
|
std::cout << "PB::Renderer::VulkanManager::CreateSurface(): Failed to create Vulkan Surface" << std::endl;
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return surface;
|
||||||
|
}
|
||||||
|
|
||||||
bool VulkanManager::Cleanup()
|
bool VulkanManager::Cleanup()
|
||||||
{
|
{
|
||||||
|
if (s_Surface != std::nullopt)
|
||||||
|
vkDestroySurfaceKHR(s_Instance.value(), s_Surface.value(), nullptr);
|
||||||
|
|
||||||
if (s_Instance != std::nullopt)
|
if (s_Instance != std::nullopt)
|
||||||
vkDestroyInstance(s_Instance.value(), nullptr);
|
vkDestroyInstance(s_Instance.value(), nullptr);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <optional>
|
#include "../VulkanRenderer.h"
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
|
|
||||||
namespace PB::Renderer
|
namespace PB::Renderer
|
||||||
{
|
{
|
||||||
@@ -9,9 +8,12 @@ namespace PB::Renderer
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static std::optional<VkInstance> s_Instance;
|
static std::optional<VkInstance> s_Instance;
|
||||||
|
static std::optional<VkSurfaceKHR> s_Surface;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static std::optional<VkInstance> Init();
|
static std::optional<VkInstance> Init();
|
||||||
static bool Cleanup();
|
static bool Cleanup();
|
||||||
|
|
||||||
|
static std::optional<VkSurfaceKHR> CreateSurface(GLFWwindow* window);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user