Blender V5.3
node_shader_script.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "node_shader_util.hh"
10
11#include "RNA_access.hh"
12
14#include "UI_resources.hh"
15
16namespace blender {
17
19
20static void node_shader_buts_script(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
21{
22 {
23 ui::Layout &row = layout.row(false);
24 row.prop(
25 ptr, "mode", ui::ITEM_R_SPLIT_EMPTY_NAME | ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
26 }
27
28 {
29 ui::Layout &row = layout.row(true);
30 if (RNA_enum_get(ptr, "mode") == NODE_SCRIPT_INTERNAL) {
31 row.prop(ptr, "script", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
32 }
33 else {
34 row.prop(ptr, "filepath", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
35 }
36 row.op("node.shader_script_update", "", ICON_FILE_REFRESH);
37 }
38}
39
41{
42 layout.separator();
43
44 node_shader_buts_script(layout, C, ptr);
45
46#if 0 /* not implemented yet */
47 if (RNA_enum_get(ptr, "mode") == NODE_SCRIPT_EXTERNAL) {
48 layout.prop(ptr, "use_auto_update", ui::ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
49 }
50#endif
51}
52
53static void init(bNodeTree * /*ntree*/, bNode *node)
54{
55 NodeShaderScript *nss = MEM_new<NodeShaderScript>("shader script node");
56 node->storage = nss;
57}
58
60{
61 NodeShaderScript *nss = static_cast<NodeShaderScript *>(node->storage);
62
63 if (nss) {
64 if (nss->bytecode) {
65 MEM_delete(nss->bytecode);
66 }
67
68 MEM_delete(nss);
69 }
70}
71
72static void node_copy_script(bNodeTree * /*dst_ntree*/, bNode *dest_node, const bNode *src_node)
73{
74 NodeShaderScript *src_nss = static_cast<NodeShaderScript *>(src_node->storage);
75 NodeShaderScript *dest_nss = MEM_dupalloc(src_nss);
76
77 if (src_nss->bytecode) {
78 dest_nss->bytecode = MEM_dupalloc(src_nss->bytecode);
79 }
80
81 dest_node->storage = dest_nss;
82}
83
84} // namespace nodes::node_shader_script_cc
85
87{
88 namespace file_ns = nodes::node_shader_script_cc;
89
90 static bke::bNodeType ntype;
91
92 sh_node_type_base(&ntype, "ShaderNodeScript"_ustr, SH_NODE_SCRIPT);
93 ntype.ui_name = "Script";
94 ntype.ui_description =
95 "Generate an OSL shader from a file or text data-block.\nNote: OSL shaders are not "
96 "supported on all GPU backends";
97 ntype.enum_name_legacy = "SCRIPT";
99 ntype.draw_buttons = file_ns::node_shader_buts_script;
100 ntype.draw_buttons_ex = file_ns::node_shader_buts_script_ex;
101 ntype.initfunc = file_ns::init;
103 ntype, "NodeShaderScript", file_ns::node_free_script, file_ns::node_copy_script);
104
106}
107
108} // namespace blender
#define NODE_CLASS_SCRIPT
Definition BKE_node.hh:489
#define SH_NODE_SCRIPT
#define C
Definition RandGen.cpp:29
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:6166
static void node_shader_buts_script_ex(ui::Layout &layout, bContext *C, PointerRNA *ptr)
static void node_copy_script(bNodeTree *, bNode *dest_node, const bNode *src_node)
static void init(bNodeTree *, bNode *node)
static void node_shader_buts_script(ui::Layout &layout, bContext *, PointerRNA *ptr)
BMesh Iterators.
int RNA_enum_get(PointerRNA *ptr, const char *name)
void register_node_type_sh_script()
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
@ NODE_SCRIPT_EXTERNAL
@ NODE_SCRIPT_INTERNAL
Defines a node type.
Definition BKE_node.hh:265
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
std::string ui_description
Definition BKE_node.hh:271
void(*) draw_buttons_ex(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:292
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
Layout & row(bool align)