Rename any instance of scene layer or render layer in code with view layer
[blender.git] / source / blender / depsgraph / intern / builder / deg_builder_nodes_layer_collection.cc
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2013 Blender Foundation.
19  * All rights reserved.
20  *
21  * Original Author: Joshua Leung
22  * Contributor(s): Based on original depsgraph.c code - Blender Foundation (2005-2013)
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/depsgraph/intern/builder/deg_builder_nodes_layer.cc
28  *  \ingroup depsgraph
29  *
30  * Methods for constructing depsgraph's nodes
31  */
32
33 #include "intern/builder/deg_builder_nodes.h"
34
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 #include "MEM_guardedalloc.h"
39
40 extern "C" {
41 #include "BLI_utildefines.h"
42 #include "BLI_listbase.h"
43 #include "BLI_string.h"
44
45 #include "BKE_layer.h"
46
47 #include "DNA_scene_types.h"
48
49 #include "DEG_depsgraph.h"
50 #include "DEG_depsgraph_build.h"
51 } /* extern "C" */
52
53 #include "intern/builder/deg_builder.h"
54 #include "intern/eval/deg_eval_copy_on_write.h"
55 #include "intern/nodes/deg_node.h"
56 #include "intern/nodes/deg_node_component.h"
57 #include "intern/nodes/deg_node_operation.h"
58 #include "intern/depsgraph_types.h"
59 #include "intern/depsgraph_intern.h"
60 #include "util/deg_util_foreach.h"
61
62 namespace DEG {
63
64 void DepsgraphNodeBuilder::build_layer_collection(
65         LayerCollection *layer_collection,
66         LayerCollectionState *state)
67 {
68         /* TODO(sergey): This will attempt to create component for each collection.
69          * Harmless but could be optimized.
70          */
71         ComponentDepsNode *comp = add_component_node(
72                 &scene_->id,
73                 DEG_NODE_TYPE_LAYER_COLLECTIONS);
74
75         add_operation_node(comp,
76                            function_bind(BKE_layer_eval_layer_collection,
77                                          _1,
78                                          layer_collection,
79                                          state->parent),
80                            DEG_OPCODE_VIEW_LAYER_EVAL,
81                            layer_collection->scene_collection->name,
82                            state->index);
83         ++state->index;
84
85         /* Recurs into nested layer collections. */
86         LayerCollection *parent = state->parent;
87         state->parent = layer_collection;
88         build_layer_collections(&layer_collection->layer_collections, state);
89         state->parent = parent;
90 }
91
92 void DepsgraphNodeBuilder::build_layer_collections(ListBase *layer_collections,
93                                                    LayerCollectionState *state)
94 {
95         LINKLIST_FOREACH (LayerCollection *, layer_collection, layer_collections) {
96                 build_layer_collection(layer_collection, state);
97         }
98 }
99
100 void DepsgraphNodeBuilder::build_view_layer_collections(
101         ViewLayer *view_layer)
102 {
103         Scene *scene_cow;
104         ViewLayer *view_layer_cow;
105         if (DEG_depsgraph_use_copy_on_write()) {
106                 /* Make sure we've got ID node, so we can get pointer to CoW datablock.
107                  */
108                 scene_cow = expand_cow_datablock(scene_);
109                 view_layer_cow = (ViewLayer *)BLI_findstring(
110                         &scene_cow->view_layers,
111                         view_layer->name,
112                         offsetof(ViewLayer, name));
113         }
114         else {
115                 scene_cow = scene_;
116                 view_layer_cow = view_layer;
117         }
118
119         LayerCollectionState state;
120         state.index = 0;
121         ComponentDepsNode *comp = add_component_node(
122                 &scene_->id,
123                 DEG_NODE_TYPE_LAYER_COLLECTIONS);
124         add_operation_node(comp,
125                            function_bind(BKE_layer_eval_layer_collection_pre,
126                                          _1,
127                                          scene_cow,
128                                          view_layer_cow),
129                            DEG_OPCODE_VIEW_LAYER_INIT,
130                            view_layer->name);
131         add_operation_node(comp,
132                            function_bind(BKE_layer_eval_layer_collection_post,
133                                          _1,
134                                          view_layer_cow),
135                            DEG_OPCODE_VIEW_LAYER_DONE,
136                            view_layer->name);
137         state.parent = NULL;
138         build_layer_collections(&view_layer_cow->layer_collections, &state);
139 }
140
141 }  // namespace DEG