diff options
Diffstat (limited to 'source/blender/blenkernel/intern/node.c')
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 65 |
1 files changed, 41 insertions, 24 deletions
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 53bac9171ae..03fdcdd0c91 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -27,6 +27,11 @@ * ***** END GPL LICENSE BLOCK ***** */ +/** \file blender/blenkernel/intern/node.c + * \ingroup bke + */ + + #ifdef WITH_PYTHON #include <Python.h> #endif @@ -897,6 +902,7 @@ void nodeGroupRemoveSocket(bNodeTree *ngroup, bNodeSocket *gsock, int in_out) case SOCK_IN: BLI_remlink(&ngroup->inputs, gsock); break; case SOCK_OUT: BLI_remlink(&ngroup->outputs, gsock); break; } + MEM_freeN(gsock); } /* ************** Add stuff ********** */ @@ -1183,6 +1189,12 @@ bNodeTree *ntreeCopyTree(bNodeTree *ntree) newtree= MEM_dupallocN(ntree); copy_libblock_data(&newtree->id, &ntree->id, TRUE); /* copy animdata and ID props */ } + + /* in case a running nodetree is copied */ + newtree->init &= ~(NTREE_EXEC_INIT); + newtree->threadstack= NULL; + newtree->stack= NULL; + newtree->nodes.first= newtree->nodes.last= NULL; newtree->links.first= newtree->links.last= NULL; @@ -1314,7 +1326,7 @@ void ntreeClearPreview(bNodeTree *ntree) /* hack warning! this function is only used for shader previews, and since it gets called multiple times per pixel for Ztransp we only add the color once. Preview gets cleared before it starts render though */ -void nodeAddToPreview(bNode *node, float *col, int x, int y) +void nodeAddToPreview(bNode *node, float *col, int x, int y, int do_manage) { bNodePreview *preview= node->preview; if(preview) { @@ -1322,7 +1334,7 @@ void nodeAddToPreview(bNode *node, float *col, int x, int y) if(x<preview->xsize && y<preview->ysize) { unsigned char *tar= preview->rect+ 4*((preview->xsize*y) + x); - if(TRUE) { + if(do_manage) { tar[0]= FTOCHAR(linearrgb_to_srgb(col[0])); tar[1]= FTOCHAR(linearrgb_to_srgb(col[1])); tar[2]= FTOCHAR(linearrgb_to_srgb(col[2])); @@ -1748,32 +1760,29 @@ void ntreeSocketUseFlags(bNodeTree *ntree) /* ************** dependency stuff *********** */ /* node is guaranteed to be not checked before */ -static int node_recurs_check(bNode *node, bNode ***nsort, int level) +static int node_recurs_check(bNode *node, bNode ***nsort) { bNode *fromnode; bNodeSocket *sock; - int has_inputlinks= 0; + int level = 0xFFF; node->done= 1; - level++; for(sock= node->inputs.first; sock; sock= sock->next) { if(sock->link) { - has_inputlinks= 1; fromnode= sock->link->fromnode; - if(fromnode && fromnode->done==0) { - fromnode->level= node_recurs_check(fromnode, nsort, level); + if(fromnode) { + if (fromnode->done==0) + fromnode->level= node_recurs_check(fromnode, nsort); + if (fromnode->level <= level) + level = fromnode->level - 1; } } } -// printf("node sort %s level %d\n", node->name, level); **nsort= node; (*nsort)++; - if(has_inputlinks) - return level; - else - return 0xFFF; + return level; } @@ -1862,7 +1871,7 @@ void ntreeSolveOrder(bNodeTree *ntree) /* recursive check */ for(node= ntree->nodes.first; node; node= node->next) { if(node->done==0) { - node->level= node_recurs_check(node, &nsort, 0); + node->level= node_recurs_check(node, &nsort); } } @@ -2318,8 +2327,15 @@ void ntreeBeginExecTree(bNodeTree *ntree) for(sock= node->inputs.first; sock; sock= sock->next) { ns = get_socket_stack(ntree->stack, sock, NULL); - if (ns) + if (ns) { ns->hasoutput = 1; + + /* sock type is needed to detect rgba or value or vector types */ + if(sock->link && sock->link->fromsock) + ns->sockettype= sock->link->fromsock->type; + else + sock->ns.sockettype= sock->type; + } if(sock->link) { bNodeLink *link= sock->link; @@ -2450,7 +2466,7 @@ static int node_only_value(bNode *node) if(node->inputs.first && node->type==CMP_NODE_MAP_VALUE) { int retval= 1; for(sock= node->inputs.first; sock; sock= sock->next) { - if(sock->link) + if(sock->link && sock->link->fromnode) retval &= node_only_value(sock->link->fromnode); } return retval; @@ -2608,7 +2624,7 @@ static void freeExecutableNode(bNodeTree *ntree) for(node= ntree->nodes.first; node; node= node->next) { if((node->exec & NODE_FINISHED)==0) { for(sock= node->inputs.first; sock; sock= sock->next) - if(sock->link) + if(sock->link && sock->link->fromnode) sock->link->fromnode->exec &= ~NODE_FREEBUFS; } } @@ -2709,7 +2725,7 @@ void ntreeCompositExecTree(bNodeTree *ntree, RenderData *rd, int do_preview) node= getExecutableNode(ntree); if(node) { if(ntree->progress && totnode) - ntree->progress(ntree->prh, (1.0 - curnode/(float)totnode)); + ntree->progress(ntree->prh, (1.0f - curnode/(float)totnode)); if(ntree->stats_draw) { char str[64]; sprintf(str, "Compositing %d %s", curnode, node->name); @@ -2759,8 +2775,8 @@ void ntreeCompositExecTree(bNodeTree *ntree, RenderData *rd, int do_preview) /* ********** copy composite tree entirely, to allow threaded exec ******************* */ /* ***************** do NOT execute this in a thread! ****************** */ -/* returns localized composite tree for execution in threads */ -/* local tree then owns all compbufs */ +/* returns localized tree for execution in threads */ +/* local tree then owns all compbufs (for composite) */ bNodeTree *ntreeLocalize(bNodeTree *ntree) { bNodeTree *ltree; @@ -2797,16 +2813,17 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree) /* end animdata uglyness */ /* ensures only a single output node is enabled */ - ntreeSetOutput(ntree); + ntreeSetOutput(ltree); for(node= ntree->nodes.first; node; node= node->next) { /* store new_node pointer to original */ node->new_node->new_node= node; - /* ensure new user input gets handled ok */ - node->need_exec= 0; if(ntree->type==NTREE_COMPOSIT) { + /* ensure new user input gets handled ok, only composites (texture nodes will break, for painting since it uses no tags) */ + node->need_exec= 0; + /* move over the compbufs */ /* right after ntreeCopyTree() oldsock pointers are valid */ @@ -2874,7 +2891,7 @@ void ntreeLocalSync(bNodeTree *localtree, bNodeTree *ntree) } } } - else if(ntree->type==NTREE_SHADER) { + else if(ELEM(ntree->type, NTREE_SHADER, NTREE_TEXTURE)) { /* copy over contents of previews */ for(lnode= localtree->nodes.first; lnode; lnode= lnode->next) { if(node_exists(ntree, lnode->new_node)) { |