55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
// =============================================
|
|
// Aster: surface.cpp
|
|
// Copyright (c) 2020-2024 Anish Bhobe
|
|
// =============================================
|
|
|
|
#include "surface.h"
|
|
|
|
#include "SDL3/SDL_vulkan.h"
|
|
#include "context.h"
|
|
#include "window.h"
|
|
|
|
Surface::Surface(Context *context, const Window *window, cstr name)
|
|
: m_Context(context)
|
|
{
|
|
VkSurfaceKHR surface;
|
|
if (!SDL_Vulkan_CreateSurface(window->m_Window, Cast<VkInstance>(m_Context->m_Instance), nullptr, &surface))
|
|
{
|
|
const char *error = SDL_GetError();
|
|
ERROR("Failed to create Surface. Cause: {}", error)
|
|
THEN_ABORT(-1);
|
|
}
|
|
|
|
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;
|
|
} |