添加JSONTOOL类到工程中
This commit is contained in:
parent
d2cad7bf2f
commit
ac0939faa4
@ -52,6 +52,7 @@ add_subdirectory(3rdpty/NvTriStrip)
|
||||
add_subdirectory(src)
|
||||
|
||||
SET(ULRE ULRE.Base
|
||||
ULRE.Util
|
||||
ULRE.RenderDevice.Vulkan
|
||||
ULRE.Platform
|
||||
MathGeoLib
|
||||
|
@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
#include<hgl/platform/Window.h>
|
||||
#include<hgl/graph/vulkan/VKInstance.h>
|
||||
#include<hgl/graph/vulkan/VKPhysicalDevice.h>
|
||||
@ -36,8 +36,8 @@ public:
|
||||
virtual ~VulkanApplicationFramework()
|
||||
{
|
||||
SAFE_CLEAR(shader_manage);
|
||||
SAFE_CLEAR(win); //win中会删除device,所以必须放在instance前删除
|
||||
SAFE_CLEAR(inst);
|
||||
SAFE_CLEAR(win);
|
||||
}
|
||||
|
||||
virtual bool Init(int w,int h)
|
||||
|
@ -26,7 +26,7 @@ class Device
|
||||
|
||||
private:
|
||||
|
||||
void CreateMainBufferAndPass();
|
||||
void CreateMainFramebuffer();
|
||||
|
||||
private:
|
||||
|
||||
|
@ -12,7 +12,7 @@ inline hgl::OSString ToOSString(const std::string &str)
|
||||
|
||||
inline std::string ToStdString(const hgl::OSString &str)
|
||||
{
|
||||
UTF8String u8_str=hgl::to_u8(str);
|
||||
hgl::UTF8String u8_str=hgl::to_u8(str);
|
||||
|
||||
return std::string(u8_str.c_str());
|
||||
}
|
||||
@ -30,6 +30,6 @@ inline std::string ToStdString(const hgl::OSString &str)
|
||||
|
||||
inline hgl::UTF8String ToUTF8String(const std::string &str)
|
||||
{
|
||||
return hgl::UTF8String(str.c_str(),str.size());
|
||||
return hgl::UTF8String(str.c_str(),int(str.size()));
|
||||
}
|
||||
|
||||
|
11
inc/hgl/util/JsonTool.h
Normal file
11
inc/hgl/util/JsonTool.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include<string>
|
||||
#include<json/json.h>
|
||||
#include<hgl/type/BaseString.h>
|
||||
|
||||
const std::string JsonToString(const Json::Value &jv_root);
|
||||
|
||||
bool ParseJson(Json::Value &root,const char *str,const int size,std::string *error_info);
|
||||
|
||||
bool LoadJson(Json::Value &,const hgl::OSString &filename);
|
||||
bool SaveJson(Json::Value &,const hgl::OSString &filename);
|
@ -1,3 +1,4 @@
|
||||
add_subdirectory(Base)
|
||||
add_subdirectory(Util)
|
||||
add_subdirectory(RenderDevice)
|
||||
add_subdirectory(Platform)
|
||||
|
@ -49,11 +49,11 @@ SET(RENDER_DEVICE_VULKAN_SOURCE VKFormat.cpp
|
||||
VKRenderable.cpp)
|
||||
|
||||
#SET(RENDER_DEVICE_VULKAN_TOML_SOURCE toml/VKPipelineCreateInfo.TOML.cpp)
|
||||
#SET(RENDER_DEVICE_VULKAN_JSON_SOURCE json/VKPipelineCreateInfo.JSON.cpp)
|
||||
SET(RENDER_DEVICE_VULKAN_JSON_SOURCE json/VKPipelineCreateInfo.JSON.cpp)
|
||||
|
||||
SOURCE_GROUP("Header Files" FILES ${RENDER_DEVICE_VULKAN_HEADER})
|
||||
SOURCE_GROUP("Source Files" FILES ${RENDER_DEVICE_VULKAN_SOURCE})
|
||||
#SOURCE_GROUP("JSON Source Files" FILES ${RENDER_DEVICE_VULKAN_JSON_SOURCE})
|
||||
SOURCE_GROUP("JSON Source Files" FILES ${RENDER_DEVICE_VULKAN_JSON_SOURCE})
|
||||
|
||||
add_library(ULRE.RenderDevice.Vulkan STATIC ${RENDER_DEVICE_VULKAN_HEADER}
|
||||
${RENDER_DEVICE_VULKAN_SOURCE}
|
||||
|
@ -30,7 +30,9 @@ Device::Device(DeviceAttribute *da)
|
||||
present.waitSemaphoreCount = 0;
|
||||
present.pResults = nullptr;
|
||||
|
||||
CreateMainBufferAndPass();
|
||||
main_rp=CreateRenderPass(attr->sc_image_views[0]->GetFormat(),attr->depth.view->GetFormat());
|
||||
|
||||
CreateMainFramebuffer();
|
||||
}
|
||||
|
||||
Device::~Device()
|
||||
@ -45,12 +47,10 @@ Device::~Device()
|
||||
delete attr;
|
||||
}
|
||||
|
||||
void Device::CreateMainBufferAndPass()
|
||||
void Device::CreateMainFramebuffer()
|
||||
{
|
||||
const int sc_count=attr->sc_image_views.GetCount();
|
||||
|
||||
main_rp=CreateRenderPass(attr->sc_image_views[0]->GetFormat(),attr->depth.view->GetFormat());
|
||||
|
||||
for(int i=0;i<sc_count;i++)
|
||||
main_fb.Add(vulkan::CreateFramebuffer(this,main_rp,attr->sc_image_views[i],attr->depth.view));
|
||||
}
|
||||
@ -58,14 +58,11 @@ void Device::CreateMainBufferAndPass()
|
||||
bool Device::Resize(uint width,uint height)
|
||||
{
|
||||
main_fb.Clear();
|
||||
delete main_rp;
|
||||
main_rp=nullptr;
|
||||
|
||||
if(!ResizeRenderDevice(attr,width,height))
|
||||
return(false);
|
||||
|
||||
CreateMainBufferAndPass();
|
||||
|
||||
CreateMainFramebuffer();
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<toml.hpp>
|
||||
#include<json/json.h>
|
||||
#include<vulkan/vulkan.h>
|
||||
#include<hgl/type/BaseString.h>
|
||||
#include<sstream>
|
||||
@ -104,13 +104,8 @@ TOML_END
|
||||
|
||||
TOML_BEGIN(VkPipelineInputAssemblyStateCreateInfo)
|
||||
{
|
||||
TOML_INTEGER(topology),
|
||||
TOML_BOOL(primitiveRestartEnable)
|
||||
}
|
||||
TOML_END
|
||||
Json::Value root;
|
||||
|
||||
void SaveToTOML(const OSString &filename,const VkGraphicsPipelineCreateInfo *info)
|
||||
{
|
||||
const auto root=toml::table
|
||||
{
|
||||
{"ver",toml::table{{"file",100},{"vulkan",100}}},
|
||||
|
1
src/Util/CMakeLists.txt
Normal file
1
src/Util/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
add_library(ULRE.Util STATIC JsonTool.cpp)
|
72
src/Util/JsonTool.cpp
Normal file
72
src/Util/JsonTool.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
#include<string>
|
||||
#include<sstream>
|
||||
#include<json/json.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/type/StdString.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::filesystem;
|
||||
using namespace std;
|
||||
|
||||
const std::string JsonToString(const Json::Value &jv_root)
|
||||
{
|
||||
Json::StreamWriterBuilder builder;
|
||||
Json::StreamWriter *writer=builder.newStreamWriter();
|
||||
|
||||
JSONCPP_OSTRINGSTREAM result;
|
||||
|
||||
writer->write(jv_root,&result);
|
||||
|
||||
delete writer;
|
||||
|
||||
return std::string(result.str());
|
||||
}
|
||||
|
||||
bool ParseJson(Json::Value &root,const char *txt,const int size,std::string *error_info)
|
||||
{
|
||||
Json::CharReaderBuilder builder;
|
||||
Json::CharReader *reader=builder.newCharReader();
|
||||
|
||||
const bool result=reader->parse(txt,txt+size,&root,error_info);
|
||||
|
||||
delete reader;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool LoadJson(Json::Value &root,const OSString &filename)
|
||||
{
|
||||
char *txt;
|
||||
int size;
|
||||
|
||||
size=LoadFileToMemory(filename,(void **)&txt);
|
||||
|
||||
if(size<=0)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("load json file failed,filename: ")+filename);
|
||||
return(false);
|
||||
}
|
||||
|
||||
bool result;
|
||||
|
||||
std::string error_info;
|
||||
|
||||
result=ParseJson(root,txt,size,&error_info);
|
||||
delete[] txt;
|
||||
|
||||
if(!result)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("parse json file failed,filename: ")+filename);
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool SaveJson(Json::Value &root,const OSString &filename)
|
||||
{
|
||||
const std::string txt=JsonToString(root);
|
||||
|
||||
return SaveMemoryToFile(filename,txt.c_str(),txt.size());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user