diff --git a/include/Nazara/Vulkan/VkSemaphore.hpp b/include/Nazara/Vulkan/VkSemaphore.hpp new file mode 100644 index 000000000..0cf871d5d --- /dev/null +++ b/include/Nazara/Vulkan/VkSemaphore.hpp @@ -0,0 +1,51 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VULKAN_VKSEMAPHORE_HPP +#define NAZARA_VULKAN_VKSEMAPHORE_HPP + +#include +#include +#include +#include + +namespace Nz +{ + namespace Vk + { + class Device; + + class NAZARA_VULKAN_API Semaphore + { + public: + inline Semaphore(Device& instance); + Semaphore(const Semaphore&) = delete; + Semaphore(Semaphore&&) = delete; + inline ~Semaphore(); + + inline bool Create(const VkSemaphoreCreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr); + inline bool Create(VkSemaphoreCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); + inline void Destroy(); + + inline VkResult GetLastErrorCode() const; + + Semaphore& operator=(const Semaphore&) = delete; + Semaphore& operator=(Semaphore&&) = delete; + + inline operator VkSemaphore(); + + private: + Device& m_device; + VkAllocationCallbacks m_allocator; + VkSemaphore m_semaphore; + VkResult m_lastErrorCode; + }; + } +} + +#include + +#endif // NAZARA_VULKAN_VKSEMAPHORE_HPP diff --git a/include/Nazara/Vulkan/VkSemaphore.inl b/include/Nazara/Vulkan/VkSemaphore.inl new file mode 100644 index 000000000..0fb61c426 --- /dev/null +++ b/include/Nazara/Vulkan/VkSemaphore.inl @@ -0,0 +1,73 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include + +namespace Nz +{ + namespace Vk + { + inline Semaphore::Semaphore(Device& device) : + m_device(device), + m_semaphore(VK_NULL_HANDLE) + { + } + + inline Semaphore::~Semaphore() + { + Destroy(); + } + + inline bool Semaphore::Create(const VkSemaphoreCreateInfo& createInfo, const VkAllocationCallbacks* allocator) + { + m_lastErrorCode = m_device.vkCreateSemaphore(m_device, &createInfo, allocator, &m_semaphore); + if (m_lastErrorCode != VkResult::VK_SUCCESS) + { + NazaraError("Failed to create Vulkan semaphore"); + return false; + } + + // Store the allocator to access them when needed + if (allocator) + m_allocator = *allocator; + else + m_allocator.pfnAllocation = nullptr; + + return true; + } + + inline bool Semaphore::Create(VkSemaphoreCreateFlags flags, const VkAllocationCallbacks* allocator) + { + VkSemaphoreCreateInfo createInfo = + { + VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, + nullptr, + flags + }; + + return Create(createInfo, allocator); + } + + inline void Semaphore::Destroy() + { + if (m_semaphore != VK_NULL_HANDLE) + m_device.vkDestroySemaphore(m_device, m_semaphore, (m_allocator.pfnAllocation) ? &m_allocator : nullptr); + } + + inline VkResult Semaphore::GetLastErrorCode() const + { + return m_lastErrorCode; + } + + inline Semaphore::operator VkSemaphore() + { + return m_semaphore; + } + } +} + +#include