Lugdunum  0.1.0
CommandBuffer.cpp
Go to the documentation of this file.
2 
6 
7 namespace lug {
8 namespace Graphics {
9 namespace Vulkan {
10 namespace API {
11 
12 CommandBuffer::CommandBuffer(VkCommandBuffer commandBuffer, const CommandPool* commandPool) : _commandBuffer(commandBuffer), _commandPool(commandPool) {}
13 
15  _commandBuffer = commandBuffer._commandBuffer;
16  _commandPool = commandBuffer._commandPool;
17 
18  commandBuffer._commandBuffer = VK_NULL_HANDLE;
19  commandBuffer._commandPool = nullptr;
20 }
21 
23  destroy();
24 
25  _commandBuffer = commandBuffer._commandBuffer;
26  _commandPool = commandBuffer._commandPool;
27 
28  commandBuffer._commandBuffer = VK_NULL_HANDLE;
29  commandBuffer._commandPool = nullptr;
30 
31  return *this;
32 }
33 
35  destroy();
36 }
37 
38 bool CommandBuffer::begin(VkCommandBufferUsageFlags flags) const {
39  VkCommandBufferBeginInfo beginInfo{
40  beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
41  beginInfo.pNext = nullptr,
42  beginInfo.flags = flags,
43  beginInfo.pInheritanceInfo = nullptr // TODO: handle pInheritanceInfo for secondary command buffers
44  };
45 
46  VkResult result = vkBeginCommandBuffer(_commandBuffer, &beginInfo);
47 
48  if (result != VK_SUCCESS) {
49  LUG_LOG.error("CommandBuffer: Can't begin the command buffer: {}", result);
50  return false;
51  }
52 
53  return true;
54 }
55 
56 bool CommandBuffer::end() const {
57  VkResult result = vkEndCommandBuffer(_commandBuffer);
58 
59  if (result != VK_SUCCESS) {
60  LUG_LOG.error("CommandBuffer: Can't end the command buffer: {}", result);
61  return false;
62  }
63 
64  return true;
65 }
66 
67 bool CommandBuffer::reset(bool releaseRessources) const {
68  VkResult result = vkResetCommandBuffer(_commandBuffer, releaseRessources ? VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT : 0);
69 
70  if (result != VK_SUCCESS) {
71  LUG_LOG.error("CommandBuffer: Can't reset the command buffer: {}", result);
72  return false;
73  }
74 
75  return true;
76 }
77 
79  if (_commandBuffer != VK_NULL_HANDLE) {
80  vkFreeCommandBuffers(static_cast<VkDevice>(*_commandPool->getDevice()), static_cast<VkCommandPool>(*_commandPool), 1, &_commandBuffer);
81  _commandBuffer = VK_NULL_HANDLE;
82  }
83 
84  _commandPool = nullptr;
85 }
86 
87 } // API
88 } // Vulkan
89 } // Graphics
90 } // lug
bool reset(bool releaseRessources=false) const
CommandBuffer & operator=(const CommandBuffer &)=delete
#define LUG_LOG
Definition: Logger.hpp:73
bool begin(VkCommandBufferUsageFlags flags=VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) const