diff options
| author | Juan Linietsky | 2018-05-07 14:30:44 -0300 |
|---|---|---|
| committer | GitHub | 2018-05-07 14:30:44 -0300 |
| commit | 0db4c576f1080bdb8819d2f83c9c01ba87d85a12 (patch) | |
| tree | f12d4f753d7812d0e7343cbab91965b3a4ca6498 /servers | |
| parent | 8c30337565326f313e398f6428eda5cb17614f14 (diff) | |
| parent | 5b50685b38bf527dff5a816ce4505a32ef682a9e (diff) | |
| download | godot-0db4c576f1080bdb8819d2f83c9c01ba87d85a12.tar.gz godot-0db4c576f1080bdb8819d2f83c9c01ba87d85a12.tar.zst godot-0db4c576f1080bdb8819d2f83c9c01ba87d85a12.zip | |
Diffstat (limited to 'servers')
| -rw-r--r-- | servers/visual/shader_language.cpp | 46 | ||||
| -rw-r--r-- | servers/visual/shader_language.h | 1 |
2 files changed, 44 insertions, 3 deletions
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index bfb9c871c..d399c548f 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -2207,6 +2207,37 @@ ShaderLanguage::DataType ShaderLanguage::get_scalar_type(DataType p_type) { return scalar_types[p_type]; } +int ShaderLanguage::get_cardinality(DataType p_type) { + static const int cardinality_table[] = { + 0, + 1, + 2, + 3, + 4, + 1, + 2, + 3, + 4, + 1, + 2, + 3, + 4, + 1, + 2, + 3, + 4, + 2, + 3, + 4, + 1, + 1, + 1, + 1, + }; + + return cardinality_table[p_type]; +} + bool ShaderLanguage::_get_completable_identifier(BlockNode *p_block, CompletionType p_type, StringName &identifier) { identifier = StringName(); @@ -3111,9 +3142,18 @@ ShaderLanguage::Node *ShaderLanguage::_reduce_expression(BlockNode *p_block, Sha if (get_scalar_type(cn->datatype) == base) { - for (int j = 0; j < cn->values.size(); j++) { - values.push_back(cn->values[j]); - } + int cardinality = get_cardinality(op->arguments[i]->get_datatype()); + if (cn->values.size() == cardinality) { + + for (int j = 0; j < cn->values.size(); j++) { + values.push_back(cn->values[j]); + } + } else if (cn->values.size() == 1) { + + for (int j = 0; j < cardinality; j++) { + values.push_back(cn->values[0]); + } + } // else: should be filtered by the parser as it's an invalid constructor } else if (get_scalar_type(cn->datatype) == cn->datatype) { ConstantNode::Value v; diff --git a/servers/visual/shader_language.h b/servers/visual/shader_language.h index 2e3881179..720511e18 100644 --- a/servers/visual/shader_language.h +++ b/servers/visual/shader_language.h @@ -533,6 +533,7 @@ public: static bool convert_constant(ConstantNode *p_constant, DataType p_to_type, ConstantNode::Value *p_value = NULL); static DataType get_scalar_type(DataType p_type); + static int get_cardinality(DataType p_type); static bool is_scalar_type(DataType p_type); static bool is_sampler_type(DataType p_type); |
