Improve performance of Add/Remove/Connect/Change nodes in visual shader
This commit is contained in:
parent
beb9ebcda0
commit
8dbf3d7c44
4 changed files with 669 additions and 479 deletions
File diff suppressed because it is too large
Load diff
|
@ -54,6 +54,10 @@ class VisualShaderGraphPlugin : public Reference {
|
||||||
GDCLASS(VisualShaderGraphPlugin, Reference);
|
GDCLASS(VisualShaderGraphPlugin, Reference);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct InputPort {
|
||||||
|
Button *default_input_button;
|
||||||
|
};
|
||||||
|
|
||||||
struct Port {
|
struct Port {
|
||||||
TextureButton *preview_button;
|
TextureButton *preview_button;
|
||||||
};
|
};
|
||||||
|
@ -64,12 +68,16 @@ private:
|
||||||
GraphNode *graph_node;
|
GraphNode *graph_node;
|
||||||
bool preview_visible;
|
bool preview_visible;
|
||||||
int preview_pos;
|
int preview_pos;
|
||||||
|
Map<int, InputPort> input_ports;
|
||||||
Map<int, Port> output_ports;
|
Map<int, Port> output_ports;
|
||||||
VBoxContainer *preview_box;
|
VBoxContainer *preview_box;
|
||||||
|
Control *custom_editor;
|
||||||
|
int editor_pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
Ref<VisualShader> visual_shader;
|
Ref<VisualShader> visual_shader;
|
||||||
Map<int, Link> links;
|
Map<int, Link> links;
|
||||||
|
List<VisualShader::Connection> connections;
|
||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -77,15 +85,29 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void register_shader(VisualShader *p_visual_shader);
|
void register_shader(VisualShader *p_visual_shader);
|
||||||
|
void set_connections(List<VisualShader::Connection> &p_connections);
|
||||||
void register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node);
|
void register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node);
|
||||||
void register_output_port(int p_id, int p_port, TextureButton *p_button);
|
void register_output_port(int p_id, int p_port, TextureButton *p_button);
|
||||||
|
void register_custom_editor(int p_node_id, Control *p_custom_editor);
|
||||||
|
void register_editor_pos(int p_node_id, int p_pos);
|
||||||
void clear_links();
|
void clear_links();
|
||||||
void set_shader_type(VisualShader::Type p_type);
|
void set_shader_type(VisualShader::Type p_type);
|
||||||
bool is_preview_visible(int p_id) const;
|
bool is_preview_visible(int p_id) const;
|
||||||
bool is_dirty() const;
|
bool is_dirty() const;
|
||||||
void make_dirty(bool p_enabled);
|
void make_dirty(bool p_enabled);
|
||||||
|
void add_node(VisualShader::Type p_type, int p_id);
|
||||||
void show_port_preview(int p_node_id, int p_port_id);
|
void remove_node(VisualShader::Type p_type, int p_id);
|
||||||
|
void connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);
|
||||||
|
void disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);
|
||||||
|
void show_port_preview(VisualShader::Type p_type, int p_node_id, int p_port_id);
|
||||||
|
void set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position);
|
||||||
|
void set_node_size(VisualShader::Type p_type, int p_id, const Vector2 &p_size);
|
||||||
|
void refresh_node_ports(VisualShader::Type p_type, int p_node);
|
||||||
|
void update_property_editor(VisualShader::Type p_type, int p_node_id);
|
||||||
|
void update_property_editor_deferred(VisualShader::Type p_type, int p_node_id);
|
||||||
|
void set_input_port_default_value(VisualShader::Type p_type, int p_node_id, int p_port_id, Variant p_value);
|
||||||
|
void register_default_input_button(int p_node_id, int p_port_id, Button *p_button);
|
||||||
|
VisualShader::Type get_shader_type() const;
|
||||||
|
|
||||||
VisualShaderGraphPlugin();
|
VisualShaderGraphPlugin();
|
||||||
~VisualShaderGraphPlugin();
|
~VisualShaderGraphPlugin();
|
||||||
|
@ -328,6 +350,7 @@ class VisualShaderEditor : public VBoxContainer {
|
||||||
|
|
||||||
bool _is_available(int p_mode);
|
bool _is_available(int p_mode);
|
||||||
void _update_created_node(GraphNode *node);
|
void _update_created_node(GraphNode *node);
|
||||||
|
void _update_uniforms();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
@ -339,6 +362,7 @@ public:
|
||||||
void remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin);
|
void remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin);
|
||||||
|
|
||||||
static VisualShaderEditor *get_singleton() { return singleton; }
|
static VisualShaderEditor *get_singleton() { return singleton; }
|
||||||
|
VisualShaderGraphPlugin *get_graph_plugin() { return graph_plugin.ptr(); }
|
||||||
|
|
||||||
void clear_custom_types();
|
void clear_custom_types();
|
||||||
void add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, bool p_highend);
|
void add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, bool p_highend);
|
||||||
|
|
|
@ -40,7 +40,6 @@ bool VisualShaderNode::is_simple_decl() const {
|
||||||
|
|
||||||
void VisualShaderNode::set_output_port_for_preview(int p_index) {
|
void VisualShaderNode::set_output_port_for_preview(int p_index) {
|
||||||
port_preview = p_index;
|
port_preview = p_index;
|
||||||
emit_signal("show_port_preview", p_index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int VisualShaderNode::get_output_port_for_preview() const {
|
int VisualShaderNode::get_output_port_for_preview() const {
|
||||||
|
@ -162,7 +161,6 @@ void VisualShaderNode::_bind_methods() {
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "output_port_for_preview"), "set_output_port_for_preview", "get_output_port_for_preview");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "output_port_for_preview"), "set_output_port_for_preview", "get_output_port_for_preview");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "default_input_values", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_default_input_values", "get_default_input_values");
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "default_input_values", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_default_input_values", "get_default_input_values");
|
||||||
ADD_SIGNAL(MethodInfo("editor_refresh_request"));
|
ADD_SIGNAL(MethodInfo("editor_refresh_request"));
|
||||||
ADD_SIGNAL(MethodInfo("show_port_preview", PropertyInfo(Variant::INT, "port_id")));
|
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(PORT_TYPE_SCALAR);
|
BIND_ENUM_CONSTANT(PORT_TYPE_SCALAR);
|
||||||
BIND_ENUM_CONSTANT(PORT_TYPE_SCALAR_INT);
|
BIND_ENUM_CONSTANT(PORT_TYPE_SCALAR_INT);
|
||||||
|
@ -319,13 +317,6 @@ VisualShaderNodeCustom::VisualShaderNodeCustom() {
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void VisualShader::set_graph_node(Type p_type, int p_id, GraphNode *p_graph_node) {
|
|
||||||
ERR_FAIL_INDEX(p_type, TYPE_MAX);
|
|
||||||
Graph *g = &graph[p_type];
|
|
||||||
ERR_FAIL_COND(!g->nodes.has(p_id));
|
|
||||||
g->nodes[p_id].graph_node = p_graph_node;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VisualShader::set_shader_type(Type p_type) {
|
void VisualShader::set_shader_type(Type p_type) {
|
||||||
current_type = p_type;
|
current_type = p_type;
|
||||||
}
|
}
|
||||||
|
@ -417,11 +408,6 @@ void VisualShader::set_node_position(Type p_type, int p_id, const Vector2 &p_pos
|
||||||
Graph *g = &graph[p_type];
|
Graph *g = &graph[p_type];
|
||||||
ERR_FAIL_COND(!g->nodes.has(p_id));
|
ERR_FAIL_COND(!g->nodes.has(p_id));
|
||||||
g->nodes[p_id].position = p_position;
|
g->nodes[p_id].position = p_position;
|
||||||
if (current_type == p_type) {
|
|
||||||
if (g->nodes[p_id].graph_node != nullptr) {
|
|
||||||
g->nodes[p_id].graph_node->set_offset(p_position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 VisualShader::get_node_position(Type p_type, int p_id) const {
|
Vector2 VisualShader::get_node_position(Type p_type, int p_id) const {
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
|
|
||||||
#include "core/string_builder.h"
|
#include "core/string_builder.h"
|
||||||
#include "scene/gui/control.h"
|
#include "scene/gui/control.h"
|
||||||
#include "scene/gui/graph_edit.h"
|
|
||||||
#include "scene/resources/shader.h"
|
#include "scene/resources/shader.h"
|
||||||
|
|
||||||
class VisualShaderNodeUniform;
|
class VisualShaderNodeUniform;
|
||||||
|
@ -76,7 +75,6 @@ private:
|
||||||
Ref<VisualShaderNode> node;
|
Ref<VisualShaderNode> node;
|
||||||
Vector2 position;
|
Vector2 position;
|
||||||
List<int> prev_connected_nodes;
|
List<int> prev_connected_nodes;
|
||||||
GraphNode *graph_node;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Graph {
|
struct Graph {
|
||||||
|
@ -129,7 +127,6 @@ protected:
|
||||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||||
|
|
||||||
public: // internal methods
|
public: // internal methods
|
||||||
void set_graph_node(Type p_type, int p_id, GraphNode *p_graph_node);
|
|
||||||
void set_shader_type(Type p_type);
|
void set_shader_type(Type p_type);
|
||||||
Type get_shader_type() const;
|
Type get_shader_type() const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue