|
@@ -1,15 +1,17 @@
|
|
|
#include "anki/resource/MaterialShaderProgramCreator.h"
|
|
#include "anki/resource/MaterialShaderProgramCreator.h"
|
|
|
#include "anki/util/Assert.h"
|
|
#include "anki/util/Assert.h"
|
|
|
#include "anki/util/Exception.h"
|
|
#include "anki/util/Exception.h"
|
|
|
-#include <boost/property_tree/ptree.hpp>
|
|
|
|
|
|
|
+#include "anki/misc/Xml.h"
|
|
|
|
|
+#include <algorithm>
|
|
|
|
|
+#include <sstream>
|
|
|
|
|
|
|
|
namespace anki {
|
|
namespace anki {
|
|
|
|
|
|
|
|
//==============================================================================
|
|
//==============================================================================
|
|
|
MaterialShaderProgramCreator::MaterialShaderProgramCreator(
|
|
MaterialShaderProgramCreator::MaterialShaderProgramCreator(
|
|
|
- const boost::property_tree::ptree& pt)
|
|
|
|
|
|
|
+ const XmlElement& el)
|
|
|
{
|
|
{
|
|
|
- parseShaderProgramTag(pt);
|
|
|
|
|
|
|
+ parseShaderProgramTag(el);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
//==============================================================================
|
|
@@ -18,20 +20,16 @@ MaterialShaderProgramCreator::~MaterialShaderProgramCreator()
|
|
|
|
|
|
|
|
//==============================================================================
|
|
//==============================================================================
|
|
|
void MaterialShaderProgramCreator::parseShaderProgramTag(
|
|
void MaterialShaderProgramCreator::parseShaderProgramTag(
|
|
|
- const boost::property_tree::ptree& pt)
|
|
|
|
|
|
|
+ const XmlElement& shaderProgramEl)
|
|
|
{
|
|
{
|
|
|
- using namespace boost::property_tree;
|
|
|
|
|
|
|
+ XmlElement shaderEl = shaderProgramEl.getChildElement("shader");
|
|
|
|
|
|
|
|
- for(const ptree::value_type& v : pt)
|
|
|
|
|
|
|
+ do
|
|
|
{
|
|
{
|
|
|
- if(v.first != "shader")
|
|
|
|
|
- {
|
|
|
|
|
- throw ANKI_EXCEPTION("Expected \"shader\" tag and not: "
|
|
|
|
|
- + v.first);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- parseShaderTag(v.second);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ parseShaderTag(shaderEl);
|
|
|
|
|
+
|
|
|
|
|
+ shaderEl = shaderEl.getNextSiblingElement("shader");
|
|
|
|
|
+ } while(shaderEl);
|
|
|
|
|
|
|
|
source = srcLines.join("\n");
|
|
source = srcLines.join("\n");
|
|
|
//std::cout << source << std::endl;
|
|
//std::cout << source << std::endl;
|
|
@@ -39,57 +37,49 @@ void MaterialShaderProgramCreator::parseShaderProgramTag(
|
|
|
|
|
|
|
|
//==============================================================================
|
|
//==============================================================================
|
|
|
void MaterialShaderProgramCreator::parseShaderTag(
|
|
void MaterialShaderProgramCreator::parseShaderTag(
|
|
|
- const boost::property_tree::ptree& pt)
|
|
|
|
|
|
|
+ const XmlElement& shaderEl)
|
|
|
{
|
|
{
|
|
|
- using namespace boost::property_tree;
|
|
|
|
|
-
|
|
|
|
|
// <type></type>
|
|
// <type></type>
|
|
|
//
|
|
//
|
|
|
- const std::string& type = pt.get<std::string>("type");
|
|
|
|
|
|
|
+ std::string type = shaderEl.getChildElement("type").getText();
|
|
|
srcLines.push_back("#pragma anki start " + type + "Shader");
|
|
srcLines.push_back("#pragma anki start " + type + "Shader");
|
|
|
|
|
|
|
|
// <includes></includes>
|
|
// <includes></includes>
|
|
|
//
|
|
//
|
|
|
std::vector<std::string> includeLines;
|
|
std::vector<std::string> includeLines;
|
|
|
|
|
|
|
|
- const ptree& includesPt = pt.get_child("includes");
|
|
|
|
|
- for(const ptree::value_type& v : includesPt)
|
|
|
|
|
|
|
+ XmlElement includesEl = shaderEl.getChildElement("includes");
|
|
|
|
|
+ XmlElement includeEl = includesEl.getChildElement("include");
|
|
|
|
|
+
|
|
|
|
|
+ do
|
|
|
{
|
|
{
|
|
|
- if(v.first != "include")
|
|
|
|
|
- {
|
|
|
|
|
- throw ANKI_EXCEPTION("Expected \"include\" tag and not: " +
|
|
|
|
|
- v.first);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ std::string fname = includeEl.getText();
|
|
|
|
|
+ includeLines.push_back(std::string("#pragma anki include \"")
|
|
|
|
|
+ + fname + "\"");
|
|
|
|
|
|
|
|
- const std::string& fname = v.second.data();
|
|
|
|
|
- includeLines.push_back(std::string("#pragma anki include \"") +
|
|
|
|
|
- fname + "\"");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ includeEl = includeEl.getNextSiblingElement("include");
|
|
|
|
|
+ } while(includeEl);
|
|
|
|
|
|
|
|
//std::sort(includeLines.begin(), includeLines.end(), compareStrings);
|
|
//std::sort(includeLines.begin(), includeLines.end(), compareStrings);
|
|
|
srcLines.insert(srcLines.end(), includeLines.begin(), includeLines.end());
|
|
srcLines.insert(srcLines.end(), includeLines.begin(), includeLines.end());
|
|
|
|
|
|
|
|
// <inputs></inputs>
|
|
// <inputs></inputs>
|
|
|
//
|
|
//
|
|
|
- boost::optional<const ptree&> insPt = pt.get_child_optional("inputs");
|
|
|
|
|
- if(insPt)
|
|
|
|
|
|
|
+ XmlElement inputsEl = shaderEl.getChildElementOptional("inputs");
|
|
|
|
|
+ if(inputsEl)
|
|
|
{
|
|
{
|
|
|
// Store the source of the uniform vars
|
|
// Store the source of the uniform vars
|
|
|
std::vector<std::string> uniformsLines;
|
|
std::vector<std::string> uniformsLines;
|
|
|
|
|
|
|
|
- for(const ptree::value_type& v : insPt.get())
|
|
|
|
|
|
|
+ XmlElement inputEl = inputsEl.getChildElement("input");
|
|
|
|
|
+ do
|
|
|
{
|
|
{
|
|
|
- if(v.first != "input")
|
|
|
|
|
- {
|
|
|
|
|
- throw ANKI_EXCEPTION("Expected \"input\" tag and not: "
|
|
|
|
|
- + v.first);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const ptree& inPt = v.second;
|
|
|
|
|
std::string line;
|
|
std::string line;
|
|
|
- parseInputTag(inPt, line);
|
|
|
|
|
|
|
+ parseInputTag(inputEl, line);
|
|
|
uniformsLines.push_back(line);
|
|
uniformsLines.push_back(line);
|
|
|
- } // end for all ins
|
|
|
|
|
|
|
+
|
|
|
|
|
+ inputEl = inputEl.getNextSiblingElement("input");
|
|
|
|
|
+ } while(inputEl);
|
|
|
|
|
|
|
|
srcLines.push_back("");
|
|
srcLines.push_back("");
|
|
|
std::sort(uniformsLines.begin(), uniformsLines.end(), compareStrings);
|
|
std::sort(uniformsLines.begin(), uniformsLines.end(), compareStrings);
|
|
@@ -101,79 +91,60 @@ void MaterialShaderProgramCreator::parseShaderTag(
|
|
|
//
|
|
//
|
|
|
srcLines.push_back("\nvoid main()\n{");
|
|
srcLines.push_back("\nvoid main()\n{");
|
|
|
|
|
|
|
|
- const ptree& opsPt = pt.get_child("operations");
|
|
|
|
|
-
|
|
|
|
|
- for(const ptree::value_type& v : opsPt)
|
|
|
|
|
|
|
+ XmlElement opsEl = shaderEl.getChildElement("operations");
|
|
|
|
|
+ XmlElement opEl = opsEl.getChildElement("operation");
|
|
|
|
|
+ do
|
|
|
{
|
|
{
|
|
|
- if(v.first != "operation")
|
|
|
|
|
- {
|
|
|
|
|
- throw ANKI_EXCEPTION("Expected \"operation\" tag and not: "
|
|
|
|
|
- + v.first);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ parseOperationTag(opEl);
|
|
|
|
|
|
|
|
- const ptree& opPt = v.second;
|
|
|
|
|
- parseOperationTag(opPt);
|
|
|
|
|
- } // end for all operations
|
|
|
|
|
|
|
+ opEl = opEl.getNextSiblingElement("operation");
|
|
|
|
|
+ } while(opEl);
|
|
|
|
|
|
|
|
srcLines.push_back("}\n");
|
|
srcLines.push_back("}\n");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
//==============================================================================
|
|
|
void MaterialShaderProgramCreator::parseInputTag(
|
|
void MaterialShaderProgramCreator::parseInputTag(
|
|
|
- const boost::property_tree::ptree& pt, std::string& line)
|
|
|
|
|
|
|
+ const XmlElement& inputEl, std::string& line)
|
|
|
{
|
|
{
|
|
|
- using namespace boost::property_tree;
|
|
|
|
|
-
|
|
|
|
|
- const std::string& name = pt.get<std::string>("name");
|
|
|
|
|
- const std::string& type = pt.get<std::string>("type");
|
|
|
|
|
|
|
+ const std::string& name = inputEl.getChildElement("name").getText();
|
|
|
|
|
+ const std::string& type = inputEl.getChildElement("type").getText();
|
|
|
|
|
|
|
|
line = "uniform " + type + " " + name + ";";
|
|
line = "uniform " + type + " " + name + ";";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
//==============================================================================
|
|
|
void MaterialShaderProgramCreator::parseOperationTag(
|
|
void MaterialShaderProgramCreator::parseOperationTag(
|
|
|
- const boost::property_tree::ptree& pt)
|
|
|
|
|
|
|
+ const XmlElement& operationTag)
|
|
|
{
|
|
{
|
|
|
- using namespace boost::property_tree;
|
|
|
|
|
-
|
|
|
|
|
// <id></id>
|
|
// <id></id>
|
|
|
- int id = pt.get<int>("id");
|
|
|
|
|
|
|
+ int id = operationTag.getChildElement("id").getInt();
|
|
|
|
|
|
|
|
// <returnType></returnType>
|
|
// <returnType></returnType>
|
|
|
- boost::optional<std::string> retTypeOpt =
|
|
|
|
|
- pt.get_optional<std::string>("returnType");
|
|
|
|
|
|
|
+ XmlElement retTypeEl = operationTag.getChildElementOptional("returnType");
|
|
|
|
|
|
|
|
std::string operationOut;
|
|
std::string operationOut;
|
|
|
- if(retTypeOpt)
|
|
|
|
|
|
|
+ if(retTypeEl)
|
|
|
{
|
|
{
|
|
|
operationOut = "operationOut" + std::to_string(id);
|
|
operationOut = "operationOut" + std::to_string(id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// <function>functionName</function>
|
|
// <function>functionName</function>
|
|
|
- const std::string& funcName = pt.get<std::string>("function");
|
|
|
|
|
|
|
+ std::string funcName = operationTag.getChildElement("function").getText();
|
|
|
|
|
|
|
|
// <arguments></arguments>
|
|
// <arguments></arguments>
|
|
|
- boost::optional<const ptree&> argsPt = pt.get_child_optional("arguments");
|
|
|
|
|
|
|
+ XmlElement argsEl = operationTag.getChildElementOptional("arguments");
|
|
|
StringList argsList;
|
|
StringList argsList;
|
|
|
|
|
|
|
|
- if(argsPt)
|
|
|
|
|
|
|
+ if(argsEl)
|
|
|
{
|
|
{
|
|
|
// Get all arguments
|
|
// Get all arguments
|
|
|
- ptree::const_iterator it = argsPt.get().begin();
|
|
|
|
|
- for(; it != argsPt.get().end(); ++it)
|
|
|
|
|
|
|
+ XmlElement argEl = argsEl.getChildElement("argument");
|
|
|
|
|
+ do
|
|
|
{
|
|
{
|
|
|
- const ptree::value_type& v = *it;
|
|
|
|
|
-
|
|
|
|
|
- if(v.first != "argument")
|
|
|
|
|
- {
|
|
|
|
|
- throw ANKI_EXCEPTION("Operation "
|
|
|
|
|
- + std::to_string(id)
|
|
|
|
|
- + ": Expected \"argument\" tag and not: " + v.first);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const std::string& argName = v.second.data();
|
|
|
|
|
- argsList.push_back(argName);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ argsList.push_back(argEl.getText());
|
|
|
|
|
+ argEl = argEl.getNextSiblingElement("argument");
|
|
|
|
|
+ } while(argEl);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Now write everything
|
|
// Now write everything
|
|
@@ -192,10 +163,10 @@ void MaterialShaderProgramCreator::parseOperationTag(
|
|
|
}
|
|
}
|
|
|
line << "\n";
|
|
line << "\n";
|
|
|
|
|
|
|
|
- if(retTypeOpt)
|
|
|
|
|
|
|
+ if(retTypeEl)
|
|
|
{
|
|
{
|
|
|
line << "#\tdefine " << operationOut << "_DEFINED\n";
|
|
line << "#\tdefine " << operationOut << "_DEFINED\n";
|
|
|
- line << '\t' << retTypeOpt.get() << " " << operationOut << " = ";
|
|
|
|
|
|
|
+ line << '\t' << retTypeEl.getText() << " " << operationOut << " = ";
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -218,4 +189,4 @@ bool MaterialShaderProgramCreator::compareStrings(
|
|
|
return a < b;
|
|
return a < b;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-} // end namespace
|
|
|
|
|
|
|
+} // end namespace anki
|