Fix shader constant sorting

This commit is contained in:
Yuri Roubinsky 2020-03-31 14:32:33 +03:00
parent e707b712e8
commit ee93c85ef1
4 changed files with 15 additions and 10 deletions

View File

@ -368,14 +368,14 @@ String ShaderCompilerGLES2::_dump_node_code(SL::Node *p_node, int p_level, Gener
// constants
for (Map<StringName, SL::ShaderNode::Constant>::Element *E = snode->constants.front(); E; E = E->next()) {
for (int i = 0; i < snode->vconstants.size(); i++) {
String gcode;
gcode += "const ";
gcode += _prestr(E->get().precision);
gcode += _typestr(E->get().type);
gcode += " " + _mkid(E->key());
gcode += _prestr(snode->vconstants[i].precision);
gcode += _typestr(snode->vconstants[i].type);
gcode += " " + _mkid(String(snode->vconstants[i].name));
gcode += "=";
gcode += _dump_node_code(E->get().initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
gcode += _dump_node_code(snode->vconstants[i].initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
gcode += ";\n";
vertex_global += gcode;
fragment_global += gcode;

View File

@ -440,14 +440,14 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
r_gen_code.fragment_global += interp_mode + "in " + vcode;
}
for (Map<StringName, SL::ShaderNode::Constant>::Element *E = pnode->constants.front(); E; E = E->next()) {
for (int i = 0; i < pnode->vconstants.size(); i++) {
String gcode;
gcode += "const ";
gcode += _prestr(E->get().precision);
gcode += _typestr(E->get().type);
gcode += " " + _mkid(E->key());
gcode += _prestr(pnode->vconstants[i].precision);
gcode += _typestr(pnode->vconstants[i].type);
gcode += " " + _mkid(String(pnode->vconstants[i].name));
gcode += "=";
gcode += _dump_node_code(E->get().initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
gcode += _dump_node_code(pnode->vconstants[i].initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
gcode += ";\n";
r_gen_code.vertex_global += gcode;
r_gen_code.fragment_global += gcode;

View File

@ -5156,6 +5156,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
while (true) {
ShaderNode::Constant constant;
constant.name = name;
constant.type = type;
constant.precision = precision;
constant.initializer = NULL;
@ -5190,6 +5191,8 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
}
shader->constants[name] = constant;
shader->vconstants.push_back(constant);
if (tk.type == TK_COMMA) {
tk = _get_token();
if (tk.type != TK_IDENTIFIER) {

View File

@ -512,6 +512,7 @@ public:
struct ShaderNode : public Node {
struct Constant {
StringName name;
DataType type;
DataPrecision precision;
ConstantNode *initializer;
@ -577,6 +578,7 @@ public:
Vector<StringName> render_modes;
Vector<Function> functions;
Vector<Constant> vconstants;
ShaderNode() :
Node(TYPE_SHADER) {}