Used GLFW to create vulkan surface (Breaks with wayland version of glfw :/)

This commit is contained in:
Warwick 2024-05-01 18:09:53 +01:00
parent f1186130b6
commit 5d672a8b0b
5 changed files with 30 additions and 8 deletions

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
# Ignore build directories
build/
.cache/
.cmake/
# CMake mess for lazy cmake usage
CMakeCache.txt

View file

@ -1,17 +1,21 @@
#include "yave_vulkan_surface.hpp"
#include "yave_vulkan_instance.hpp"
#include <iostream>
#include <ostream>
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
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

View file

@ -3,7 +3,6 @@
#include "yave_vulkan_instance.hpp"
#include "yave_window.hpp"
#include <vulkan/vulkan_core.h>
#include <stdexcept>
// 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;

View file

@ -1,25 +1,38 @@
#include "yave_window.hpp"
#include <iostream>
#include <stdexcept>
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

View file

@ -1,7 +1,9 @@
#pragma once
#define GLFW_INCLUDE_VULKAN
#define GLFW_EXPOSE_NATIVE_WAYLAND
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
#include <string>
@ -13,6 +15,8 @@ private:
void initWindow();
static void glfwErrorCallback (int error, const char* description);
const int width;
const int height;
std::string windowName;