VulkanSurface
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
/*********************************************************************
|
||||||
|
* \file GraphicsSurface.hpp
|
||||||
|
*
|
||||||
|
* \author Romain BOULLARD
|
||||||
|
* \date September 2026
|
||||||
|
*********************************************************************/
|
||||||
|
#ifndef BIGFOOT_GRAPHICSINTERFACE_GRAPHICSSURFACE_HPP
|
||||||
|
#define BIGFOOT_GRAPHICSINTERFACE_GRAPHICSSURFACE_HPP
|
||||||
|
#include <GraphicsInterface/GraphicsInstance.hpp>
|
||||||
|
|
||||||
|
#include <Utils/Factory.hpp>
|
||||||
|
#include <Utils/TargetMacros.h>
|
||||||
|
|
||||||
|
#include <GraphicsInterface/GraphicsAPI_generated.hpp>
|
||||||
|
|
||||||
|
#include <EASTL/functional.h>
|
||||||
|
#include <EASTL/unique_ptr.h>
|
||||||
|
|
||||||
|
#ifdef BIGFOOT_WINDOWS
|
||||||
|
#include <Windows.h>
|
||||||
|
#elif defined BIGFOOT_LINUX
|
||||||
|
#include <X11/X.h>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Bigfoot
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The native window handles needed to create a GraphicsSurface
|
||||||
|
*/
|
||||||
|
struct SurfaceCreateInfo
|
||||||
|
{
|
||||||
|
#ifdef BIGFOOT_WINDOWS
|
||||||
|
HWND m_windowHandle = nullptr;
|
||||||
|
HINSTANCE m_windowInstance = nullptr;
|
||||||
|
#elif defined BIGFOOT_LINUX
|
||||||
|
Display* m_display = nullptr;
|
||||||
|
Window m_window = 0;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
class GraphicsSurface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~GraphicsSurface() = default;
|
||||||
|
|
||||||
|
GraphicsSurface(const GraphicsSurface& p_surface) = delete;
|
||||||
|
GraphicsSurface(GraphicsSurface&& p_surface) = delete;
|
||||||
|
|
||||||
|
GraphicsSurface& operator=(const GraphicsSurface& p_surface) = delete;
|
||||||
|
GraphicsSurface& operator=(GraphicsSurface&& p_surface) = delete;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
GraphicsSurface() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************************/
|
||||||
|
|
||||||
|
using GraphicsSurfaceFactory =
|
||||||
|
Factory<GraphicsSurface,
|
||||||
|
GraphicsAPI,
|
||||||
|
eastl::function<eastl::unique_ptr<GraphicsSurface>(const GraphicsInstance&, const SurfaceCreateInfo&)>>;
|
||||||
|
} // namespace Bigfoot
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*********************************************************************
|
||||||
|
* \file VulkanSurface.hpp
|
||||||
|
*
|
||||||
|
* \author Romain BOULLARD
|
||||||
|
* \date September 2026
|
||||||
|
*********************************************************************/
|
||||||
|
#ifndef BIGFOOT_GRAPHICSVULKAN_VULKANSURFACE_HPP
|
||||||
|
#define BIGFOOT_GRAPHICSVULKAN_VULKANSURFACE_HPP
|
||||||
|
#include <GraphicsVulkan/VulkanInclude.hpp>
|
||||||
|
#include <GraphicsVulkan/VulkanInstance.hpp>
|
||||||
|
|
||||||
|
#include <GraphicsInterface/GraphicsSurface.hpp>
|
||||||
|
|
||||||
|
namespace Bigfoot::Vulkan
|
||||||
|
{
|
||||||
|
class VulkanSurface final: public GraphicsSurface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
* Creates a vk::SurfaceKHR for the given native window.
|
||||||
|
*
|
||||||
|
* \param p_instance The instance to create the surface from
|
||||||
|
* \param p_surfaceCreateInfo The native window handles to create the surface for
|
||||||
|
*/
|
||||||
|
VulkanSurface(const VulkanInstance& p_instance, const SurfaceCreateInfo& p_surfaceCreateInfo);
|
||||||
|
|
||||||
|
~VulkanSurface() override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the underlying Vulkan surface handle
|
||||||
|
*
|
||||||
|
* \return The vk::SurfaceKHR handle
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
vk::SurfaceKHR GetHandle() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* The instance
|
||||||
|
*/
|
||||||
|
const VulkanInstance& m_instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The surface
|
||||||
|
*/
|
||||||
|
vk::SurfaceKHR m_surface;
|
||||||
|
};
|
||||||
|
} // namespace Bigfoot::Vulkan
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*********************************************************************
|
||||||
|
* \file VulkanSurface.cpp
|
||||||
|
*
|
||||||
|
* \author Romain BOULLARD
|
||||||
|
* \date September 2026
|
||||||
|
*********************************************************************/
|
||||||
|
#include <GraphicsVulkan/VulkanSurface.hpp>
|
||||||
|
|
||||||
|
#include <GraphicsVulkan/GraphicsVulkanAssertHandler.hpp>
|
||||||
|
#include <GraphicsVulkan/VulkanFormatters.hpp>
|
||||||
|
|
||||||
|
namespace Bigfoot::Vulkan
|
||||||
|
{
|
||||||
|
VulkanSurface::VulkanSurface(const VulkanInstance& p_instance, const SurfaceCreateInfo& p_surfaceCreateInfo):
|
||||||
|
m_instance(p_instance)
|
||||||
|
{
|
||||||
|
#ifdef BIGFOOT_WINDOWS
|
||||||
|
const vk::Win32SurfaceCreateInfoKHR createInfo {{},
|
||||||
|
p_surfaceCreateInfo.m_windowInstance,
|
||||||
|
p_surfaceCreateInfo.m_windowHandle};
|
||||||
|
const vk::ResultValue<vk::SurfaceKHR> surface = m_instance.GetHandle().createWin32SurfaceKHR(createInfo);
|
||||||
|
#elif defined BIGFOOT_LINUX
|
||||||
|
const vk::XlibSurfaceCreateInfoKHR createInfo {{}, p_surfaceCreateInfo.m_display, p_surfaceCreateInfo.m_window};
|
||||||
|
const vk::ResultValue<vk::SurfaceKHR> surface = m_instance.GetHandle().createXlibSurfaceKHR(createInfo);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CRITICAL_ASSERT(GraphicsVulkanAssertHandler,
|
||||||
|
surface.result == vk::Result::eSuccess,
|
||||||
|
"({}) Failed to create Vulkan surface",
|
||||||
|
surface.result);
|
||||||
|
m_surface = surface.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************************/
|
||||||
|
|
||||||
|
VulkanSurface::~VulkanSurface()
|
||||||
|
{
|
||||||
|
m_instance.GetHandle().destroySurfaceKHR(m_surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************************/
|
||||||
|
|
||||||
|
vk::SurfaceKHR VulkanSurface::GetHandle() const
|
||||||
|
{
|
||||||
|
return m_surface;
|
||||||
|
}
|
||||||
|
} // namespace Bigfoot::Vulkan
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/*********************************************************************
|
||||||
|
* \file VulkanSurface.cpp
|
||||||
|
*
|
||||||
|
* \author Romain BOULLARD
|
||||||
|
* \date September 2026
|
||||||
|
*********************************************************************/
|
||||||
|
#include <GraphicsVulkan/VulkanSurface.hpp>
|
||||||
|
|
||||||
|
#include <GraphicsVulkan/VulkanInstance.hpp>
|
||||||
|
|
||||||
|
#include <Utils/TargetMacros.h>
|
||||||
|
|
||||||
|
#define GLFW_INCLUDE_NONE
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#ifdef BIGFOOT_WINDOWS
|
||||||
|
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||||
|
#elif defined BIGFOOT_LINUX
|
||||||
|
#define GLFW_EXPOSE_NATIVE_X11
|
||||||
|
#endif
|
||||||
|
#include <GLFW/glfw3native.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
namespace Bigfoot::Vulkan
|
||||||
|
{
|
||||||
|
class VulkanSurfaceFixture: public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
void SetUp() override
|
||||||
|
{
|
||||||
|
ASSERT_EQ(glfwInit(), GLFW_TRUE);
|
||||||
|
|
||||||
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||||
|
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
||||||
|
m_window = glfwCreateWindow(64, 64, "VulkanSurfaceTests", nullptr, nullptr);
|
||||||
|
ASSERT_NE(m_window, nullptr);
|
||||||
|
|
||||||
|
#ifdef BIGFOOT_WINDOWS
|
||||||
|
m_surfaceCreateInfo.m_windowHandle = glfwGetWin32Window(m_window);
|
||||||
|
m_surfaceCreateInfo.m_windowInstance = GetModuleHandle(nullptr);
|
||||||
|
#elif defined BIGFOOT_LINUX
|
||||||
|
m_surfaceCreateInfo.m_display = glfwGetX11Display();
|
||||||
|
m_surfaceCreateInfo.m_window = glfwGetX11Window(m_window);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void TearDown() override
|
||||||
|
{
|
||||||
|
glfwDestroyWindow(m_window);
|
||||||
|
glfwTerminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
VulkanInstance m_instance {"VulkanSurfaceTests", Version {1, 0, 0}};
|
||||||
|
GLFWwindow* m_window = nullptr;
|
||||||
|
SurfaceCreateInfo m_surfaceCreateInfo;
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************************/
|
||||||
|
|
||||||
|
TEST_F(VulkanSurfaceFixture, Constructor_ShouldCreateAValidSurface)
|
||||||
|
{
|
||||||
|
const VulkanSurface surface {m_instance, m_surfaceCreateInfo};
|
||||||
|
|
||||||
|
EXPECT_TRUE(surface.GetHandle());
|
||||||
|
}
|
||||||
|
} // namespace Bigfoot::Vulkan
|
||||||
Reference in New Issue
Block a user