重构完成,glfw链接失效
parent
31dbcc2aa6
commit
f3212fc19d
|
@ -14,6 +14,7 @@ include_directories(external/tinygltf)
|
|||
include_directories(external/ktx/include)
|
||||
include_directories(external/ktx/other_include)
|
||||
include_directories(external/glfw-3.4/include)
|
||||
include_directories(external/glfw)
|
||||
include_directories(base)
|
||||
|
||||
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 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.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));
|
||||
|
@ -86,7 +87,7 @@ public:
|
|||
float getFarClip() {
|
||||
return zfar;
|
||||
}
|
||||
|
||||
// 投影计算
|
||||
void setPerspective(float fov, float aspect, float znear, float zfar)
|
||||
{
|
||||
this->fov = fov;
|
||||
|
@ -153,6 +154,7 @@ public:
|
|||
{
|
||||
if (moving())
|
||||
{
|
||||
// 相机朝向
|
||||
glm::vec3 camFront;
|
||||
camFront.x = -cos(glm::radians(rotation.x)) * sin(glm::radians(rotation.y));
|
||||
camFront.y = sin(glm::radians(rotation.x));
|
||||
|
@ -161,6 +163,7 @@ public:
|
|||
|
||||
float moveSpeed = deltaTime * movementSpeed;
|
||||
|
||||
// 位置的平移计算
|
||||
if (keys.up)
|
||||
position += camFront * moveSpeed;
|
||||
if (keys.down)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -8,43 +8,17 @@
|
|||
|
||||
#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 <chrono>
|
||||
#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 <sstream>
|
||||
#include <array>
|
||||
#include <numeric>
|
||||
|
||||
|
||||
#include "vulkan/vulkan.h"
|
||||
|
||||
#include "VulkanTools.h"
|
||||
|
@ -54,51 +28,37 @@
|
|||
#include "VulkanDevice.hpp"
|
||||
#include "VulkanSwapChain.hpp"
|
||||
|
||||
#include "imgui/imgui.h"
|
||||
//#include "imgui/imgui.h"
|
||||
|
||||
class VulkanExampleBase
|
||||
{
|
||||
private:
|
||||
float fpsTimer = 0.0f;
|
||||
|
||||
uint32_t frameCounter = 0;
|
||||
uint32_t destWidth;
|
||||
uint32_t destHeight;
|
||||
|
||||
bool resizing = false;
|
||||
void handleMouseMove(int32_t x, int32_t y);
|
||||
//void handleMouseMove(int32_t x, int32_t y);
|
||||
PFN_vkCreateDebugReportCallbackEXT vkCreateDebugReportCallback;
|
||||
PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallback;
|
||||
VkDebugReportCallbackEXT debugReportCallback;
|
||||
struct MultisampleTarget {
|
||||
struct {
|
||||
VkImage image;
|
||||
VkImageView view;
|
||||
VkDeviceMemory memory;
|
||||
} color;
|
||||
struct {
|
||||
VkImage image;
|
||||
VkImageView view;
|
||||
VkDeviceMemory memory;
|
||||
} depth;
|
||||
} multisampleTarget;
|
||||
|
||||
protected:
|
||||
VkInstance instance;
|
||||
VkPhysicalDevice physicalDevice;
|
||||
|
||||
VkPhysicalDeviceProperties deviceProperties;
|
||||
VkPhysicalDeviceFeatures deviceFeatures;
|
||||
|
||||
VkPhysicalDeviceMemoryProperties deviceMemoryProperties;
|
||||
VkDevice device;
|
||||
vks::VulkanDevice *vulkanDevice;
|
||||
|
||||
|
||||
VkQueue queue;
|
||||
VkFormat depthFormat;
|
||||
VkCommandPool cmdPool;
|
||||
VkRenderPass renderPass;
|
||||
|
||||
std::vector<VkFramebuffer>frameBuffers;
|
||||
uint32_t currentBuffer = 0;
|
||||
VkDescriptorPool descriptorPool;
|
||||
VkPipelineCache pipelineCache;
|
||||
VulkanSwapChain swapChain;
|
||||
std::string title = "Vulkan Example";
|
||||
std::string name = "vulkanExample";
|
||||
|
||||
|
||||
//VulkanSwapChain swapChain;
|
||||
void windowResize();
|
||||
public:
|
||||
static std::vector<const char*> args;
|
||||
|
@ -106,67 +66,31 @@ public:
|
|||
bool prepared = false;
|
||||
uint32_t width = 1280;
|
||||
uint32_t height = 720;
|
||||
float frameTimer = 1.0f;
|
||||
Camera camera;
|
||||
glm::vec2 mousePos;
|
||||
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;
|
||||
|
||||
|
||||
bool paused = false;
|
||||
|
||||
|
||||
struct ColorAttachment {
|
||||
VkImage image;
|
||||
VkDeviceMemory memory;
|
||||
VkImageView view;
|
||||
} colorAttachment;
|
||||
|
||||
|
||||
|
||||
|
||||
std::vector<VkImageView> swapChainImageViews;
|
||||
|
||||
|
||||
struct GamePadState {
|
||||
glm::vec2 axisLeft = glm::vec2(0.0f);
|
||||
glm::vec2 axisRight = glm::vec2(0.0f);
|
||||
} gamePadState;
|
||||
|
||||
struct MouseButtons {
|
||||
bool left = false;
|
||||
bool right = false;
|
||||
bool middle = false;
|
||||
} mouseButtons;
|
||||
|
||||
|
||||
|
||||
|
||||
VulkanExampleBase();
|
||||
virtual ~VulkanExampleBase();
|
||||
|
||||
void initVulkan();
|
||||
|
||||
virtual VkResult createInstance(bool enableValidation);
|
||||
virtual void render() = 0;
|
||||
//virtual void render() = 0;
|
||||
virtual void windowResized();
|
||||
virtual void setupFrameBuffer();
|
||||
void createSwapChainFramebuffer();
|
||||
|
@ -178,6 +102,4 @@ public:
|
|||
VkFormat findDepthFormat();
|
||||
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
|
||||
#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 <stdlib.h>
|
||||
|
@ -14,27 +19,34 @@
|
|||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <optional>
|
||||
#include <filesystem>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "VulkanExampleBase.h"
|
||||
//#include "VulkanExampleBase.h"
|
||||
#include "glTFModel.h"
|
||||
#include <VulkanTexture.hpp>
|
||||
#include "VulkanDevice.hpp"
|
||||
#include "ui.hpp"
|
||||
#include <VulkanUtils.hpp>
|
||||
#include <camera.hpp>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define ENABLE_VALIDATION false
|
||||
|
||||
|
||||
|
||||
class PlumageRender : public VulkanExampleBase
|
||||
class PlumageRender
|
||||
{
|
||||
public:
|
||||
bool wireframe = false;
|
||||
|
@ -42,8 +54,41 @@ public:
|
|||
bool ToneMapping = true;
|
||||
bool pbrEnabled = true;
|
||||
|
||||
std::vector<const char*> args;
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
|
@ -56,6 +101,7 @@ public:
|
|||
|
||||
}signal;
|
||||
|
||||
bool prepared = false;
|
||||
|
||||
struct Models
|
||||
{
|
||||
|
@ -106,6 +152,9 @@ public:
|
|||
|
||||
|
||||
}chineseUI;
|
||||
|
||||
VkInstance instance;
|
||||
|
||||
struct UniformBufferSet {
|
||||
Buffer scene;
|
||||
Buffer skybox;
|
||||
|
@ -190,6 +239,27 @@ public:
|
|||
|
||||
} 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;
|
||||
glm::vec3 modelPos = glm::vec3(0.0f);
|
||||
|
@ -303,48 +373,157 @@ public:
|
|||
|
||||
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()
|
||||
{
|
||||
// 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);
|
||||
~PlumageRender();
|
||||
|
||||
|
||||
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();
|
||||
|
||||
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 loadScene(std::string filename);
|
||||
void loadEnvironment(std::string filename);
|
||||
|
@ -360,9 +539,9 @@ public:
|
|||
void updateUniformBuffers();
|
||||
void updateShaderData();
|
||||
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 prepare();
|
||||
void submitWork(VkCommandBuffer cmdBuffer, VkQueue queue);
|
||||
|
||||
void writeImageToFile(std::string filePath);
|
||||
|
@ -374,4 +553,5 @@ public:
|
|||
virtual void render();
|
||||
virtual void updateUIOverlay();
|
||||
virtual void fileDropped(std::string filename);
|
||||
void destroyVulkan();
|
||||
};
|
Loading…
Reference in New Issue