重构完成,glfw链接失效
parent
31dbcc2aa6
commit
f3212fc19d
|
@ -14,6 +14,7 @@ include_directories(external/tinygltf)
|
||||||
include_directories(external/ktx/include)
|
include_directories(external/ktx/include)
|
||||||
include_directories(external/ktx/other_include)
|
include_directories(external/ktx/other_include)
|
||||||
include_directories(external/glfw-3.4/include)
|
include_directories(external/glfw-3.4/include)
|
||||||
|
include_directories(external/glfw)
|
||||||
include_directories(base)
|
include_directories(base)
|
||||||
|
|
||||||
OPTION(USE_D2D_WSI "Build the project using Direct to Display swapchain" OFF)
|
OPTION(USE_D2D_WSI "Build the project using Direct to Display swapchain" OFF)
|
||||||
|
|
|
@ -23,6 +23,7 @@ private:
|
||||||
glm::mat4 rotM = glm::mat4(1.0f);
|
glm::mat4 rotM = glm::mat4(1.0f);
|
||||||
glm::mat4 transM;
|
glm::mat4 transM;
|
||||||
|
|
||||||
|
//根据传入角度,绕x,y,z轴旋转
|
||||||
rotM = glm::rotate(rotM, glm::radians(rotation.x * (flipY ? -1.0f : 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f));
|
rotM = glm::rotate(rotM, glm::radians(rotation.x * (flipY ? -1.0f : 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||||
rotM = glm::rotate(rotM, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
rotM = glm::rotate(rotM, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
rotM = glm::rotate(rotM, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
rotM = glm::rotate(rotM, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||||
|
@ -86,7 +87,7 @@ public:
|
||||||
float getFarClip() {
|
float getFarClip() {
|
||||||
return zfar;
|
return zfar;
|
||||||
}
|
}
|
||||||
|
// 投影计算
|
||||||
void setPerspective(float fov, float aspect, float znear, float zfar)
|
void setPerspective(float fov, float aspect, float znear, float zfar)
|
||||||
{
|
{
|
||||||
this->fov = fov;
|
this->fov = fov;
|
||||||
|
@ -153,6 +154,7 @@ public:
|
||||||
{
|
{
|
||||||
if (moving())
|
if (moving())
|
||||||
{
|
{
|
||||||
|
// 相机朝向
|
||||||
glm::vec3 camFront;
|
glm::vec3 camFront;
|
||||||
camFront.x = -cos(glm::radians(rotation.x)) * sin(glm::radians(rotation.y));
|
camFront.x = -cos(glm::radians(rotation.x)) * sin(glm::radians(rotation.y));
|
||||||
camFront.y = sin(glm::radians(rotation.x));
|
camFront.y = sin(glm::radians(rotation.x));
|
||||||
|
@ -161,6 +163,7 @@ public:
|
||||||
|
|
||||||
float moveSpeed = deltaTime * movementSpeed;
|
float moveSpeed = deltaTime * movementSpeed;
|
||||||
|
|
||||||
|
// 位置的平移计算
|
||||||
if (keys.up)
|
if (keys.up)
|
||||||
position += camFront * moveSpeed;
|
position += camFront * moveSpeed;
|
||||||
if (keys.down)
|
if (keys.down)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -8,43 +8,17 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#pragma comment(linker, "/subsystem:windows")
|
|
||||||
#include <windows.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <io.h>
|
|
||||||
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
|
|
||||||
#include <android/native_activity.h>
|
|
||||||
#include <android/asset_manager.h>
|
|
||||||
#include <android_native_app_glue.h>
|
|
||||||
#include <sys/system_properties.h>
|
|
||||||
#include "VulkanAndroid.h"
|
|
||||||
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
|
|
||||||
#include <wayland-client.h>
|
|
||||||
#elif defined(_DIRECT2DISPLAY)
|
|
||||||
//
|
|
||||||
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
|
||||||
#include <xcb/xcb.h>
|
|
||||||
#elif defined(VK_USE_PLATFORM_MACOS_MVK)
|
|
||||||
#include <Cocoa/Cocoa.h>
|
|
||||||
#include <Carbon/Carbon.h>
|
|
||||||
#include <QuartzCore/CAMetalLayer.h>
|
|
||||||
#include <CoreVideo/CVDisplayLink.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#define GLM_FORCE_RADIANS
|
|
||||||
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
|
||||||
#define GLM_ENABLE_EXPERIMENTAL
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
|
||||||
|
|
||||||
#include "vulkan/vulkan.h"
|
#include "vulkan/vulkan.h"
|
||||||
|
|
||||||
#include "VulkanTools.h"
|
#include "VulkanTools.h"
|
||||||
|
@ -54,51 +28,37 @@
|
||||||
#include "VulkanDevice.hpp"
|
#include "VulkanDevice.hpp"
|
||||||
#include "VulkanSwapChain.hpp"
|
#include "VulkanSwapChain.hpp"
|
||||||
|
|
||||||
#include "imgui/imgui.h"
|
//#include "imgui/imgui.h"
|
||||||
|
|
||||||
class VulkanExampleBase
|
class VulkanExampleBase
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
float fpsTimer = 0.0f;
|
|
||||||
uint32_t frameCounter = 0;
|
uint32_t frameCounter = 0;
|
||||||
uint32_t destWidth;
|
|
||||||
uint32_t destHeight;
|
|
||||||
bool resizing = false;
|
bool resizing = false;
|
||||||
void handleMouseMove(int32_t x, int32_t y);
|
//void handleMouseMove(int32_t x, int32_t y);
|
||||||
PFN_vkCreateDebugReportCallbackEXT vkCreateDebugReportCallback;
|
PFN_vkCreateDebugReportCallbackEXT vkCreateDebugReportCallback;
|
||||||
PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallback;
|
PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallback;
|
||||||
VkDebugReportCallbackEXT debugReportCallback;
|
VkDebugReportCallbackEXT debugReportCallback;
|
||||||
struct MultisampleTarget {
|
|
||||||
struct {
|
|
||||||
VkImage image;
|
|
||||||
VkImageView view;
|
|
||||||
VkDeviceMemory memory;
|
|
||||||
} color;
|
|
||||||
struct {
|
|
||||||
VkImage image;
|
|
||||||
VkImageView view;
|
|
||||||
VkDeviceMemory memory;
|
|
||||||
} depth;
|
|
||||||
} multisampleTarget;
|
|
||||||
protected:
|
protected:
|
||||||
VkInstance instance;
|
VkInstance instance;
|
||||||
VkPhysicalDevice physicalDevice;
|
|
||||||
VkPhysicalDeviceProperties deviceProperties;
|
VkPhysicalDeviceProperties deviceProperties;
|
||||||
VkPhysicalDeviceFeatures deviceFeatures;
|
|
||||||
VkPhysicalDeviceMemoryProperties deviceMemoryProperties;
|
VkPhysicalDeviceMemoryProperties deviceMemoryProperties;
|
||||||
VkDevice device;
|
|
||||||
vks::VulkanDevice *vulkanDevice;
|
|
||||||
VkQueue queue;
|
VkQueue queue;
|
||||||
VkFormat depthFormat;
|
VkFormat depthFormat;
|
||||||
VkCommandPool cmdPool;
|
VkCommandPool cmdPool;
|
||||||
VkRenderPass renderPass;
|
|
||||||
std::vector<VkFramebuffer>frameBuffers;
|
std::vector<VkFramebuffer>frameBuffers;
|
||||||
uint32_t currentBuffer = 0;
|
uint32_t currentBuffer = 0;
|
||||||
VkDescriptorPool descriptorPool;
|
|
||||||
VkPipelineCache pipelineCache;
|
|
||||||
VulkanSwapChain swapChain;
|
//VulkanSwapChain swapChain;
|
||||||
std::string title = "Vulkan Example";
|
|
||||||
std::string name = "vulkanExample";
|
|
||||||
void windowResize();
|
void windowResize();
|
||||||
public:
|
public:
|
||||||
static std::vector<const char*> args;
|
static std::vector<const char*> args;
|
||||||
|
@ -106,67 +66,31 @@ public:
|
||||||
bool prepared = false;
|
bool prepared = false;
|
||||||
uint32_t width = 1280;
|
uint32_t width = 1280;
|
||||||
uint32_t height = 720;
|
uint32_t height = 720;
|
||||||
float frameTimer = 1.0f;
|
|
||||||
Camera camera;
|
|
||||||
glm::vec2 mousePos;
|
|
||||||
bool paused = false;
|
bool paused = false;
|
||||||
uint32_t lastFPS = 0;
|
|
||||||
|
|
||||||
struct Settings {
|
|
||||||
uint32_t width = 1280;
|
|
||||||
uint32_t height = 720;
|
|
||||||
bool validation = true; // 校验层开关
|
|
||||||
bool fullscreen = false; // 全屏开关
|
|
||||||
bool vsync = false; // 垂直同步开关
|
|
||||||
bool multiSampling = true; // 多重采样
|
|
||||||
bool rotateModel = true; // 模型自旋转(暂时失效)
|
|
||||||
bool headless = false; // 无头开关
|
|
||||||
bool outputPNGimage = false;
|
|
||||||
uint32_t endFrameIndex = 75;
|
|
||||||
bool enableSaveToImageSequeue = true; // 图片序列开关(暂时弃用)
|
|
||||||
uint32_t outputFrameCount = 100; // 图片序列结束帧
|
|
||||||
bool takeScreenShot = false; // 截屏(暂时弃用)
|
|
||||||
uint32_t startFrameCount = 1; // 图片序列开始帧
|
|
||||||
|
|
||||||
uint32_t videoFrameRate = 25;
|
|
||||||
|
|
||||||
VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_4_BIT; // 多重采样倍率
|
|
||||||
} settings;
|
|
||||||
|
|
||||||
struct DepthStencil {
|
|
||||||
VkImage image;
|
|
||||||
VkDeviceMemory mem;
|
|
||||||
VkImageView view;
|
|
||||||
} depthStencil;
|
|
||||||
|
|
||||||
struct ColorAttachment {
|
|
||||||
VkImage image;
|
|
||||||
VkDeviceMemory memory;
|
|
||||||
VkImageView view;
|
|
||||||
} colorAttachment;
|
|
||||||
|
|
||||||
std::vector<VkImageView> swapChainImageViews;
|
|
||||||
|
|
||||||
struct GamePadState {
|
struct GamePadState {
|
||||||
glm::vec2 axisLeft = glm::vec2(0.0f);
|
glm::vec2 axisLeft = glm::vec2(0.0f);
|
||||||
glm::vec2 axisRight = glm::vec2(0.0f);
|
glm::vec2 axisRight = glm::vec2(0.0f);
|
||||||
} gamePadState;
|
} gamePadState;
|
||||||
|
|
||||||
struct MouseButtons {
|
|
||||||
bool left = false;
|
|
||||||
bool right = false;
|
|
||||||
bool middle = false;
|
|
||||||
} mouseButtons;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
VulkanExampleBase();
|
VulkanExampleBase();
|
||||||
virtual ~VulkanExampleBase();
|
virtual ~VulkanExampleBase();
|
||||||
|
|
||||||
void initVulkan();
|
//virtual void render() = 0;
|
||||||
|
|
||||||
virtual VkResult createInstance(bool enableValidation);
|
|
||||||
virtual void render() = 0;
|
|
||||||
virtual void windowResized();
|
virtual void windowResized();
|
||||||
virtual void setupFrameBuffer();
|
virtual void setupFrameBuffer();
|
||||||
void createSwapChainFramebuffer();
|
void createSwapChainFramebuffer();
|
||||||
|
@ -178,6 +102,4 @@ public:
|
||||||
VkFormat findDepthFormat();
|
VkFormat findDepthFormat();
|
||||||
VkFormat findSupportedFormat(const std::vector<VkFormat>& candidates, VkImageTiling tiling, VkFormatFeatureFlags features);
|
VkFormat findSupportedFormat(const std::vector<VkFormat>& candidates, VkImageTiling tiling, VkFormatFeatureFlags features);
|
||||||
|
|
||||||
void renderLoop();
|
|
||||||
void renderFrame();
|
|
||||||
};
|
};
|
||||||
|
|
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -3,8 +3,13 @@
|
||||||
|
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
#include "stb/stb_image_write.h"
|
#include "stb/stb_image_write.h"
|
||||||
|
#define GLFW_INCLUDE_VULKAN
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#define GLM_FORCE_RADIANS
|
||||||
|
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
||||||
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -14,27 +19,34 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <GLFW/glfw3.h>
|
#include <optional>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
#include "VulkanExampleBase.h"
|
//#include "VulkanExampleBase.h"
|
||||||
#include "glTFModel.h"
|
#include "glTFModel.h"
|
||||||
#include <VulkanTexture.hpp>
|
#include <VulkanTexture.hpp>
|
||||||
#include "VulkanDevice.hpp"
|
#include "VulkanDevice.hpp"
|
||||||
#include "ui.hpp"
|
#include "ui.hpp"
|
||||||
#include <VulkanUtils.hpp>
|
#include <VulkanUtils.hpp>
|
||||||
|
#include <camera.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define ENABLE_VALIDATION false
|
#define ENABLE_VALIDATION false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PlumageRender : public VulkanExampleBase
|
class PlumageRender
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool wireframe = false;
|
bool wireframe = false;
|
||||||
|
@ -42,8 +54,41 @@ public:
|
||||||
bool ToneMapping = true;
|
bool ToneMapping = true;
|
||||||
bool pbrEnabled = true;
|
bool pbrEnabled = true;
|
||||||
|
|
||||||
|
std::vector<const char*> args;
|
||||||
|
|
||||||
GLFWwindow* window;
|
GLFWwindow* window;
|
||||||
|
|
||||||
|
const std::vector<const char*> validationLayers = {
|
||||||
|
"VK_LAYER_KHRONOS_validation"
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::vector<const char*> swapchainExtensions = {
|
||||||
|
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
|
||||||
|
//"VK_EXT_headless_surface"
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string title;
|
||||||
|
std::string name;
|
||||||
|
Camera camera;
|
||||||
|
|
||||||
|
VkPhysicalDevice physicalDevice;
|
||||||
|
VkPhysicalDeviceFeatures deviceFeatures;
|
||||||
|
VkDevice device;
|
||||||
|
vks::VulkanDevice* vulkanDevice;
|
||||||
|
|
||||||
|
std::vector<VkImageView> swapChainImageViews;
|
||||||
|
|
||||||
|
VkRenderPass renderPass;
|
||||||
|
|
||||||
|
VkPipelineCache pipelineCache;
|
||||||
|
|
||||||
|
float fpsTimer = 0.0f;
|
||||||
|
|
||||||
|
VkDescriptorPool descriptorPool;
|
||||||
|
|
||||||
|
uint32_t currentBuffer;
|
||||||
|
|
||||||
struct stat
|
struct stat
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -56,6 +101,7 @@ public:
|
||||||
|
|
||||||
}signal;
|
}signal;
|
||||||
|
|
||||||
|
bool prepared = false;
|
||||||
|
|
||||||
struct Models
|
struct Models
|
||||||
{
|
{
|
||||||
|
@ -106,6 +152,9 @@ public:
|
||||||
|
|
||||||
|
|
||||||
}chineseUI;
|
}chineseUI;
|
||||||
|
|
||||||
|
VkInstance instance;
|
||||||
|
|
||||||
struct UniformBufferSet {
|
struct UniformBufferSet {
|
||||||
Buffer scene;
|
Buffer scene;
|
||||||
Buffer skybox;
|
Buffer skybox;
|
||||||
|
@ -190,6 +239,27 @@ public:
|
||||||
|
|
||||||
} filePath;
|
} filePath;
|
||||||
|
|
||||||
|
struct Settings {
|
||||||
|
uint32_t width = 1280;
|
||||||
|
uint32_t height = 720;
|
||||||
|
bool validation = true; // 校验层开关
|
||||||
|
bool fullscreen = false; // 全屏开关
|
||||||
|
bool vsync = false; // 垂直同步开关
|
||||||
|
bool multiSampling = true; // 多重采样
|
||||||
|
bool rotateModel = true; // 模型自旋转(暂时失效)
|
||||||
|
bool headless = false; // 无头开关
|
||||||
|
bool outputPNGimage = false;
|
||||||
|
uint32_t endFrameIndex = 75;
|
||||||
|
bool enableSaveToImageSequeue = true; // 图片序列开关(暂时弃用)
|
||||||
|
uint32_t outputFrameCount = 100; // 图片序列结束帧
|
||||||
|
bool takeScreenShot = false; // 截屏(暂时弃用)
|
||||||
|
uint32_t startFrameCount = 1; // 图片序列开始帧
|
||||||
|
uint32_t selectedPhysicalDeviceIndex = 0; // 选定的显卡索引,数组形式从0开始
|
||||||
|
uint32_t videoFrameRate = 25;
|
||||||
|
|
||||||
|
VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_4_BIT; // 多重采样倍率
|
||||||
|
} settings;
|
||||||
|
|
||||||
|
|
||||||
float modelrot = 0.0f;
|
float modelrot = 0.0f;
|
||||||
glm::vec3 modelPos = glm::vec3(0.0f);
|
glm::vec3 modelPos = glm::vec3(0.0f);
|
||||||
|
@ -303,48 +373,157 @@ public:
|
||||||
|
|
||||||
bool framebufferResized = false;
|
bool framebufferResized = false;
|
||||||
|
|
||||||
|
VkDebugUtilsMessengerEXT debugMessenger;
|
||||||
|
|
||||||
|
VkSurfaceKHR surface;
|
||||||
|
|
||||||
|
VkQueue graphicQueue;
|
||||||
|
VkQueue presentQueue;
|
||||||
|
|
||||||
|
VkSwapchainKHR swapChainKHR;
|
||||||
|
VkFormat swapChainImageFormat;
|
||||||
|
std::vector<VkImage> swapChainImages;
|
||||||
|
VkExtent2D swapChainExtent;
|
||||||
|
|
||||||
|
uint32_t imageIndex;
|
||||||
|
|
||||||
|
VkCommandPool commandPool;
|
||||||
|
|
||||||
|
struct QueueFamilyIndices
|
||||||
|
{
|
||||||
|
std::optional<uint32_t> graphicsFamily;
|
||||||
|
std::optional<uint32_t> presentFamily;
|
||||||
|
|
||||||
|
bool isGraphicsFamilyComplete()
|
||||||
|
{
|
||||||
|
return graphicsFamily.has_value();
|
||||||
|
}
|
||||||
|
bool isPresentFamilyComplete()
|
||||||
|
{
|
||||||
|
return presentFamily.has_value();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SwapChainSupportDetails
|
||||||
|
{
|
||||||
|
VkSurfaceCapabilitiesKHR capabilities;
|
||||||
|
std::vector<VkSurfaceFormatKHR> formats;
|
||||||
|
std::vector<VkPresentModeKHR> presentModes;
|
||||||
|
};
|
||||||
|
|
||||||
|
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR fpGetPhysicalDeviceSurfacePresentModesKHR;
|
||||||
|
|
||||||
|
struct MultisampleTarget {
|
||||||
|
struct {
|
||||||
|
VkImage image;
|
||||||
|
VkImageView view;
|
||||||
|
VkDeviceMemory memory;
|
||||||
|
} colorAttachment;
|
||||||
|
struct {
|
||||||
|
VkImage image;
|
||||||
|
VkImageView view;
|
||||||
|
VkDeviceMemory memory;
|
||||||
|
} depthAttachment;
|
||||||
|
} multisampleTarget;
|
||||||
|
|
||||||
|
struct DepthAttachment {
|
||||||
|
VkImage image;
|
||||||
|
VkDeviceMemory memory;
|
||||||
|
VkImageView view;
|
||||||
|
} depthAttachment;
|
||||||
|
|
||||||
|
struct ColorAttachment {
|
||||||
|
VkImage image;
|
||||||
|
VkDeviceMemory memory;
|
||||||
|
VkImageView view;
|
||||||
|
} colorAttachment;
|
||||||
|
|
||||||
|
std::vector<VkFramebuffer> framebuffers;
|
||||||
|
|
||||||
|
uint32_t lastFPS = 0;
|
||||||
|
float frameTimer = 1.0f;
|
||||||
|
uint32_t frameCounter =0;
|
||||||
|
|
||||||
|
glm::vec2 mousePos;
|
||||||
|
|
||||||
|
struct MouseButtons {
|
||||||
|
bool left = false;
|
||||||
|
bool right = false;
|
||||||
|
bool middle = false;
|
||||||
|
} mouseButtons;
|
||||||
|
|
||||||
|
|
||||||
PlumageRender();
|
PlumageRender();
|
||||||
~PlumageRender()
|
~PlumageRender();
|
||||||
{
|
|
||||||
// Clean up used Vulkan resources
|
|
||||||
// Note : Inherited destructor cleans up resources stored in base class
|
|
||||||
vkDestroyPipeline(device, pipelines.skybox, nullptr);
|
|
||||||
vkDestroyPipeline(device, pipelines.pbr, nullptr);
|
|
||||||
vkDestroyPipeline(device, pipelines.pbrAlphaBlend, nullptr);
|
|
||||||
|
|
||||||
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
|
||||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.scene, nullptr);
|
|
||||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.material, nullptr);
|
|
||||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.node, nullptr);
|
|
||||||
|
|
||||||
models.scene.destroy(device);
|
|
||||||
models.skybox.destroy(device);
|
|
||||||
|
|
||||||
for (auto buffer : uniformBuffers) {
|
|
||||||
buffer.params.destroy();
|
|
||||||
buffer.scene.destroy();
|
|
||||||
buffer.skybox.destroy();
|
|
||||||
}
|
|
||||||
for (auto fence : waitFences) {
|
|
||||||
vkDestroyFence(device, fence, nullptr);
|
|
||||||
}
|
|
||||||
for (auto semaphore : renderCompleteSemaphores) {
|
|
||||||
vkDestroySemaphore(device, semaphore, nullptr);
|
|
||||||
}
|
|
||||||
for (auto semaphore : presentCompleteSemaphores) {
|
|
||||||
vkDestroySemaphore(device, semaphore, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
textures.environmentCube.destroy();
|
|
||||||
textures.irradianceCube.destroy();
|
|
||||||
textures.prefilteredCube.destroy();
|
|
||||||
textures.lutBrdf.destroy();
|
|
||||||
textures.empty.destroy();
|
|
||||||
delete gui;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void initVulkan();
|
||||||
VkResult createInstance();
|
VkResult createInstance();
|
||||||
|
|
||||||
|
bool checkValidationLayerSupport();
|
||||||
|
std::vector<const char*> getRequiredExtensions();
|
||||||
|
void setupDebugMessager();
|
||||||
|
void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& debugCreateInfo);
|
||||||
|
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
|
||||||
|
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||||
|
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
|
||||||
|
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
||||||
|
void* pUserData);
|
||||||
|
VkResult CreateDebugUtilsMessengerEXT(
|
||||||
|
VkInstance instance,
|
||||||
|
const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
|
||||||
|
const VkAllocationCallbacks* pAllocator,
|
||||||
|
VkDebugUtilsMessengerEXT* pDebugMessenger);
|
||||||
|
|
||||||
|
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator);
|
||||||
|
|
||||||
|
void createSurface();
|
||||||
|
|
||||||
|
void pickupPhysicalDevice();
|
||||||
|
bool isDeviceSuitable(VkPhysicalDevice device);
|
||||||
|
bool checkDeviceExtensionSupport(VkPhysicalDevice device);
|
||||||
|
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device);
|
||||||
|
SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device);
|
||||||
|
|
||||||
|
// 创建程序使用的逻辑设备
|
||||||
|
void createLogicalDevice();
|
||||||
|
|
||||||
|
void prepare();
|
||||||
|
|
||||||
|
// 创建交换链
|
||||||
|
void createSwapChain();
|
||||||
|
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats);
|
||||||
|
VkPresentModeKHR chooseSwapPresentMode(const std::vector<VkPresentModeKHR>& availablePresentModes);
|
||||||
|
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities);
|
||||||
|
void cleanupSwapChain();
|
||||||
|
|
||||||
|
void createCommandPool();
|
||||||
|
|
||||||
|
void createRenderPass();
|
||||||
|
VkFormat findDepthFormat();
|
||||||
|
VkFormat findSupportedFormat(const std::vector<VkFormat>& candidates, VkImageTiling tiling, VkFormatFeatureFlags features);
|
||||||
|
bool hasStencilComponent(VkFormat format);
|
||||||
|
|
||||||
|
void createPipelineCache();
|
||||||
|
|
||||||
|
void createFramebuffer();
|
||||||
|
void createSwapChainFramebuffer();
|
||||||
|
void createImageView();
|
||||||
|
|
||||||
|
void renderLoop();
|
||||||
|
|
||||||
|
void drawFrame();
|
||||||
|
|
||||||
|
|
||||||
|
bool swapChainAcquireNextImage(bool framebuffeerResized, uint32_t imageIndex, uint32_t frameIndex);
|
||||||
|
|
||||||
|
void recreateSwapChain();
|
||||||
|
|
||||||
|
void submitToGraphicQueue(uint32_t frameIndex, uint32_t currentBuffer);
|
||||||
|
|
||||||
|
void imageToQueuePresent(uint32_t frameIndex, uint32_t imageIndex, bool framebufferResized);
|
||||||
|
|
||||||
void renderNode(glTFModel::Node* node, uint32_t cbIndex, glTFModel::Material::AlphaMode alphaMode);
|
void renderNode(glTFModel::Node* node, uint32_t cbIndex, glTFModel::Material::AlphaMode alphaMode);
|
||||||
void loadScene(std::string filename);
|
void loadScene(std::string filename);
|
||||||
void loadEnvironment(std::string filename);
|
void loadEnvironment(std::string filename);
|
||||||
|
@ -360,9 +539,9 @@ public:
|
||||||
void updateUniformBuffers();
|
void updateUniformBuffers();
|
||||||
void updateShaderData();
|
void updateShaderData();
|
||||||
void initWindow(int Width,int Height);
|
void initWindow(int Width,int Height);
|
||||||
void framebufferResizeCallback(GLFWwindow* window, int width, int height);
|
static void framebufferResizeCallback(GLFWwindow* window, int width, int height);
|
||||||
|
|
||||||
void windowResized();
|
void windowResized();
|
||||||
void prepare();
|
|
||||||
void submitWork(VkCommandBuffer cmdBuffer, VkQueue queue);
|
void submitWork(VkCommandBuffer cmdBuffer, VkQueue queue);
|
||||||
|
|
||||||
void writeImageToFile(std::string filePath);
|
void writeImageToFile(std::string filePath);
|
||||||
|
@ -374,4 +553,5 @@ public:
|
||||||
virtual void render();
|
virtual void render();
|
||||||
virtual void updateUIOverlay();
|
virtual void updateUIOverlay();
|
||||||
virtual void fileDropped(std::string filename);
|
virtual void fileDropped(std::string filename);
|
||||||
|
void destroyVulkan();
|
||||||
};
|
};
|
Loading…
Reference in New Issue