From 6d992abb541d4e772ef1fbc16d0b82ca3a6b343d Mon Sep 17 00:00:00 2001 From: Yuri Rubinsky Date: Sat, 23 Jul 2022 09:38:59 +0300 Subject: [PATCH] Fix some errors after shader preprocessor PR --- editor/plugins/shader_editor_plugin.cpp | 6 ++-- servers/rendering/shader_preprocessor.cpp | 44 +++++------------------ servers/rendering/shader_preprocessor.h | 2 -- 3 files changed, 12 insertions(+), 40 deletions(-) diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index e7e7751f3b5..4af44da35bb 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -381,7 +381,7 @@ void ShaderTextEditor::_validate_script() { //preprocessor error ERR_FAIL_COND(err_positions.size() == 0); - String error_text; + String error_text = error_pp; int error_line = err_positions.front()->get().line; if (err_positions.size() == 1) { // Error in main file @@ -1198,12 +1198,12 @@ void ShaderEditorPlugin::edit(Object *p_object) { Ref vs = es.shader; if (vs.is_valid()) { es.visual_shader_editor = memnew(VisualShaderEditor); - es.visual_shader_editor->edit(vs.ptr()); shader_tabs->add_child(es.visual_shader_editor); + es.visual_shader_editor->edit(vs.ptr()); } else { es.shader_editor = memnew(ShaderEditor); - es.shader_editor->edit(s); shader_tabs->add_child(es.shader_editor); + es.shader_editor->edit(s); es.shader_editor->connect("validation_changed", callable_mp(this, &ShaderEditorPlugin::_update_shader_list_status)); } } diff --git a/servers/rendering/shader_preprocessor.cpp b/servers/rendering/shader_preprocessor.cpp index 9623d110108..a7b274b3e27 100644 --- a/servers/rendering/shader_preprocessor.cpp +++ b/servers/rendering/shader_preprocessor.cpp @@ -344,41 +344,23 @@ void ShaderPreprocessor::process_directive(Tokenizer *p_tokenizer) { } if (directive == "if") { - if (check_directive_before_type(p_tokenizer, directive)) { - process_if(p_tokenizer); - } + process_if(p_tokenizer); } else if (directive == "ifdef") { - if (check_directive_before_type(p_tokenizer, directive)) { - process_ifdef(p_tokenizer); - } + process_ifdef(p_tokenizer); } else if (directive == "ifndef") { - if (check_directive_before_type(p_tokenizer, directive)) { - process_ifndef(p_tokenizer); - } + process_ifndef(p_tokenizer); } else if (directive == "else") { - if (check_directive_before_type(p_tokenizer, directive)) { - process_else(p_tokenizer); - } + process_else(p_tokenizer); } else if (directive == "endif") { - if (check_directive_before_type(p_tokenizer, directive)) { - process_endif(p_tokenizer); - } + process_endif(p_tokenizer); } else if (directive == "define") { - if (check_directive_before_type(p_tokenizer, directive)) { - process_define(p_tokenizer); - } + process_define(p_tokenizer); } else if (directive == "undef") { - if (check_directive_before_type(p_tokenizer, directive)) { - process_undef(p_tokenizer); - } + process_undef(p_tokenizer); } else if (directive == "include") { - if (check_directive_before_type(p_tokenizer, directive)) { - process_include(p_tokenizer); - } + process_include(p_tokenizer); } else if (directive == "pragma") { - if (check_directive_before_type(p_tokenizer, directive)) { - process_pragma(p_tokenizer); - } + process_pragma(p_tokenizer); } else { set_error(RTR("Unknown directive."), p_tokenizer->get_line()); } @@ -880,14 +862,6 @@ void ShaderPreprocessor::set_error(const String &p_error, int p_line) { } } -bool ShaderPreprocessor::check_directive_before_type(Tokenizer *p_tokenizer, const String &p_directive) { - if (p_tokenizer->get_index() < state->shader_type_pos) { - set_error(vformat(RTR("`#%s` may not be defined before `shader_type`."), p_directive), p_tokenizer->get_line()); - return false; - } - return true; -} - ShaderPreprocessor::Define *ShaderPreprocessor::create_define(const String &p_body) { ShaderPreprocessor::Define *define = memnew(Define); define->body = p_body; diff --git a/servers/rendering/shader_preprocessor.h b/servers/rendering/shader_preprocessor.h index 9bac7060496..a93fb680dd2 100644 --- a/servers/rendering/shader_preprocessor.h +++ b/servers/rendering/shader_preprocessor.h @@ -136,7 +136,6 @@ private: int include_depth = 0; String current_include; String current_shader_type; - int shader_type_pos = -1; String error; List include_positions; RBMap> skipped_conditions; @@ -179,7 +178,6 @@ private: String next_directive(Tokenizer *p_tokenizer, const Vector &p_directives); void add_to_output(const String &p_str); void set_error(const String &p_error, int p_line); - bool check_directive_before_type(Tokenizer *p_tokenizer, const String &p_directive); static Define *create_define(const String &p_body);