diff --git a/base/renderConfig.cpp b/base/renderConfig.cpp new file mode 100644 index 0000000..ec0315a --- /dev/null +++ b/base/renderConfig.cpp @@ -0,0 +1,46 @@ +#include "renderConfig.h" + +void PlumageConfig::PlumageConfiguration::writrConfigurationToJson() +{ + nlohmann::json configJson = nlohmann::json + { + {"width",settings.width}, + {"height",settings.height}, + {"validation",settings.validation}, + {"fullscreen",settings.fullscreen}, + {"vsync",settings.vsync}, + {"multiSampling",settings.multiSampling}, + {"rotateModel",settings.rotateModel}, + //{"headless",settings.headless}, + //{"outputPNGimage",settings.outputPNGimage}, + //{"enableSaveToImageSequeue",settings.enableSaveToImageSequeue}, + {"outputFrameCount",settings.endFrameIndex}, + //{"takeScreenShot",settings.takeScreenShot}, + {"startFrameCount",settings.endFrameIndex}, + {"videoFrameRate",settings.videoFrameRate}, + {"sampleCount",settings.sampleCount}, + //{"",settings.}, + //{"",settings.} + }; + + + std::ofstream configJsonFile(filePath.configFilePath); + std::setw(4); + //configJson >> configJsonFile; + configJsonFile << configJson; +} + +void PlumageConfig::PlumageConfiguration::readConfigurationToJson(std::string configFilePath) +{ + nlohmann::json configJsonFile; + std::ifstream jfile("test.json"); + jfile >> configJsonFile; +} + +PlumageConfig::PlumageConfiguration::PlumageConfiguration() +{ +} + +PlumageConfig::PlumageConfiguration::~PlumageConfiguration() +{ +} \ No newline at end of file diff --git a/src/render/renderConfig.h b/base/renderConfig.h similarity index 86% rename from src/render/renderConfig.h rename to base/renderConfig.h index 4b76611..206885d 100644 --- a/src/render/renderConfig.h +++ b/base/renderConfig.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -14,8 +15,7 @@ namespace PlumageConfig class PlumageConfiguration { public: - PlumageConfiguration(); - ~PlumageConfiguration(); + struct Settings { uint32_t width = 1280; @@ -24,19 +24,26 @@ namespace PlumageConfig bool fullscreen = false; // 全屏开关 bool vsync = false; // 垂直同步开关 bool multiSampling = false; // 多重采样 - bool rotateModel = true; // 模型自旋转(暂时失效) + VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_4_BIT; // 多重采样倍率 + bool rotateModel = true; // 模型自旋转 + uint32_t modelRotateSpeed = 2; bool headless = false; // 无头开关 bool outputPNGimage = false; - bool enableSaveToImageSequeue = true; // 图片序列开关(暂时弃用) - uint32_t outputFrameCount = 50; // 图片序列结束帧 - bool takeScreenShot = false; // 截屏(暂时弃用) - uint32_t startFrameCount = 1; // 图片序列开始帧 + //bool enableSaveToImageSequeue = true; // 图片序列开关(暂时弃用) + uint32_t startFrameIndex = 1; // 图片序列开始帧 + uint32_t endFrameIndex = 50; // 图片序列结束帧 + uint32_t videoFrameRate = 25; // 视频帧率 + uint32_t selectedPhysicalDeviceIndex = 0; + float fovX; + float fovY; + float cX; + float cY; + glm::vec3 bottomCenter; + glm::vec3 bottomNormal; - uint32_t videoFrameRate = 25; - - VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_4_BIT; // 多重采样倍率 - } settings; + }settings; + struct FilePath { //model path std::string glTFModelFilePath = getAssetPath() + "models/DamagedHelmet/DamagedHelmet.gltf"; @@ -88,26 +95,24 @@ namespace PlumageConfig // script file path std::string image2videoBatFilePath = getAssetPath() + "script/image2video.bat"; std::string image2videoShFilePath = getAssetPath() + "script/image2video.sh"; - + // 配置文件路径,命令行传入后保存在这 std::string configFilePath = getAssetPath() + "config/config.json"; } filePath; - + void writrConfigurationToJson(); void readConfigurationToJson(std::string configFilePath); + PlumageConfiguration(); + ~PlumageConfiguration(); + private: }; - - PlumageConfiguration::PlumageConfiguration() - { - } - - PlumageConfiguration::~PlumageConfiguration() - { - } + + + } diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index b8e704b..4ae3c01 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -53,7 +53,7 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation) if (!settings.headless) { - instanceExtensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME); + //instanceExtensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME); // Enable surface extensions depending on os #if defined(_WIN32) instanceExtensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); @@ -78,6 +78,7 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation) + VkInstanceCreateInfo instanceCreateInfo = {}; instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; instanceCreateInfo.pNext = NULL; @@ -87,11 +88,11 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation) instanceCreateInfo.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; #endif + if (settings.validation) { + instanceExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); + } if (instanceExtensions.size() > 0) { - if (settings.validation) { - instanceExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); - } instanceCreateInfo.enabledExtensionCount = (uint32_t)instanceExtensions.size(); instanceCreateInfo.ppEnabledExtensionNames = instanceExtensions.data(); } @@ -356,11 +357,11 @@ VulkanExampleBase::VulkanExampleBase() } if ((args[i] == std::string("-w")) || (args[i] == std::string("--width"))) { uint32_t w = strtol(args[i + 1], &numConvPtr, 10); - if (numConvPtr != args[i + 1]) { width = w; }; + if (numConvPtr != args[i + 1]) { settings.width = w; }; } if ((args[i] == std::string("-h")) || (args[i] == std::string("--height"))) { uint32_t h = strtol(args[i + 1], &numConvPtr, 10); - if (numConvPtr != args[i + 1]) { height = h; }; + if (numConvPtr != args[i + 1]) { settings.height = h; }; } } /* @@ -568,8 +569,8 @@ void VulkanExampleBase::setupFrameBuffer() imageCI.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; imageCI.imageType = VK_IMAGE_TYPE_2D; imageCI.format = colorFormat; - imageCI.extent.width = width; - imageCI.extent.height = height; + imageCI.extent.width = settings.width; + imageCI.extent.height = settings.height; imageCI.extent.depth = 1; imageCI.mipLevels = 1; imageCI.arrayLayers = 1; @@ -611,8 +612,8 @@ void VulkanExampleBase::setupFrameBuffer() // Depth target imageCI.imageType = VK_IMAGE_TYPE_2D; imageCI.format = depthFormat; - imageCI.extent.width = width; - imageCI.extent.height = height; + imageCI.extent.width = settings.width; + imageCI.extent.height = settings.height; imageCI.extent.depth = 1; imageCI.mipLevels = 1; imageCI.arrayLayers = 1; @@ -652,8 +653,8 @@ void VulkanExampleBase::setupFrameBuffer() VkImageCreateInfo image = vks::initializers::imageCreateInfo(); image.imageType = VK_IMAGE_TYPE_2D; image.format = colorFormat; - image.extent.width = width; - image.extent.height = height; + image.extent.width = settings.width; + image.extent.height = settings.height; image.extent.depth = 1; image.mipLevels = 1; image.arrayLayers = 1; @@ -692,7 +693,7 @@ void VulkanExampleBase::setupFrameBuffer() depthImageCI.pNext = NULL; depthImageCI.imageType = VK_IMAGE_TYPE_2D; depthImageCI.format = depthFormat; - depthImageCI.extent = { width, height, 1 }; + depthImageCI.extent = { settings.width, settings.height, 1 }; depthImageCI.mipLevels = 1; depthImageCI.arrayLayers = 1; depthImageCI.samples = VK_SAMPLE_COUNT_1_BIT; @@ -751,12 +752,12 @@ void VulkanExampleBase::setupFrameBuffer() frameBufferCI.renderPass = renderPass; frameBufferCI.attachmentCount = settings.multiSampling ? 4 :2; frameBufferCI.pAttachments = attachments; - frameBufferCI.width = width; - frameBufferCI.height = height; + frameBufferCI.width = settings.width; + frameBufferCI.height = settings.height; frameBufferCI.layers = 1; // Create frame buffers for every swap chain image - frameBuffers.resize(settings.outputFrameCount - settings.startFrameCount + 1); + frameBuffers.resize(settings.endFrameIndex - settings.startFrameIndex + 1); for (uint32_t i = 0; i < frameBuffers.size(); i++) { if (settings.multiSampling) { attachments[1] = colorAttachment.view; diff --git a/base/vulkanexamplebase.h b/base/vulkanexamplebase.h index 8a7b941..5a7f84a 100644 --- a/base/vulkanexamplebase.h +++ b/base/vulkanexamplebase.h @@ -23,6 +23,7 @@ #include #include +#include "renderConfig.h" #include "vulkan/vulkan.h" #include "VulkanTools.h" @@ -80,6 +81,10 @@ protected: //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; @@ -100,26 +105,8 @@ public: }signal; - struct Settings { - uint32_t width = 1280; - uint32_t height = 720; - bool validation = true; // 鏍¢獙灞傚紑鍏 - bool fullscreen = false; // 鍏ㄥ睆寮鍏 - bool vsync = false; // 鍨傜洿鍚屾寮鍏 - bool multiSampling = false; // 澶氶噸閲囨牱 - bool rotateModel = true; // 妯″瀷鑷棆杞(鏆傛椂澶辨晥) - bool headless = false; // 鏃犲ご寮鍏 - bool outputPNGimage = false; - bool enableSaveToImageSequeue = true; // 鍥剧墖搴忓垪寮鍏筹紙鏆傛椂寮冪敤锛 - uint32_t outputFrameCount = 50; // 鍥剧墖搴忓垪缁撴潫甯 - bool takeScreenShot = false; // 鎴睆锛堟殏鏃跺純鐢級 - uint32_t startFrameCount = 1; // 鍥剧墖搴忓垪寮濮嬪抚 - - uint32_t videoFrameRate = 25; - - VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_4_BIT; // 澶氶噸閲囨牱鍊嶇巼 - } settings; - + + /* struct FilePath { //model path std::string glTFModelFilePath = getAssetPath() + "models/DamagedHelmet/DamagedHelmet.gltf"; @@ -173,7 +160,7 @@ public: std::string image2videoShFilePath = getAssetPath() + "script/image2video.sh"; } filePath; - + */ struct DepthStencil { VkImage image; VkDeviceMemory mem; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 662877a..1f4173d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,8 +33,11 @@ function(buildHomework HOMEWORK_NAME) add_executable(${HOMEWORK_NAME} ${MAIN_CPP} ${SOURCE} ${MAIN_HEADER} ${SHADERS_GLSL} ${SHADERS_HLSL} ${README_FILES} "render/glTFModel.h" "render/glTFModel.cpp" + #"render/render.h" + #"render/render.cpp" - "render/renderFoundation.h" "render/renderFoundation.cpp" "render/renderConfig.cpp" "render/renderConfig.h") + + ) target_link_libraries(${HOMEWORK_NAME} base ${Vulkan_LIBRARY}) else(WIN32) add_executable(${HOMEWORK_NAME} ${MAIN_CPP} ${SOURCE} ${MAIN_HEADER} ${SHADERS_GLSL} ${SHADERS_HLSL} ${README_FILES}) diff --git a/src/render/render.cpp b/src/render/render.cpp index ac844b4..c3df350 100644 --- a/src/render/render.cpp +++ b/src/render/render.cpp @@ -1548,7 +1548,7 @@ PlumageRender::PlumageRender() camera.rotationSpeed = 0.25f; camera.movementSpeed = 0.1f; - auto frameRange = settings.outputFrameCount - settings.startFrameCount + 1; + auto frameRange = settings.endFrameIndex - settings.startFrameIndex + 1; waitFences.resize(renderAhead); presentCompleteSemaphores.resize(renderAhead); @@ -1841,7 +1841,7 @@ PlumageRender::PlumageRender() void PlumageRender::outputImageSequence() { - if (savedFrameCounter == settings.startFrameCount) + if (savedFrameCounter == settings.startFrameIndex) { std::cout << "clean up directory for image sequence generation" << std::endl; removeImageSequence(); @@ -1849,7 +1849,7 @@ PlumageRender::PlumageRender() filePath.deviceSpecFilePath = filePath.imageOutputPath + "/device" + std::to_string(selectedPhysicalDeviceIndex); - if (savedFrameCounter > settings.outputFrameCount) + if (savedFrameCounter > settings.endFrameIndex) { if (signal.imageSequenceOutputComplete) // 閬垮厤閲嶅鏀瑰彉涓簍rue { @@ -1929,7 +1929,7 @@ PlumageRender::PlumageRender() void PlumageRender::removeImageSequence() { - if (savedFrameCounter != settings.startFrameCount) + if (savedFrameCounter != settings.endFrameIndex) { if (!signal.imageSequenceToVideoComplete) { diff --git a/src/render/render.h b/src/render/render.h index 17c112b..9fb871b 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -238,7 +238,7 @@ public: UI* gui; - uint64_t savedFrameCounter = settings.startFrameCount; + uint64_t savedFrameCounter = settings.startFrameIndex; PlumageRender(); diff --git a/src/render/renderConfig.cpp b/src/render/renderConfig.cpp deleted file mode 100644 index 262ed3c..0000000 --- a/src/render/renderConfig.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "renderConfig.h" - -void PlumageConfig::PlumageConfiguration::writrConfigurationToJson() -{ - nlohmann::json configJsonFile = nlohmann::json - { - {"width",settings.width}, - {"height",settings.height}, - {"validation",settings.validation}, - {"fullscreen",settings.fullscreen}, - {"vsync",settings.vsync}, - {"multiSampling",settings.multiSampling}, - {"rotateModel",settings.rotateModel}, - {"headless",settings.headless}, - {"outputPNGimage",settings.outputPNGimage}, - {"enableSaveToImageSequeue",settings.enableSaveToImageSequeue}, - {"outputFrameCount",settings.outputFrameCount}, - {"takeScreenShot",settings.takeScreenShot}, - {"startFrameCount",settings.startFrameCount}, - {"videoFrameRate",settings.videoFrameRate}, - {"sampleCount",settings.sampleCount}, - {"",settings.}, - {"",settings.} - }; -} - -void PlumageConfig::PlumageConfiguration::readConfigurationToJson(std::string configFilePath) -{ - nlohmann::json configJsonFile; - std::ifstream jfile("test.json"); - jfile >> configJsonFile; -}