// ============================================= // Aster: surface.cpp // Copyright (c) 2020-2024 Anish Bhobe // ============================================= #include "surface.h" #include "context.h" #include "window.h" Surface::Surface(Context *context, const Window *window, cstr name) : m_Context(context) { VkSurfaceKHR surface; auto result = Cast( glfwCreateWindowSurface(Cast(m_Context->m_Instance), window->m_Window, nullptr, &surface)); ERROR_IF(Failed(result), "Failed to create Surface with {}", result) THEN_ABORT(result) ELSE_DEBUG("Surface {} Created", m_Name); m_Surface = vk::SurfaceKHR(surface); } Surface::~Surface() { if (m_Context && m_Surface) { m_Context->m_Instance.destroy(m_Surface, nullptr); DEBUG("Surface Destroyed"); m_Surface = nullptr; m_Context = nullptr; } } Surface::Surface(Surface &&other) noexcept : m_Context(Take(other.m_Context)) , m_Surface(Take(other.m_Surface)) , m_Name(std::move(other.m_Name)) { } Surface & Surface::operator=(Surface &&other) noexcept { if (this == &other) return *this; m_Context = Take(other.m_Context); m_Surface = Take(other.m_Surface); m_Name = std::move(other.m_Name); return *this; }