Merge branch 'master' into blender2.8
[blender.git] / source / blender / depsgraph / intern / builder / deg_builder_nodes_layer.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_scene.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
43 #include "BKE_layer.h"
44
45 #include "DNA_scene_types.h"
46
47 #include "DEG_depsgraph.h"
48 #include "DEG_depsgraph_build.h"
49 } /* extern "C" */
50
51 #include "intern/builder/deg_builder.h"
52 #include "intern/eval/deg_eval_copy_on_write.h"
53 #include "intern/nodes/deg_node.h"
54 #include "intern/nodes/deg_node_component.h"
55 #include "intern/nodes/deg_node_operation.h"
56 #include "intern/depsgraph_types.h"
57 #include "intern/depsgraph_intern.h"
58 #include "util/deg_util_foreach.h"
59
60 namespace DEG {
61
62 void DepsgraphNodeBuilder::build_layer_collection(Scene *scene,
63                                                   LayerCollection *layer_collection,
64                                                   LayerCollectionState *state)
65 {
66         /* TODO(sergey): This will attempt to create component for each collection.
67          * Harmless but could be optimized.
68          */
69         ComponentDepsNode *comp = add_component_node(&scene->id, DEG_NODE_TYPE_LAYER_COLLECTIONS);
70
71         add_operation_node(comp,
72                            function_bind(BKE_layer_eval_layer_collection,
73                                          _1,
74                                          layer_collection,
75                                          state->parent),
76                            DEG_OPCODE_SCENE_LAYER_EVAL,
77                            layer_collection->scene_collection->name,
78                            state->index);
79         ++state->index;
80
81         /* Recurs into nested layer collections. */
82         LayerCollection *parent = state->parent;
83         state->parent = layer_collection;
84         build_layer_collections(scene, &layer_collection->layer_collections, state);
85         state->parent = parent;
86 }
87
88 void DepsgraphNodeBuilder::build_layer_collections(Scene *scene,
89                                                    ListBase *layer_collections,
90                                                    LayerCollectionState *state)
91 {
92         LINKLIST_FOREACH (LayerCollection *, layer_collection, layer_collections) {
93                 build_layer_collection(scene, layer_collection, state);
94         }
95 }
96
97 void DepsgraphNodeBuilder::build_scene_layer_collections(Scene *scene)
98 {
99 #ifdef WITH_COPY_ON_WRITE
100         /* Make sure we've got ID node, so we can get pointer to CoW datablock. */
101         IDDepsNode *id_node = add_id_node(&scene->id);
102         Scene *scene_cow = (Scene *)deg_expand_copy_on_write_datablock(m_graph,
103                                                                        id_node);
104 #else
105         Scene *scene_cow = scene;
106 #endif
107
108         LayerCollectionState state;
109         state.index = 0;
110         LINKLIST_FOREACH (SceneLayer *, scene_layer, &scene_cow->render_layers) {
111                 ComponentDepsNode *comp = add_component_node(&scene->id, DEG_NODE_TYPE_LAYER_COLLECTIONS);
112
113                 add_operation_node(comp,
114                                    function_bind(BKE_layer_eval_layer_collection_pre, _1, scene_cow, scene_layer),
115                                    DEG_OPCODE_SCENE_LAYER_INIT,
116                                    scene_layer->name);
117                 add_operation_node(comp,
118                                    function_bind(BKE_layer_eval_layer_collection_post, _1, scene_layer),
119                                    DEG_OPCODE_SCENE_LAYER_DONE,
120                                    scene_layer->name);
121
122                 state.parent = NULL;
123                 build_layer_collections(scene, &scene_layer->layer_collections, &state);
124         }
125 }
126
127 }  // namespace DEG