From 494ea78610c267f34c231c7ace9b98f4d87a6f99 Mon Sep 17 00:00:00 2001 From: Yuri Roubinski Date: Sun, 25 Aug 2019 09:22:09 +0300 Subject: [PATCH] Small performance fix for preview in visual shader --- .../plugins/visual_shader_editor_plugin.cpp | 22 ++++++++++--------- editor/plugins/visual_shader_editor_plugin.h | 1 + 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 0bfe366a6d5..55ff3fc3ddb 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -2058,16 +2058,20 @@ void VisualShaderEditor::_show_preview_text() { preview_showed = !preview_showed; preview_vbox->set_visible(preview_showed); if (preview_showed) { - if (shader_error) { - error_text->set_visible(true); - } else { - error_text->set_visible(false); + if (pending_update_preview) { + _update_preview(); + pending_update_preview = false; } } } void VisualShaderEditor::_update_preview() { + if (!preview_showed) { + pending_update_preview = true; + return; + } + String code = visual_shader->get_code(); preview_text->set_text(code); @@ -2081,16 +2085,13 @@ void VisualShaderEditor::_update_preview() { } if (err != OK) { preview_text->set_line_as_marked(sl.get_error_line() - 1, true); - if (preview_showed) { - error_text->set_visible(true); - } + error_text->set_visible(true); + String text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text(); error_text->set_text(text); shader_error = true; } else { - if (preview_showed) { - error_text->set_visible(false); - } + error_text->set_visible(false); shader_error = false; } } @@ -2163,6 +2164,7 @@ VisualShaderEditor::VisualShaderEditor() { ShaderLanguage::get_keyword_list(&keyword_list); preview_showed = false; + pending_update_preview = false; shader_error = false; to_node = -1; diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index 5be214f9a99..a2e9516a6eb 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -70,6 +70,7 @@ class VisualShaderEditor : public VBoxContainer { PanelContainer *error_panel; Label *error_label; + bool pending_update_preview; bool shader_error; VBoxContainer *preview_vbox; TextEdit *preview_text;