/* * Vulkan Example base class * * Copyright (C) 2016 by Sascha Willems - www.saschawillems.de * * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) */ #pragma once #include #include #include #define GLM_FORCE_RADIANS #define GLM_FORCE_DEPTH_ZERO_TO_ONE #define GLM_ENABLE_EXPERIMENTAL //#define GLM_FORCE_LEFT_HANDED #include #include #include #include #include #include #include "renderConfig.h" #include "vulkan/vulkan.h" #include "VulkanTools.h" #include "camera.hpp" #include "keycodes.hpp" #include "VulkanDevice.hpp" //#include "VulkanSwapChain.hpp" //#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); 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::vectorframeBuffers; uint32_t currentBuffer = 0; VkDescriptorPool descriptorPool; VkPipelineCache pipelineCache; //VulkanSwapChain swapChain; std::string title = "Vulkan Example"; std::string name = "vulkanExample"; //void windowResize(); public: static std::vector args; // temporary PlumageConfig::PlumageConfiguration setter; PlumageConfig::PlumageConfiguration::Settings settings = setter.settings; PlumageConfig::PlumageConfiguration::FilePath filePath = setter.filePath; uint32_t selectedPhysicalDeviceIndex = 0; bool prepared = false; float frameTimer = 1.0f; Camera camera; glm::vec2 mousePos; bool paused = false; uint32_t lastFPS = 0; VkFormat colorFormat = VK_FORMAT_R8G8B8A8_SRGB; uint32_t queueFamilyIndex; uint32_t renderingFrameIndex = 3; struct Signal { bool imageSequenceOutputComplete = false; bool imageSequenceToVideoComplete = false; }signal; /* struct FilePath { //model path std::string glTFModelFilePath = getAssetPath() + "models/DamagedHelmet/DamagedHelmet.gltf"; std::string modelVertShaderPath = getAssetPath() + "buster_drone/shaders/glsl/mesh.vert.spv"; std::string modelFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/mesh.frag.spv"; //ui std::string uiVertShaderPath = getAssetPath() + "shaders/ui.vert.spv"; std::string uiFragShaderPath = getAssetPath() + "shaders/ui.frag.spv"; // skybox path std::string skyboxModleFilePath = getAssetPath() + "models/cube.gltf"; std::string skyboxVertShaderPath = getAssetPath() + "shaders/skybox.vert.spv"; std::string skyboxFragShaderPath = getAssetPath() + "shaders/skybox.frag.spv"; std::string iblTexturesFilePath = getAssetPath() + "textures/hdr/gcanyon_cube.ktx"; //tonemapping std::string tonemappingVertShaderPath = getAssetPath() + "buster_drone/shaders/glsl/genbrdflut.vert.spv"; std::string tonemappingEnableFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/tonemapping_enable.frag.spv"; std::string tonemappingDisableFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/tonemapping_disable.frag.spv"; // cube map std::string irradianceFragShaderPath = getAssetPath() + "shaders/irradiancecube.frag.spv"; std::string filterVertShaderPath = getAssetPath() + "shaders/filtercube.vert.spv"; std::string prefilterEnvmapFragShaderPath = getAssetPath() + "shaders/prefilterenvmap.frag.spv"; //brdf cube map std::string brdfVertShaderPath = getAssetPath() + "shaders/genbrdflut.vert.spv"; std::string brdfFragShaderPath = getAssetPath() + "shaders/genbrdflut.frag.spv"; // environment map texture std::string envMapFilePath = getAssetPath() + "environments/metro_noord_4k_hdr16f_cube.ktx"; std::string emptyEnvmapFilePath = getAssetPath() + "textures/empty.ktx"; // pbr shader std::string pbrVertShaderPath = getAssetPath() + "shaders/pbr.vert.spv"; std::string pbrFragShaderPath = getAssetPath() + "shaders/pbr_khr.frag.spv"; //ttf file path std::string ttfFilePath = getAssetPath() + "/data/Roboto-Medium.ttf"; // output file path std::string imageOutputPath = getAssetPath() + "output/imageSequence"; std::string videoOutputPath = getAssetPath() + "output/video"; std::string totalImageOutputPath; std::string deviceSpecFilePath; // script file path std::string image2videoBatFilePath = getAssetPath() + "script/image2video.bat"; std::string image2videoShFilePath = getAssetPath() + "script/image2video.sh"; } filePath; */ struct DepthStencil { VkImage image; VkDeviceMemory mem; VkImageView view; } depthStencil; struct ColorAttachment { VkImage image; VkDeviceMemory memory; VkImageView view; } colorAttachment; 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; // OS specific VulkanExampleBase(); virtual ~VulkanExampleBase(); void initVulkan(); virtual VkResult createInstance(bool enableValidation); virtual void render() = 0; //virtual void windowResized(); virtual void setupFrameBuffer(); virtual void prepare(); virtual void fileDropped(std::string filename); void initSwapchain(); void setupSwapChain(); void renderLoop(); void renderFrame(); };