Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorThomas Dinges <blender@dingto.org>2015-01-22 11:58:11 +0300
committerThomas Dinges <blender@dingto.org>2015-01-22 11:59:16 +0300
commit1aa8f0d3c02f65c4e70a5e87dd45f44a135a66a2 (patch)
tree901835c54a87815ab774c7b95f1efefae69d1720 /intern
parent82702db4078768eb4b9a59050b17ab1b537eb48a (diff)
Cleanup / Cycles: Code de-duplication for graph node relinking.
Differential Revision: https://developer.blender.org/D1018
Diffstat (limited to 'intern')
-rw-r--r--intern/cycles/render/graph.cpp76
-rw-r--r--intern/cycles/render/graph.h1
2 files changed, 23 insertions, 54 deletions
diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp
index 84fe55b69dd..6d05e5249cb 100644
--- a/intern/cycles/render/graph.cpp
+++ b/intern/cycles/render/graph.cpp
@@ -227,6 +227,21 @@ void ShaderGraph::disconnect(ShaderInput *to)
from->links.erase(remove(from->links.begin(), from->links.end(), to), from->links.end());
}
+void ShaderGraph::relink(vector<ShaderInput*> inputs, vector<ShaderInput*> outputs, ShaderOutput *output)
+{
+ /* Remove nodes and re-link if output isn't NULL. */
+ foreach(ShaderInput *sock, inputs) {
+ if(sock->link)
+ disconnect(sock);
+ }
+
+ foreach(ShaderInput *sock, outputs) {
+ disconnect(sock);
+ if(output)
+ connect(output, sock);
+ }
+}
+
void ShaderGraph::finalize(bool do_bump, bool do_osl)
{
/* before compiling, the shader graph may undergo a number of modifications.
@@ -383,14 +398,7 @@ void ShaderGraph::remove_unneeded_nodes()
(!bg->inputs[1]->link && bg->inputs[1]->value.x == 0.0f)) {
vector<ShaderInput*> inputs = bg->outputs[0]->links;
- foreach(ShaderInput *sock, bg->inputs) {
- if(sock->link)
- disconnect(sock);
- }
-
- foreach(ShaderInput *input, inputs)
- disconnect(input);
-
+ relink(bg->inputs, inputs, NULL);
removed[bg->id] = true;
any_node_removed = true;
}
@@ -404,15 +412,7 @@ void ShaderGraph::remove_unneeded_nodes()
ShaderOutput *output = mix->inputs[1]->link;
vector<ShaderInput*> inputs = mix->outputs[0]->links;
- foreach(ShaderInput *sock, mix->inputs)
- if(sock->link)
- disconnect(sock);
-
- foreach(ShaderInput *input, inputs) {
- disconnect(input);
- if(output)
- connect(output, input);
- }
+ relink(mix->inputs, inputs, output);
removed[mix->id] = true;
any_node_removed = true;
}
@@ -425,15 +425,7 @@ void ShaderGraph::remove_unneeded_nodes()
ShaderOutput *output = mix->inputs[1]->link;
vector<ShaderInput*> inputs = mix->outputs[0]->links;
- foreach(ShaderInput *sock, mix->inputs)
- if(sock->link)
- disconnect(sock);
-
- foreach(ShaderInput *input, inputs) {
- disconnect(input);
- if(output)
- connect(output, input);
- }
+ relink(mix->inputs, inputs, output);
removed[mix->id] = true;
any_node_removed = true;
}
@@ -441,16 +433,8 @@ void ShaderGraph::remove_unneeded_nodes()
else if(mix->inputs[0]->value.x == 1.0f) {
ShaderOutput *output = mix->inputs[2]->link;
vector<ShaderInput*> inputs = mix->outputs[0]->links;
-
- foreach(ShaderInput *sock, mix->inputs)
- if(sock->link)
- disconnect(sock);
-
- foreach(ShaderInput *input, inputs) {
- disconnect(input);
- if(output)
- connect(output, input);
- }
+
+ relink(mix->inputs, inputs, output);
removed[mix->id] = true;
any_node_removed = true;
}
@@ -467,15 +451,7 @@ void ShaderGraph::remove_unneeded_nodes()
ShaderOutput *output = mix->inputs[1]->link;
vector<ShaderInput*> inputs = mix->outputs[0]->links;
- foreach(ShaderInput *sock, mix->inputs)
- if(sock->link)
- disconnect(sock);
-
- foreach(ShaderInput *input, inputs) {
- disconnect(input);
- if(output)
- connect(output, input);
- }
+ relink(mix->inputs, inputs, output);
removed[mix->id] = true;
any_node_removed = true;
}
@@ -484,15 +460,7 @@ void ShaderGraph::remove_unneeded_nodes()
ShaderOutput *output = mix->inputs[2]->link;
vector<ShaderInput*> inputs = mix->outputs[0]->links;
- foreach(ShaderInput *sock, mix->inputs)
- if(sock->link)
- disconnect(sock);
-
- foreach(ShaderInput *input, inputs) {
- disconnect(input);
- if(output)
- connect(output, input);
- }
+ relink(mix->inputs, inputs, output);
removed[mix->id] = true;
any_node_removed = true;
}
diff --git a/intern/cycles/render/graph.h b/intern/cycles/render/graph.h
index f9ac16787e6..6821d012166 100644
--- a/intern/cycles/render/graph.h
+++ b/intern/cycles/render/graph.h
@@ -247,6 +247,7 @@ public:
void connect(ShaderOutput *from, ShaderInput *to);
void disconnect(ShaderInput *to);
+ void relink(vector<ShaderInput*> inputs, vector<ShaderInput*> outputs, ShaderOutput *output);
void remove_unneeded_nodes();
void finalize(bool do_bump = false, bool do_osl = false);