jGL
Loading...
Searching...
No Matches
command.h
Go to the documentation of this file.
1#ifndef COMMAND
2#define COMMAND
3
6
8
9namespace jGL::Vulkan
10{
11 class Command
12 {
13
14 public:
15
16 Command() = default;
17
18 Command(const Device & device, const unsigned concurrentFrames)
19 : commandPool(CommandPool(device))
20 {
21 commandBuffer = CommandBuffer(device, commandPool, concurrentFrames);
22 }
23
24 const VkCommandPool & getVkCommandPool() const { return commandPool.getVkCommandPool(); }
25 const std::vector<VkCommandBuffer> & getVkCommandBuffers() const { return commandBuffer.getVkCommandBuffers(); }
26 const VkCommandBuffer & getVkCommandBuffer(size_t i) const { return commandBuffer.getVkCommandBuffers()[i]; }
27
28 VkCommandBuffer beginCommand(const Device & device) const
29 {
30 VkCommandBufferAllocateInfo allocInfo{};
31 allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
32 allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
33 allocInfo.commandPool = commandPool.getVkCommandPool();
34 allocInfo.commandBufferCount = 1;
35
36 VkCommandBuffer commandBuffer;
37 vkAllocateCommandBuffers(device.getVkDevice(), &allocInfo, &commandBuffer);
38
39 VkCommandBufferBeginInfo beginInfo{};
40 beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
41 beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
42
43 vkBeginCommandBuffer(commandBuffer, &beginInfo);
44
45 return commandBuffer;
46 }
47
48 void endCommand(const Device & device, VkCommandBuffer commandBuffer) const {
49 vkEndCommandBuffer(commandBuffer);
50
51 VkSubmitInfo submitInfo{};
52 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
53 submitInfo.commandBufferCount = 1;
54 submitInfo.pCommandBuffers = &commandBuffer;
55
56 vkQueueSubmit(device.getLogicalDevice().getGraphicsQueue(), 1, &submitInfo, VK_NULL_HANDLE);
57 vkQueueWaitIdle(device.getLogicalDevice().getGraphicsQueue());
58
59 vkFreeCommandBuffers(device.getVkDevice(), commandPool.getVkCommandPool(), 1, &commandBuffer);
60 }
61
62 private:
63
64 CommandPool commandPool;
65 CommandBuffer commandBuffer;
66 };
67}
68
69#endif /* COMMAND */
Definition commandBuffer.h:12
const std::vector< VkCommandBuffer > & getVkCommandBuffers() const
Definition commandBuffer.h:20
Definition commandPool.h:9
const VkCommandPool & getVkCommandPool() const
Definition commandPool.h:17
Definition command.h:12
const VkCommandPool & getVkCommandPool() const
Definition command.h:24
void endCommand(const Device &device, VkCommandBuffer commandBuffer) const
Definition command.h:48
const std::vector< VkCommandBuffer > & getVkCommandBuffers() const
Definition command.h:25
Command(const Device &device, const unsigned concurrentFrames)
Definition command.h:18
VkCommandBuffer beginCommand(const Device &device) const
Definition command.h:28
const VkCommandBuffer & getVkCommandBuffer(size_t i) const
Definition command.h:26
Definition device.h:10
const LogicalDevice & getLogicalDevice() const
Definition device.h:23
const VkDevice & getVkDevice() const
Definition device.h:24
const VkQueue & getGraphicsQueue() const
Definition logicalDevice.h:20
Definition buffer.h:10