Blender V5.0
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
17
19{
20 uiLayout *row;
21
22 row = &layout->row(false);
23 row->prop(ptr, "mode", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_EXPAND, std::nullopt, ICON_NONE);
24
25 row = &layout->row(true);
26
27 if (RNA_enum_get(ptr, "mode") == NODE_SCRIPT_INTERNAL) {
28 row->prop(ptr, "script", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
29 }
30 else {
31 row->prop(ptr, "filepath", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
32 }
33
34 row->op("node.shader_script_update", "", ICON_FILE_REFRESH);
35}
36
38{
39 layout->separator();
40
42
43#if 0 /* not implemented yet */
44 if (RNA_enum_get(ptr, "mode") == NODE_SCRIPT_EXTERNAL) {
45 layout->prop(ptr, "use_auto_update", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
46 }
47#endif
48}
49
50static void init(bNodeTree * /*ntree*/, bNode *node)
51{
52 NodeShaderScript *nss = MEM_callocN<NodeShaderScript>("shader script node");
53 node->storage = nss;
54}
55
56static void node_free_script(bNode *node)
57{
58 NodeShaderScript *nss = static_cast<NodeShaderScript *>(node->storage);
59
60 if (nss) {
61 if (nss->bytecode) {
62 MEM_freeN(nss->bytecode);
63 }
64
65 MEM_freeN(nss);
66 }
67}
68
69static void node_copy_script(bNodeTree * /*dst_ntree*/, bNode *dest_node, const bNode *src_node)
70{
71 NodeShaderScript *src_nss = static_cast<NodeShaderScript *>(src_node->storage);
72 NodeShaderScript *dest_nss = static_cast<NodeShaderScript *>(MEM_dupallocN(src_nss));
73
74 if (src_nss->bytecode) {
75 dest_nss->bytecode = static_cast<char *>(MEM_dupallocN(src_nss->bytecode));
76 }
77
78 dest_node->storage = dest_nss;
79}
80
81} // namespace blender::nodes::node_shader_script_cc
82
84{
85 namespace file_ns = blender::nodes::node_shader_script_cc;
86
87 static blender::bke::bNodeType ntype;
88
89 sh_node_type_base(&ntype, "ShaderNodeScript", SH_NODE_SCRIPT);
90 ntype.ui_name = "Script";
91 ntype.ui_description =
92 "Generate an OSL shader from a file or text data-block.\nNote: OSL shaders are not "
93 "supported on all GPU backends";
94 ntype.enum_name_legacy = "SCRIPT";
96 ntype.draw_buttons = file_ns::node_shader_buts_script;
97 ntype.draw_buttons_ex = file_ns::node_shader_buts_script_ex;
98 ntype.initfunc = file_ns::init;
100 ntype, "NodeShaderScript", file_ns::node_free_script, file_ns::node_copy_script);
101
103}
#define NODE_CLASS_SCRIPT
Definition BKE_node.hh:458
#define SH_NODE_SCRIPT
@ NODE_SCRIPT_INTERNAL
@ NODE_SCRIPT_EXTERNAL
#define C
Definition RandGen.cpp:29
@ UI_ITEM_R_SPLIT_EMPTY_NAME
@ UI_ITEM_R_EXPAND
void init()
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_dupallocN(const void *vmemh)
Definition mallocn.cc:143
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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:5414
static void node_copy_script(bNodeTree *, bNode *dest_node, const bNode *src_node)
static void node_shader_buts_script_ex(uiLayout *layout, bContext *C, PointerRNA *ptr)
static void node_shader_buts_script(uiLayout *layout, bContext *, PointerRNA *ptr)
void register_node_type_sh_script()
void sh_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void * storage
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
void(* draw_buttons_ex)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:261
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
uiLayout & row(bool align)
PointerRNA op(wmOperatorType *ot, std::optional< blender::StringRef > name, int icon, blender::wm::OpCallContext context, eUI_Item_Flag flag)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
PointerRNA * ptr
Definition wm_files.cc:4238