Blender V4.3
node_shader_common.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 "DNA_node_types.h"
10
11#include "BLI_utildefines.h"
12
13#include "BKE_node.hh"
14#include "BKE_node_runtime.hh"
15
16#include "NOD_common.h"
17#include "NOD_shader.h"
18#include "node_common.h"
19#include "node_exec.hh"
20#include "node_shader_util.hh"
21
22#include "RNA_access.hh"
23
24/**** GROUP ****/
25
26static void group_gpu_copy_inputs(bNode *gnode, GPUNodeStack *in, bNodeStack *gstack)
27{
28 bNodeTree *ngroup = (bNodeTree *)gnode->id;
29
30 for (bNode *node : ngroup->all_nodes()) {
31 if (node->type == NODE_GROUP_INPUT) {
32 int a;
33 LISTBASE_FOREACH_INDEX (bNodeSocket *, sock, &node->outputs, a) {
34 bNodeStack *ns = node_get_socket_stack(gstack, sock);
35 if (ns) {
36 /* convert the external gpu stack back to internal node stack data */
37 node_data_from_gpu_stack(ns, &in[a]);
38 }
39 }
40 }
41 }
42}
43
44/* Copy internal results to the external outputs.
45 */
46static void group_gpu_move_outputs(bNode *gnode, GPUNodeStack *out, bNodeStack *gstack)
47{
48 const bNodeTree &ngroup = *reinterpret_cast<bNodeTree *>(gnode->id);
49
50 ngroup.ensure_topology_cache();
51 const bNode *group_output_node = ngroup.group_output_node();
52 if (!group_output_node) {
53 return;
54 }
55
56 int a;
57 LISTBASE_FOREACH_INDEX (bNodeSocket *, sock, &group_output_node->inputs, a) {
58 bNodeStack *ns = node_get_socket_stack(gstack, sock);
59 if (ns) {
60 /* convert the node stack data result back to gpu stack */
61 node_gpu_stack_from_data(&out[a], sock->type, ns);
62 }
63 }
64}
65
67 GPUMaterial *mat, bNode *node, bNodeExecData *execdata, GPUNodeStack *in, GPUNodeStack *out)
68{
69 bNodeTreeExec *exec = static_cast<bNodeTreeExec *>(execdata->data);
70
71 if (!node->id) {
72 return 0;
73 }
74
75 group_gpu_copy_inputs(node, in, exec->stack);
76 ntreeExecGPUNodes(exec, mat, nullptr);
77 group_gpu_move_outputs(node, out, exec->stack);
78
79 return 1;
80}
81
83{
84 static blender::bke::bNodeType ntype;
85
86 /* NOTE: cannot use #sh_node_type_base for node group, because it would map the node type
87 * to the shared #NODE_GROUP integer type id. */
88
90 &ntype, "ShaderNodeGroup", "Group", "GROUP", NODE_CLASS_GROUP);
91 ntype.type = NODE_GROUP;
97 ntype.rna_ext.srna = RNA_struct_find("ShaderNodeGroup");
98 BLI_assert(ntype.rna_ext.srna != nullptr);
100
101 blender::bke::node_type_size(&ntype, 140, 60, 400);
105
107}
108
110{
111 /* These methods can be overridden but need a default implementation otherwise. */
112 if (ntype->poll == nullptr) {
113 ntype->poll = sh_node_poll_default;
114 }
115 if (ntype->insert_link == nullptr) {
117 }
119 ntype->gpu_fn = gpu_group_execute;
120}
#define NODE_GROUP
Definition BKE_node.hh:800
#define NODE_CLASS_GROUP
Definition BKE_node.hh:409
#define NODE_GROUP_INPUT
Definition BKE_node.hh:805
#define BLI_assert(a)
Definition BLI_assert.h:50
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
void node_type_size(bNodeType *ntype, int width, int minwidth, int maxwidth)
Definition node.cc:4602
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
void node_type_base_custom(bNodeType *ntype, const char *idname, const char *name, const char *enum_name, short nclass)
Definition node.cc:4364
void node_group_declare(NodeDeclarationBuilder &b)
int node_group_ui_class(const bNode *node)
void node_group_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
bool node_group_poll_instance(const bNode *node, const bNodeTree *nodetree, const char **r_disabled_hint)
std::string node_group_ui_description(const bNode &node)
bNodeStack * node_get_socket_stack(bNodeStack *stack, bNodeSocket *sock)
Definition node_exec.cc:29
static int gpu_group_execute(GPUMaterial *mat, bNode *node, bNodeExecData *execdata, GPUNodeStack *in, GPUNodeStack *out)
void register_node_type_sh_group()
void register_node_type_sh_custom_group(blender::bke::bNodeType *ntype)
static void group_gpu_copy_inputs(bNode *gnode, GPUNodeStack *in, bNodeStack *gstack)
static void group_gpu_move_outputs(bNode *gnode, GPUNodeStack *out, bNodeStack *gstack)
void node_data_from_gpu_stack(bNodeStack *ns, GPUNodeStack *gs)
void node_gpu_stack_from_data(GPUNodeStack *gs, int type, bNodeStack *ns)
void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, bNode *output_node, int *depth_level)
bool sh_node_poll_default(const blender::bke::bNodeType *, const bNodeTree *ntree, const char **r_disabled_hint)
static void exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
bool node_insert_link_default(bNodeTree *, bNode *, bNodeLink *)
Definition node_util.cc:281
StructRNA * RNA_struct_find(const char *identifier)
void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
StructRNA * srna
Definition RNA_types.hh:780
ListBase inputs
struct ID * id
Defines a node type.
Definition BKE_node.hh:218
int(* ui_class)(const bNode *node)
Definition BKE_node.hh:252
bool(* poll_instance)(const bNode *node, const bNodeTree *nodetree, const char **r_disabled_hint)
Definition BKE_node.hh:304
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:249
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:318
std::string(* ui_description_fn)(const bNode &node)
Definition BKE_node.hh:254
bool(* poll)(const bNodeType *ntype, const bNodeTree *nodetree, const char **r_disabled_hint)
Definition BKE_node.hh:299
bool(* insert_link)(bNodeTree *ntree, bNode *node, bNodeLink *link)
Definition BKE_node.hh:309
NodeDeclareFunction declare
Definition BKE_node.hh:347