Blender V4.3
node_composite_switchview.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BKE_context.hh"
10#include "BKE_lib_id.hh"
11
12#include "UI_interface.hh"
13#include "UI_resources.hh"
14
15#include "COM_node_operation.hh"
16
18
19/* **************** SWITCH VIEW ******************** */
20
22
24{
25 b.add_output<decl::Color>(N_("Image"));
26
27 const bNode *node = b.node_or_null();
28 if (node == nullptr) {
29 return;
30 }
31
32 Scene *scene = reinterpret_cast<Scene *>(node->id);
33
34 if (scene != nullptr) {
35 /* add the new views */
36 LISTBASE_FOREACH (SceneRenderView *, srv, &scene->r.views) {
37 if (srv->viewflag & SCE_VIEW_DISABLE) {
38 continue;
39 }
40 b.add_input<decl::Color>(N_(srv->name)).default_value({0.0f, 0.0f, 0.0f, 1.0f});
41 }
42 }
43}
44
45static void init_switch_view(const bContext *C, PointerRNA *ptr)
46{
47 Scene *scene = CTX_data_scene(C);
48 bNode *node = (bNode *)ptr->data;
49
50 /* store scene for dynamic declaration */
51 node->id = (ID *)scene;
52 id_us_plus(node->id);
53}
54
55using namespace blender::realtime_compositor;
56
58 public:
60
61 void execute() override
62 {
63 Result &result = get_result("Image");
64
65 /* A context that is not multi view, pass the first input through as a fallback. */
66 if (context().get_view_name().is_empty()) {
67 Result &input = get_input(node().input(0)->identifier);
68 input.pass_through(result);
69 return;
70 }
71
72 Result &input = get_input(context().get_view_name());
73 input.pass_through(result);
74 }
75};
76
78{
79 return new SwitchViewOperation(context, node);
80}
81
82} // namespace blender::nodes::node_composite_switchview_cc
83
85{
87
88 static blender::bke::bNodeType ntype;
89
90 cmp_node_type_base(&ntype, CMP_NODE_SWITCH_VIEW, "Switch View", NODE_CLASS_CONVERTER);
91 ntype.declare = file_ns::node_declare;
92 ntype.initfunc_api = file_ns::init_switch_view;
93 ntype.get_compositor_operation = file_ns::get_compositor_operation;
94
96}
Scene * CTX_data_scene(const bContext *C)
void id_us_plus(ID *id)
Definition lib_id.cc:351
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:410
#define LISTBASE_FOREACH(type, var, list)
@ SCE_VIEW_DISABLE
NodeOperation(Context &context, DNode node)
Result & get_input(StringRef identifier) const
Definition operation.cc:144
Result & get_result(StringRef identifier)
Definition operation.cc:46
local_group_size(16, 16) .push_constant(Type b
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void node_declare(NodeDeclarationBuilder &b)
static void init_switch_view(const bContext *C, PointerRNA *ptr)
void register_node_type_cmp_switch_view()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
Definition DNA_ID.h:413
void * data
Definition RNA_types.hh:42
Defines a node type.
Definition BKE_node.hh:218
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:324
NodeDeclareFunction declare
Definition BKE_node.hh:347
void(* initfunc_api)(const bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:280
#define N_(msgid)
PointerRNA * ptr
Definition wm_files.cc:4126