BROKEN trying to set up surface current issues is GLFW window pointer is null

This commit is contained in:
Warwick 2023-12-06 13:35:15 +00:00
parent e5f420a238
commit 4792f3ffde
6 changed files with 56 additions and 3 deletions

View file

@ -1,10 +1,12 @@
#include "application.hpp"
#include "yave_vulkan_instance.hpp"
#include "yave_vulkan_surface.hpp"
namespace yave {
void Application::run() {
YaveVulkanInstance VI = YaveVulkanInstance();
YaveVulkanSurface VS = YaveVulkanSurface(VI, yaveWindow);
while (!yaveWindow.shouldClose()) {
glfwPollEvents();

View file

@ -49,6 +49,7 @@ public:
YaveVulkanInstance(const YaveVulkanInstance &) = delete;
YaveVulkanInstance &operator=(const YaveVulkanInstance &) = delete;
VkInstance *getVkInstance(){return &instance;}
YaveVulkanInstance();
~YaveVulkanInstance();
};

View file

@ -0,0 +1,17 @@
#include "yave_vulkan_surface.hpp"
#include "yave_vulkan_instance.hpp"
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)) {
throw std::runtime_error("failed to create window surface!");
}
}
YaveVulkanSurface::~YaveVulkanSurface() {}
} // namespace yave

View file

@ -0,0 +1,31 @@
#pragma once
#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
#include <vulkan/vulkan_wayland.h>
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#define GLFW_EXPOSE_NATIVE_WAYLAND
#include <GLFW/glfw3native.h>
namespace yave {
class YaveVulkanSurface {
private:
VkSurfaceKHR surface;
public:
YaveVulkanSurface(YaveVulkanInstance &yaveVulkanInstance, YaveWindow &window);
~YaveVulkanSurface();
// Delete Copy constructors
// This class should match one to one with vulkan instances
YaveVulkanSurface(const YaveVulkanSurface &) = delete;
YaveVulkanSurface &operator=(const YaveVulkanSurface &) = delete;
};
} // namespace yave

View file

@ -27,6 +27,8 @@ public:
YaveWindow(int w, int h, std::string name);
~YaveWindow();
GLFWwindow *getGLFWWindow() { return window; }
// Tell apllicaton that the user has attempted to close the window
bool shouldClose() { return glfwWindowShouldClose(window); }
};

View file

@ -1,13 +1,13 @@
# CMake toolchain file
# linker flags
set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,--strip-debug")
#set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,--strip-debug")
# cflags
set(CMAKE_CXX_FLAGS_INIT "-ansi -Wall")
# cflags for debug build
set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g3 -ggdb3")
set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g -ggdb")
# cflags for release build
set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG -s")