Updated the window to hold the vulkan context and a vulkan surface as well as providing a cast operator for the surface
This commit is contained in:
@@ -4,9 +4,13 @@
|
|||||||
#ifndef VK_SUCCESS
|
#ifndef VK_SUCCESS
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <vulkan/vk_enum_string_helper.h>
|
||||||
|
#include "containers/basalt_darray.h"
|
||||||
|
|
||||||
namespace basalt
|
namespace basalt
|
||||||
{
|
{
|
||||||
|
class Context;
|
||||||
|
|
||||||
class Window
|
class Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -15,16 +19,19 @@ namespace basalt
|
|||||||
Window(Window&& other) noexcept;
|
Window(Window&& other) noexcept;
|
||||||
Window& operator =(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;
|
~Window(void) noexcept;
|
||||||
|
|
||||||
void swap(Window& other) noexcept;
|
void swap(Window& other) noexcept;
|
||||||
operator GLFWwindow* (void) const noexcept;
|
operator GLFWwindow* (void) const noexcept;
|
||||||
|
operator VkSurfaceKHR (void) const noexcept;
|
||||||
|
|
||||||
const bool should_close(void) const noexcept;
|
const bool should_close(void) const noexcept;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
basalt::Context* ctx;
|
||||||
GLFWwindow* window = nullptr;
|
GLFWwindow* window = nullptr;
|
||||||
|
VkSurfaceKHR surface;
|
||||||
const char* window_title = "N/A";
|
const char* window_title = "N/A";
|
||||||
uint16_t width = 0;
|
uint16_t width = 0;
|
||||||
uint16_t height = 0;
|
uint16_t height = 0;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "vulkan/basalt_window.h"
|
#include "vulkan/basalt_window.h"
|
||||||
|
#include "vulkan/basalt_context.h"
|
||||||
|
|
||||||
basalt::Window::Window(Window&& other) noexcept
|
basalt::Window::Window(Window&& other) noexcept
|
||||||
{
|
{
|
||||||
@@ -6,11 +7,12 @@ basalt::Window::Window(Window&& other) noexcept
|
|||||||
this->window_title = other.window_title;
|
this->window_title = other.window_title;
|
||||||
this->height = other.height;
|
this->height = other.height;
|
||||||
this->width = other.width;
|
this->width = other.width;
|
||||||
|
this->ctx = other.ctx;
|
||||||
other.height = 0;
|
other.height = 0;
|
||||||
other.width = 0;
|
other.width = 0;
|
||||||
other.window = nullptr;
|
other.window = nullptr;
|
||||||
other.window_title = nullptr;
|
other.window_title = nullptr;
|
||||||
|
other.ctx = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
basalt::Window& basalt::Window::operator=(Window&& other) noexcept
|
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->window_title = other.window_title;
|
||||||
this->height = other.height;
|
this->height = other.height;
|
||||||
this->width = other.width;
|
this->width = other.width;
|
||||||
|
this->ctx = other.ctx;
|
||||||
other.height = 0;
|
other.height = 0;
|
||||||
other.width = 0;
|
other.width = 0;
|
||||||
other.window = nullptr;
|
other.window = nullptr;
|
||||||
other.window_title = nullptr;
|
other.window_title = nullptr;
|
||||||
|
other.ctx = nullptr;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
basalt::Window::Window(uint16_t width, uint16_t height, const char* title) :
|
basalt::Window::Window(basalt::Context& ctx, uint16_t width, uint16_t height, const char* title) :
|
||||||
width(width), height(height), window_title(title)
|
ctx(&ctx), width(width), height(height), window_title(title)
|
||||||
{
|
{
|
||||||
glfwInit();
|
glfwInit();
|
||||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||||
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
|
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
|
||||||
this->window = glfwCreateWindow(width, height, title, nullptr, nullptr);
|
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
|
basalt::Window::~Window(void) noexcept
|
||||||
{
|
{
|
||||||
|
vkDestroySurfaceKHR(*this->ctx, this->surface, this->ctx->vk_alloc);
|
||||||
glfwDestroyWindow(this->window);
|
glfwDestroyWindow(this->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +73,8 @@ void basalt::Window::swap(Window& other) noexcept
|
|||||||
basalt::Window::operator GLFWwindow* (void) const noexcept
|
basalt::Window::operator GLFWwindow* (void) const noexcept
|
||||||
{ return this->window; }
|
{ return this->window; }
|
||||||
|
|
||||||
|
basalt::Window::operator VkSurfaceKHR(void) const noexcept
|
||||||
|
{ return this->surface; }
|
||||||
|
|
||||||
const bool basalt::Window::should_close(void) const noexcept
|
const bool basalt::Window::should_close(void) const noexcept
|
||||||
{
|
{ return glfwWindowShouldClose(this->window); }
|
||||||
return glfwWindowShouldClose(this->window);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user