完成将配置类独立

test-headless
ink-soul 2024-04-17 11:26:38 +08:00
parent 014b6e1c4d
commit 8461390496
8 changed files with 106 additions and 96 deletions

View File

@ -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()
{
}

View File

@ -3,6 +3,7 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <glm/glm.hpp>
#include <json.hpp>
#include <vulkan/vulkan.h>
@ -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()
{
}
}

View File

@ -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;

View File

@ -23,6 +23,7 @@
#include <array>
#include <numeric>
#include "renderConfig.h"
#include "vulkan/vulkan.h"
#include "VulkanTools.h"
@ -80,6 +81,10 @@ protected:
//void windowResize();
public:
static std::vector<const char*> 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;

View File

@ -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})

View File

@ -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) // 避免重复改变为true
{
@ -1929,7 +1929,7 @@ PlumageRender::PlumageRender()
void PlumageRender::removeImageSequence()
{
if (savedFrameCounter != settings.startFrameCount)
if (savedFrameCounter != settings.endFrameIndex)
{
if (!signal.imageSequenceToVideoComplete)
{

View File

@ -238,7 +238,7 @@ public:
UI* gui;
uint64_t savedFrameCounter = settings.startFrameCount;
uint64_t savedFrameCounter = settings.startFrameIndex;
PlumageRender();

View File

@ -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;
}