Implement some classes

This commit is contained in:
Lynix
2020-04-19 01:37:56 +02:00
parent 5c3eb31d4a
commit 4dc8920a73
24 changed files with 138 additions and 951 deletions

View File

@@ -0,0 +1,34 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - OpenGL Renderer"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_OPENGLRENDERER_SURFACE_HPP
#define NAZARA_OPENGLRENDERER_SURFACE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/Renderer/RenderSurface.hpp>
namespace Nz
{
class NAZARA_OPENGLRENDERER_API DummySurface : public RenderSurface
{
public:
DummySurface() = default;
~DummySurface() = default;
bool Create(WindowHandle handle) override;
void Destroy() override;
inline WindowHandle GetWindowHandle() const;
private:
WindowHandle m_handle;
};
}
#include <Nazara/OpenGLRenderer/DummySurface.inl>
#endif // NAZARA_OPENGLRENDERER_SURFACE_HPP

View File

@@ -2,14 +2,14 @@
// This file is part of the "Nazara Engine - OpenGL Renderer"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/OpenGLRenderer/OpenGLSurface.hpp>
#include <Nazara/OpenGLRenderer/DummySurface.hpp>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz
{
inline Vk::Surface& OpenGLSurface::GetSurface()
inline WindowHandle DummySurface::GetWindowHandle() const
{
return m_surface;
return m_handle;
}
}

View File

@@ -10,7 +10,6 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Renderer/CommandBuffer.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/CommandBuffer.hpp>
#include <vector>
namespace Nz
@@ -18,19 +17,13 @@ namespace Nz
class NAZARA_OPENGLRENDERER_API OpenGLCommandBuffer final : public CommandBuffer
{
public:
inline OpenGLCommandBuffer(Vk::AutoCommandBuffer commandBuffer);
inline OpenGLCommandBuffer(std::vector<Vk::AutoCommandBuffer> commandBuffers);
inline OpenGLCommandBuffer();
OpenGLCommandBuffer(const OpenGLCommandBuffer&) = delete;
OpenGLCommandBuffer(OpenGLCommandBuffer&&) noexcept = default;
~OpenGLCommandBuffer() = default;
inline Vk::CommandBuffer& GetCommandBuffer(std::size_t imageIndex = 0);
OpenGLCommandBuffer& operator=(const OpenGLCommandBuffer&) = delete;
OpenGLCommandBuffer& operator=(OpenGLCommandBuffer&&) = delete;
private:
std::vector<Vk::AutoCommandBuffer> m_commandBuffers;
};
}

View File

@@ -7,20 +7,6 @@
namespace Nz
{
inline OpenGLCommandBuffer::OpenGLCommandBuffer(Vk::AutoCommandBuffer commandBuffer)
{
m_commandBuffers.push_back(std::move(commandBuffer));
}
inline OpenGLCommandBuffer::OpenGLCommandBuffer(std::vector<Vk::AutoCommandBuffer> commandBuffers) :
m_commandBuffers(std::move(commandBuffers))
{
}
inline Vk::CommandBuffer& OpenGLCommandBuffer::GetCommandBuffer(std::size_t imageIndex)
{
return m_commandBuffers[imageIndex].Get();
}
}
#include <Nazara/OpenGLRenderer/DebugOff.hpp>

View File

@@ -10,7 +10,6 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Renderer/CommandBufferBuilder.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/CommandBuffer.hpp>
namespace Nz
{
@@ -19,7 +18,7 @@ namespace Nz
class NAZARA_OPENGLRENDERER_API OpenGLCommandBufferBuilder final : public CommandBufferBuilder
{
public:
inline OpenGLCommandBufferBuilder(Vk::CommandBuffer& commandBuffer, std::size_t imageIndex = 0);
OpenGLCommandBufferBuilder() = default;
OpenGLCommandBufferBuilder(const OpenGLCommandBufferBuilder&) = delete;
OpenGLCommandBufferBuilder(OpenGLCommandBufferBuilder&&) noexcept = default;
~OpenGLCommandBufferBuilder() = default;
@@ -41,9 +40,6 @@ namespace Nz
void EndDebugRegion() override;
void EndRenderPass() override;
inline Vk::CommandBuffer& GetCommandBuffer();
inline std::size_t GetMaxFramebufferCount() const;
void PreTransferBarrier() override;
void PostTransferBarrier() override;
@@ -52,12 +48,6 @@ namespace Nz
OpenGLCommandBufferBuilder& operator=(const OpenGLCommandBufferBuilder&) = delete;
OpenGLCommandBufferBuilder& operator=(OpenGLCommandBufferBuilder&&) = delete;
private:
Vk::CommandBuffer& m_commandBuffer;
const OpenGLRenderPass* m_currentRenderPass;
std::size_t m_framebufferCount;
std::size_t m_imageIndex;
};
}

View File

@@ -7,22 +7,6 @@
namespace Nz
{
inline OpenGLCommandBufferBuilder::OpenGLCommandBufferBuilder(Vk::CommandBuffer& commandBuffer, std::size_t imageIndex) :
m_commandBuffer(commandBuffer),
m_framebufferCount(0),
m_imageIndex(imageIndex)
{
}
inline Vk::CommandBuffer& OpenGLCommandBufferBuilder::GetCommandBuffer()
{
return m_commandBuffer;
}
inline std::size_t OpenGLCommandBufferBuilder::GetMaxFramebufferCount() const
{
return m_framebufferCount;
}
}
#include <Nazara/OpenGLRenderer/DebugOff.hpp>

View File

@@ -10,31 +10,19 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Renderer/Framebuffer.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Framebuffer.hpp>
namespace Nz
{
class NAZARA_OPENGLRENDERER_API OpenGLFramebuffer : public Framebuffer
{
public:
enum class Type
{
Multiple,
Single
};
inline OpenGLFramebuffer(Type type);
OpenGLFramebuffer() = default;
OpenGLFramebuffer(const OpenGLFramebuffer&) = delete;
OpenGLFramebuffer(OpenGLFramebuffer&&) noexcept = default;
~OpenGLFramebuffer() = default;
inline Type GetType() const;
OpenGLFramebuffer& operator=(const OpenGLFramebuffer&) = delete;
OpenGLFramebuffer& operator=(OpenGLFramebuffer&&) noexcept = default;
private:
Type m_type;
};
}

View File

@@ -7,15 +7,6 @@
namespace Nz
{
inline OpenGLFramebuffer::OpenGLFramebuffer(Type type) :
m_type(type)
{
}
inline auto OpenGLFramebuffer::GetType() const -> Type
{
return m_type;
}
}
#include <Nazara/OpenGLRenderer/DebugOff.hpp>

View File

@@ -10,53 +10,34 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Renderer/RenderImage.hpp>
#include <Nazara/OpenGLRenderer/OpenGLUploadPool.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/CommandBuffer.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/CommandPool.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Fence.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Semaphore.hpp>
#include <vector>
namespace Nz
{
class VkRenderWindow;
class OpenGLRenderWindow;
class NAZARA_OPENGLRENDERER_API OpenGLRenderImage : public RenderImage
{
public:
OpenGLRenderImage(VkRenderWindow& owner);
OpenGLRenderImage(OpenGLRenderWindow& owner);
OpenGLRenderImage(const OpenGLRenderImage&) = delete;
OpenGLRenderImage(OpenGLRenderImage&&) noexcept = default;
~OpenGLRenderImage();
~OpenGLRenderImage() = default;
void Execute(const std::function<void(CommandBufferBuilder& builder)>& callback, QueueTypeFlags queueTypeFlags) override;
inline Vk::Fence& GetInFlightFence();
inline Vk::Semaphore& GetImageAvailableSemaphore();
inline UInt32 GetImageIndex();
inline Vk::Semaphore& GetRenderFinishedSemaphore();
OpenGLUploadPool& GetUploadPool() override;
void SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags) override;
void SubmitCommandBuffer(VkCommandBuffer commandBuffer, QueueTypeFlags queueTypeFlags);
void Present() override;
inline void Reset(UInt32 imageIndex);
OpenGLRenderImage& operator=(const OpenGLRenderImage&) = delete;
OpenGLRenderImage& operator=(OpenGLRenderImage&&) = delete;
private:
std::size_t m_currentCommandBuffer;
std::vector<Vk::AutoCommandBuffer> m_inFlightCommandBuffers;
std::vector<VkCommandBuffer> m_graphicalCommandsBuffers;
VkRenderWindow& m_owner;
Vk::CommandPool m_commandPool;
Vk::Fence m_inFlightFence;
Vk::Semaphore m_imageAvailableSemaphore;
Vk::Semaphore m_renderFinishedSemaphore;
OpenGLRenderWindow& m_owner;
OpenGLUploadPool m_uploadPool;
UInt32 m_imageIndex;
};
}

View File

@@ -7,33 +7,6 @@
namespace Nz
{
inline Vk::Fence& Nz::OpenGLRenderImage::GetInFlightFence()
{
return m_inFlightFence;
}
inline Vk::Semaphore& OpenGLRenderImage::GetImageAvailableSemaphore()
{
return m_imageAvailableSemaphore;
}
inline UInt32 OpenGLRenderImage::GetImageIndex()
{
return m_imageIndex;
}
inline Vk::Semaphore& OpenGLRenderImage::GetRenderFinishedSemaphore()
{
return m_renderFinishedSemaphore;
}
inline void OpenGLRenderImage::Reset(UInt32 imageIndex)
{
m_graphicalCommandsBuffers.clear();
m_currentCommandBuffer = 0;
m_imageIndex = imageIndex;
m_uploadPool.Reset();
}
}
#include <Nazara/OpenGLRenderer/DebugOff.hpp>

View File

@@ -10,7 +10,6 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Renderer/RenderPass.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/RenderPass.hpp>
#include <vector>
namespace Nz
@@ -18,21 +17,13 @@ namespace Nz
class NAZARA_OPENGLRENDERER_API OpenGLRenderPass final : public RenderPass
{
public:
inline OpenGLRenderPass(Vk::RenderPass renderPass, std::initializer_list<PixelFormat> formats); //< FIXME
OpenGLRenderPass() = default;
OpenGLRenderPass(const OpenGLRenderPass&) = delete;
OpenGLRenderPass(OpenGLRenderPass&&) noexcept = default;
~OpenGLRenderPass() = default;
inline PixelFormat GetAttachmentFormat(std::size_t attachmentIndex) const;
inline Vk::RenderPass& GetRenderPass();
inline const Vk::RenderPass& GetRenderPass() const;
OpenGLRenderPass& operator=(const OpenGLRenderPass&) = delete;
OpenGLRenderPass& operator=(OpenGLRenderPass&&) noexcept = default;
private:
std::vector<PixelFormat> m_formats;
Vk::RenderPass m_renderPass;
};
}

View File

@@ -7,26 +7,6 @@
namespace Nz
{
inline OpenGLRenderPass::OpenGLRenderPass(Vk::RenderPass renderPass, std::initializer_list<PixelFormat> formats) :
m_formats(std::begin(formats), std::end(formats)),
m_renderPass(std::move(renderPass))
{
}
inline PixelFormat OpenGLRenderPass::GetAttachmentFormat(std::size_t attachmentIndex) const
{
return m_formats[attachmentIndex];
}
inline Vk::RenderPass& OpenGLRenderPass::GetRenderPass()
{
return m_renderPass;
}
inline const Vk::RenderPass& OpenGLRenderPass::GetRenderPass() const
{
return m_renderPass;
}
}
#include <Nazara/OpenGLRenderer/DebugOff.hpp>

View File

@@ -8,27 +8,13 @@
#define NAZARA_OPENGLRENDERER_RENDERWINDOW_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Renderer/RendererImpl.hpp>
#include <Nazara/Renderer/RenderWindowImpl.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/OpenGLDevice.hpp>
#include <Nazara/OpenGLRenderer/OpenGLMultipleFramebuffer.hpp>
#include <Nazara/OpenGLRenderer/OpenGLFramebuffer.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderImage.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderPass.hpp>
#include <Nazara/OpenGLRenderer/VkRenderTarget.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/CommandBuffer.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/CommandPool.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Device.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/DeviceMemory.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Framebuffer.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Image.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/QueueHandle.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Surface.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Swapchain.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
#include <Nazara/Renderer/RenderWindowImpl.hpp>
#include <optional>
#include <vector>
@@ -37,54 +23,31 @@ namespace Nz
class NAZARA_OPENGLRENDERER_API OpenGLRenderWindow : public RenderWindowImpl
{
public:
VkRenderWindow();
VkRenderWindow(const VkRenderWindow&) = delete;
VkRenderWindow(VkRenderWindow&&) = delete; ///TODO
virtual ~VkRenderWindow();
OpenGLRenderWindow();
~OpenGLRenderWindow() = default;
OpenGLRenderImage& Acquire() override;
bool Create(RendererImpl* renderer, RenderSurface* surface, const Vector2ui& size, const RenderWindowParameters& parameters) override;
std::unique_ptr<CommandPool> CreateCommandPool(QueueType queueType) override;
inline const OpenGLFramebuffer& GetFramebuffer() const override;
inline OpenGLDevice& GetDevice();
inline const OpenGLDevice& GetDevice() const;
inline Vk::QueueHandle& GetGraphicsQueue();
const OpenGLFramebuffer& GetFramebuffer() const override;
const OpenGLRenderPass& GetRenderPass() const override;
inline const Vk::Swapchain& GetSwapchain() const;
std::shared_ptr<RenderDevice> GetRenderDevice() override;
void Present(UInt32 imageIndex, VkSemaphore waitSemaphore = VK_NULL_HANDLE);
VkRenderWindow& operator=(const VkRenderWindow&) = delete;
VkRenderWindow& operator=(VkRenderWindow&&) = delete; ///TODO
void Present();
private:
bool SetupDepthBuffer(const Vector2ui& size);
bool SetupRenderPass();
bool SetupSwapchain(const Vk::PhysicalDevice& deviceInfo, Vk::Surface& surface, const Vector2ui& size);
std::size_t m_currentFrame;
Clock m_clock;
VkFormat m_depthStencilFormat;
VkSurfaceFormatKHR m_surfaceFormat;
std::optional<OpenGLMultipleFramebuffer> m_framebuffer;
std::optional<OpenGLRenderPass> m_renderPass;
std::shared_ptr<OpenGLDevice> m_device;
std::vector<Vk::Fence*> m_inflightFences;
std::vector<OpenGLRenderImage> m_concurrentImageData;
Vk::DeviceMemory m_depthBufferMemory;
Vk::Image m_depthBuffer;
Vk::ImageView m_depthBufferView;
Vk::QueueHandle m_graphicsQueue;
Vk::QueueHandle m_presentQueue;
Vk::QueueHandle m_transferQueue;
Vk::Swapchain m_swapchain;
std::vector<OpenGLRenderImage> m_renderImage;
std::unique_ptr<GL::Context> m_context;
OpenGLFramebuffer m_framebuffer;
OpenGLRenderPass m_renderPass;
};
}
#include <Nazara/OpenGLRenderer/VkRenderWindow.inl>
#include <Nazara/OpenGLRenderer/OpenGLRenderWindow.inl>
#endif // NAZARA_OPENGLRENDERER_RENDERWINDOW_HPP

View File

@@ -2,49 +2,11 @@
// This file is part of the "Nazara Engine - OpenGL Renderer"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/OpenGLRenderer/VkRenderWindow.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderWindow.hpp>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz
{
inline const OpenGLMultipleFramebuffer& VkRenderWindow::GetFramebuffer() const
{
return *m_framebuffer;
}
inline OpenGLDevice& VkRenderWindow::GetDevice()
{
return *m_device;
}
inline const OpenGLDevice& VkRenderWindow::GetDevice() const
{
return *m_device;
}
inline Vk::QueueHandle& VkRenderWindow::GetGraphicsQueue()
{
return m_graphicsQueue;
}
inline const Vk::Swapchain& VkRenderWindow::GetSwapchain() const
{
return m_swapchain;
}
inline std::shared_ptr<RenderDevice> Nz::VkRenderWindow::GetRenderDevice()
{
return m_device;
}
inline void VkRenderWindow::Present(UInt32 imageIndex, VkSemaphore waitSemaphore)
{
NazaraAssert(imageIndex < m_inflightFences.size(), "Invalid image index");
m_presentQueue.Present(m_swapchain, imageIndex, waitSemaphore);
m_currentFrame = (m_currentFrame + 1) % m_inflightFences.size();
}
}
#include <Nazara/OpenGLRenderer/DebugOff.hpp>

View File

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

View File

@@ -9,9 +9,8 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/Renderer/UploadPool.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Buffer.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/DeviceMemory.hpp>
#include <optional>
#include <vector>
@@ -20,18 +19,13 @@ namespace Nz
class NAZARA_OPENGLRENDERER_API OpenGLUploadPool : public UploadPool
{
public:
struct OpenGLAllocation : Allocation
{
VkBuffer buffer;
};
inline OpenGLUploadPool(Vk::Device& device, UInt64 blockSize);
inline OpenGLUploadPool(UInt64 blockSize);
OpenGLUploadPool(const OpenGLUploadPool&) = delete;
OpenGLUploadPool(OpenGLUploadPool&&) noexcept = default;
~OpenGLUploadPool() = default;
OpenGLAllocation& Allocate(UInt64 size) override;
OpenGLAllocation& Allocate(UInt64 size, UInt64 alignment) override;
Allocation& Allocate(UInt64 size) override;
Allocation& Allocate(UInt64 size, UInt64 alignment) override;
void Reset() override;
@@ -41,15 +35,11 @@ namespace Nz
private:
struct Block
{
Vk::DeviceMemory blockMemory;
Vk::Buffer buffer;
//< TODO
UInt64 freeOffset;
};
UInt64 m_blockSize;
Vk::Device& m_device;
std::vector<Block> m_blocks;
std::vector<OpenGLAllocation> m_allocations;
};
}

View File

@@ -7,9 +7,8 @@
namespace Nz
{
inline OpenGLUploadPool::OpenGLUploadPool(Vk::Device& device, UInt64 blockSize) :
m_blockSize(blockSize),
m_device(device)
inline OpenGLUploadPool::OpenGLUploadPool(UInt64 blockSize) :
m_blockSize(blockSize)
{
}
}