From 25c627360dfa0f0ab68361d6906242d438e370ee Mon Sep 17 00:00:00 2001 From: Evgeny Prikazchikov Date: Thu, 30 Oct 2025 16:00:16 +0300 Subject: [PATCH] Shader Graph String refactoring --- .../shadertools/converter/functions/camera.h | 28 ++-- .../converter/functions/constvalue.h | 40 +++--- .../converter/functions/coordinates.h | 20 +-- .../converter/functions/customfunction.h | 21 +-- .../converter/functions/function.cpp | 49 +++---- .../converter/functions/function.h | 26 ++-- .../converter/functions/imageeffects.h | 14 +- .../converter/functions/logicoperator.h | 36 +++--- .../converter/functions/materialparam.h | 4 +- .../converter/functions/mathoperator.h | 120 +++++++++--------- .../converter/functions/matrixoperations.h | 51 ++++---- .../shadertools/converter/functions/surface.h | 30 ++--- .../converter/functions/texturesample.h | 33 +++-- .../shadertools/converter/functions/time.h | 18 +-- .../converter/functions/trigonometry.h | 24 ++-- .../converter/functions/vectoroperator.h | 67 +++++----- .../shadertools/converter/shadergraph.cpp | 53 ++++---- modules/uikit/includes/uisystem.h | 7 +- modules/uikit/src/components/widget.cpp | 12 +- modules/uikit/src/uisystem.cpp | 14 ++ thirdparty/next/inc/core/astring.h | 7 + thirdparty/next/src/core/astring.cpp | 30 +++++ 22 files changed, 381 insertions(+), 323 deletions(-) diff --git a/modules/editor/shadertools/converter/functions/camera.h b/modules/editor/shadertools/converter/functions/camera.h index d1e6b565a..d045eb9e1 100644 --- a/modules/editor/shadertools/converter/functions/camera.h +++ b/modules/editor/shadertools/converter/functions/camera.h @@ -15,7 +15,7 @@ class CameraPosition : public ShaderNode { m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR3)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { stack.push("g.cameraPosition.xyz"); return ShaderNode::build(code, stack, link, depth, type); } @@ -33,7 +33,7 @@ class CameraDirection : public ShaderNode { m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR3)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { stack.push("g.cameraTarget.xyz"); return ShaderNode::build(code, stack, link, depth, type); } @@ -55,15 +55,15 @@ class ScreenSize : public ShaderNode { m_outputs.push_back(std::make_pair("1/Height", MetaType::FLOAT)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(link.oport->m_name == "Width") { - stack.append("g.cameraScreen.x"); + stack.push("g.cameraScreen.x"); } else if(link.oport->m_name == "Height") { - stack.append("g.cameraScreen.y"); + stack.push("g.cameraScreen.y"); } else if(link.oport->m_name == "1/Width") { - stack.append("g.cameraScreen.z"); + stack.push("g.cameraScreen.z"); } else if(link.oport->m_name == "1/Height") { - stack.append("g.cameraScreen.w"); + stack.push("g.cameraScreen.w"); } return ShaderNode::build(code, stack, link, depth, type); @@ -89,21 +89,21 @@ class ScreenPosition : public ShaderNode { m_outputs.push_back(std::make_pair(w, MetaType::FLOAT)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { - code += QString("\tvec4 local%1 = gl_FragCoord").arg(depth) + (m_normalized ? " / g.cameraScreen;\n" : ";\n"); + code += TString("\tvec4 local%1 = gl_FragCoord").arg(TString::number(depth)) + (m_normalized ? " / g.cameraScreen;\n" : ";\n"); } int32_t result = ShaderNode::build(code, stack, link, depth, type); if(link.oport->m_name == x) { - stack.append(convert("local" + QString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 0)); + stack.push(convert(TString("local") + TString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 0)); } else if(link.oport->m_name == y) { - stack.append(convert("local" + QString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 1)); + stack.push(convert(TString("local") + TString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 1)); } else if(link.oport->m_name == z) { - stack.append(convert("local" + QString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 2)); + stack.push(convert(TString("local") + TString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 2)); } else if(link.oport->m_name == w) { - stack.append(convert("local" + QString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 3)); + stack.push(convert(TString("local") + TString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 3)); } return result; @@ -138,7 +138,7 @@ class ProjectionMatrix : public ShaderNode { m_outputs.push_back(std::make_pair("Output", MetaType::MATRIX4)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_inverted) { stack.push("g.cameraProjectionInv"); } else { diff --git a/modules/editor/shadertools/converter/functions/constvalue.h b/modules/editor/shadertools/converter/functions/constvalue.h index da07b8a73..1b24cf0a1 100644 --- a/modules/editor/shadertools/converter/functions/constvalue.h +++ b/modules/editor/shadertools/converter/functions/constvalue.h @@ -17,7 +17,7 @@ class ConstPi : public ShaderNode { setName("PI"); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { stack.push("3.141592653589793"); return ShaderNode::build(code, stack, link, depth, type); } @@ -37,7 +37,7 @@ class ConstEuler : public ShaderNode { setName("Euler"); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { stack.push("2.718281828459045"); return ShaderNode::build(code, stack, link, depth, type); } @@ -57,7 +57,7 @@ class ConstGoldenRatio : public ShaderNode { setName("GoldenRatio"); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { stack.push("1.618033988749895"); return ShaderNode::build(code, stack, link, depth, type); } @@ -89,8 +89,8 @@ class ConstFloat : public ShaderNode { m_value = value; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { - stack.push(QString::number(m_value)); + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + stack.push(TString::number(m_value)); return ShaderNode::build(code, stack, link, depth, type); } @@ -125,8 +125,8 @@ class ConstInt : public ShaderNode { m_value = value; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { - stack.push(QString::number(m_value)); + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + stack.push(TString::number(m_value)); return ShaderNode::build(code, stack, link, depth, type); } @@ -159,8 +159,8 @@ class ConstVector2 : public ShaderNode { m_value = value; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { - stack.push(QString("vec2(%1, %2)").arg(m_value.x).arg(m_value.y)); + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + stack.push(TString("vec2(%1, %2)").arg(TString::number(m_value.x), TString::number(m_value.y))); return ShaderNode::build(code, stack, link, depth, type); } @@ -193,8 +193,8 @@ class ConstVector3 : public ShaderNode { m_value = value; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { - stack.push(QString("vec3(%1, %2, %3)").arg(m_value.x).arg(m_value.y).arg(m_value.z)); + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + stack.push(TString("vec3(%1, %2, %3)").arg(TString::number(m_value.x), TString::number(m_value.y), TString::number(m_value.z))); return ShaderNode::build(code, stack, link, depth, type); } @@ -229,8 +229,9 @@ class ConstVector4 : public ShaderNode { m_value = value; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { - stack.push(QString("vec4(%1, %2, %3, %4)").arg(m_value.x).arg(m_value.y).arg(m_value.z).arg(m_value.w)); + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + stack.push(TString("vec4(%1, %2, %3, %4)").arg(TString::number(m_value.x), TString::number(m_value.y), + TString::number(m_value.z), TString::number(m_value.w))); return ShaderNode::build(code, stack, link, depth, type); } @@ -265,8 +266,9 @@ class ConstColor : public ShaderNode { m_value = value; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { - stack.push(QString("vec4(%1, %2, %3, %4)").arg(m_value.x).arg(m_value.y).arg(m_value.z).arg(m_value.w)); + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + stack.push(TString("vec4(%1, %2, %3, %4)").arg(TString::number(m_value.x), TString::number(m_value.y), + TString::number(m_value.z), TString::number(m_value.w))); return ShaderNode::build(code, stack, link, depth, type); } @@ -321,11 +323,11 @@ class ConstMatrix3 : public ShaderNode { m_value2 = value; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { stack.push(QString("mat3(%1, %2, %3, %4, %5, %6, %7, %8, %9)") .arg(m_value0.x).arg(m_value0.y).arg(m_value0.z) .arg(m_value1.x).arg(m_value1.y).arg(m_value1.z) - .arg(m_value2.x).arg(m_value2.y).arg(m_value2.z)); + .arg(m_value2.x).arg(m_value2.y).arg(m_value2.z).toStdString()); return ShaderNode::build(code, stack, link, depth, type); } @@ -393,12 +395,12 @@ class ConstMatrix4 : public ShaderNode { m_value3 = value; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { stack.push(QString("mat4(%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %15, %16)") .arg(m_value0.x).arg(m_value0.y).arg(m_value0.z).arg(m_value0.w) .arg(m_value1.x).arg(m_value1.y).arg(m_value1.z).arg(m_value1.w) .arg(m_value2.x).arg(m_value2.y).arg(m_value2.z).arg(m_value2.w) - .arg(m_value3.x).arg(m_value3.y).arg(m_value3.z).arg(m_value3.w)); + .arg(m_value3.x).arg(m_value3.y).arg(m_value3.z).arg(m_value3.w).toStdString()); return ShaderNode::build(code, stack, link, depth, type); } diff --git a/modules/editor/shadertools/converter/functions/coordinates.h b/modules/editor/shadertools/converter/functions/coordinates.h index f328e8d2a..060e3ba84 100644 --- a/modules/editor/shadertools/converter/functions/coordinates.h +++ b/modules/editor/shadertools/converter/functions/coordinates.h @@ -17,9 +17,9 @@ class ProjectionCoord : public ShaderNode { m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR3)); } - int32_t build(QString &code, QStack &stack,const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack,const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { - code += QString("\tvec3 local%1 = (0.5 *( _vertex.xyz / _vertex.w ) + 0.5);\n").arg(depth); + code += TString("\tvec3 local%1 = (0.5 *( _vertex.xyz / _vertex.w ) + 0.5);\n").arg(TString::number(depth)); } return ShaderNode::build(code, stack, link, depth, type); } @@ -41,8 +41,8 @@ class TexCoord : public ShaderNode { m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR2)); } - int32_t build(QString &code, QStack &stack,const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { - stack.push(QString("_uv%1").arg(m_index)); + int32_t build(TString &code, std::stack &stack,const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + stack.push(TString("_uv%1").arg(TString::number((int)m_index))); return ShaderNode::build(code, stack, link, depth, type); } @@ -72,14 +72,14 @@ class CoordPanner : public ShaderNode { m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR2)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { - QStringList args = getArguments(code, stack, depth, type); - if(!args.isEmpty()) { - QString value = args[0]; - value.append(QString(" + vec2(%1, %2) * g.time").arg(QString::number(m_speed.x), QString::number(m_speed.y))); + std::vector args = getArguments(code, stack, depth, type); + if(!args.empty()) { + TString value = args[0]; + value.append(TString(" + vec2(%1, %2) * g.time").arg(TString::number(m_speed.x), TString::number(m_speed.y))); - code.append(QString("\tvec2 local%1 = %2;\n").arg(QString::number(depth), value)); + code.append(TString("\tvec2 local%1 = %2;\n").arg(TString::number(depth), value)); } else { reportMessage(TString("Missing argument ") + UV); return m_position; diff --git a/modules/editor/shadertools/converter/functions/customfunction.h b/modules/editor/shadertools/converter/functions/customfunction.h index 5cf0fc8d6..44de18f0b 100644 --- a/modules/editor/shadertools/converter/functions/customfunction.h +++ b/modules/editor/shadertools/converter/functions/customfunction.h @@ -21,8 +21,9 @@ class CustomFunction : public ShaderNode { void exposeFunction(const TString &path) { QFile file(path.data()); if(file.open(QFile::ReadOnly | QFile::Text)) { + QByteArray byteData = file.readAll(); pugi::xml_document doc; - if(doc.load_string(file.readAll().data()).status == pugi::status_ok) { + if(doc.load_string(byteData.data()).status == pugi::status_ok) { pugi::xml_node function = doc.document_element(); m_funcName = Url(function.attribute("name").as_string()).baseName(); @@ -111,19 +112,19 @@ class CustomFunction : public ShaderNode { return Variant(); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { if(!m_func.isEmpty()) { static_cast(m_graph)->addFragmentFunction(m_funcName, m_func); int l_type = 0; - QStringList arguments = getArguments(code, stack, depth, l_type); + std::vector args = getArguments(code, stack, depth, l_type); if(link.oport->m_type != MetaType::INVALID) { type = link.oport->m_type; } - QString expr = QString("%1(%2)").arg(m_funcName.data(), arguments.join(", ")); + TString expr = TString("%1(%2)").arg(m_funcName, TString::join(StringList(args.begin(), args.end()), ", ")); if(m_graph->isSingleConnection(link.oport)) { stack.push(expr); } else { @@ -135,7 +136,7 @@ class CustomFunction : public ShaderNode { return ShaderNode::build(code, stack, link, depth, type); } - QString defaultValue(const TString &key, uint32_t &type) const override { + TString defaultValue(const TString &key, uint32_t &type) const override { Variant value = property(key.data()); if(value.type() == MetaType::STRING) { @@ -152,24 +153,24 @@ class CustomFunction : public ShaderNode { switch(type) { case MetaType::FLOAT: { - return QString::number(value.toFloat()); + return TString::number(value.toFloat()); } case MetaType::VECTOR2: { Vector2 v = value.value(); - return QString("vec2(%1, %2)").arg(v.x).arg(v.y); + return TString("vec2(%1, %2)").arg(TString::number(v.x), TString::number(v.y)); } case MetaType::VECTOR3: { Vector3 v = value.value(); - return QString("vec3(%1, %2, %3)").arg(v.x).arg(v.y).arg(v.z); + return TString("vec3(%1, %2, %3)").arg(TString::number(v.x), TString::number(v.y), TString::number(v.z)); } case MetaType::VECTOR4: { Vector4 v = value.value(); - return QString("vec4(%1, %2, %3, %4)").arg(v.x).arg(v.y).arg(v.z).arg(v.w); + return TString("vec4(%1, %2, %3, %4)").arg(TString::number(v.x), TString::number(v.y), TString::number(v.z), TString::number(v.w)); } default: break; } - return QString(); + return TString(); } protected: diff --git a/modules/editor/shadertools/converter/functions/function.cpp b/modules/editor/shadertools/converter/functions/function.cpp index bc877b388..b27a42714 100644 --- a/modules/editor/shadertools/converter/functions/function.cpp +++ b/modules/editor/shadertools/converter/functions/function.cpp @@ -23,7 +23,7 @@ void ShaderNode::createParams() { } } -int32_t ShaderNode::build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) { +int32_t ShaderNode::build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) { Q_UNUSED(code) Q_UNUSED(link) @@ -38,12 +38,12 @@ int32_t ShaderNode::build(QString &code, QStack &stack, const AbstractN return m_position; } -int32_t ShaderNode::compile(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) { +int32_t ShaderNode::compile(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) { if(m_position == -1) { - QStringList args = getArguments(code, stack, depth, type); + std::vector args = getArguments(code, stack, depth, type); if(args.size() == m_inputs.size()) { - QString expr = makeExpression(args); + TString expr = makeExpression(args); if(m_graph->isSingleConnection(link.oport)) { stack.push(expr); } else { @@ -60,8 +60,8 @@ int32_t ShaderNode::compile(QString &code, QStack &stack, const Abstrac return ShaderNode::build(code, stack, link, depth, type); } -QStringList ShaderNode::getArguments(QString &code, QStack &stack, int32_t &depth, int32_t &type) { - QStringList result; +std::vector ShaderNode::getArguments(TString &code, std::stack &stack, int32_t &depth, int32_t &type) { + std::vector result; for(const NodePort &it : m_ports) { if(it.m_out == true) { @@ -69,7 +69,7 @@ QStringList ShaderNode::getArguments(QString &code, QStack &stack, int3 } uint32_t defaultType = 0; - QString value = defaultValue(it.m_name, defaultType); + TString value = defaultValue(it.m_name, defaultType); const AbstractNodeGraph::Link *l = m_graph->findLink(this, &it); if(l) { @@ -82,25 +82,26 @@ QStringList ShaderNode::getArguments(QString &code, QStack &stack, int3 int32_t target = l->iport->m_type == MetaType::INVALID ? type : l->iport->m_type; - if(stack.isEmpty()) { - value = convert(QString("local%1").arg(QString::number(index)), l_type, target); + if(stack.empty()) { + value = convert(TString("local%1").arg(TString::number(index)), l_type, target); } else { - value = convert(stack.pop(), l_type, target); + value = convert(stack.top(), l_type, target); + stack.pop(); } } } if(!value.isEmpty()) { - result << value; + result.push_back(value); } } return result; } -QString ShaderNode::convert(const QString &value, uint32_t current, uint32_t target, uint8_t component) { - QString prefix; - QString suffix; +TString ShaderNode::convert(const TString &value, uint32_t current, uint32_t target, uint8_t component) { + TString prefix; + TString suffix; const char *names[] = {".x", ".y", ".z", ".w"}; @@ -110,9 +111,9 @@ QString ShaderNode::convert(const QString &value, uint32_t current, uint32_t tar case MetaType::FLOAT: { prefix = "int("; suffix = ")"; } break; case MetaType::VECTOR2: case MetaType::VECTOR3: - case MetaType::VECTOR4: { prefix = "int("; suffix = QString(names[component]) + ")"; } break; + case MetaType::VECTOR4: { prefix = "int("; suffix = TString(names[component]) + ")"; } break; case MetaType::MATRIX3: - case MetaType::MATRIX4: { prefix = "int("; suffix = QString("[0]") + QString(names[component]) + ")"; } break; + case MetaType::MATRIX4: { prefix = "int("; suffix = TString("[0]") + TString(names[component]) + ")"; } break; case MetaType::STRING: { prefix = "int(texture("; suffix = ", _uv0).x)"; } break; default: break; } @@ -124,7 +125,7 @@ QString ShaderNode::convert(const QString &value, uint32_t current, uint32_t tar case MetaType::VECTOR3: case MetaType::VECTOR4: { prefix = ""; suffix = names[component]; } break; case MetaType::MATRIX3: - case MetaType::MATRIX4: { prefix = ""; suffix = QString("[0]") + names[component]; } break; + case MetaType::MATRIX4: { prefix = ""; suffix = TString("[0]") + names[component]; } break; case MetaType::STRING: { prefix = "texture("; suffix = ", _uv0).x"; } break; default: break; } @@ -170,16 +171,16 @@ QString ShaderNode::convert(const QString &value, uint32_t current, uint32_t tar return (prefix + value + suffix); } -QString ShaderNode::localValue(int type, int index, const QString &value, const QString &name) { - QString s_name = name; +TString ShaderNode::localValue(int type, int index, const TString &value, const TString &name) { + TString s_name = name; if(s_name.isEmpty()) { - s_name = "local" + QString::number(index); + s_name = TString("local") + TString::number(index); } - return QString("\t%1 %2 = %3;\n").arg(typeToString(type), s_name, value); + return TString("\t%1 %2 = %3;\n").arg(typeToString(type), s_name, value); } -QString ShaderNode::typeToString(int type) { +TString ShaderNode::typeToString(int type) { switch(type) { case MetaType::INTEGER: return "int"; break; case MetaType::VECTOR2: return "vec2"; break; @@ -190,7 +191,7 @@ QString ShaderNode::typeToString(int type) { default: return "float"; break; } - return QString(); + return TString(); } void ShaderNode::switchPreview() { @@ -254,7 +255,7 @@ Widget *ShaderNode::widget() { m_previewBtn->icon()->setItem("Arrow"); m_previewBtn->setIconSize(Vector2(16.0f, 8.0f)); - bool res = Object::connect(m_previewBtn, _SIGNAL(clicked()), this, _SLOT(switchPreview())); + Object::connect(m_previewBtn, _SIGNAL(clicked()), this, _SLOT(switchPreview())); RectTransform *previewRect = m_previewBtn->rectTransform(); if(previewRect) { diff --git a/modules/editor/shadertools/converter/functions/function.h b/modules/editor/shadertools/converter/functions/function.h index fa17842b3..977782ab6 100644 --- a/modules/editor/shadertools/converter/functions/function.h +++ b/modules/editor/shadertools/converter/functions/function.h @@ -16,7 +16,7 @@ #include -#include +#include namespace { const char *a("A"); @@ -53,25 +53,25 @@ class ShaderNode : public GraphNode { } Vector2 defaultSize() const override { - return Vector2(150.0f, 30.0f); + return Vector2(154.0f, 30.0f); } virtual void createParams(); - virtual int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type); + virtual int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type); - int32_t compile(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type); + int32_t compile(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type); - virtual QString makeExpression(const QStringList &args) const { - return QString("%1(%2)").arg(m_expression, args.join(", ")); + virtual TString makeExpression(const std::vector &args) const { + return TString("%1(%2)").arg(m_expression, TString::join(StringList(args.begin(), args.end()), ", ")); } - QStringList getArguments(QString &code, QStack &stack, int32_t &depth, int32_t &type); + std::vector getArguments(TString &code, std::stack &stack, int32_t &depth, int32_t &type); - virtual QString defaultValue(const TString &key, uint32_t &type) const { + virtual TString defaultValue(const TString &key, uint32_t &type) const { A_UNUSED(key); type = MetaType::INVALID; - return QString(); + return TString(); } virtual int getOutType(int inType, const AbstractNodeGraph::Link *l) { @@ -83,11 +83,11 @@ class ShaderNode : public GraphNode { return m_type; } - static QString convert(const QString &value, uint32_t current, uint32_t target, uint8_t component = 0); + static TString convert(const TString &value, uint32_t current, uint32_t target, uint8_t component = 0); - static QString localValue(int type, int index, const QString &value, const QString &name = QString()); + static TString localValue(int type, int index, const TString &value, const TString &name = TString()); - static QString typeToString(int type); + static TString typeToString(int type); void switchPreview(); @@ -104,7 +104,7 @@ class ShaderNode : public GraphNode { std::list> m_inputs; std::list> m_outputs; - QString m_expression; + TString m_expression; int32_t m_position; int32_t m_type; diff --git a/modules/editor/shadertools/converter/functions/imageeffects.h b/modules/editor/shadertools/converter/functions/imageeffects.h index 5f65159c0..ee1c602d3 100644 --- a/modules/editor/shadertools/converter/functions/imageeffects.h +++ b/modules/editor/shadertools/converter/functions/imageeffects.h @@ -1,7 +1,7 @@ #ifndef IMAGEEFFECTS_H #define IMAGEEFFECTS_H -#include "customfunction.h" +#include "function.h" class Desaturate : public ShaderNode { A_OBJECT(Desaturate, ShaderNode, Shader/Image Effects) @@ -23,11 +23,11 @@ class Desaturate : public ShaderNode { m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR3)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { - QStringList arguments = getArguments(code, stack, depth, type); + std::vector args = getArguments(code, stack, depth, type); - QString expr = QString("mix(%1, vec3(dot(%1, vec3(0.299, 0.587, 0.114))), %2)").arg(arguments[0], arguments[1]); + TString expr = TString("mix(%1, vec3(dot(%1, vec3(0.299, 0.587, 0.114))), %2)").arg(args[0], args[1]); if(m_graph->isSingleConnection(link.oport)) { stack.push(expr); @@ -38,12 +38,12 @@ class Desaturate : public ShaderNode { return ShaderNode::build(code, stack, link, depth, type); } - QString defaultValue(const TString &key, uint32_t &) const override { + TString defaultValue(const TString &key, uint32_t &) const override { if(key == "Fraction") { - return QString::number(m_fraction); + return TString::number(m_fraction); } - return QString("vec3(%1, %2, %3)").arg(m_default.x).arg(m_default.y).arg(m_default.z); + return TString("vec3(%1, %2, %3)").arg(TString::number(m_default.x), TString::number(m_default.y), TString::number(m_default.z)); } Vector3 rgb() const { diff --git a/modules/editor/shadertools/converter/functions/logicoperator.h b/modules/editor/shadertools/converter/functions/logicoperator.h index 435988b11..ca2c197f6 100644 --- a/modules/editor/shadertools/converter/functions/logicoperator.h +++ b/modules/editor/shadertools/converter/functions/logicoperator.h @@ -41,12 +41,12 @@ class If : public ShaderNode { } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { - QStringList arg = getArguments(code, stack, depth, type); + std::vector arg = getArguments(code, stack, depth, type); - QString expr = QString("((%1 - %6 > %2) ? %3 : (%1 - %6 <= %2 && %1 + %6 >= %2) ? %4 : %5)"). - arg(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5]); + TString expr = TString("((%1 - %6 > %2) ? %3 : (%1 - %6 <= %2 && %1 + %6 >= %2) ? %4 : %5)") + .arg(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5]); if(m_graph->isSingleConnection(link.oport)) { stack.push(expr); @@ -64,19 +64,19 @@ class If : public ShaderNode { return m_type; } - QString defaultValue(const TString &key, uint32_t &) const override { + TString defaultValue(const TString &key, uint32_t &) const override { if(key == a) { - return convert(QString::number(m_a), MetaType::FLOAT, m_type); + return convert(TString::number(m_a), MetaType::FLOAT, m_type); } else if(key == b) { - return convert(QString::number(m_b), MetaType::FLOAT, m_type); + return convert(TString::number(m_b), MetaType::FLOAT, m_type); } if(key == agb) { - return convert(QString::number(m_agb), MetaType::FLOAT, m_type); + return convert(TString::number(m_agb), MetaType::FLOAT, m_type); } else if(key == alb) { - return convert(QString::number(m_alb), MetaType::FLOAT, m_type); + return convert(TString::number(m_alb), MetaType::FLOAT, m_type); } else if(key == aeb) { - return convert(QString::number(m_aeb), MetaType::FLOAT, m_type); + return convert(TString::number(m_aeb), MetaType::FLOAT, m_type); } - return QString(); + return TString(); } private: @@ -146,7 +146,7 @@ class Compare : public ShaderNode { } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { } @@ -160,17 +160,17 @@ class Compare : public ShaderNode { return m_type; } - QString defaultValue(const TString &key, uint32_t &) const override { + TString defaultValue(const TString &key, uint32_t &) const override { if(key == a) { - return convert(QString::number(m_a), MetaType::FLOAT, m_type); + return convert(TString::number(m_a), MetaType::FLOAT, m_type); } else if(key == b) { - return convert(QString::number(m_b), MetaType::FLOAT, m_type); + return convert(TString::number(m_b), MetaType::FLOAT, m_type); } if(key == _TRUE) { - return convert(QString::number(m_true), MetaType::FLOAT, m_type); + return convert(TString::number(m_true), MetaType::FLOAT, m_type); } else if(key == _FALSE) { - return convert(QString::number(m_false), MetaType::FLOAT, m_type); + return convert(TString::number(m_false), MetaType::FLOAT, m_type); } - return QString(); + return TString(); } private: diff --git a/modules/editor/shadertools/converter/functions/materialparam.h b/modules/editor/shadertools/converter/functions/materialparam.h index 8fe52db38..05ea967d5 100644 --- a/modules/editor/shadertools/converter/functions/materialparam.h +++ b/modules/editor/shadertools/converter/functions/materialparam.h @@ -22,7 +22,7 @@ class ParamFloat : public ShaderNode { setName("ParamFloat"); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(type == 0) { type = link.oport->m_type; } @@ -67,7 +67,7 @@ class ParamVector : public ShaderNode { setName("ParamVector"); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(type == 0) { type = link.oport->m_type; } diff --git a/modules/editor/shadertools/converter/functions/mathoperator.h b/modules/editor/shadertools/converter/functions/mathoperator.h index 3774d18bc..7711455df 100644 --- a/modules/editor/shadertools/converter/functions/mathoperator.h +++ b/modules/editor/shadertools/converter/functions/mathoperator.h @@ -21,12 +21,12 @@ class MathOperation : public ShaderNode { m_outputs.push_back(std::make_pair("Output", MetaType::INVALID)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } - QString makeExpression(const QStringList &args) const override { - return QString("(%1 %2 %3)").arg(args[0], m_expression, args[1]); + TString makeExpression(const std::vector &args) const override { + return TString("(%1 %2 %3)").arg(args[0], m_expression, args[1]); } }; @@ -99,7 +99,7 @@ class Step : public ShaderNode { m_expression = "step"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -122,7 +122,7 @@ class Smoothstep : public ShaderNode { m_expression = "smoothstep"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -145,7 +145,7 @@ class Mix : public ShaderNode { m_expression = "mix"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -168,7 +168,7 @@ class Clamp : public ShaderNode { m_expression = "clamp"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -190,7 +190,7 @@ class Min : public ShaderNode { m_expression = "min"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -212,7 +212,7 @@ class Max : public ShaderNode { m_expression = "max"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -234,7 +234,7 @@ class Power : public ShaderNode { m_expression = "pow"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -255,7 +255,7 @@ class SquareRoot : public ShaderNode { m_expression = "sqrt"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -276,7 +276,7 @@ class Logarithm : public ShaderNode { m_expression = "log"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -295,12 +295,12 @@ class Logarithm10 : public ShaderNode { m_outputs.push_back(std::make_pair("", MetaType::FLOAT)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } - QString makeExpression(const QStringList &args) const override { - return QString("((1.0f / log(10.0f)) * log(%1))").arg(args[0]); + TString makeExpression(const std::vector &args) const override { + return TString("((1.0f / log(10.0f)) * log(%1))").arg(args[0]); } }; @@ -320,7 +320,7 @@ class Logarithm2 : public ShaderNode { m_expression = "log2"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -341,7 +341,7 @@ class FWidth : public ShaderNode { m_expression = "fwidth"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -363,7 +363,7 @@ class Abs : public ShaderNode { m_expression = "abs"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -384,7 +384,7 @@ class Sign : public ShaderNode { m_expression = "sign"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -405,7 +405,7 @@ class Floor : public ShaderNode { m_expression = "floor"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -426,7 +426,7 @@ class Ceil : public ShaderNode { m_expression = "ceil"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -447,7 +447,7 @@ class Round : public ShaderNode { m_expression = "round"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -468,7 +468,7 @@ class Truncate : public ShaderNode { m_expression = "trunc"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -489,7 +489,7 @@ class Fract : public ShaderNode { m_expression = "fract"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -510,7 +510,7 @@ class DDX : public ShaderNode { m_expression = "dFdx"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -531,7 +531,7 @@ class DDY : public ShaderNode { m_expression = "dFdy"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -552,7 +552,7 @@ class Exp : public ShaderNode { m_expression = "exp"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -573,7 +573,7 @@ class Exp2 : public ShaderNode { m_expression = "exp2"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -594,7 +594,7 @@ class Remainder : public ShaderNode { m_expression = "mod"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -615,7 +615,7 @@ class RSqrt : public ShaderNode { m_expression = "inversesqrt"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } }; @@ -635,12 +635,12 @@ class Fmod : public ShaderNode { m_outputs.push_back(std::make_pair("", MetaType::INVALID)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } - QString makeExpression(const QStringList &args) const override { - return QString("(%1 - %2 * trunc(%1 / %2)) ").arg(args[0], args[1]); + TString makeExpression(const std::vector &args) const override { + return TString("(%1 - %2 * trunc(%1 / %2)) ").arg(args[0], args[1]); } }; @@ -660,12 +660,12 @@ class InverseLerp : public ShaderNode { m_outputs.push_back(std::make_pair("", MetaType::INVALID)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } - QString makeExpression(const QStringList &args) const override { - return QString("((%3 - %1) / (%2 - %1))").arg(args[0], args[1], args[2]); + TString makeExpression(const std::vector &args) const override { + return TString("((%3 - %1) / (%2 - %1))").arg(args[0], args[1], args[2]); } }; @@ -683,12 +683,12 @@ class Negate : public ShaderNode { m_outputs.push_back(std::make_pair("", MetaType::INVALID)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } - QString makeExpression(const QStringList &args) const override { - return QString("(-%1)").arg(args[0]); + TString makeExpression(const std::vector &args) const override { + return TString("(-%1)").arg(args[0]); } }; @@ -706,12 +706,12 @@ class Saturate : public ShaderNode { m_outputs.push_back(std::make_pair("", MetaType::INVALID)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } - QString makeExpression(const QStringList &args) const override { - return QString("clamp(%1, 0.0f, 1.0f)").arg(args[0]); + TString makeExpression(const std::vector &args) const override { + return TString("clamp(%1, 0.0f, 1.0f)").arg(args[0]); } }; @@ -730,12 +730,12 @@ class Scale : public ShaderNode { m_outputs.push_back(std::make_pair("", MetaType::INVALID)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } - QString makeExpression(const QStringList &args) const override { - return QString("(%1 * %2)").arg(args[0], args[1]); + TString makeExpression(const std::vector &args) const override { + return TString("(%1 * %2)").arg(args[0], args[1]); } }; @@ -755,12 +755,12 @@ class ScaleAndOffset : public ShaderNode { m_outputs.push_back(std::make_pair("", MetaType::INVALID)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } - QString makeExpression(const QStringList &args) const override { - return QString("(%1 * %2 + %3)").arg(args[0], args[1], args[2]); + TString makeExpression(const std::vector &args) const override { + return TString("(%1 * %2 + %3)").arg(args[0], args[1], args[2]); } }; @@ -778,12 +778,12 @@ class OneMinus : public ShaderNode { m_outputs.push_back(std::make_pair("", MetaType::INVALID)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } - QString makeExpression(const QStringList &args) const override { - return QString("(%1 - %2)").arg(convert("1.0f", MetaType::FLOAT, m_type), args[0]); + TString makeExpression(const std::vector &args) const override { + return TString("(%1 - %2)").arg(convert("1.0f", MetaType::FLOAT, m_type), args[0]); } }; @@ -801,12 +801,12 @@ class TriangleWave : public ShaderNode { m_outputs.push_back(std::make_pair("", MetaType::INVALID)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } - QString makeExpression(const QStringList &args) const override { - return QString("(2.0f * abs(2.0f * (%1 - floor(0.5f + %1)) ) - 1.0f)").arg(args[0]); + TString makeExpression(const std::vector &args) const override { + return TString("(2.0f * abs(2.0f * (%1 - floor(0.5f + %1)) ) - 1.0f)").arg(args[0]); } }; @@ -824,12 +824,12 @@ class SquareWave : public ShaderNode { m_outputs.push_back(std::make_pair("", MetaType::INVALID)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } - QString makeExpression(const QStringList &args) const override { - return QString("(1.0f - 2.0f * round(fract(%1))").arg(args[0]); + TString makeExpression(const std::vector &args) const override { + return TString("(1.0f - 2.0f * round(fract(%1))").arg(args[0]); } }; @@ -847,12 +847,12 @@ class SawtoothWave : public ShaderNode { m_outputs.push_back(std::make_pair("", MetaType::INVALID)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { return compile(code, stack, link, depth, type); } - QString makeExpression(const QStringList &args) const override { - return QString("(2.0f * (%1 - floor(0.5f + %1)))").arg(args[0]); + TString makeExpression(const std::vector &args) const override { + return TString("(2.0f * (%1 - floor(0.5f + %1)))").arg(args[0]); } }; diff --git a/modules/editor/shadertools/converter/functions/matrixoperations.h b/modules/editor/shadertools/converter/functions/matrixoperations.h index 3221475d6..035e3ef1d 100644 --- a/modules/editor/shadertools/converter/functions/matrixoperations.h +++ b/modules/editor/shadertools/converter/functions/matrixoperations.h @@ -27,13 +27,13 @@ class MatrixOperation : public ShaderNode { m_value3[3] = 1.0f; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { type = m_outputs.front().second; - QStringList arguments = getArguments(code, stack, depth, type); + std::vector args = getArguments(code, stack, depth, type); - QString expr = QString("%1(%2)").arg(m_function, arguments[0]); + TString expr = TString("%1(%2)").arg(m_function, args[0]); if(m_graph->isSingleConnection(link.oport)) { stack.push(expr); @@ -44,13 +44,14 @@ class MatrixOperation : public ShaderNode { return ShaderNode::build(code, stack, link, depth, type); } - QString defaultValue(const TString &, uint32_t &type) const override { + TString defaultValue(const TString &, uint32_t &type) const override { type = MetaType::MATRIX4; + return QString("mat4(%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %15, %16)") .arg(m_value0.x).arg(m_value1.x).arg(m_value2.x).arg(m_value3.x) .arg(m_value0.y).arg(m_value1.y).arg(m_value2.y).arg(m_value3.y) .arg(m_value0.z).arg(m_value1.z).arg(m_value2.z).arg(m_value3.z) - .arg(m_value0.w).arg(m_value1.w).arg(m_value2.w).arg(m_value3.w); + .arg(m_value0.w).arg(m_value1.w).arg(m_value2.w).arg(m_value3.w).toStdString(); } Vector4 value0() const { @@ -95,7 +96,7 @@ class MatrixOperation : public ShaderNode { Vector4 m_value2; Vector4 m_value3; - QString m_function; + TString m_function; uint16_t m_type; @@ -162,7 +163,7 @@ class ExtractPosition : public ShaderNode { m_outputs.push_back(std::make_pair("XYZW", MetaType::VECTOR4)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { type = m_outputs.front().second; @@ -172,9 +173,9 @@ class ExtractPosition : public ShaderNode { static_cast(m_graph)->addFragmentFunction("ExtractPosition", func); - QStringList arguments = getArguments(code, stack, depth, type); + std::vector args = getArguments(code, stack, depth, type); - QString expr = QString("ExtractPosition(%1)").arg(arguments[0]); + TString expr = TString("ExtractPosition(%1)").arg(args[0]); if(m_graph->isSingleConnection(link.oport)) { stack.push(expr); @@ -185,13 +186,13 @@ class ExtractPosition : public ShaderNode { return ShaderNode::build(code, stack, link, depth, type); } - QString defaultValue(const TString &, uint32_t &type) const override { + TString defaultValue(const TString &, uint32_t &type) const override { type = MetaType::MATRIX4; return QString("mat4(%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %15, %16)") .arg(m_value0.x).arg(m_value1.x).arg(m_value2.x).arg(m_value3.x) .arg(m_value0.y).arg(m_value1.y).arg(m_value2.y).arg(m_value3.y) .arg(m_value0.z).arg(m_value1.z).arg(m_value2.z).arg(m_value3.z) - .arg(m_value0.w).arg(m_value1.w).arg(m_value2.w).arg(m_value3.w); + .arg(m_value0.w).arg(m_value1.w).arg(m_value2.w).arg(m_value3.w).toStdString(); } Vector4 value0() const { @@ -256,14 +257,14 @@ class MakeMatrix : public ShaderNode { m_outputs.push_back(std::make_pair("", MetaType::MATRIX4)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { type = m_outputs.front().second; - QStringList arguments = getArguments(code, stack, depth, type); + std::vector args = getArguments(code, stack, depth, type); - QString expr = QString("mat4(%1, %2, %3, %4)") - .arg(arguments[0], arguments[1], arguments[2], arguments[3]); + TString expr = TString("mat4(%1, %2, %3, %4)") + .arg(args[0], args[1], args[2], args[3]); if(m_graph->isSingleConnection(link.oport)) { stack.push(expr); @@ -274,21 +275,21 @@ class MakeMatrix : public ShaderNode { return ShaderNode::build(code, stack, link, depth, type); } - QString defaultValue(const TString &key, uint32_t &) const override { + TString defaultValue(const TString &key, uint32_t &) const override { if(key == "Vector0") { - return QString("vec4(%1, %2, %3, %4)") - .arg(m_value0.x).arg(m_value0.y).arg(m_value0.z).arg(m_value0.w); + return TString("vec4(%1, %2, %3, %4)") + .arg(TString::number(m_value0.x), TString::number(m_value0.y), TString::number(m_value0.z), TString::number(m_value0.w)); } else if(key == "Vector1") { - return QString("vec4(%1, %2, %3, %4)") - .arg(m_value1.x).arg(m_value1.y).arg(m_value1.z).arg(m_value1.w); + return TString("vec4(%1, %2, %3, %4)") + .arg(TString::number(m_value1.x), TString::number(m_value1.y), TString::number(m_value1.z), TString::number(m_value1.w)); } else if(key == "Vector2") { - return QString("vec4(%1, %2, %3, %4)") - .arg(m_value2.x).arg(m_value2.y).arg(m_value2.z).arg(m_value2.w); + return TString("vec4(%1, %2, %3, %4)") + .arg(TString::number(m_value2.x), TString::number(m_value2.y), TString::number(m_value2.z), TString::number(m_value2.w)); } else if(key == "Vector3") { - return QString("vec4(%1, %2, %3, %4)") - .arg(m_value3.x).arg(m_value3.y).arg(m_value3.z).arg(m_value3.w); + return TString("vec4(%1, %2, %3, %4)") + .arg(TString::number(m_value3.x), TString::number(m_value3.y), TString::number(m_value3.z), TString::number(m_value3.w)); } - return QString(); + return TString(); } Vector4 value0() const { diff --git a/modules/editor/shadertools/converter/functions/surface.h b/modules/editor/shadertools/converter/functions/surface.h index 38d946f6b..608a1677a 100644 --- a/modules/editor/shadertools/converter/functions/surface.h +++ b/modules/editor/shadertools/converter/functions/surface.h @@ -23,25 +23,25 @@ class Fresnel : public ShaderNode { m_outputs.push_back(std::make_pair("Output", MetaType::FLOAT)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { - QStringList args = getArguments(code, stack, depth, type); + std::vector args = getArguments(code, stack, depth, type); // f0 = 0.04 - code.append(QString("float local%1 = 0.04 + (1.0 - 0.04) * pow(1.0 - dot(%2, -%3), %4);\n") - .arg(QString::number(depth), args[0], args[1], args[2])); + code.append(TString("float local%1 = 0.04 + (1.0 - 0.04) * pow(1.0 - dot(%2, -%3), %4);\n") + .arg(TString::number(depth), args[0], args[1], args[2])); } return ShaderNode::build(code, stack, link, depth, type); } - QString defaultValue(const TString &key, uint32_t &) const override { + TString defaultValue(const TString &key, uint32_t &) const override { if(key == "Normal") { return "_n"; } else if(key == "View Dir") { return "_view"; } - return QString::number(m_power); + return TString::number(m_power); } float power() const { @@ -72,18 +72,18 @@ class SurfaceDepth : public ShaderNode { m_outputs.push_back(std::make_pair("Depth", MetaType::FLOAT)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { - QStringList args = getArguments(code, stack, depth, type); + std::vector args = getArguments(code, stack, depth, type); - code.append(QString("float local%1 = (- _modelView * vec4(%2, 1.0f)).z;\n") - .arg(QString::number(depth), args[0])); + code.append(TString("float local%1 = (- _modelView * vec4(%2, 1.0f)).z;\n") + .arg(TString::number(depth), args[0])); } return ShaderNode::build(code, stack, link, depth, type); } - QString defaultValue(const TString &key, uint32_t &) const override { + TString defaultValue(const TString &key, uint32_t &) const override { return "_vertex.xyz"; } }; @@ -100,7 +100,7 @@ class WorldBitangent : public ShaderNode { m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR3)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { stack.push("_b"); } @@ -120,7 +120,7 @@ class WorldNormal : public ShaderNode { m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR3)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { stack.push("_n"); } @@ -140,7 +140,7 @@ class WorldPosition : public ShaderNode { m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR3)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { stack.push("_vertex.xyz"); } @@ -160,7 +160,7 @@ class WorldTangent : public ShaderNode { m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR3)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { stack.push("_t"); } diff --git a/modules/editor/shadertools/converter/functions/texturesample.h b/modules/editor/shadertools/converter/functions/texturesample.h index a46f8a2c7..ba0a68a1b 100644 --- a/modules/editor/shadertools/converter/functions/texturesample.h +++ b/modules/editor/shadertools/converter/functions/texturesample.h @@ -15,11 +15,11 @@ class TextureFunction : public ShaderNode { public: TextureFunction() { } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { type = MetaType::VECTOR4; - QString expr = makeExpression(getArguments(code, stack, depth, type)); + TString expr = makeExpression(getArguments(code, stack, depth, type)); code.append(localValue(type, depth, expr)); } @@ -36,7 +36,7 @@ class TextureFunction : public ShaderNode { } else if(link.oport->m_name == a) { channel = 3; } - stack.push(convert("local" + QString::number(result), + stack.push(convert(TString("local") + TString::number(result), MetaType::VECTOR4, (channel > -1) ? MetaType::FLOAT : MetaType::VECTOR4, channel)); @@ -49,16 +49,16 @@ class TextureFunction : public ShaderNode { return result; } - QString defaultValue(const TString &, uint32_t &) const override { + TString defaultValue(const TString &, uint32_t &) const override { return "_uv0"; } - QString makeExpression(const QStringList &args) const override { - return QString("texture(%2, %3)").arg(m_name.c_str(), args[0]); + TString makeExpression(const std::vector &args) const override { + return TString("texture(%1, %2)").arg(m_name, args[0]); } protected: - std::string m_name; + TString m_name; Vector4 m_sub; @@ -80,14 +80,14 @@ class TextureObject : public TextureFunction { m_outputs.push_back(std::make_pair("Texture", MetaType::STRING)); } - int32_t build(QString &code, QStack &stack,const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { int result = static_cast(m_graph)->addTexture(Engine::reference(m_texture), m_sub, false); if(result < 0) { reportMessage("Missing texture"); return -1; } - stack.push(QString("texture%1").arg(result)); + stack.push(TString("texture%1").arg(TString::number(result))); return ShaderNode::build(code, stack, link, depth, type); } @@ -126,14 +126,14 @@ class TextureSample : public TextureFunction { m_outputs.push_back(std::make_pair(a, MetaType::FLOAT)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { int result = static_cast(m_graph)->addTexture(Engine::reference(m_texture), m_sub, false); if(result < 0) { reportMessage("Missing texture"); return -1; } - m_name = QString("texture%1").arg(result).toStdString(); + m_name = TString("texture%1").arg(TString::number(result)); return TextureFunction::build(code, stack, link, depth, type); } @@ -171,19 +171,18 @@ class RenderTargetSample : public TextureFunction { m_outputs.push_back(std::make_pair(a, MetaType::FLOAT)); } - int32_t build(QString &code, QStack &stack,const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack,const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { static_cast(m_graph)->addTexture(m_name, m_sub, ShaderRootNode::Target); return TextureFunction::build(code, stack, link, depth, type); } - std::string targetName() const { + TString targetName() const { return m_name; } - void setTargetName(const std::string &name) { + void setTargetName(const TString &name) { m_name = name; - } }; @@ -206,14 +205,14 @@ class TextureSampleCube : public TextureSample { m_outputs.push_back(std::make_pair(a, MetaType::FLOAT)); } - int32_t build(QString &code, QStack &stack,const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack,const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { int result = static_cast(m_graph)->addTexture(Engine::reference(m_texture), m_sub, ShaderRootNode::Cube); if(result < 0) { reportMessage("Missing texture"); return -1; } - m_name = QString("texture%1").arg(result).toStdString(); + m_name = TString("texture%1").arg(TString::number(result)); return TextureFunction::build(code, stack, link, depth, type); } diff --git a/modules/editor/shadertools/converter/functions/time.h b/modules/editor/shadertools/converter/functions/time.h index cef67f1a7..bb0f9256e 100644 --- a/modules/editor/shadertools/converter/functions/time.h +++ b/modules/editor/shadertools/converter/functions/time.h @@ -21,11 +21,11 @@ class Time : public ShaderNode { m_outputs.push_back(std::make_pair("Output", MetaType::FLOAT)); } - int32_t build(QString &code, QStack &stack,const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack,const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { - QStringList args = getArguments(code, stack, depth, type); + std::vector args = getArguments(code, stack, depth, type); - QString value = getVariable() + " * " + args[0]; + TString value = getVariable() + " * " + args[0]; if(m_graph->isSingleConnection(link.oport)) { stack.push(value); @@ -36,11 +36,11 @@ class Time : public ShaderNode { return ShaderNode::build(code, stack, link, depth, type); } - QString defaultValue(const TString &, uint32_t &) const override { - return QString::number(m_scale); + TString defaultValue(const TString &, uint32_t &) const override { + return TString::number(m_scale); } - virtual QString getVariable() const { + virtual TString getVariable() const { return "g.time"; } @@ -62,7 +62,7 @@ class DeltaTime : public Time { public: DeltaTime() { } - QString getVariable() const override { + TString getVariable() const override { return "g.deltaTime"; } }; @@ -77,7 +77,7 @@ class CosTime : public Time { public: CosTime() { } - QString getVariable() const override { + TString getVariable() const override { return "cos(g.time)"; } }; @@ -92,7 +92,7 @@ class SinTime : public Time { public: SinTime() { } - QString getVariable() const override { + TString getVariable() const override { return "sin(g.time)"; } }; diff --git a/modules/editor/shadertools/converter/functions/trigonometry.h b/modules/editor/shadertools/converter/functions/trigonometry.h index c7b81244f..174e22fda 100644 --- a/modules/editor/shadertools/converter/functions/trigonometry.h +++ b/modules/editor/shadertools/converter/functions/trigonometry.h @@ -19,7 +19,7 @@ class ArcCosine : public ShaderNode { m_expression = "acos"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } @@ -41,7 +41,7 @@ class ArcSine : public ShaderNode { m_expression = "asin"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } @@ -63,7 +63,7 @@ class ArcTangent : public ShaderNode { m_expression = "atan"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } @@ -86,7 +86,7 @@ class ArcTangent2 : public ShaderNode { m_expression = "atan"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } @@ -108,7 +108,7 @@ class Cosine : public ShaderNode { m_expression = "cos"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } @@ -130,7 +130,7 @@ class CosineHyperbolic : public ShaderNode { m_expression = "cosh"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } @@ -152,7 +152,7 @@ class Sine : public ShaderNode { m_expression = "sin"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } @@ -174,7 +174,7 @@ class SineHyperbolic : public ShaderNode { m_expression = "sinh"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } @@ -196,7 +196,7 @@ class Tangent : public ShaderNode { m_expression = "tan"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } @@ -218,7 +218,7 @@ class TangentHyperbolic : public ShaderNode { m_expression = "tanh"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } @@ -240,7 +240,7 @@ class Degrees : public ShaderNode { m_expression = "degrees"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } @@ -262,7 +262,7 @@ class Radians : public ShaderNode { m_expression = "radians"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } diff --git a/modules/editor/shadertools/converter/functions/vectoroperator.h b/modules/editor/shadertools/converter/functions/vectoroperator.h index 79d99158f..83d31b99d 100644 --- a/modules/editor/shadertools/converter/functions/vectoroperator.h +++ b/modules/editor/shadertools/converter/functions/vectoroperator.h @@ -27,7 +27,7 @@ class CrossProduct : public ShaderNode { m_expression = "cross"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::VECTOR3; return compile(code, stack, link, depth, type); } @@ -50,7 +50,7 @@ class Distance : public ShaderNode { m_expression = "distance"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } @@ -73,7 +73,7 @@ class DotProduct : public ShaderNode { m_expression = "dot"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } @@ -95,7 +95,7 @@ class Length : public ShaderNode { m_expression = "length"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } @@ -117,7 +117,7 @@ class Normalize : public ShaderNode { m_expression = "normalize"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::FLOAT; return compile(code, stack, link, depth, type); } @@ -140,7 +140,7 @@ class Reflect : public ShaderNode { m_expression = "reflect"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::VECTOR3; return compile(code, stack, link, depth, type); } @@ -164,7 +164,7 @@ class Refract : public ShaderNode { m_expression = "refract"; } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { type = MetaType::VECTOR3; return compile(code, stack, link, depth, type); } @@ -187,11 +187,11 @@ class Append : public VectorOperator { m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR4)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { int i = 0; - QString value("vec4("); + TString value("vec4("); for(auto &it : m_ports) { if(it.m_out == false) { @@ -202,16 +202,17 @@ class Append : public VectorOperator { int32_t l_type = 0; int32_t index = node->build(code, stack, *l, depth, l_type); if(index >= 0) { - if(stack.isEmpty()) { - value += convert(QString("local%1").arg(QString::number(index)), l_type, MetaType::FLOAT); + if(stack.empty()) { + value += convert(TString("local%1").arg(TString::number(index)), l_type, MetaType::FLOAT); } else { - value += convert(stack.pop(), l_type, MetaType::FLOAT); + value += convert(stack.top(), l_type, MetaType::FLOAT); + stack.pop(); } } else { - value += QString::number(m_default[i]); + value += TString::number(m_default[i]); } } else { - value += QString::number(m_default[i]); + value += TString::number(m_default[i]); } if(i < 3) { value += ", "; @@ -257,11 +258,11 @@ class Split : public VectorOperator { m_outputs.push_back(std::make_pair(w, MetaType::FLOAT)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { int i = 0; - QString value = QString("vec4(%1, %2, %3, %4)").arg(m_default.x, m_default.y, m_default.z, m_default.w); + TString value = TString("vec4(%1, %2, %3, %4)").arg(TString::number(m_default.x), TString::number(m_default.y), TString::number(m_default.z), TString::number(m_default.w)); const AbstractNodeGraph::Link *l = m_graph->findLink(this, &m_ports.back()); if(l) { @@ -270,17 +271,18 @@ class Split : public VectorOperator { int32_t l_type = 0; int32_t index = node->build(code, stack, *l, depth, l_type); if(index >= 0) { - if(stack.isEmpty()) { - value = convert(QString("local%1").arg(QString::number(index)), l_type, MetaType::VECTOR4); + if(stack.empty()) { + value = convert(TString("local%1").arg(TString::number(index)), l_type, MetaType::VECTOR4); } else { - value = convert(stack.pop(), l_type, MetaType::VECTOR4); + value = convert(stack.top(), l_type, MetaType::VECTOR4); + stack.pop(); } } } for(auto &it : m_ports) { if(link.oport == &it) { - value += QString(".%1").arg(it.m_name.toLower().data()); + value += TString(".%1").arg(it.m_name.toLower()); } } @@ -350,11 +352,12 @@ class Swizzle : public VectorOperator { m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR4)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { int i = 0; - QString value = QString("vec4(%1, %2, %3, %4)").arg(m_default.x, m_default.y, m_default.z, m_default.w); + TString value = TString("vec4(%1, %2, %3, %4)").arg(TString::number(m_default.x), TString::number(m_default.y), + TString::number(m_default.z), TString::number(m_default.w)); const AbstractNodeGraph::Link *l = m_graph->findLink(this, &m_ports.back()); if(l) { @@ -363,10 +366,11 @@ class Swizzle : public VectorOperator { int32_t l_type = 0; int32_t index = node->build(code, stack, *l, depth, l_type); if(index >= 0) { - if(stack.isEmpty()) { - value = convert(QString("local%1").arg(QString::number(index)), l_type, MetaType::VECTOR4); + if(stack.empty()) { + value = convert(TString("local%1").arg(TString::number(index)), l_type, MetaType::VECTOR4); } else { - value = convert(stack.pop(), l_type, MetaType::VECTOR4); + value = convert(stack.top(), l_type, MetaType::VECTOR4); + stack.pop(); } } } @@ -437,7 +441,7 @@ class Mask : public VectorOperator { m_outputs.push_back(std::make_pair("Output", MetaType::INVALID)); } - int32_t build(QString &code, QStack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { + int32_t build(TString &code, std::stack &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override { if(m_position == -1) { const AbstractNodeGraph::Link *l = m_graph->findLink(this, &m_ports.back()); if(l) { @@ -446,7 +450,7 @@ class Mask : public VectorOperator { int32_t l_type = MetaType::VECTOR4; int32_t index = node->build(code, stack, *l, depth, l_type); if(index >= 0) { - QString mask; + TString mask; if(m_r) { mask += "r"; type = MetaType::FLOAT; @@ -480,11 +484,12 @@ class Mask : public VectorOperator { } } - QString value; - if(stack.isEmpty()) { - value = QString("local%1.%2").arg(QString::number(index), mask); + TString value; + if(stack.empty()) { + value = TString("local%1.%2").arg(TString::number(index), mask); } else { - value = QString("%1.%2").arg(stack.pop(), mask); + value = TString("%1.%2").arg(stack.top(), mask); + stack.pop(); } if(m_graph->isSingleConnection(link.oport)) { diff --git a/modules/editor/shadertools/converter/shadergraph.cpp b/modules/editor/shadertools/converter/shadergraph.cpp index 468012d38..3ebef8a99 100644 --- a/modules/editor/shadertools/converter/shadergraph.cpp +++ b/modules/editor/shadertools/converter/shadergraph.cpp @@ -32,6 +32,7 @@ #include "functions/trigonometry.h" #include "functions/logicoperator.h" #include "functions/vectoroperator.h" +#include "functions/customfunction.h" #include "shaderbuilder.h" @@ -591,19 +592,19 @@ TString ShaderGraph::buildFrom(GraphNode *node, Stage stage) { } } - QString result; + TString result; if(node == nullptr) { - return result.toStdString(); + return result; } int32_t depth = 0; ShaderNode *f = dynamic_cast(node); if(f) { if(stage == Vertex) { - return result.toStdString(); + return result; } - QStack stack; + std::stack stack; Link link; link.sender = f; for(auto &port : f->ports()) { @@ -613,15 +614,16 @@ TString ShaderGraph::buildFrom(GraphNode *node, Stage stage) { } } - QString type = "\tEmissive = %1;\n"; + TString type = "\tEmissive = %1;\n"; int32_t size = 0; int32_t index = f->build(result, stack, link, depth, size); if(index >= 0) { - if(stack.isEmpty()) { - result.append(type.arg(ShaderNode::convert("local" + QString::number(index), size, MetaType::VECTOR3))); + if(stack.empty()) { + result.append(type.arg(ShaderNode::convert(TString("local") + TString::number(index), size, MetaType::VECTOR3))); } else { - result.append(type.arg(ShaderNode::convert(stack.pop(), size, MetaType::VECTOR3))); + result.append(type.arg(ShaderNode::convert(stack.top(), size, MetaType::VECTOR3))); + stack.pop(); } } else { result.append(type.arg("vec3(0.0)")); @@ -630,24 +632,25 @@ TString ShaderGraph::buildFrom(GraphNode *node, Stage stage) { } else { for(NodePort &port : node->ports()) { // Iterate all ports for the node if(port.m_out == false && port.m_userFlags == stage) { - QString name = port.m_name.data(); + TString name = port.m_name; name.remove(' '); - QString value; + TString value; bool isDefault = true; const Link *link = findLink(node, &port); if(link) { ShaderNode *node = dynamic_cast(link->sender); if(node) { - QStack stack; + std::stack stack; int32_t size = 0; int32_t index = node->build(result, stack, *link, depth, size); if(index >= 0) { - if(stack.isEmpty()) { - value = ShaderNode::convert("local" + QString::number(index), size, port.m_type); + if(stack.empty()) { + value = ShaderNode::convert(TString("local") + TString::number(index), size, port.m_type); } else { - value = ShaderNode::convert(stack.pop(), size, port.m_type); + value = ShaderNode::convert(stack.top(), size, port.m_type); + stack.pop(); } isDefault = false; } @@ -657,31 +660,31 @@ TString ShaderGraph::buildFrom(GraphNode *node, Stage stage) { if(isDefault) { // Default value switch(port.m_type) { case MetaType::FLOAT: { - value = QString::number(port.m_var.toFloat()); + value = TString::number(port.m_var.toFloat()); } break; case MetaType::VECTOR2: { Vector2 v(port.m_var.toVector2()); - value = QString("vec2(%1, %2)").arg(QString::number(v.x), - QString::number(v.y)); + value = TString("vec2(%1, %2)").arg(TString::number(v.x), + TString::number(v.y)); } break; case MetaType::VECTOR3: { Vector3 v(port.m_var.toVector3()); - value = QString("vec3(%1, %2, %3)").arg(QString::number(v.x), - QString::number(v.y), - QString::number(v.z)); + value = TString("vec3(%1, %2, %3)").arg(TString::number(v.x), + TString::number(v.y), + TString::number(v.z)); } break; case MetaType::VECTOR4: { Vector4 v(port.m_var.toVector4()); - value = QString("vec4(%1, %2, %3, %4)").arg(QString::number(v.x), - QString::number(v.y), - QString::number(v.z), - QString::number(v.w)); + value = TString("vec4(%1, %2, %3, %4)").arg(TString::number(v.x), + TString::number(v.y), + TString::number(v.z), + TString::number(v.w)); } break; default: break; } } - result.append(QString("\t%1 = %2;\n").arg(name, value)); + result.append(TString("\t%1 = %2;\n").arg(name, value)); } } } diff --git a/modules/uikit/includes/uisystem.h b/modules/uikit/includes/uisystem.h index 879a9380d..18d5408a2 100644 --- a/modules/uikit/includes/uisystem.h +++ b/modules/uikit/includes/uisystem.h @@ -14,8 +14,11 @@ class UiSystem : public System { int threadPolicy() const override; - void addWidget(Widget *widget); - void removeWidget(Widget *widget); + static void addWidget(Widget *widget); + static void removeWidget(Widget *widget); + + static void riseWidget(Widget *widget); + static void lowerWidget(Widget *widget); static std::list &widgets(); diff --git a/modules/uikit/src/components/widget.cpp b/modules/uikit/src/components/widget.cpp index 14b3472a9..25ab78d3c 100644 --- a/modules/uikit/src/components/widget.cpp +++ b/modules/uikit/src/components/widget.cpp @@ -109,15 +109,11 @@ void Widget::drawSub(CommandBuffer &buffer) { \sa raise() */ void Widget::lower() { - UiSystem *render = static_cast(system()); - for(auto it : childWidgets()) { it->lower(); } - auto &widgets = render->widgets(); - widgets.remove(this); - widgets.push_front(this); + UiSystem::lowerWidget(this); } /*! Raises this widget to the top of the widget's stack. @@ -125,11 +121,7 @@ void Widget::lower() { \sa lower() */ void Widget::raise() { - UiSystem *render = static_cast(system()); - - auto &widgets = render->widgets(); - widgets.remove(this); - widgets.push_back(this); + UiSystem::riseWidget(this); for(auto it : childWidgets()) { it->raise(); diff --git a/modules/uikit/src/uisystem.cpp b/modules/uikit/src/uisystem.cpp index 97c2bca68..730337a17 100644 --- a/modules/uikit/src/uisystem.cpp +++ b/modules/uikit/src/uisystem.cpp @@ -118,6 +118,20 @@ void UiSystem::removeWidget(Widget *widget) { m_uiComponents.remove(widget); } +void UiSystem::riseWidget(Widget *widget) { + if(widget) { + m_uiComponents.remove(widget); + m_uiComponents.push_back(widget); + } +} + +void UiSystem::lowerWidget(Widget *widget) { + if(widget) { + m_uiComponents.remove(widget); + m_uiComponents.push_front(widget); + } +} + std::list &UiSystem::widgets() { return m_uiComponents; } diff --git a/thirdparty/next/inc/core/astring.h b/thirdparty/next/inc/core/astring.h index d2f085cea..0dd9ef3a1 100644 --- a/thirdparty/next/inc/core/astring.h +++ b/thirdparty/next/inc/core/astring.h @@ -133,6 +133,13 @@ class NEXT_LIBRARY_EXPORT TString { static TString fromWString(const std::wstring &in); static TString fromUtf32(const std::u32string &in); + TString arg(const TString &arg1); + TString arg(const TString &arg1, const TString &arg2); + TString arg(const TString &arg1, const TString &arg2, const TString &arg3); + TString arg(const TString &arg1, const TString &arg2, const TString &arg3, const TString &arg4); + TString arg(const TString &arg1, const TString &arg2, const TString &arg3, const TString &arg4, const TString &arg5); + TString arg(const TString &arg1, const TString &arg2, const TString &arg3, const TString &arg4, const TString &arg5, const TString &arg6); + private: std::string m_data; diff --git a/thirdparty/next/src/core/astring.cpp b/thirdparty/next/src/core/astring.cpp index a7d8f6b7f..6fc944664 100644 --- a/thirdparty/next/src/core/astring.cpp +++ b/thirdparty/next/src/core/astring.cpp @@ -431,3 +431,33 @@ std::u32string TString::toUtf32() const { } return result; } + +TString TString::arg(const TString &arg1) { + TString result(*this); + return result.replace("%1", arg1); +} + +TString TString::arg(const TString &arg1, const TString &arg2) { + TString result(*this); + return result.replace("%1", arg1).replace("%2", arg2); +} + +TString TString::arg(const TString &arg1, const TString &arg2, const TString &arg3) { + TString result(*this); + return result.replace("%1", arg1).replace("%2", arg2).replace("%3", arg3); +} + +TString TString::arg(const TString &arg1, const TString &arg2, const TString &arg3, const TString &arg4) { + TString result(*this); + return result.replace("%1", arg1).replace("%2", arg2).replace("%3", arg3).replace("%4", arg4); +} + +TString TString::arg(const TString &arg1, const TString &arg2, const TString &arg3, const TString &arg4, const TString &arg5) { + TString result(*this); + return result.replace("%1", arg1).replace("%2", arg2).replace("%3", arg3).replace("%4", arg4).replace("%5", arg5); +} + +TString TString::arg(const TString &arg1, const TString &arg2, const TString &arg3, const TString &arg4, const TString &arg5, const TString &arg6) { + TString result(*this); + return result.replace("%1", arg1).replace("%2", arg2).replace("%3", arg3).replace("%4", arg4).replace("%5", arg5).replace("%6", arg6); +}