From 5d672a8b0b94a4fdc00240fe2674ccaf93ad2804 Mon Sep 17 00:00:00 2001 From: Warwick Date: Wed, 1 May 2024 18:09:53 +0100 Subject: [PATCH] Used GLFW to create vulkan surface (Breaks with wayland version of glfw :/) --- .gitignore | 1 + src/yave_vulkan_surface.cpp | 16 ++++++++++------ src/yave_vulkan_surface.hpp | 2 +- src/yave_window.cpp | 15 ++++++++++++++- src/yave_window.hpp | 4 ++++ 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index ea8aac5..b7e4d5f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Ignore build directories build/ .cache/ +.cmake/ # CMake mess for lazy cmake usage CMakeCache.txt diff --git a/src/yave_vulkan_surface.cpp b/src/yave_vulkan_surface.cpp index 7e0dcb1..3c7353b 100644 --- a/src/yave_vulkan_surface.cpp +++ b/src/yave_vulkan_surface.cpp @@ -1,17 +1,21 @@ #include "yave_vulkan_surface.hpp" #include "yave_vulkan_instance.hpp" +#include +#include + +#define GLFW_INCLUDE_VULKAN +#include namespace yave { + YaveVulkanSurface::YaveVulkanSurface(YaveVulkanInstance &yaveVulkanInstance, YaveWindow &window) { - VkWaylandSurfaceCreateInfoKHR createInfo{}; - createInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR; - createInfo.display = glfwGetWaylandDisplay(); - createInfo.surface = glfwGetWaylandWindow(window.getGLFWWindow()); - //VkInstance *vkInstance = yaveVulkanInstance.getVkInstance(); - if (vkCreateWaylandSurfaceKHR((*yaveVulkanInstance.getVkInstance()), &createInfo, nullptr, &surface)) { + if (glfwCreateWindowSurface(*yaveVulkanInstance.getVkInstance(), window.getGLFWWindow(), nullptr, + &surface)) { throw std::runtime_error("failed to create window surface!"); } } + YaveVulkanSurface::~YaveVulkanSurface() {} + } // namespace yave diff --git a/src/yave_vulkan_surface.hpp b/src/yave_vulkan_surface.hpp index 5dcb70c..2874ede 100644 --- a/src/yave_vulkan_surface.hpp +++ b/src/yave_vulkan_surface.hpp @@ -3,7 +3,6 @@ #include "yave_vulkan_instance.hpp" #include "yave_window.hpp" #include -#include // This engine is for now Wayland only!!! #define VK_USE_PLATFORM_WAYLAND_KHR @@ -23,6 +22,7 @@ private: public: YaveVulkanSurface(YaveVulkanInstance &yaveVulkanInstance, YaveWindow &window); ~YaveVulkanSurface(); + // // Delete Copy constructors // This class should match one to one with vulkan instances YaveVulkanSurface(const YaveVulkanSurface &) = delete; diff --git a/src/yave_window.cpp b/src/yave_window.cpp index d077e8b..2c2dece 100644 --- a/src/yave_window.cpp +++ b/src/yave_window.cpp @@ -1,25 +1,38 @@ #include "yave_window.hpp" +#include +#include namespace yave { YaveWindow::YaveWindow(int w, int h, std::string name) : width{w}, height{h}, windowName{name} { + glfwSetErrorCallback(YaveWindow::glfwErrorCallback); initWindow(); } +void YaveWindow::glfwErrorCallback(int error, const char *description) { + std::cerr<< "GLFW Error " << error << ": " << description << std::endl; +} + YaveWindow::~YaveWindow() { glfwDestroyWindow(window); glfwTerminate(); } void YaveWindow::initWindow() { - glfwInit(); + if (!glfwInit()) { + throw std::runtime_error("GLFW failed to initialise!"); + } glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); // Don't use OpenGL glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // Vulkan doesn't like to be resized // Create window with no OpenGL context window = glfwCreateWindow(width, height, windowName.c_str(), nullptr, nullptr); + + if (window == nullptr) { + throw std::runtime_error("GLFW failed to create a window!"); + } } } // namespace yave diff --git a/src/yave_window.hpp b/src/yave_window.hpp index 0ec6e18..1d96ff8 100644 --- a/src/yave_window.hpp +++ b/src/yave_window.hpp @@ -1,7 +1,9 @@ #pragma once #define GLFW_INCLUDE_VULKAN +#define GLFW_EXPOSE_NATIVE_WAYLAND #include +#include #include @@ -13,6 +15,8 @@ private: void initWindow(); + static void glfwErrorCallback (int error, const char* description); + const int width; const int height; std::string windowName;