diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-10-29 19:24:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-29 19:24:08 +0100 |
commit | d749b738ad3f49107ec061dfa3679b14238ff681 (patch) | |
tree | ff51cb80c376c51c0ee266cb8d01f13049f0e6ee /servers | |
parent | b8daad97790a2bb855336b94525d74153c966e0b (diff) | |
parent | 76eb48641390ab9513776a3e8829ea739fa015e8 (diff) |
Merge pull request #33159 from Chaosus/shader_fix2
Added check if field name in the shader is equal to builtin
Diffstat (limited to 'servers')
-rw-r--r-- | servers/visual/shader_language.cpp | 41 | ||||
-rw-r--r-- | servers/visual/shader_language.h | 1 |
2 files changed, 42 insertions, 0 deletions
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 4e5e816c02..46f65bb758 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -4754,6 +4754,11 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } + if (has_builtin(p_functions, name)) { + _set_error("Redefinition of '" + String(name) + "'"); + return ERR_PARSE_ERROR; + } + if (uniform) { ShaderNode::Uniform uniform2; @@ -5002,6 +5007,11 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } + if (has_builtin(p_functions, name)) { + _set_error("Redefinition of '" + String(name) + "'"); + return ERR_PARSE_ERROR; + } + tk = _get_token(); if (tk.type != TK_PARENTHESIS_OPEN) { if (type == TYPE_VOID) { @@ -5060,6 +5070,11 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } + if (has_builtin(p_functions, name)) { + _set_error("Redefinition of '" + String(name) + "'"); + return ERR_PARSE_ERROR; + } + tk = _get_token(); } else if (tk.type == TK_SEMICOLON) { @@ -5161,6 +5176,12 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } } + + if (has_builtin(p_functions, pname)) { + _set_error("Redefinition of '" + String(pname) + "'"); + return ERR_PARSE_ERROR; + } + FunctionNode::Argument arg; arg.type = ptype; arg.name = pname; @@ -5227,6 +5248,26 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return OK; } +bool ShaderLanguage::has_builtin(const Map<StringName, ShaderLanguage::FunctionInfo> &p_functions, const StringName &p_name) { + + if (p_functions.has("vertex")) { + if (p_functions["vertex"].built_ins.has(p_name)) { + return true; + } + } + if (p_functions.has("fragment")) { + if (p_functions["fragment"].built_ins.has(p_name)) { + return true; + } + } + if (p_functions.has("light")) { + if (p_functions["light"].built_ins.has(p_name)) { + return true; + } + } + return false; +} + Error ShaderLanguage::_find_last_flow_op_in_op(ControlFlowNode *p_flow, FlowOperation p_op) { bool found = false; diff --git a/servers/visual/shader_language.h b/servers/visual/shader_language.h index ceeaaf8872..e62881f5c6 100644 --- a/servers/visual/shader_language.h +++ b/servers/visual/shader_language.h @@ -645,6 +645,7 @@ public: Map<StringName, BuiltInInfo> built_ins; bool can_discard; }; + static bool has_builtin(const Map<StringName, ShaderLanguage::FunctionInfo> &p_functions, const StringName &p_name); private: struct KeyWord { |