vOOlkan
An object oriented approach to Vulkan
Fence.h
Go to the documentation of this file.
1#ifndef VULKAN_FENCE
2#define VULKAN_FENCE
3
4#include <vulkan/vulkan.h>
5#include <iostream>
6
7#include "VulkanException.h"
8#include "LogicalDevice.h"
9
10
11namespace Vulkan::SynchronizationPrimitives { class Fence; }
12
14public:
15
16 Fence(const LogicalDevice& virtualGpu) : virtualGpu{ virtualGpu } {
17 VkFenceCreateInfo fenceInfo{};
18 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
20
21 if (VkResult result = vkCreateFence(+virtualGpu, &fenceInfo, nullptr, &fence); result != VK_SUCCESS) {
22 throw VulkanException{ "Failed to create fence", result };
23 }
24
25 std::cout << "\n+ Fence created";
26 }
27
28 Fence(const Fence&) = delete;
29 Fence& operator=(const Fence&) = delete;
30
31
32 Fence(Fence&& movedFrom) noexcept : fence{ movedFrom.fence }, virtualGpu{ movedFrom.virtualGpu } {
33 movedFrom.fence = nullptr;
34 std::cout << "\n> Fence moved";
35 }
36
37 //FIXTHIS implement this the right way
38 Fence& operator=(Fence&&) = default;
39
41 vkDestroyFence(+virtualGpu, fence, nullptr);
42 std::cout << "\n- Fence destroyed";
43 }
44
45 const VkFence& operator+() const {
46 return fence;
47 }
48
49
50private:
51 VkFence fence;
52 const LogicalDevice& virtualGpu;
53};
54
55#endif
A logical device is an abstraction of the physical GPU which we can mainly use to send commands.
Definition: LogicalDevice.h:15
Fence & operator=(const Fence &)=delete
Fence(const LogicalDevice &virtualGpu)
Definition: Fence.h:16
Fence(Fence &&movedFrom) noexcept
Definition: Fence.h:32
const VkFence & operator+() const
Definition: Fence.h:45
Fence & operator=(Fence &&)=default
Generic runtime exception thrown by Vulkan-related functions.
Definition: VulkanException.h:13
Definition: Barriers.h:10