// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Vulkan renderer" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #include #include namespace Nz::Vk { template DeviceObject::DeviceObject() : m_handle(VK_NULL_HANDLE) { } template DeviceObject::DeviceObject(DeviceObject&& object) noexcept : m_device(std::move(object.m_device)), m_allocator(object.m_allocator), m_handle(object.m_handle), m_lastErrorCode(object.m_lastErrorCode) { object.m_handle = VK_NULL_HANDLE; } template DeviceObject::~DeviceObject() { Destroy(); } template bool DeviceObject::Create(Device& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator) { Destroy(); m_device = &device; m_lastErrorCode = C::CreateHelper(*m_device, &createInfo, allocator, &m_handle); if (m_lastErrorCode != VkResult::VK_SUCCESS) { NazaraError("Failed to create Vulkan device object: " + TranslateVulkanError(m_lastErrorCode)); return false; } // Store the allocator to access them when needed if (allocator) m_allocator = *allocator; else m_allocator.pfnAllocation = nullptr; return true; } template void DeviceObject::Destroy() { if (IsValid()) { C::DestroyHelper(*m_device, m_handle, (m_allocator.pfnAllocation) ? &m_allocator : nullptr); m_handle = VK_NULL_HANDLE; } } template bool DeviceObject::IsValid() const { return m_handle != VK_NULL_HANDLE; } template Device* DeviceObject::GetDevice() const { return m_device; } template VkResult DeviceObject::GetLastErrorCode() const { return m_lastErrorCode; } template template void DeviceObject::SetDebugName(T&& name) { return m_device->SetDebugName(ObjectType, VulkanHandleToInteger(m_handle), std::forward(name)); } template auto DeviceObject::operator=(DeviceObject&& object) noexcept -> DeviceObject& { std::swap(m_allocator, object.m_allocator); std::swap(m_device, object.m_device); std::swap(m_handle, object.m_handle); std::swap(m_lastErrorCode, object.m_lastErrorCode); return *this; } template DeviceObject::operator VkType() const { return m_handle; } } #include