diff --git a/include/vulkan/basalt_window.h b/include/vulkan/basalt_window.h index c4e2601..92f3179 100644 --- a/include/vulkan/basalt_window.h +++ b/include/vulkan/basalt_window.h @@ -4,9 +4,13 @@ #ifndef VK_SUCCESS #include #endif +#include +#include "containers/basalt_darray.h" namespace basalt { + class Context; + class Window { public: @@ -15,16 +19,19 @@ namespace basalt Window(Window&& other) noexcept; Window& operator =(Window&& other) noexcept; - Window(uint16_t width, uint16_t height, const char* title); + Window(basalt::Context& ctx, uint16_t width, uint16_t height, const char* title); ~Window(void) noexcept; void swap(Window& other) noexcept; operator GLFWwindow* (void) const noexcept; + operator VkSurfaceKHR (void) const noexcept; const bool should_close(void) const noexcept; protected: + basalt::Context* ctx; GLFWwindow* window = nullptr; + VkSurfaceKHR surface; const char* window_title = "N/A"; uint16_t width = 0; uint16_t height = 0; diff --git a/src/vulkan/basalt_window.cpp b/src/vulkan/basalt_window.cpp index 30d5219..f897241 100644 --- a/src/vulkan/basalt_window.cpp +++ b/src/vulkan/basalt_window.cpp @@ -1,4 +1,5 @@ #include "vulkan/basalt_window.h" +#include "vulkan/basalt_context.h" basalt::Window::Window(Window&& other) noexcept { @@ -6,11 +7,12 @@ basalt::Window::Window(Window&& other) noexcept this->window_title = other.window_title; this->height = other.height; this->width = other.width; + this->ctx = other.ctx; other.height = 0; other.width = 0; other.window = nullptr; other.window_title = nullptr; - + other.ctx = nullptr; } basalt::Window& basalt::Window::operator=(Window&& other) noexcept @@ -21,25 +23,30 @@ basalt::Window& basalt::Window::operator=(Window&& other) noexcept this->window_title = other.window_title; this->height = other.height; this->width = other.width; + this->ctx = other.ctx; other.height = 0; other.width = 0; other.window = nullptr; other.window_title = nullptr; + other.ctx = nullptr; return *this; } -basalt::Window::Window(uint16_t width, uint16_t height, const char* title) : - width(width), height(height), window_title(title) +basalt::Window::Window(basalt::Context& ctx, uint16_t width, uint16_t height, const char* title) : + ctx(&ctx), width(width), height(height), window_title(title) { glfwInit(); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); this->window = glfwCreateWindow(width, height, title, nullptr, nullptr); + VkResult err = VK_SUCCESS; + VK_ASSERT(glfwCreateWindowSurface(*this->ctx, this->window, this->ctx->vk_alloc, &this->surface), "Failed to create vulkan window surface\n\tAt %s:%d\n\tError %s\n"); } basalt::Window::~Window(void) noexcept { + vkDestroySurfaceKHR(*this->ctx, this->surface, this->ctx->vk_alloc); glfwDestroyWindow(this->window); } @@ -66,7 +73,8 @@ void basalt::Window::swap(Window& other) noexcept basalt::Window::operator GLFWwindow* (void) const noexcept { return this->window; } +basalt::Window::operator VkSurfaceKHR(void) const noexcept +{ return this->surface; } + const bool basalt::Window::should_close(void) const noexcept -{ - return glfwWindowShouldClose(this->window); -} +{ return glfwWindowShouldClose(this->window); }