Blender V5.3
COM_shader_node.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include "BLI_string_ref.hh"
8#include "BLI_vector.hh"
9
10#include "DNA_node_types.h"
11
12#include "GPU_material.hh"
13
14namespace blender::compositor {
15
16/* ------------------------------------------------------------------------------------------------
17 * Shader Node
18 *
19 * A shader node encapsulates a compositor node tree that is capable of being used together with
20 * other shader nodes to construct a Shader Operation using the GPU material compiler. A GPU node
21 * stack for each of the node inputs and outputs is stored and populated during construction in
22 * order to represent the node as a GPU node inside the GPU material graph, see GPU_material.hh for
23 * more information. The compiler is expected to initialize the input links of the node inputs
24 * before invoking the compile method. See the discussion in COM_shader_operation.hh for more
25 * information. */
27 private:
28 /* The node that this operation represents. */
29 const bNode &node_;
30 /* The GPU node stacks of the inputs of the node. Those are populated during construction in the
31 * populate_inputs method. The links of the inputs are initialized by the GPU material compiler
32 * prior to calling the compile method. There is an extra stack at the end to mark the end of the
33 * array, as this is what the GPU module functions expect. */
35 /* The GPU node stacks of the outputs of the node. Those are populated during construction in the
36 * populate_outputs method. There is an extra stack at the end to mark the end of the array, as
37 * this is what the GPU module functions expect. */
38 Vector<GPUNodeStack> outputs_;
39
40 public:
41 /* Construct the node by populating both its inputs and outputs. */
42 ShaderNode(const bNode &node);
43
44 /* Compile the node by adding the appropriate GPU material graph nodes and linking the
45 * appropriate resources. */
46 void compile(GPUMaterial *material);
47
48 /* Returns the GPU node stack of the input with the given identifier. */
49 GPUNodeStack &get_input(StringRef identifier);
50
51 /* Returns the GPU node stack of the output with the given identifier. */
53
54 private:
55 /* Populate the inputs of the node. The input link is set to nullptr and is expected to be
56 * initialized by the GPU material compiler before calling the compile method. */
57 void populate_inputs();
58 /* Populate the outputs of the node. The output link is set to nullptr and is expected to be
59 * initialized by the compile method. */
60 void populate_outputs();
61};
62
63} // namespace blender::compositor
GPUNodeStack & get_input(StringRef identifier)
void compile(GPUMaterial *material)
ShaderNode(const bNode &node)
GPUNodeStack & get_output(StringRef identifier)