Blender V5.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
8
9#include "DNA_node_types.h"
10
11#include "BKE_node.hh"
12#include "BKE_node_runtime.hh"
13
14#include "NOD_common.hh"
15#include "NOD_shader.h"
16#include "node_common.h"
17#include "node_exec.hh"
18#include "node_shader_util.hh"
19
20#include "RNA_access.hh"
21
22namespace blender {
23
24/**** GROUP ****/
25
27{
28 bNodeTree *ngroup = id_cast<bNodeTree *>(gnode->id);
29
30 for (bNode *node : ngroup->all_nodes()) {
31 if (node->is_group_input()) {
32
33 for (const auto [a, sock] : node->outputs.enumerate()) {
34 bNodeStack *ns = node_get_socket_stack(gstack, &sock);
35 if (ns) {
36 /* convert the external gpu stack back to internal node stack data */
38 }
39 }
40 }
41 }
42}
43
44/* Copy internal results to the external outputs.
45 */
47{
48 bNodeTree &ngroup = *reinterpret_cast<bNodeTree *>(gnode->id);
49
50 ngroup.ensure_topology_cache();
51 bNode *group_output_node = ngroup.group_output_node();
52 if (!group_output_node) {
53 return;
54 }
55
56 for (const auto [a, sock] : group_output_node->inputs.enumerate()) {
57 bNodeStack *ns = node_get_socket_stack(gstack, &sock);
58 if (ns) {
59 /* convert the node stack data result back to gpu stack */
60 node_gpu_stack_from_data(&out[a], &sock, ns);
61 }
62 }
63}
64
67{
68 bNodeTreeExec *exec = static_cast<bNodeTreeExec *>(execdata->data);
69
70 if (!node->id) {
71 return 0;
72 }
73
75 ntreeExecGPUNodes(exec, mat, nullptr);
77
78 return 1;
79}
80
82{
83 static bke::bNodeType ntype;
84
85 /* NOTE: cannot use #sh_node_type_base for node group, because it would map the node type
86 * to the shared #NODE_GROUP integer type id. */
87
88 bke::node_type_base_custom(ntype, "ShaderNodeGroup", "Group", "GROUP", NODE_CLASS_GROUP);
89 ntype.enum_name_legacy = "GROUP";
90 ntype.type_legacy = NODE_GROUP;
96 ntype.rna_ext.srna = RNA_struct_find("ShaderNodeGroup");
97 BLI_assert(ntype.rna_ext.srna != nullptr);
99
104
106}
107
109{
110 /* These methods can be overridden but need a default implementation otherwise. */
111 if (ntype->poll == nullptr) {
112 ntype->poll = sh_node_poll_default;
113 }
114 if (ntype->insert_link == nullptr) {
116 }
118 ntype->gpu_fn = gpu_group_execute;
119}
120
121} // namespace blender
#define NODE_GROUP
Definition BKE_node.hh:865
#define NODE_CLASS_GROUP
Definition BKE_node.hh:483
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_base_custom(bNodeType &ntype, StringRefNull idname, StringRefNull name, StringRefNull enum_name, short nclass)
Definition node.cc:5896
void node_group_declare(NodeDeclarationBuilder &b)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void node_gpu_stack_from_data(GPUNodeStack *gs, bNodeSocket *socket, bNodeStack *ns)
int node_group_ui_class(const bNode *node)
bool sh_node_poll_default(const bke::bNodeType *, const bNodeTree *ntree, const char **r_disabled_hint)
std::string node_group_ui_description(const bNode &node)
void node_group_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
static void group_gpu_copy_inputs(bNode *gnode, GPUNodeStack *in, bNodeStack *gstack)
StructRNA * RNA_struct_find(const char *identifier)
void node_data_from_gpu_stack(bNodeStack *ns, GPUNodeStack *gs)
bNodeStack * node_get_socket_stack(bNodeStack *stack, bNodeSocket *sock)
Definition node_exec.cc:39
bool node_insert_link_default(bke::NodeInsertLinkParams &)
Definition node_util.cc:223
void register_node_type_sh_custom_group(bke::bNodeType *ntype)
static void group_gpu_move_outputs(bNode *gnode, GPUNodeStack *out, bNodeStack *gstack)
void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
static int gpu_group_execute(GPUMaterial *mat, bNode *node, bNodeExecData *execdata, GPUNodeStack *in, GPUNodeStack *out)
void register_node_type_sh_group()
void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, bNode *output_node, const int *depth_level)
bool node_group_poll_instance(const bNode *node, const bNodeTree *nodetree, const char **r_disabled_hint)
ListBaseT< bNodeSocket > inputs
static constexpr int GroupMin
Definition BKE_node.hh:256
Defines a node type.
Definition BKE_node.hh:265
void(*) labelfunc(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:301
bool(*) poll(const bNodeType *ntype, const bNodeTree *nodetree, const char **r_disabled_hint)
Definition BKE_node.hh:352
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
std::string(*) ui_description_fn(const bNode &node)
Definition BKE_node.hh:309
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
int(*) ui_class(const bNode *node)
Definition BKE_node.hh:307
bool(*) insert_link(NodeInsertLinkParams &params)
Definition BKE_node.hh:364
bool(*) poll_instance(const bNode *node, const bNodeTree *nodetree, const char **r_disabled_hint)
Definition BKE_node.hh:359