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
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
#include "util/magic_enum.hpp"
|
||||
#include "util/types.h"
|
||||
#include "util/vkfw.hpp"
|
||||
|
||||
namespace vk {
|
||||
using DebugUtilsMessengerUnique = vk::UniqueHandle<vk::DebugUtilsMessengerEXT, vk::DispatchLoaderDynamic>;
|
||||
|
@ -34,11 +34,11 @@ class VulkanApp {
|
|||
initWindow();
|
||||
initVulkan();
|
||||
mainLoop();
|
||||
cleanup();
|
||||
}
|
||||
|
||||
private:
|
||||
GLFWwindow* mWindow;
|
||||
vkfw::UniqueInstance mGLFWInstance;
|
||||
vkfw::UniqueWindow mWindow;
|
||||
|
||||
vk::UniqueInstance mInstance;
|
||||
|
||||
|
@ -61,12 +61,16 @@ class VulkanApp {
|
|||
};
|
||||
|
||||
fn initWindow() -> void {
|
||||
glfwInit();
|
||||
using namespace vkfw;
|
||||
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||
mGLFWInstance = initUnique();
|
||||
|
||||
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 {
|
||||
|
@ -78,12 +82,7 @@ class VulkanApp {
|
|||
}
|
||||
|
||||
fn mainLoop() -> void {
|
||||
while (!glfwWindowShouldClose(mWindow)) { glfwPollEvents(); }
|
||||
}
|
||||
|
||||
fn cleanup() -> void {
|
||||
glfwDestroyWindow(mWindow);
|
||||
glfwTerminate();
|
||||
while (!mWindow->shouldClose()) { vkfw::waitEvents(); }
|
||||
}
|
||||
|
||||
fn createInstance() -> void {
|
||||
|
@ -143,18 +142,7 @@ class VulkanApp {
|
|||
mDebugMessenger = mInstance->createDebugUtilsMessengerEXTUnique(messengerCreateInfo, nullptr, mLoader);
|
||||
}
|
||||
|
||||
fn createSurface() -> void {
|
||||
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 createSurface() -> void { mSurface = vkfw::createWindowSurfaceUnique(mInstance.get(), mWindow.get()); }
|
||||
|
||||
fn pickPhysicalDevice() -> void {
|
||||
std::vector<vk::PhysicalDevice> devices = mInstance->enumeratePhysicalDevices();
|
||||
|
@ -243,16 +231,9 @@ class VulkanApp {
|
|||
}
|
||||
|
||||
static fn getRequiredExtensions() -> std::vector<const char*> {
|
||||
u32 glfwExtensionCount = 0;
|
||||
const char** glfwExtensions = nullptr;
|
||||
glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
|
||||
std::span<const char*> extensionsSpan = vkfw::getRequiredInstanceExtensions();
|
||||
|
||||
std::vector<const char*> extensions;
|
||||
|
||||
if (glfwExtensions) {
|
||||
std::span<const char*> extSpan(glfwExtensions, glfwExtensionCount);
|
||||
extensions.assign(extSpan.begin(), extSpan.end());
|
||||
}
|
||||
std::vector extensions(extensionsSpan.begin(), extensionsSpan.end());
|
||||
|
||||
if (enableValidationLayers)
|
||||
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