Skip to content

Commit

Permalink
Shader serialization mostly complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Raikiri committed Oct 13, 2024
1 parent a1ed88d commit 48d8c78
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions source/LegitScriptEmBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,50 @@ namespace ls
instance.reset(new ls::LegitScript(slider_float_func, slider_int_func, text_func));
}

json SerializeSamplers(const std::vector<ls::ScriptShaderDesc::Sampler> samplers)
{
auto arr = json::array();
for(auto sampler : samplers)
{
arr.push_back(json::object({{"type", sampler.type}, {"name", sampler.name}}));
}
return arr;
}
json SerializeUniforms(const std::vector<ls::ScriptShaderDesc::Uniform> uniforms)
{
auto arr = json::array();
for(auto uniform : uniforms)
{
arr.push_back(json::object({{"type", uniform.type}, {"name", uniform.name}}));
}
return arr;
}
json SerializeInouts(const std::vector<ls::ScriptShaderDesc::Inouts> inouts)
{
auto arr = json::array();
for(auto inout : inouts)
{
arr.push_back(json::object({{"type", inout.type}, {"name", inout.name}}));
}
return arr;
}
std::string OutputShaderDescsJson(const ls::ScriptShaderDescs &descs)
{
auto arr = json::array();
for(auto desc : descs)
{
json json_desc = {{"name", desc.name}, {"body", desc.body}};
json json_desc;
json_desc["name"] = desc.name;
json_desc["body"] = desc.body;
json_desc["samplers"] = SerializeSamplers(desc.samplers);
json_desc["uniforms"] = SerializeUniforms(desc.uniforms);
json_desc["outs"] = SerializeInouts(desc.outs);
arr.push_back(json_desc);
}

return std::string(arr.dump(2));
json shader_descs_json;
shader_descs_json["shader_descs"] = arr;
return std::string(shader_descs_json.dump(2));
}

std::string LoadScript(std::string script_source)
Expand Down

0 comments on commit 48d8c78

Please sign in to comment.