diff --git a/aster/context.cpp b/aster/context.cpp index d78bd78..212ca52 100644 --- a/aster/context.cpp +++ b/aster/context.cpp @@ -122,3 +122,19 @@ Context::~Context() glfwTerminate(); } + +Context::Context(Context &&other) noexcept + : m_Instance(Take(other.m_Instance)) + , m_DebugMessenger(Take(other.m_DebugMessenger)) +{ +} + +Context & +Context::operator=(Context &&other) noexcept +{ + if (this == &other) + return *this; + m_Instance = Take(other.m_Instance); + m_DebugMessenger = Take(other.m_DebugMessenger); + return *this; +} diff --git a/aster/context.h b/aster/context.h index 7fa3415..e814053 100644 --- a/aster/context.h +++ b/aster/context.h @@ -23,4 +23,10 @@ struct Context final // Ctor/Dtor Context(cstr appName, Version version, bool enableValidation = true); ~Context(); + + // Move + Context(Context &&other) noexcept; + Context &operator=(Context &&other) noexcept; + + DISALLOW_COPY_AND_ASSIGN(Context); }; diff --git a/aster/device.cpp b/aster/device.cpp index 9e74b45..11a02be 100644 --- a/aster/device.cpp +++ b/aster/device.cpp @@ -108,4 +108,24 @@ Device::GetQueue(const u32 familyIndex, const u32 queueIndex) const vk::Queue queue; m_Device.getQueue(familyIndex, queueIndex, &queue); return queue; +} + +Device::Device(Device &&other) noexcept + : m_Name(std::move(other.m_Name)) + , m_PhysicalDevice(Take(other.m_PhysicalDevice)) + , m_Device(Take(other.m_Device)) + , m_Allocator(Take(other.m_Allocator)) +{ +} + +Device & +Device::operator=(Device &&other) noexcept +{ + if (this == &other) + return *this; + m_Name = std::move(other.m_Name); + m_PhysicalDevice = Take(other.m_PhysicalDevice); + m_Device = Take(other.m_Device); + m_Allocator = Take(other.m_Allocator); + return *this; } \ No newline at end of file diff --git a/aster/device.h b/aster/device.h index c104405..e2a2d01 100644 --- a/aster/device.h +++ b/aster/device.h @@ -28,13 +28,20 @@ struct Device final vk::Device m_Device = nullptr; VmaAllocator m_Allocator = nullptr; + template + requires vk::isVulkanHandleType::value void SetName(const T &object, cstr name) const; + [[nodiscard]] vk::Queue GetQueue(u32 familyIndex, u32 queueIndex) const; + + // Ctor/Dtor Device(const Context *context, PhysicalDevice *physicalDevice, Features *enabledFeatures, const eastl::vector &queueAllocations, NameString &&name); ~Device(); - template - requires vk::isVulkanHandleType::value void SetName(const T &object, cstr name) const; - [[nodiscard]] vk::Queue GetQueue(u32 familyIndex, u32 queueIndex) const; + // Move + Device(Device &&other) noexcept; + Device &operator=(Device &&other) noexcept; + + DISALLOW_COPY_AND_ASSIGN(Device); }; template diff --git a/aster/global.h b/aster/global.h index b20c552..040514a 100644 --- a/aster/global.h +++ b/aster/global.h @@ -34,7 +34,11 @@ constexpr u32 ASTER_API_VERSION = VK_API_VERSION_1_3; #define CODE_LOC " @ " __FILE__ ":" VULKAN_HPP_STRINGIFY(__LINE__) -#define FORCE_TODO static_assert(false) +#define DISALLOW_COPY_AND_ASSIGN(CLASS_NAME) \ + CLASS_NAME(const CLASS_NAME &other) = delete; \ + CLASS_NAME &operator=(const CLASS_NAME &other) = delete + +#define Take(ELEMENT) eastl::exchange(ELEMENT, {}) [[nodiscard]] inline bool Failed(const vk::Result result) diff --git a/aster/physical_device.h b/aster/physical_device.h index 7c977db..5f8e828 100644 --- a/aster/physical_device.h +++ b/aster/physical_device.h @@ -37,7 +37,7 @@ GetSurfaceFormats(vk::PhysicalDevice physicalDevice, vk::SurfaceKHR surface); [[nodiscard]] eastl::vector GetSurfacePresentModes(vk::PhysicalDevice physicalDevice, vk::SurfaceKHR surface); -struct PhysicalDevice +struct PhysicalDevice final { vk::PhysicalDevice m_PhysicalDevice; vk::PhysicalDeviceProperties m_DeviceProperties; diff --git a/aster/swapchain.cpp b/aster/swapchain.cpp index 5c97f99..d731eb4 100644 --- a/aster/swapchain.cpp +++ b/aster/swapchain.cpp @@ -21,6 +21,32 @@ Swapchain::~Swapchain() this->Cleanup(); } +Swapchain::Swapchain(Swapchain &&other) noexcept + : m_Device(other.m_Device) + , m_Swapchain(Take(other.m_Swapchain)) + , m_Name(std::move(other.m_Name)) + , m_Extent(other.m_Extent) + , m_Format(other.m_Format) + , m_Images(std::move(other.m_Images)) + , m_ImageViews(std::move(other.m_ImageViews)) +{ +} + +Swapchain & +Swapchain::operator=(Swapchain &&other) noexcept +{ + if (this == &other) + return *this; + m_Device = other.m_Device; + m_Swapchain = Take(other.m_Swapchain); + m_Name = std::move(other.m_Name); + m_Extent = other.m_Extent; + m_Format = other.m_Format; + m_Images = std::move(other.m_Images); + m_ImageViews = std::move(other.m_ImageViews); + return *this; +} + void Swapchain::Create(const Window *window) { diff --git a/aster/swapchain.h b/aster/swapchain.h index e22a176..2d827b8 100644 --- a/aster/swapchain.h +++ b/aster/swapchain.h @@ -23,9 +23,17 @@ struct Swapchain final eastl::fixed_vector m_Images; eastl::fixed_vector m_ImageViews; + void Create(const Window *window); + + // Ctor/Dtor Swapchain(const Window *window, const Device *device, NameString &&name); ~Swapchain(); - void Create(const Window *window); + + // Move + Swapchain(Swapchain &&other) noexcept; + Swapchain &operator=(Swapchain &&other) noexcept; + + DISALLOW_COPY_AND_ASSIGN(Swapchain); private: void Cleanup(); diff --git a/aster/window.cpp b/aster/window.cpp index 104e988..b5fac6a 100644 --- a/aster/window.cpp +++ b/aster/window.cpp @@ -79,7 +79,7 @@ Window::~Window() DEBUG("Surface Destroyed"); } - if (m_Window != nullptr) + if (m_Window) { glfwDestroyWindow(m_Window); m_Window = nullptr; @@ -87,3 +87,23 @@ Window::~Window() DEBUG("Window '{}' Destroyed", m_Name); } + +Window::Window(Window &&other) noexcept + : m_Context(other.m_Context) + , m_Window(Take(other.m_Window)) + , m_Surface(Take(other.m_Surface)) + , m_Name(Take(other.m_Name)) +{ +} + +Window & +Window::operator=(Window &&other) noexcept +{ + if (this == &other) + return *this; + m_Context = other.m_Context; + m_Window = Take(other.m_Window); + m_Surface = Take(other.m_Surface); + m_Name = Take(other.m_Name); + return *this; +} diff --git a/aster/window.h b/aster/window.h index 34843ab..1174c9c 100644 --- a/aster/window.h +++ b/aster/window.h @@ -34,4 +34,10 @@ struct Window final // Ctor/Dtor Window(cstr title, Context *context, vk::Extent2D extent, b8 isFullScreen = false); ~Window(); + + // Move + Window(Window &&other) noexcept; + Window &operator=(Window &&other) noexcept; + + DISALLOW_COPY_AND_ASSIGN(Window); };