抽象vulkan 基类,梳理代码。
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
#ifndef VULKAN_UTILS_H
|
||||
#define VULKAN_UTILS_H
|
||||
|
||||
#define VK_CHECK(x) \
|
||||
do \
|
||||
{ \
|
||||
VkResult err = x; \
|
||||
if (err) \
|
||||
{ \
|
||||
assert(false); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifdef _WIN32
|
||||
#define logOut std::cout
|
||||
#define GLFW_INCLUDE_VULKAN
|
||||
#include <GLFW/glfw3.h>
|
||||
#else
|
||||
#define logOut aout
|
||||
#include <vulkan/vulkan.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <assert.h>
|
||||
|
||||
struct QueueFamilyIndices {
|
||||
std::optional<uint32_t> graphicsFamily;
|
||||
std::optional<uint32_t> presentFamily;
|
||||
|
||||
bool isComplete() {
|
||||
return graphicsFamily.has_value() && presentFamily.has_value();
|
||||
}
|
||||
};
|
||||
|
||||
class AppBase
|
||||
{
|
||||
public:
|
||||
std::vector<char> readFile(const std::string& enginePath);
|
||||
VkShaderModule createShaderModule(VkDevice& device, const std::vector<char>& code);
|
||||
const std::vector<const char*> validationLayers = {"VK_LAYER_KHRONOS_validation"};
|
||||
protected:
|
||||
VkInstance instance;
|
||||
void createInstance();
|
||||
bool checkValidationLayerSupport();
|
||||
void setupDebugMessenger();
|
||||
bool checkSwapChainSupport(VkPhysicalDevice device, VkSurfaceKHR& surface);
|
||||
bool checkDeviceExtensionSupport(VkPhysicalDevice device);
|
||||
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR& surface);
|
||||
bool isDeviceSuitable(VkPhysicalDevice device, VkSurfaceKHR& surface);
|
||||
void pickPhysicalDevice(VkPhysicalDevice& physicalDevice, VkSurfaceKHR& surface);
|
||||
#ifdef _WIN32
|
||||
GLFWwindow *window;
|
||||
#endif
|
||||
|
||||
bool enableValidationLayers = true;
|
||||
VkDebugUtilsMessengerEXT debugMessenger;
|
||||
};
|
||||
|
||||
#endif // VULKAN_UTILS_H
|
||||
Reference in New Issue
Block a user