summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-07-15 15:45:07 +0200
committerGitHub <noreply@github.com>2019-07-15 15:45:07 +0200
commite6230a36f866c09f5ef9d70af33709d95b6fd812 (patch)
tree0bd2f017a572124caf497734229c98d4e70eb610 /drivers
parent7e27da54d8ac3cacd7ecdcb8cdf009d76702ed69 (diff)
parentc37379456fddb6515ec9e95b273a668accb3357b (diff)
Merge pull request #30500 from Chaosus/shader_arrays
Implemented local shader arrays
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gles2/shader_compiler_gles2.cpp74
-rw-r--r--drivers/gles3/shader_compiler_gles3.cpp66
2 files changed, 140 insertions, 0 deletions
diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp
index ee34a478b1..af88d0172a 100644
--- a/drivers/gles2/shader_compiler_gles2.cpp
+++ b/drivers/gles2/shader_compiler_gles2.cpp
@@ -510,7 +510,81 @@ String ShaderCompilerGLES2::_dump_node_code(SL::Node *p_node, int p_level, Gener
}
}
} break;
+ case SL::Node::TYPE_ARRAY_DECLARATION: {
+ SL::ArrayDeclarationNode *var_dec_node = (SL::ArrayDeclarationNode *)p_node;
+
+ StringBuffer<> declaration;
+
+ declaration += _prestr(var_dec_node->precision);
+ declaration += _typestr(var_dec_node->datatype);
+
+ for (int i = 0; i < var_dec_node->declarations.size(); i++) {
+
+ if (i > 0) {
+ declaration += ",";
+ }
+
+ declaration += " ";
+
+ declaration += _mkid(var_dec_node->declarations[i].name);
+ declaration += "[";
+ declaration += itos(var_dec_node->declarations[i].size);
+ declaration += "]";
+ }
+
+ code += declaration.as_string();
+ } break;
+ case SL::Node::TYPE_ARRAY: {
+ SL::ArrayNode *var_node = (SL::ArrayNode *)p_node;
+
+ if (p_assigning && p_actions.write_flag_pointers.has(var_node->name)) {
+ *p_actions.write_flag_pointers[var_node->name] = true;
+ }
+
+ if (p_default_actions.usage_defines.has(var_node->name) && !used_name_defines.has(var_node->name)) {
+ String define = p_default_actions.usage_defines[var_node->name];
+
+ if (define.begins_with("@")) {
+ define = p_default_actions.usage_defines[define.substr(1, define.length())];
+ }
+
+ r_gen_code.custom_defines.push_back(define.utf8());
+ used_name_defines.insert(var_node->name);
+ }
+
+ if (p_actions.usage_flag_pointers.has(var_node->name) && !used_flag_pointers.has(var_node->name)) {
+ *p_actions.usage_flag_pointers[var_node->name] = true;
+ used_flag_pointers.insert(var_node->name);
+ }
+
+ if (p_default_actions.renames.has(var_node->name)) {
+ code += p_default_actions.renames[var_node->name];
+ } else {
+ code += _mkid(var_node->name);
+ }
+
+ if (var_node->call_expression != NULL) {
+ code += ".";
+ code += _dump_node_code(var_node->call_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
+ }
+
+ if (var_node->index_expression != NULL) {
+ code += "[";
+ code += _dump_node_code(var_node->index_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
+ code += "]";
+ }
+
+ if (var_node->name == time_name) {
+ if (current_func_name == vertex_name) {
+ r_gen_code.uses_vertex_time = true;
+ }
+ if (current_func_name == fragment_name || current_func_name == light_name) {
+ r_gen_code.uses_fragment_time = true;
+ }
+ }
+
+ } break;
case SL::Node::TYPE_CONSTANT: {
SL::ConstantNode *const_node = (SL::ConstantNode *)p_node;
diff --git a/drivers/gles3/shader_compiler_gles3.cpp b/drivers/gles3/shader_compiler_gles3.cpp
index b0f0a71d56..ae68f0a06d 100644
--- a/drivers/gles3/shader_compiler_gles3.cpp
+++ b/drivers/gles3/shader_compiler_gles3.cpp
@@ -607,6 +607,72 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
}
} break;
+ case SL::Node::TYPE_ARRAY_DECLARATION: {
+
+ SL::ArrayDeclarationNode *vdnode = (SL::ArrayDeclarationNode *)p_node;
+
+ String declaration = _prestr(vdnode->precision) + _typestr(vdnode->datatype);
+ for (int i = 0; i < vdnode->declarations.size(); i++) {
+ if (i > 0) {
+ declaration += ",";
+ } else {
+ declaration += " ";
+ }
+ declaration += _mkid(vdnode->declarations[i].name);
+ declaration += "[";
+ declaration += itos(vdnode->declarations[i].size);
+ declaration += "]";
+ }
+
+ code += declaration;
+ } break;
+ case SL::Node::TYPE_ARRAY: {
+ SL::ArrayNode *vnode = (SL::ArrayNode *)p_node;
+
+ if (p_assigning && p_actions.write_flag_pointers.has(vnode->name)) {
+ *p_actions.write_flag_pointers[vnode->name] = true;
+ }
+
+ if (p_default_actions.usage_defines.has(vnode->name) && !used_name_defines.has(vnode->name)) {
+ String define = p_default_actions.usage_defines[vnode->name];
+ if (define.begins_with("@")) {
+ define = p_default_actions.usage_defines[define.substr(1, define.length())];
+ }
+ r_gen_code.defines.push_back(define.utf8());
+ used_name_defines.insert(vnode->name);
+ }
+
+ if (p_actions.usage_flag_pointers.has(vnode->name) && !used_flag_pointers.has(vnode->name)) {
+ *p_actions.usage_flag_pointers[vnode->name] = true;
+ used_flag_pointers.insert(vnode->name);
+ }
+
+ if (p_default_actions.renames.has(vnode->name))
+ code = p_default_actions.renames[vnode->name];
+ else
+ code = _mkid(vnode->name);
+
+ if (vnode->call_expression != NULL) {
+ code += ".";
+ code += _dump_node_code(vnode->call_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
+ }
+
+ if (vnode->index_expression != NULL) {
+ code += "[";
+ code += _dump_node_code(vnode->index_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
+ code += "]";
+ }
+
+ if (vnode->name == time_name) {
+ if (current_func_name == vertex_name) {
+ r_gen_code.uses_vertex_time = true;
+ }
+ if (current_func_name == fragment_name || current_func_name == light_name) {
+ r_gen_code.uses_fragment_time = true;
+ }
+ }
+
+ } break;
case SL::Node::TYPE_CONSTANT: {
SL::ConstantNode *cnode = (SL::ConstantNode *)p_node;
return get_constant_text(cnode->datatype, cnode->values);