I can now render meshes !
Former-commit-id: 5f292c0f81730f8fa26d7c930130671da6c8a26d [formerly 2145d599592770fe9a6cf65c46e10400417c4726] Former-commit-id: c0740828e97fcb2a704d55f9d769a371f8d6a4d3
This commit is contained in:
parent
c78daeb888
commit
a5690a0aef
|
|
@ -24,6 +24,11 @@ namespace Nz
|
|||
Buffer(Buffer&&) = default;
|
||||
~Buffer() = default;
|
||||
|
||||
bool BindBufferMemory(VkDeviceMemory memory, VkDeviceSize offset = 0);
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
VkMemoryRequirements GetMemoryRequirements() const;
|
||||
|
||||
Buffer& operator=(const Buffer&) = delete;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,34 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool Buffer::BindBufferMemory(VkDeviceMemory memory, VkDeviceSize offset)
|
||||
{
|
||||
m_lastErrorCode = m_device->vkBindBufferMemory(*m_device, m_handle, memory, offset);
|
||||
if (m_lastErrorCode != VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to bind buffer memory");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Buffer::Create(const DeviceHandle& device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkBufferCreateInfo createInfo = {
|
||||
VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
flags, // VkBufferCreateFlags flags;
|
||||
size, // VkDeviceSize size;
|
||||
usage, // VkBufferUsageFlags usage;
|
||||
VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
|
||||
0, // uint32_t queueFamilyIndexCount;
|
||||
nullptr // const uint32_t* pQueueFamilyIndices;
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkMemoryRequirements Buffer::GetMemoryRequirements() const
|
||||
{
|
||||
NazaraAssert(IsValid(), "Invalid buffer");
|
||||
|
|
|
|||
|
|
@ -34,9 +34,13 @@ namespace Nz
|
|||
|
||||
inline void BeginRenderPass(const VkRenderPassBeginInfo& beginInfo, VkSubpassContents contents = VK_SUBPASS_CONTENTS_INLINE);
|
||||
|
||||
inline void BindIndexBuffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType);
|
||||
inline void BindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline);
|
||||
inline void BindVertexBuffer(UInt32 binding, const VkBuffer buffer, const VkDeviceSize offset);
|
||||
inline void BindVertexBuffers(UInt32 firstBinding, UInt32 bindingCount, const VkBuffer* buffer, const VkDeviceSize* offset);
|
||||
|
||||
inline void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0);
|
||||
inline void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, Int32 vertexOffset = 0, UInt32 firstInstance = 0);
|
||||
|
||||
inline bool End();
|
||||
|
||||
|
|
|
|||
|
|
@ -128,16 +128,36 @@ namespace Nz
|
|||
return m_pool->GetDevice()->vkCmdBeginRenderPass(m_handle, &beginInfo, contents);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindIndexBuffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdBindIndexBuffer(m_handle, buffer, offset, indexType);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdBindPipeline(m_handle, pipelineBindPoint, pipeline);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindVertexBuffer(UInt32 binding, const VkBuffer buffer, const VkDeviceSize offset)
|
||||
{
|
||||
return BindVertexBuffers(binding, 1, &buffer, &offset);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindVertexBuffers(UInt32 firstBinding, UInt32 bindingCount, const VkBuffer* buffer, const VkDeviceSize* offset)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdBindVertexBuffers(m_handle, firstBinding, bindingCount, buffer, offset);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::Draw(UInt32 vertexCount, UInt32 instanceCount, UInt32 firstVertex, UInt32 firstInstance)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdDraw(m_handle, vertexCount, instanceCount, firstVertex, firstInstance);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::DrawIndexed(UInt32 indexCount, UInt32 instanceCount, UInt32 firstVertex, Int32 vertexOffset, UInt32 firstInstance)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdDrawIndexed(m_handle, indexCount, instanceCount, firstVertex, vertexOffset, firstInstance);
|
||||
}
|
||||
|
||||
inline bool CommandBuffer::End()
|
||||
{
|
||||
m_lastErrorCode = m_pool->GetDevice()->vkEndCommandBuffer(m_handle);
|
||||
|
|
|
|||
|
|
@ -19,21 +19,29 @@ namespace Nz
|
|||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
DeviceMemory() = default;
|
||||
DeviceMemory();
|
||||
DeviceMemory(const DeviceMemory&) = delete;
|
||||
DeviceMemory(DeviceMemory&&) = default;
|
||||
DeviceMemory(DeviceMemory&& memory);
|
||||
~DeviceMemory() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(const DeviceHandle& device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
inline void* GetMappedPointer();
|
||||
|
||||
inline bool Map(VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags = 0);
|
||||
|
||||
inline void Unmap();
|
||||
|
||||
DeviceMemory& operator=(const DeviceMemory&) = delete;
|
||||
DeviceMemory& operator=(DeviceMemory&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkMemoryAllocateInfo* allocInfo, const VkAllocationCallbacks* allocator, VkDeviceMemory* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkDeviceMemory handle, const VkAllocationCallbacks* allocator);
|
||||
|
||||
void* m_mappedPtr;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,18 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline DeviceMemory::DeviceMemory() :
|
||||
m_mappedPtr(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceMemory::DeviceMemory(DeviceMemory&& memory) :
|
||||
DeviceObject(std::move(memory))
|
||||
{
|
||||
m_mappedPtr = memory.m_mappedPtr;
|
||||
memory.m_mappedPtr = nullptr;
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::Create(const DeviceHandle& device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkMemoryAllocateInfo allocInfo =
|
||||
|
|
@ -44,6 +56,31 @@ namespace Nz
|
|||
return false;
|
||||
}
|
||||
|
||||
inline void* DeviceMemory::GetMappedPointer()
|
||||
{
|
||||
return m_mappedPtr;
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::Map(VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags)
|
||||
{
|
||||
m_lastErrorCode = m_device->vkMapMemory(*m_device, m_handle, offset, size, flags, &m_mappedPtr);
|
||||
if (m_lastErrorCode != VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to map device memory");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void DeviceMemory::Unmap()
|
||||
{
|
||||
NazaraAssert(m_mappedPtr != nullptr, "Memory is not mapped");
|
||||
|
||||
m_device->vkUnmapMemory(*m_device, m_handle);
|
||||
m_mappedPtr = nullptr;
|
||||
}
|
||||
|
||||
inline VkResult DeviceMemory::CreateHelper(const DeviceHandle& device, const VkMemoryAllocateInfo* allocInfo, const VkAllocationCallbacks* allocator, VkDeviceMemory* handle)
|
||||
{
|
||||
return device->vkAllocateMemory(*device, allocInfo, allocator, handle);
|
||||
|
|
|
|||
Loading…
Reference in New Issue