Split CommandBuffer into Auto and normal variants
This commit is contained in:
parent
91a5e70ac5
commit
e53e15d1aa
|
|
@ -5,6 +5,7 @@
|
|||
#ifndef NAZARA_GLOBAL_VULKANRENDERER_WRAPPER_HPP
|
||||
#define NAZARA_GLOBAL_VULKANRENDERER_WRAPPER_HPP
|
||||
|
||||
#include <Nazara/VulkanRenderer/Wrapper/AutoFree.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Buffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/CommandPool.hpp>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (C) 2020 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_VKAUTOFREE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKAUTOFREE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
|
||||
namespace Nz::Vk
|
||||
{
|
||||
template<typename T>
|
||||
class AutoFree
|
||||
{
|
||||
public:
|
||||
template<typename... Args> AutoFree(Args&&... args);
|
||||
AutoFree(const AutoFree&) = default;
|
||||
AutoFree(AutoFree&&) = default;
|
||||
~AutoFree();
|
||||
|
||||
T& Get();
|
||||
const T& Get() const;
|
||||
|
||||
T* operator->();
|
||||
const T* operator->() const;
|
||||
|
||||
operator T&();
|
||||
operator const T&() const;
|
||||
|
||||
AutoFree& operator=(const AutoFree&) = delete;
|
||||
AutoFree& operator=(AutoFree&&) = default;
|
||||
|
||||
private:
|
||||
T m_object;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/Wrapper/AutoFree.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKAUTOFREE_HPP
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
// Copyright (C) 2020 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/Wrapper/AutoFree.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz::Vk
|
||||
{
|
||||
template<typename T>
|
||||
template<typename... Args>
|
||||
AutoFree<T>::AutoFree(Args&&... args) :
|
||||
m_object(std::forward<Args>(args)...)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
AutoFree<T>::~AutoFree()
|
||||
{
|
||||
m_object.Free();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T& AutoFree<T>::Get()
|
||||
{
|
||||
return m_object;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T& AutoFree<T>::Get() const
|
||||
{
|
||||
return m_object;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* AutoFree<T>::operator->()
|
||||
{
|
||||
return &m_object;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T* AutoFree<T>::operator->() const
|
||||
{
|
||||
return &m_object;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
AutoFree<T>::operator T&()
|
||||
{
|
||||
return Get();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
AutoFree<T>::operator const T&() const
|
||||
{
|
||||
return Get();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/AutoFree.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/CommandPool.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
|
|
@ -24,7 +25,7 @@ namespace Nz
|
|||
inline CommandBuffer();
|
||||
CommandBuffer(const CommandBuffer&) = delete;
|
||||
inline CommandBuffer(CommandBuffer&& commandBuffer);
|
||||
inline ~CommandBuffer();
|
||||
~CommandBuffer() = default;
|
||||
|
||||
inline bool Begin(const VkCommandBufferBeginInfo& info);
|
||||
inline bool Begin(VkCommandBufferUsageFlags flags = 0);
|
||||
|
|
@ -90,10 +91,16 @@ namespace Nz
|
|||
inline CommandBuffer(CommandPool& pool, VkCommandBuffer handle);
|
||||
|
||||
CommandPool* m_pool;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkCommandBuffer m_handle;
|
||||
VkResult m_lastErrorCode;
|
||||
};
|
||||
|
||||
class AutoCommandBuffer : public AutoFree<CommandBuffer>
|
||||
{
|
||||
public:
|
||||
using AutoFree::AutoFree;
|
||||
|
||||
operator VkCommandBuffer() const { return Get(); }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,11 +32,6 @@ namespace Nz
|
|||
commandBuffer.m_handle = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
inline CommandBuffer::~CommandBuffer()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
inline bool CommandBuffer::Begin(const VkCommandBufferBeginInfo& info)
|
||||
{
|
||||
m_lastErrorCode = m_pool->GetDevice()->vkBeginCommandBuffer(m_handle, &info);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/AutoFree.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DescriptorPool.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
|
|
@ -24,7 +25,7 @@ namespace Nz
|
|||
inline DescriptorSet();
|
||||
DescriptorSet(const DescriptorSet&) = delete;
|
||||
inline DescriptorSet(DescriptorSet&& descriptorSet) noexcept;
|
||||
inline ~DescriptorSet();
|
||||
~DescriptorSet() = default;
|
||||
|
||||
inline void Free();
|
||||
|
||||
|
|
@ -56,6 +57,15 @@ namespace Nz
|
|||
DescriptorPool* m_pool;
|
||||
VkDescriptorSet m_handle;
|
||||
};
|
||||
|
||||
class AutoDescriptorSet : public AutoFree<DescriptorSet>
|
||||
{
|
||||
public:
|
||||
using AutoFree::AutoFree;
|
||||
|
||||
explicit operator bool() const { return Get(); }
|
||||
operator VkDescriptorSet() const { return Get(); }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,11 +31,6 @@ namespace Nz
|
|||
descriptorSet.m_handle = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
inline DescriptorSet::~DescriptorSet()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
inline void DescriptorSet::Free()
|
||||
{
|
||||
if (m_handle)
|
||||
|
|
|
|||
Loading…
Reference in New Issue