vkfw
This commit is contained in:
parent
ee96290c80
commit
ffd3f44464
49
src/main.cpp
49
src/main.cpp
|
@ -10,8 +10,8 @@
|
||||||
#define VULKAN_HPP_NO_CONSTRUCTORS
|
#define VULKAN_HPP_NO_CONSTRUCTORS
|
||||||
#include <vulkan/vulkan.hpp>
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
#include "util/magic_enum.hpp"
|
|
||||||
#include "util/types.h"
|
#include "util/types.h"
|
||||||
|
#include "util/vkfw.hpp"
|
||||||
|
|
||||||
namespace vk {
|
namespace vk {
|
||||||
using DebugUtilsMessengerUnique = vk::UniqueHandle<vk::DebugUtilsMessengerEXT, vk::DispatchLoaderDynamic>;
|
using DebugUtilsMessengerUnique = vk::UniqueHandle<vk::DebugUtilsMessengerEXT, vk::DispatchLoaderDynamic>;
|
||||||
|
@ -34,11 +34,11 @@ class VulkanApp {
|
||||||
initWindow();
|
initWindow();
|
||||||
initVulkan();
|
initVulkan();
|
||||||
mainLoop();
|
mainLoop();
|
||||||
cleanup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLFWwindow* mWindow;
|
vkfw::UniqueInstance mGLFWInstance;
|
||||||
|
vkfw::UniqueWindow mWindow;
|
||||||
|
|
||||||
vk::UniqueInstance mInstance;
|
vk::UniqueInstance mInstance;
|
||||||
|
|
||||||
|
@ -61,12 +61,16 @@ class VulkanApp {
|
||||||
};
|
};
|
||||||
|
|
||||||
fn initWindow() -> void {
|
fn initWindow() -> void {
|
||||||
glfwInit();
|
using namespace vkfw;
|
||||||
|
|
||||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
mGLFWInstance = initUnique();
|
||||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
|
||||||
|
|
||||||
mWindow = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
|
WindowHints hints;
|
||||||
|
|
||||||
|
hints.clientAPI = ClientAPI::eNone;
|
||||||
|
hints.resizable = false;
|
||||||
|
|
||||||
|
mWindow = createWindowUnique(WIDTH, HEIGHT, "Vulkan", hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initVulkan() -> void {
|
fn initVulkan() -> void {
|
||||||
|
@ -78,12 +82,7 @@ class VulkanApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mainLoop() -> void {
|
fn mainLoop() -> void {
|
||||||
while (!glfwWindowShouldClose(mWindow)) { glfwPollEvents(); }
|
while (!mWindow->shouldClose()) { vkfw::waitEvents(); }
|
||||||
}
|
|
||||||
|
|
||||||
fn cleanup() -> void {
|
|
||||||
glfwDestroyWindow(mWindow);
|
|
||||||
glfwTerminate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn createInstance() -> void {
|
fn createInstance() -> void {
|
||||||
|
@ -143,18 +142,7 @@ class VulkanApp {
|
||||||
mDebugMessenger = mInstance->createDebugUtilsMessengerEXTUnique(messengerCreateInfo, nullptr, mLoader);
|
mDebugMessenger = mInstance->createDebugUtilsMessengerEXTUnique(messengerCreateInfo, nullptr, mLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn createSurface() -> void {
|
fn createSurface() -> void { mSurface = vkfw::createWindowSurfaceUnique(mInstance.get(), mWindow.get()); }
|
||||||
VkSurfaceKHR surface = nullptr;
|
|
||||||
|
|
||||||
VkResult result = glfwCreateWindowSurface(mInstance.get(), mWindow, nullptr, &surface);
|
|
||||||
|
|
||||||
if (result != VK_SUCCESS)
|
|
||||||
throw std::runtime_error(
|
|
||||||
"Failed to create window surface! Error code: " + string(magic_enum::enum_name(result))
|
|
||||||
);
|
|
||||||
|
|
||||||
mSurface = vk::UniqueSurfaceKHR(surface, mInstance.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pickPhysicalDevice() -> void {
|
fn pickPhysicalDevice() -> void {
|
||||||
std::vector<vk::PhysicalDevice> devices = mInstance->enumeratePhysicalDevices();
|
std::vector<vk::PhysicalDevice> devices = mInstance->enumeratePhysicalDevices();
|
||||||
|
@ -243,16 +231,9 @@ class VulkanApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
static fn getRequiredExtensions() -> std::vector<const char*> {
|
static fn getRequiredExtensions() -> std::vector<const char*> {
|
||||||
u32 glfwExtensionCount = 0;
|
std::span<const char*> extensionsSpan = vkfw::getRequiredInstanceExtensions();
|
||||||
const char** glfwExtensions = nullptr;
|
|
||||||
glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
|
|
||||||
|
|
||||||
std::vector<const char*> extensions;
|
std::vector extensions(extensionsSpan.begin(), extensionsSpan.end());
|
||||||
|
|
||||||
if (glfwExtensions) {
|
|
||||||
std::span<const char*> extSpan(glfwExtensions, glfwExtensionCount);
|
|
||||||
extensions.assign(extSpan.begin(), extSpan.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enableValidationLayers)
|
if (enableValidationLayers)
|
||||||
extensions.push_back("VK_EXT_debug_utils");
|
extensions.push_back("VK_EXT_debug_utils");
|
||||||
|
|
5015
src/util/vkfw.hpp
Normal file
5015
src/util/vkfw.hpp
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue