Add buffer support
This commit is contained in:
@@ -36,8 +36,8 @@
|
||||
#include <Nazara/Renderer/GlslWriter.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/RenderBuffer.hpp>
|
||||
#include <Nazara/Renderer/RenderDeviceInfo.hpp>
|
||||
#include <Nazara/Renderer/RenderDevice.hpp>
|
||||
#include <Nazara/Renderer/RenderDeviceInstance.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RendererImpl.hpp>
|
||||
#include <Nazara/Renderer/RenderPipeline.hpp>
|
||||
|
||||
@@ -7,31 +7,56 @@
|
||||
#ifndef NAZARA_RENDERBUFFER_HPP
|
||||
#define NAZARA_RENDERBUFFER_HPP
|
||||
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/RenderDevice.hpp>
|
||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
||||
#include <Nazara/Utility/SoftwareBuffer.hpp>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class RenderDevice;
|
||||
|
||||
class NAZARA_RENDERER_API RenderBuffer : public AbstractBuffer
|
||||
{
|
||||
public:
|
||||
RenderBuffer() = default;
|
||||
inline RenderBuffer(Buffer* parent, BufferType type);
|
||||
RenderBuffer(const RenderBuffer&) = delete;
|
||||
RenderBuffer(RenderBuffer&&) = default;
|
||||
~RenderBuffer() = default;
|
||||
|
||||
virtual bool Fill(const void* data, UInt32 offset, UInt32 size) = 0;
|
||||
bool Fill(const void* data, UInt32 offset, UInt32 size) override final;
|
||||
|
||||
bool Initialize(UInt32 size, BufferUsageFlags usage) override;
|
||||
|
||||
AbstractBuffer* GetHardwareBuffer(RenderDevice* device);
|
||||
DataStorage GetStorage() const override;
|
||||
|
||||
virtual void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) = 0;
|
||||
virtual bool Unmap() = 0;
|
||||
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) override final;
|
||||
bool Unmap() override final;
|
||||
|
||||
RenderBuffer& operator=(const RenderBuffer&) = delete;
|
||||
RenderBuffer& operator=(RenderBuffer&&) = default;
|
||||
|
||||
public: //< temp
|
||||
bool Synchronize(RenderDevice* device);
|
||||
|
||||
private:
|
||||
SoftwareBuffer m_softwareBuffer;
|
||||
};
|
||||
struct HardwareBuffer
|
||||
{
|
||||
std::unique_ptr<AbstractBuffer> buffer;
|
||||
bool synchronized = false;
|
||||
};
|
||||
|
||||
BufferUsageFlags m_usage;
|
||||
SoftwareBuffer m_softwareBuffer;
|
||||
Buffer* m_parent;
|
||||
BufferType m_type;
|
||||
std::size_t m_size;
|
||||
std::unordered_map<RenderDevice*, HardwareBuffer> m_hardwareBuffers;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/RenderBuffer.inl>
|
||||
|
||||
@@ -2,11 +2,18 @@
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/RenderBuffer.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline RenderBuffer::RenderBuffer(Buffer* parent, BufferType type) :
|
||||
m_softwareBuffer(parent, type),
|
||||
m_parent(parent),
|
||||
m_type(type)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/DebugOff.hpp>
|
||||
|
||||
@@ -4,20 +4,28 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_RENDERDEVICE_HPP
|
||||
#define NAZARA_RENDERDEVICE_HPP
|
||||
#ifndef NAZARA_RENDERDEVICEINSTANCE_HPP
|
||||
#define NAZARA_RENDERDEVICEINSTANCE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct RenderDevice
|
||||
class Buffer;
|
||||
|
||||
class NAZARA_RENDERER_API RenderDevice
|
||||
{
|
||||
RenderDeviceType type;
|
||||
String name;
|
||||
public:
|
||||
RenderDevice() = default;
|
||||
virtual ~RenderDevice();
|
||||
|
||||
virtual std::unique_ptr<AbstractBuffer> InstantiateBuffer(Buffer* parent, BufferType type) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RENDERER_HPP
|
||||
#include <Nazara/Renderer/RenderDevice.inl>
|
||||
|
||||
#endif // NAZARA_RENDERDEVICEINSTANCE_HPP
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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/RenderDevice.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
23
include/Nazara/Renderer/RenderDeviceInfo.hpp
Normal file
23
include/Nazara/Renderer/RenderDeviceInfo.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
// 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_RENDERDEVICE_HPP
|
||||
#define NAZARA_RENDERDEVICE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct RenderDeviceInfo
|
||||
{
|
||||
RenderDeviceType type;
|
||||
String name;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RENDERER_HPP
|
||||
@@ -1,26 +0,0 @@
|
||||
// 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
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class RendererImpl;
|
||||
class RenderSurface;
|
||||
|
||||
class NAZARA_RENDERER_API RenderWindowImpl
|
||||
@@ -24,7 +25,7 @@ namespace Nz
|
||||
RenderWindowImpl() = default;
|
||||
virtual ~RenderWindowImpl();
|
||||
|
||||
virtual bool Create(RenderSurface* surface, const Vector2ui& size, const RenderWindowParameters& parameters) = 0;
|
||||
virtual bool Create(RendererImpl* renderer, RenderSurface* surface, const Vector2ui& size, const RenderWindowParameters& parameters) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <Nazara/Renderer/RenderDevice.hpp>
|
||||
#include <Nazara/Renderer/RenderDeviceInfo.hpp>
|
||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <vector>
|
||||
@@ -21,7 +21,7 @@ namespace Nz
|
||||
{
|
||||
class Buffer;
|
||||
class RendererImpl;
|
||||
class RenderDeviceInstance;
|
||||
class RenderDevice;
|
||||
class RenderSurface;
|
||||
class RenderWindowImpl;
|
||||
|
||||
@@ -33,11 +33,10 @@ namespace Nz
|
||||
RendererImpl() = default;
|
||||
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 std::shared_ptr<RenderDevice> InstanciateRenderDevice(std::size_t deviceIndex) = 0;
|
||||
|
||||
virtual bool IsBetterThan(const RendererImpl* other) const = 0;
|
||||
|
||||
@@ -45,7 +44,7 @@ namespace Nz
|
||||
virtual String QueryAPIString() const = 0;
|
||||
virtual UInt32 QueryAPIVersion() const = 0;
|
||||
|
||||
virtual std::vector<RenderDevice> QueryRenderDevices() const = 0;
|
||||
virtual std::vector<RenderDeviceInfo> QueryRenderDevices() const = 0;
|
||||
|
||||
virtual bool Prepare(const ParameterList& parameters) = 0;
|
||||
};
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Nz
|
||||
|
||||
bool Initialize(UInt32 size, BufferUsageFlags usage) override;
|
||||
|
||||
const UInt8* GetData() const;
|
||||
DataStorage GetStorage() const override;
|
||||
|
||||
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) override;
|
||||
|
||||
@@ -11,8 +11,10 @@
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Renderer/RendererImpl.hpp>
|
||||
#include <Nazara/Renderer/RenderWindowImpl.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkRenderTarget.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/CommandPool.hpp>
|
||||
@@ -39,11 +41,12 @@ namespace Nz
|
||||
void BuildPreRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
|
||||
void BuildPostRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
|
||||
|
||||
bool Create(RenderSurface* surface, const Vector2ui& size, const RenderWindowParameters& parameters) override;
|
||||
bool Create(RendererImpl* renderer, 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 GetFramebufferCount() const override;
|
||||
inline VulkanDevice& GetDevice();
|
||||
inline const VulkanDevice& GetDevice() const;
|
||||
inline UInt32 GetPresentableFamilyQueue() const;
|
||||
inline const Vk::Swapchain& GetSwapchain() const;
|
||||
|
||||
@@ -62,8 +65,8 @@ namespace Nz
|
||||
VkFormat m_colorFormat;
|
||||
VkFormat m_depthStencilFormat;
|
||||
VkPhysicalDevice m_physicalDevice;
|
||||
std::shared_ptr<VulkanDevice> m_device;
|
||||
std::vector<Vk::Framebuffer> m_frameBuffers;
|
||||
Vk::DeviceHandle m_device;
|
||||
Vk::DeviceMemory m_depthBufferMemory;
|
||||
Vk::Image m_depthBuffer;
|
||||
Vk::ImageView m_depthBufferView;
|
||||
|
||||
@@ -7,9 +7,14 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline const Vk::DeviceHandle& VkRenderWindow::GetDevice() const
|
||||
inline VulkanDevice& VkRenderWindow::GetDevice()
|
||||
{
|
||||
return m_device;
|
||||
return *m_device;
|
||||
}
|
||||
|
||||
inline const VulkanDevice& VkRenderWindow::GetDevice() const
|
||||
{
|
||||
return *m_device;
|
||||
}
|
||||
|
||||
inline const Vk::Framebuffer& VkRenderWindow::GetFrameBuffer(UInt32 imageIndex) const
|
||||
|
||||
@@ -16,17 +16,28 @@
|
||||
#include <Nazara/VulkanRenderer/Wrapper/PhysicalDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Surface.hpp>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class VulkanDevice;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API Vulkan
|
||||
{
|
||||
public:
|
||||
struct QueueFamily
|
||||
{
|
||||
UInt32 familyIndex;
|
||||
float priority;
|
||||
};
|
||||
|
||||
Vulkan() = delete;
|
||||
~Vulkan() = delete;
|
||||
|
||||
static Vk::DeviceHandle CreateDevice(VkPhysicalDevice gpu, const Vk::Surface& surface, UInt32* presentableFamilyQueue);
|
||||
static std::shared_ptr<VulkanDevice> CreateDevice(VkPhysicalDevice gpu);
|
||||
static std::shared_ptr<VulkanDevice> CreateDevice(VkPhysicalDevice gpu, const Vk::Surface& surface, UInt32* presentableFamilyQueue);
|
||||
static std::shared_ptr<VulkanDevice> CreateDevice(VkPhysicalDevice gpu, const QueueFamily* queueFamilies, std::size_t queueFamilyCount);
|
||||
|
||||
static Vk::Instance& GetInstance();
|
||||
|
||||
@@ -37,12 +48,13 @@ namespace Nz
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static Vk::DeviceHandle SelectDevice(VkPhysicalDevice gpu, const Vk::Surface& surface, UInt32* presentableFamilyQueue);
|
||||
static std::shared_ptr<VulkanDevice> SelectDevice(VkPhysicalDevice gpu);
|
||||
static std::shared_ptr<VulkanDevice> SelectDevice(VkPhysicalDevice gpu, const Vk::Surface& surface, UInt32* presentableFamilyQueue);
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static std::list<Vk::Device> s_devices;
|
||||
static std::vector<std::weak_ptr<VulkanDevice>> s_devices;
|
||||
static std::vector<Vk::PhysicalDevice> s_physDevices;
|
||||
static Vk::Instance s_instance;
|
||||
static ParameterList s_initializationParameters;
|
||||
|
||||
@@ -9,25 +9,26 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
||||
#include <Nazara/Utility/SoftwareBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Buffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DeviceMemory.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
//TODO: Move all the software stuff to the Renderer
|
||||
class Buffer;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API VulkanBuffer : public AbstractBuffer
|
||||
{
|
||||
public:
|
||||
inline VulkanBuffer(Buffer* parent, BufferType type);
|
||||
inline VulkanBuffer(const Vk::DeviceHandle& device, Buffer* parent, BufferType type);
|
||||
VulkanBuffer(const VulkanBuffer&) = delete;
|
||||
VulkanBuffer(VulkanBuffer&&) = delete; ///TODO
|
||||
virtual ~VulkanBuffer();
|
||||
|
||||
bool Fill(const void* data, UInt32 offset, UInt32 size) override;
|
||||
|
||||
inline Nz::Vk::Buffer& GetBufferHandle();
|
||||
bool Initialize(UInt32 size, BufferUsageFlags usage) override;
|
||||
|
||||
DataStorage GetStorage() const override;
|
||||
@@ -39,8 +40,11 @@ namespace Nz
|
||||
VulkanBuffer& operator=(VulkanBuffer&&) = delete; ///TODO
|
||||
|
||||
private:
|
||||
BufferUsageFlags m_usage;
|
||||
SoftwareBuffer m_softwareData;
|
||||
Buffer* m_parent;
|
||||
BufferType m_type;
|
||||
Nz::Vk::Buffer m_buffer;
|
||||
Nz::Vk::DeviceHandle m_device;
|
||||
Nz::Vk::DeviceMemory m_memory;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,17 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline VulkanBuffer::VulkanBuffer(Buffer* parent, BufferType type) :
|
||||
m_softwareData(parent, type)
|
||||
inline VulkanBuffer::VulkanBuffer(const Vk::DeviceHandle& device, Buffer* parent, BufferType type) :
|
||||
m_device(device),
|
||||
m_parent(parent),
|
||||
m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
inline Nz::Vk::Buffer& Nz::VulkanBuffer::GetBufferHandle()
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
||||
@@ -7,26 +7,26 @@
|
||||
#ifndef NAZARA_VULKANRENDERER_VULKANDEVICE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VULKANDEVICE_HPP
|
||||
|
||||
#include <Nazara/Renderer/RenderDeviceInstance.hpp>
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Renderer/RenderDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanBuffer.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
|
||||
class NAZARA_VULKANRENDERER_API VulkanDevice : public RenderDevice, public Vk::Device
|
||||
{
|
||||
public:
|
||||
VulkanDevice(Vk::DeviceHandle device);
|
||||
using Device::Device;
|
||||
VulkanDevice(const VulkanDevice&) = delete;
|
||||
VulkanDevice(VulkanDevice&&) = delete; ///TODO?
|
||||
~VulkanDevice();
|
||||
|
||||
VulkanDevice& operator=(const VulkanDevice&) = delete;
|
||||
VulkanDevice& operator=(VulkanDevice&&) = delete; ///TODO
|
||||
std::unique_ptr<AbstractBuffer> InstantiateBuffer(Buffer* parent, BufferType type) override;
|
||||
|
||||
private:
|
||||
Vk::DeviceHandle m_device;
|
||||
VulkanDevice& operator=(const VulkanDevice&) = delete;
|
||||
VulkanDevice& operator=(VulkanDevice&&) = delete; ///TODO?
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user