diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2018-03-15 20:24:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-15 20:24:44 +0100 |
commit | d3648b51b1bca6cba16a1d78c0b3d22671a9f66c (patch) | |
tree | 076014f6112fb34e9e200ce48a5c9661ce61caff /servers/visual/shader_language.cpp | |
parent | d5f3f3ddc262114f2d26ca864a9d78597d8fe7c6 (diff) | |
parent | 479f531635438430a36b487f00824699a6afd575 (diff) | |
download | redot-engine-d3648b51b1bca6cba16a1d78c0b3d22671a9f66c.tar.gz |
Merge pull request #17533 from JFonS/shader_allow_hint_defaults
Hinted shader uniforms can have a default value
Diffstat (limited to 'servers/visual/shader_language.cpp')
-rw-r--r-- | servers/visual/shader_language.cpp | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index f5c926c093..d5a9bfb606 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -3702,26 +3702,6 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct //todo parse default value tk = _get_token(); - if (tk.type == TK_OP_ASSIGN) { - - Node *expr = _parse_and_reduce_expression(NULL, Map<StringName, BuiltInInfo>()); - if (!expr) - return ERR_PARSE_ERROR; - if (expr->type != Node::TYPE_CONSTANT) { - _set_error("Expected constant expression after '='"); - return ERR_PARSE_ERROR; - } - - ConstantNode *cn = static_cast<ConstantNode *>(expr); - - uniform.default_value.resize(cn->values.size()); - - if (!convert_constant(cn, uniform.type, uniform.default_value.ptrw())) { - _set_error("Can't convert constant to " + get_datatype_name(uniform.type)); - return ERR_PARSE_ERROR; - } - tk = _get_token(); - } if (tk.type == TK_COLON) { //hint @@ -3837,6 +3817,27 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct tk = _get_token(); } + if (tk.type == TK_OP_ASSIGN) { + + Node *expr = _parse_and_reduce_expression(NULL, Map<StringName, BuiltInInfo>()); + if (!expr) + return ERR_PARSE_ERROR; + if (expr->type != Node::TYPE_CONSTANT) { + _set_error("Expected constant expression after '='"); + return ERR_PARSE_ERROR; + } + + ConstantNode *cn = static_cast<ConstantNode *>(expr); + + uniform.default_value.resize(cn->values.size()); + + if (!convert_constant(cn, uniform.type, uniform.default_value.ptrw())) { + _set_error("Can't convert constant to " + get_datatype_name(uniform.type)); + return ERR_PARSE_ERROR; + } + tk = _get_token(); + } + shader->uniforms[name] = uniform; if (tk.type != TK_SEMICOLON) { |