Cleanup: remove redundant doxygen \file argument
[blender.git] / source / blender / depsgraph / intern / builder / deg_builder_nodes_view_layer.cc
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file \ingroup depsgraph
21  *
22  * Methods for constructing depsgraph's nodes
23  */
24
25 #include "intern/builder/deg_builder_nodes.h"
26
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 #include "MEM_guardedalloc.h"
31
32 #include "BLI_utildefines.h"
33 #include "BLI_blenlib.h"
34 #include "BLI_string.h"
35
36 extern "C" {
37 #include "DNA_freestyle_types.h"
38 #include "DNA_layer_types.h"
39 #include "DNA_node_types.h"
40 #include "DNA_object_types.h"
41 #include "DNA_scene_types.h"
42
43 #include "BKE_layer.h"
44 #include "BKE_main.h"
45 #include "BKE_node.h"
46 } /* extern "C" */
47
48 #include "DEG_depsgraph.h"
49 #include "DEG_depsgraph_build.h"
50
51 #include "intern/builder/deg_builder.h"
52 #include "intern/depsgraph.h"
53 #include "intern/node/deg_node.h"
54 #include "intern/node/deg_node_component.h"
55 #include "intern/node/deg_node_operation.h"
56 #include "intern/depsgraph_type.h"
57
58 namespace DEG {
59
60 void DepsgraphNodeBuilder::build_layer_collections(ListBase *lb)
61 {
62         const int restrict_flag = (graph_->mode == DAG_EVAL_VIEWPORT) ?
63                 COLLECTION_RESTRICT_VIEW : COLLECTION_RESTRICT_RENDER;
64
65         for (LayerCollection *lc = (LayerCollection *)lb->first; lc; lc = lc->next) {
66                 if (lc->collection->flag & restrict_flag) {
67                         continue;
68                 }
69                 if ((lc->flag & LAYER_COLLECTION_EXCLUDE) == 0) {
70                         build_collection(lc, lc->collection);
71                 }
72                 build_layer_collections(&lc->layer_collections);
73         }
74 }
75
76 void DepsgraphNodeBuilder::build_view_layer(
77         Scene *scene,
78         ViewLayer *view_layer,
79         eDepsNode_LinkedState_Type linked_state)
80 {
81         /* NOTE: Pass view layer index of 0 since after scene CoW there is
82          * only one view layer in there. */
83         view_layer_index_ = 0;
84         /* Scene ID block. */
85         add_id_node(&scene->id);
86         /* Time source. */
87         add_time_source();
88         /* Setup currently building context. */
89         scene_ = scene;
90         view_layer_ = view_layer;
91         /* Get pointer to a CoW version of scene ID. */
92         Scene *scene_cow = get_cow_datablock(scene);
93         /* Scene objects. */
94         int select_color = 1;
95         /* NOTE: Base is used for function bindings as-is, so need to pass CoW base,
96          * but object is expected to be an original one. Hence we go into some
97          * tricks here iterating over the view layer. */
98         int base_index = 0;
99         const int base_flag = (graph_->mode == DAG_EVAL_VIEWPORT) ?
100                 BASE_ENABLED_VIEWPORT : BASE_ENABLED_RENDER;
101         LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
102                 /* object itself */
103                 const bool is_object_visible = (base->flag & base_flag);
104                 if (is_object_visible) {
105                         build_object(base_index,
106                                      base->object,
107                                      linked_state,
108                                      is_object_visible);
109                         ++base_index;
110                 }
111                 base->object->select_color = select_color++;
112         }
113         build_layer_collections(&view_layer->layer_collections);
114         if (scene->camera != NULL) {
115                 build_object(-1, scene->camera, DEG_ID_LINKED_INDIRECTLY, true);
116         }
117         /* Rigidbody. */
118         if (scene->rigidbody_world != NULL) {
119                 build_rigidbody(scene);
120         }
121         /* Scene's animation and drivers. */
122         if (scene->adt != NULL) {
123                 build_animdata(&scene->id);
124         }
125         /* World. */
126         if (scene->world != NULL) {
127                 build_world(scene->world);
128         }
129         /* Compositor nodes */
130         if (scene->nodetree != NULL) {
131                 build_compositor(scene);
132         }
133         /* Cache file. */
134         LISTBASE_FOREACH (CacheFile *, cachefile, &bmain_->cachefiles) {
135                 build_cachefile(cachefile);
136         }
137         /* Masks. */
138         LISTBASE_FOREACH (Mask *, mask, &bmain_->mask) {
139                 build_mask(mask);
140         }
141         /* Movie clips. */
142         LISTBASE_FOREACH (MovieClip *, clip, &bmain_->movieclip) {
143                 build_movieclip(clip);
144         }
145         /* Material override. */
146         if (view_layer->mat_override != NULL) {
147                 build_material(view_layer->mat_override);
148         }
149         /* Freestyle collections. */
150         LISTBASE_FOREACH (FreestyleLineSet *, fls, &view_layer->freestyle_config.linesets) {
151                 if (fls->group != NULL) {
152                         build_collection(NULL, fls->group);
153                 }
154         }
155         /* Collections. */
156         add_operation_node(&scene->id,
157                            NodeType::LAYER_COLLECTIONS,
158                            OperationCode::VIEW_LAYER_EVAL,
159                            function_bind(BKE_layer_eval_view_layer_indexed,
160                                          _1,
161                                          scene_cow,
162                                          view_layer_index_));
163         /* Parameters evaluation for scene relations mainly. */
164         add_operation_node(
165                 &scene->id, NodeType::PARAMETERS, OperationCode::SCENE_EVAL);
166         /* Build all set scenes. */
167         if (scene->set != NULL) {
168                 ViewLayer *set_view_layer = BKE_view_layer_default_render(scene->set);
169                 build_view_layer(scene->set, set_view_layer, DEG_ID_LINKED_VIA_SET);
170         }
171 }
172
173 }  // namespace DEG