stories/engine/utils.h

82 lines
2.2 KiB
C++

#pragma once
#include <vector>
#include <vulkan/vulkan.h>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <optional>
#include <fstream>
namespace Engine {
struct Support {
Support();
void logSupported(const std::string& header);
std::vector<const char*> supported;
std::vector<const char*> unsupported;
std::vector<const char*> unsupportedCritical;
};
struct SwapChainSupportDetails {
VkSurfaceCapabilitiesKHR capabilities;
std::vector<VkSurfaceFormatKHR> formats;
std::vector<VkPresentModeKHR> presentModes;
bool adequate() const;
};
struct QueueFamilyIndices {
std::optional<uint32_t> graphicsFamily;
std::optional<uint32_t> presentFamily;
bool isComplete() const;
};
Support getVulkanLayers(const std::set<std::string>& requestedLayers);
Support getVulkanExtensions(const std::set<std::string>& requestedExtensions, const std::vector<const char*>& criticalExtensions);
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats);
VkPresentModeKHR chooseSwapPresentMode(const std::vector<VkPresentModeKHR>& availablePresentModes);
std::vector<VkExtensionProperties> getAvailableVulkanExtensions();
std::vector<VkLayerProperties> getAvailableVulkanLayers();
void populateDebugMessengerCreateInfo(
VkDebugUtilsMessengerCreateInfoEXT& createInfo,
PFN_vkDebugUtilsMessengerCallbackEXT debugCallback
);
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VkDebugUtilsMessageTypeFlagsEXT messageType,
const VkDebugUtilsMessengerCallbackDataEXT* callbackData,
void* userData
)
{
std::cerr << "validation layer: " << callbackData->pMessage << std::endl;
return true;
}
VkResult createDebugUtilsMessengerEXT(
VkInstance instance,
const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkDebugUtilsMessengerEXT* pDebugMessenger
);
void destroyDebugUtilsMessengerEXT(
VkInstance instance,
VkDebugUtilsMessengerEXT debugMessenger,
const VkAllocationCallbacks* pAllocator
);
std::vector<char> readFile(const std::string& filename);
}