Commit WIP about RenderSurface

This commit is contained in:
Lynix 2016-11-10 12:54:10 +01:00
parent 86b892c3bc
commit c136f8eddc
22 changed files with 321 additions and 37 deletions

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_RENDERDEVICEINSTANCE_HPP
#define NAZARA_RENDERDEVICEINSTANCE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/Config.hpp>
namespace Nz
{
///TODO: Rename
class NAZARA_RENDERER_API RenderDeviceInstance
{
public:
RenderDeviceInstance() = default;
virtual ~RenderDeviceInstance();
};
}
#include <Nazara/Renderer/RenderDeviceInstance.inl>
#endif // NAZARA_RENDERDEVICEINSTANCE_HPP

View File

@ -0,0 +1,12 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/RenderDeviceInstance.hpp>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz
{
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_RENDERSURFACE_HPP
#define NAZARA_RENDERSURFACE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/WindowHandle.hpp>
#include <Nazara/Renderer/Config.hpp>
namespace Nz
{
///TODO: Rename
class NAZARA_RENDERER_API RenderSurface
{
public:
RenderSurface() = default;
virtual ~RenderSurface();
virtual bool Create(WindowHandle handle) = 0;
virtual void Destroy() = 0;
};
}
#include <Nazara/Renderer/RenderSurface.inl>
#endif // NAZARA_RENDERSURFACE_HPP

View File

@ -0,0 +1,12 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/RenderSurface.hpp>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz
{
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@ -11,6 +11,7 @@
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Renderer/RenderSurface.hpp>
#include <Nazara/Renderer/RenderWindowImpl.hpp>
#include <Nazara/Renderer/RenderWindowParameters.hpp>
#include <Nazara/Utility/Window.hpp>
@ -52,6 +53,7 @@ namespace Nz
private:
std::unique_ptr<RenderWindowImpl> m_impl;
Clock m_clock;
std::unique_ptr<RenderSurface> m_surface;
RenderWindowParameters m_parameters;
unsigned int m_framerateLimit;
};

View File

@ -16,13 +16,15 @@
namespace Nz
{
class RenderSurface;
class NAZARA_RENDERER_API RenderWindowImpl
{
public:
RenderWindowImpl() = default;
virtual ~RenderWindowImpl();
virtual bool Create(WindowHandle handle, const Vector2ui& size, const RenderWindowParameters& parameters) = 0;
virtual bool Create(RenderSurface* surface, const Vector2ui& size, const RenderWindowParameters& parameters) = 0;
};
}

View File

@ -21,6 +21,8 @@ namespace Nz
class AbstractBuffer;
class Buffer;
class RendererImpl;
class RenderDeviceInstance;
class RenderSurface;
class RenderWindowImpl;
using CreateRendererImplFunc = RendererImpl*(*)();
@ -32,8 +34,11 @@ namespace Nz
virtual ~RendererImpl();
virtual std::unique_ptr<AbstractBuffer> CreateHardwareBufferImpl(Buffer* parent, BufferType type) = 0;
virtual std::unique_ptr<RenderSurface> CreateRenderSurfaceImpl() = 0;
virtual std::unique_ptr<RenderWindowImpl> CreateRenderWindowImpl() = 0;
virtual std::unique_ptr<RenderDeviceInstance> InstanciateRenderDevice(std::size_t deviceIndex) = 0;
virtual bool IsBetterThan(const RendererImpl* other) const = 0;
virtual RenderAPI QueryAPI() const = 0;

View File

@ -39,13 +39,12 @@ namespace Nz
void BuildPreRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
void BuildPostRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
bool Create(WindowHandle handle, const Vector2ui& size, const RenderWindowParameters& parameters) override;
bool Create(RenderSurface* surface, const Vector2ui& size, const RenderWindowParameters& parameters) override;
inline const Vk::Framebuffer& GetFrameBuffer(UInt32 imageIndex) const override;
inline UInt32 GetFramebufferCount() const;
inline const Vk::DeviceHandle& GetDevice() const;
inline UInt32 GetPresentableFamilyQueue() const;
inline const Vk::Surface& GetSurface() const;
inline const Vk::Swapchain& GetSwapchain() const;
void Present(UInt32 imageIndex) override;
@ -56,7 +55,7 @@ namespace Nz
private:
bool SetupDepthBuffer(const Vector2ui& size);
bool SetupRenderPass(const Vector2ui& size);
bool SetupSwapchain(const Vector2ui& size);
bool SetupSwapchain(Vk::Surface& surface, const Vector2ui& size);
Clock m_clock;
VkColorSpaceKHR m_colorSpace;
@ -69,7 +68,6 @@ namespace Nz
Vk::Image m_depthBuffer;
Vk::ImageView m_depthBufferView;
Vk::Queue m_presentQueue;
Vk::Surface m_surface;
Vk::Swapchain m_swapchain;
UInt32 m_presentableFamilyQueue;
};

View File

@ -27,11 +27,6 @@ namespace Nz
return m_presentableFamilyQueue;
}
inline const Vk::Surface& VkRenderWindow::GetSurface() const
{
return m_surface;
}
inline const Vk::Swapchain& VkRenderWindow::GetSwapchain() const
{
return m_swapchain;

View File

@ -0,0 +1,35 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Vulkan Renderer"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_VULKANRENDERER_VULKANDEVICE_HPP
#define NAZARA_VULKANRENDERER_VULKANDEVICE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/RenderDeviceInstance.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Device.hpp>
#include <vector>
namespace Nz
{
//TODO: Move all the software stuff to the Renderer
class NAZARA_VULKANRENDERER_API VulkanDevice : public RenderDeviceInstance
{
public:
VulkanDevice(Vk::DeviceHandle device);
~VulkanDevice();
VulkanDevice& operator=(const VulkanDevice&) = delete;
VulkanDevice& operator=(VulkanDevice&&) = delete; ///TODO
private:
Vk::DeviceHandle m_device;
};
}
#include <Nazara/VulkanRenderer/VulkanDevice.inl>
#endif // NAZARA_VULKANRENDERER_VULKANDEVICE_HPP

View File

@ -0,0 +1,12 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Vulkan Renderer"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/VulkanRenderer/VulkanDevice.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
namespace Nz
{
}
#include <Nazara/VulkanRenderer/DebugOff.hpp>

View File

@ -25,8 +25,12 @@ namespace Nz
VulkanRenderer() = default;
~VulkanRenderer();
std::unique_ptr<AbstractBuffer> CreateHardwareBufferImpl(Buffer* parent, BufferType type) override;
std::unique_ptr<RenderSurface> CreateRenderSurfaceImpl() override;
std::unique_ptr<RenderWindowImpl> CreateRenderWindowImpl() override;
std::unique_ptr<RenderDeviceInstance> InstanciateRenderDevice(std::size_t deviceIndex) override;
bool IsBetterThan(const RendererImpl* other) const override;
RenderAPI QueryAPI() const override;

View File

@ -0,0 +1,40 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Vulkan Renderer"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_VULKANRENDERER_SURFACE_HPP
#define NAZARA_VULKANRENDERER_SURFACE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/RenderSurface.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Surface.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Swapchain.hpp>
namespace Nz
{
class NAZARA_VULKANRENDERER_API VulkanSurface : public RenderSurface
{
public:
VulkanSurface();
VulkanSurface(const VulkanSurface&) = delete;
VulkanSurface(VulkanSurface&&) = delete; ///TODO
virtual ~VulkanSurface();
bool Create(WindowHandle handle) override;
void Destroy() override;
inline Vk::Surface& GetSurface();
VulkanSurface& operator=(const VulkanSurface&) = delete;
VulkanSurface& operator=(VulkanSurface&&) = delete; ///TODO
private:
Vk::Surface m_surface;
};
}
#include <Nazara/VulkanRenderer/VulkanSurface.inl>
#endif // NAZARA_VULKANRENDERER_SURFACE_HPP

View File

@ -0,0 +1,16 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Vulkan Renderer"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/VulkanRenderer/VulkanSurface.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
namespace Nz
{
inline Vk::Surface& VulkanSurface::GetSurface()
{
return m_surface;
}
}
#include <Nazara/VulkanRenderer/DebugOff.hpp>

View File

@ -0,0 +1,11 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/RenderDeviceInstance.hpp>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz
{
RenderDeviceInstance::~RenderDeviceInstance() = default;
}

View File

@ -0,0 +1,11 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/RenderSurface.hpp>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz
{
RenderSurface::~RenderSurface() = default;
}

View File

@ -35,14 +35,22 @@ namespace Nz
bool RenderWindow::OnWindowCreated()
{
auto surface = Renderer::GetRendererImpl()->CreateRenderSurfaceImpl();
if (!surface->Create(GetHandle()))
{
NazaraError("Failed to create render surface: " + Error::GetLastError());
return false;
}
auto impl = Renderer::GetRendererImpl()->CreateRenderWindowImpl();
if (!impl->Create(GetHandle(), Vector2ui(GetWidth(), GetHeight()), m_parameters))
if (!impl->Create(surface.get(), Vector2ui(GetWidth(), GetHeight()), m_parameters))
{
NazaraError("Failed to create render window implementation: " + Error::GetLastError());
return false;
}
m_impl = std::move(impl);
m_surface = std::move(surface);
m_clock.Restart();
@ -52,6 +60,7 @@ namespace Nz
void RenderWindow::OnWindowDestroy()
{
m_impl.reset();
m_surface.reset();
}
void RenderWindow::OnWindowResized()

View File

@ -7,6 +7,7 @@
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
#include <Nazara/VulkanRenderer/Vulkan.hpp>
#include <Nazara/VulkanRenderer/VulkanSurface.hpp>
#include <array>
#include <stdexcept>
#include <Nazara/VulkanRenderer/Debug.hpp>
@ -14,7 +15,6 @@
namespace Nz
{
VkRenderWindow::VkRenderWindow() :
m_surface(Nz::Vulkan::GetInstance()),
m_physicalDevice(nullptr),
m_depthStencilFormat(VK_FORMAT_MAX_ENUM)
{
@ -27,7 +27,6 @@ namespace Nz
m_renderPass.Destroy();
m_swapchain.Destroy();
m_surface.Destroy();
}
bool VkRenderWindow::Acquire(UInt32* imageIndex) const
@ -65,25 +64,13 @@ namespace Nz
//commandBuffer.SetImageLayout(m_swapchain.GetBuffer(imageIndex).image, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
}
bool VkRenderWindow::Create(WindowHandle handle, const Vector2ui& size, const RenderWindowParameters& parameters)
bool VkRenderWindow::Create(RenderSurface* surface, const Vector2ui& size, const RenderWindowParameters& parameters)
{
#if defined(NAZARA_PLATFORM_WINDOWS)
HWND winHandle = reinterpret_cast<HWND>(handle);
HINSTANCE instance = reinterpret_cast<HINSTANCE>(GetWindowLongPtrW(winHandle, GWLP_HINSTANCE));
bool success = m_surface.Create(instance, winHandle);
#else
#error This OS is not supported by Vulkan
#endif
if (!success)
{
NazaraError("Failed to create Vulkan surface");
return false;
}
m_physicalDevice = Vulkan::GetPhysicalDevices()[0].device;
m_device = Vulkan::SelectDevice(m_physicalDevice, m_surface, &m_presentableFamilyQueue);
Vk::Surface& vulkanSurface = static_cast<VulkanSurface*>(surface)->GetSurface();
m_device = Vulkan::SelectDevice(m_physicalDevice, vulkanSurface, &m_presentableFamilyQueue);
if (!m_device)
{
NazaraError("Failed to get compatible Vulkan device");
@ -93,7 +80,7 @@ namespace Nz
m_presentQueue = m_device->GetQueue(m_presentableFamilyQueue, 0);
std::vector<VkSurfaceFormatKHR> surfaceFormats;
if (!m_surface.GetFormats(m_physicalDevice, &surfaceFormats))
if (!vulkanSurface.GetFormats(m_physicalDevice, &surfaceFormats))
{
NazaraError("Failed to query supported surface formats");
return false;
@ -159,7 +146,7 @@ namespace Nz
}
}
if (!SetupSwapchain(size))
if (!SetupSwapchain(vulkanSurface, size))
{
NazaraError("Failed to create swapchain");
return false;
@ -369,10 +356,10 @@ namespace Nz
return m_renderPass.Create(m_device, createInfo);
}
bool VkRenderWindow::SetupSwapchain(const Vector2ui& size)
bool VkRenderWindow::SetupSwapchain(Vk::Surface& surface, const Vector2ui& size)
{
VkSurfaceCapabilitiesKHR surfaceCapabilities;
if (!m_surface.GetCapabilities(m_physicalDevice, &surfaceCapabilities))
if (!surface.GetCapabilities(m_physicalDevice, &surfaceCapabilities))
{
NazaraError("Failed to query surface capabilities");
return false;
@ -392,7 +379,7 @@ namespace Nz
extent = surfaceCapabilities.currentExtent;
std::vector<VkPresentModeKHR> presentModes;
if (!m_surface.GetPresentModes(m_physicalDevice, &presentModes))
if (!surface.GetPresentModes(m_physicalDevice, &presentModes))
{
NazaraError("Failed to query supported present modes");
return false;
@ -415,7 +402,7 @@ namespace Nz
VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
nullptr,
0,
m_surface,
surface,
imageCount,
m_colorFormat,
m_colorSpace,

View File

@ -392,7 +392,10 @@ namespace Nz
}
if (presentableQueueFamilyIndex != UINT32_MAX)
{
*presentableFamilyQueue = presentableQueueFamilyIndex;
return device.CreateHandle();
}
}
}

View File

@ -0,0 +1,11 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Vulkan Renderer"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/VulkanRenderer/VulkanDevice.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
namespace Nz
{
VulkanDevice::~VulkanDevice() = default;
}

View File

@ -4,6 +4,9 @@
#include <Nazara/VulkanRenderer/VulkanRenderer.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Renderer/RenderDeviceInstance.hpp>
#include <Nazara/VulkanRenderer/VulkanBuffer.hpp>
#include <Nazara/VulkanRenderer/VulkanSurface.hpp>
#include <Nazara/VulkanRenderer/VkRenderWindow.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Loader.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
@ -15,11 +18,26 @@ namespace Nz
Vulkan::Uninitialize();
}
std::unique_ptr<AbstractBuffer> VulkanRenderer::CreateHardwareBufferImpl(Buffer* parent, BufferType type)
{
return nullptr; //< TODO
}
std::unique_ptr<RenderSurface> VulkanRenderer::CreateRenderSurfaceImpl()
{
return std::make_unique<VulkanSurface>();
}
std::unique_ptr<RenderWindowImpl> VulkanRenderer::CreateRenderWindowImpl()
{
return std::make_unique<VkRenderWindow>();
}
std::unique_ptr<RenderDeviceInstance> VulkanRenderer::InstanciateRenderDevice(std::size_t deviceIndex)
{
return std::unique_ptr<RenderDeviceInstance>();
}
bool VulkanRenderer::IsBetterThan(const RendererImpl* other) const
{
if (other->QueryAPI() == RenderAPI_Vulkan && QueryAPIVersion() < other->QueryAPIVersion())
@ -41,14 +59,14 @@ namespace Nz
String VulkanRenderer::QueryAPIString() const
{
StringStream ss;
ss << "Vulkan renderer " << VK_VERSION_MAJOR(m_apiVersion) << '.' << VK_VERSION_MINOR(m_apiVersion) << '.' << VK_VERSION_PATCH(m_apiVersion);
ss << "Vulkan renderer " << VK_VERSION_MAJOR(APIVersion) << '.' << VK_VERSION_MINOR(APIVersion) << '.' << VK_VERSION_PATCH(APIVersion);
return ss;
}
UInt32 VulkanRenderer::QueryAPIVersion() const
{
return m_apiVersion;
return APIVersion;
}
std::vector<RenderDevice> VulkanRenderer::QueryRenderDevices() const

View File

@ -0,0 +1,45 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Vulkan Renderer"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/VulkanRenderer/VulkanSurface.hpp>
#include <Nazara/VulkanRenderer/Vulkan.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
namespace Nz
{
VulkanSurface::VulkanSurface() :
m_surface(Vulkan::GetInstance())
{
}
VulkanSurface::~VulkanSurface() = default;
bool VulkanSurface::Create(WindowHandle handle)
{
bool success = false;
#if defined(NAZARA_PLATFORM_WINDOWS)
{
HWND winHandle = reinterpret_cast<HWND>(handle);
HINSTANCE instance = reinterpret_cast<HINSTANCE>(GetWindowLongPtrW(winHandle, GWLP_HINSTANCE));
success = m_surface.Create(instance, winHandle);
}
#else
#error This OS is not supported by Vulkan
#endif
if (!success)
{
NazaraError("Failed to create Vulkan surface: " + TranslateVulkanError(m_surface.GetLastErrorCode()));
return false;
}
return true;
}
void VulkanSurface::Destroy()
{
m_surface.Destroy();
}
}