1 /**
2 A custom shader program with a visual editor.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.visualshader;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 import godot.classdb;
24 import godot.shader;
25 import godot.resource;
26 import godot.reference;
27 import godot.visualshadernode;
28 /**
29 A custom shader program with a visual editor.
30 
31 This class allows you to define a custom shader program that can be used for various materials to render objects.
32 The visual shader editor creates the shader.
33 */
34 @GodotBaseClass struct VisualShader
35 {
36 	package(godot) enum string _GODOT_internal_name = "VisualShader";
37 public:
38 @nogc nothrow:
39 	union { /** */ godot_object _godot_object; /** */ Shader _GODOT_base; }
40 	alias _GODOT_base this;
41 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
42 	package(godot) __gshared bool _classBindingInitialized = false;
43 	package(godot) static struct GDNativeClassBinding
44 	{
45 		__gshared:
46 		@GodotName("_input_type_changed") GodotMethod!(void, long, long) _inputTypeChanged;
47 		@GodotName("_queue_update") GodotMethod!(void) _queueUpdate;
48 		@GodotName("_update_shader") GodotMethod!(void) _updateShader;
49 		@GodotName("add_node") GodotMethod!(void, long, VisualShaderNode, Vector2, long) addNode;
50 		@GodotName("can_connect_nodes") GodotMethod!(bool, long, long, long, long, long) canConnectNodes;
51 		@GodotName("connect_nodes") GodotMethod!(GodotError, long, long, long, long, long) connectNodes;
52 		@GodotName("connect_nodes_forced") GodotMethod!(void, long, long, long, long, long) connectNodesForced;
53 		@GodotName("disconnect_nodes") GodotMethod!(void, long, long, long, long, long) disconnectNodes;
54 		@GodotName("get_graph_offset") GodotMethod!(Vector2) getGraphOffset;
55 		@GodotName("get_node") GodotMethod!(VisualShaderNode, long, long) getNode;
56 		@GodotName("get_node_connections") GodotMethod!(Array, long) getNodeConnections;
57 		@GodotName("get_node_list") GodotMethod!(PoolIntArray, long) getNodeList;
58 		@GodotName("get_node_position") GodotMethod!(Vector2, long, long) getNodePosition;
59 		@GodotName("get_valid_node_id") GodotMethod!(long, long) getValidNodeId;
60 		@GodotName("is_node_connection") GodotMethod!(bool, long, long, long, long, long) isNodeConnection;
61 		@GodotName("remove_node") GodotMethod!(void, long, long) removeNode;
62 		@GodotName("set_graph_offset") GodotMethod!(void, Vector2) setGraphOffset;
63 		@GodotName("set_mode") GodotMethod!(void, long) setMode;
64 		@GodotName("set_node_position") GodotMethod!(void, long, long, Vector2) setNodePosition;
65 	}
66 	/// 
67 	pragma(inline, true) bool opEquals(in VisualShader other) const
68 	{ return _godot_object.ptr is other._godot_object.ptr; }
69 	/// 
70 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
71 	{ _godot_object.ptr = n; return null; }
72 	/// 
73 	pragma(inline, true) bool opEquals(typeof(null) n) const
74 	{ return _godot_object.ptr is n; }
75 	/// 
76 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
77 	mixin baseCasts;
78 	/// Construct a new instance of VisualShader.
79 	/// Note: use `memnew!VisualShader` instead.
80 	static VisualShader _new()
81 	{
82 		static godot_class_constructor constructor;
83 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("VisualShader");
84 		if(constructor is null) return typeof(this).init;
85 		return cast(VisualShader)(constructor());
86 	}
87 	@disable new(size_t s);
88 	/// 
89 	enum Type : int
90 	{
91 		/**
92 		A vertex shader, operating on vertices.
93 		*/
94 		typeVertex = 0,
95 		/**
96 		A fragment shader, operating on fragments (pixels).
97 		*/
98 		typeFragment = 1,
99 		/**
100 		A shader for light calculations.
101 		*/
102 		typeLight = 2,
103 		/**
104 		Represents the size of the $(D type) enum.
105 		*/
106 		typeMax = 3,
107 	}
108 	/// 
109 	enum Constants : int
110 	{
111 		/**
112 		
113 		*/
114 		nodeIdInvalid = -1,
115 		typeVertex = 0,
116 		/**
117 		
118 		*/
119 		nodeIdOutput = 0,
120 		typeFragment = 1,
121 		typeLight = 2,
122 		typeMax = 3,
123 	}
124 	/**
125 	
126 	*/
127 	void _inputTypeChanged(in long arg0, in long arg1)
128 	{
129 		Array _GODOT_args = Array.make();
130 		_GODOT_args.append(arg0);
131 		_GODOT_args.append(arg1);
132 		String _GODOT_method_name = String("_input_type_changed");
133 		this.callv(_GODOT_method_name, _GODOT_args);
134 	}
135 	/**
136 	
137 	*/
138 	void _queueUpdate()
139 	{
140 		Array _GODOT_args = Array.make();
141 		String _GODOT_method_name = String("_queue_update");
142 		this.callv(_GODOT_method_name, _GODOT_args);
143 	}
144 	/**
145 	
146 	*/
147 	void _updateShader() const
148 	{
149 		Array _GODOT_args = Array.make();
150 		String _GODOT_method_name = String("_update_shader");
151 		this.callv(_GODOT_method_name, _GODOT_args);
152 	}
153 	/**
154 	Adds the specified node to the shader.
155 	*/
156 	void addNode(in long type, VisualShaderNode node, in Vector2 position, in long id)
157 	{
158 		checkClassBinding!(typeof(this))();
159 		ptrcall!(void)(GDNativeClassBinding.addNode, _godot_object, type, node, position, id);
160 	}
161 	/**
162 	Returns `true` if the specified nodes and ports can be connected together.
163 	*/
164 	bool canConnectNodes(in long type, in long from_node, in long from_port, in long to_node, in long to_port) const
165 	{
166 		checkClassBinding!(typeof(this))();
167 		return ptrcall!(bool)(GDNativeClassBinding.canConnectNodes, _godot_object, type, from_node, from_port, to_node, to_port);
168 	}
169 	/**
170 	Connects the specified nodes and ports.
171 	*/
172 	GodotError connectNodes(in long type, in long from_node, in long from_port, in long to_node, in long to_port)
173 	{
174 		checkClassBinding!(typeof(this))();
175 		return ptrcall!(GodotError)(GDNativeClassBinding.connectNodes, _godot_object, type, from_node, from_port, to_node, to_port);
176 	}
177 	/**
178 	Connects the specified nodes and ports, even if they can't be connected. Such connection is invalid and will not function properly.
179 	*/
180 	void connectNodesForced(in long type, in long from_node, in long from_port, in long to_node, in long to_port)
181 	{
182 		checkClassBinding!(typeof(this))();
183 		ptrcall!(void)(GDNativeClassBinding.connectNodesForced, _godot_object, type, from_node, from_port, to_node, to_port);
184 	}
185 	/**
186 	Connects the specified nodes and ports.
187 	*/
188 	void disconnectNodes(in long type, in long from_node, in long from_port, in long to_node, in long to_port)
189 	{
190 		checkClassBinding!(typeof(this))();
191 		ptrcall!(void)(GDNativeClassBinding.disconnectNodes, _godot_object, type, from_node, from_port, to_node, to_port);
192 	}
193 	/**
194 	
195 	*/
196 	Vector2 getGraphOffset() const
197 	{
198 		checkClassBinding!(typeof(this))();
199 		return ptrcall!(Vector2)(GDNativeClassBinding.getGraphOffset, _godot_object);
200 	}
201 	/**
202 	Returns the shader node instance with specified `type` and `id`.
203 	*/
204 	Ref!VisualShaderNode getNode(in long type, in long id) const
205 	{
206 		checkClassBinding!(typeof(this))();
207 		return ptrcall!(VisualShaderNode)(GDNativeClassBinding.getNode, _godot_object, type, id);
208 	}
209 	/**
210 	Returns the list of connected nodes with the specified type.
211 	*/
212 	Array getNodeConnections(in long type) const
213 	{
214 		checkClassBinding!(typeof(this))();
215 		return ptrcall!(Array)(GDNativeClassBinding.getNodeConnections, _godot_object, type);
216 	}
217 	/**
218 	Returns the list of all nodes in the shader with the specified type.
219 	*/
220 	PoolIntArray getNodeList(in long type) const
221 	{
222 		checkClassBinding!(typeof(this))();
223 		return ptrcall!(PoolIntArray)(GDNativeClassBinding.getNodeList, _godot_object, type);
224 	}
225 	/**
226 	Returns the position of the specified node within the shader graph.
227 	*/
228 	Vector2 getNodePosition(in long type, in long id) const
229 	{
230 		checkClassBinding!(typeof(this))();
231 		return ptrcall!(Vector2)(GDNativeClassBinding.getNodePosition, _godot_object, type, id);
232 	}
233 	/**
234 	
235 	*/
236 	long getValidNodeId(in long type) const
237 	{
238 		checkClassBinding!(typeof(this))();
239 		return ptrcall!(long)(GDNativeClassBinding.getValidNodeId, _godot_object, type);
240 	}
241 	/**
242 	Returns `true` if the specified node and port connection exist.
243 	*/
244 	bool isNodeConnection(in long type, in long from_node, in long from_port, in long to_node, in long to_port) const
245 	{
246 		checkClassBinding!(typeof(this))();
247 		return ptrcall!(bool)(GDNativeClassBinding.isNodeConnection, _godot_object, type, from_node, from_port, to_node, to_port);
248 	}
249 	/**
250 	Removes the specified node from the shader.
251 	*/
252 	void removeNode(in long type, in long id)
253 	{
254 		checkClassBinding!(typeof(this))();
255 		ptrcall!(void)(GDNativeClassBinding.removeNode, _godot_object, type, id);
256 	}
257 	/**
258 	
259 	*/
260 	void setGraphOffset(in Vector2 offset)
261 	{
262 		checkClassBinding!(typeof(this))();
263 		ptrcall!(void)(GDNativeClassBinding.setGraphOffset, _godot_object, offset);
264 	}
265 	/**
266 	Sets the mode of this shader.
267 	*/
268 	void setMode(in long mode)
269 	{
270 		checkClassBinding!(typeof(this))();
271 		ptrcall!(void)(GDNativeClassBinding.setMode, _godot_object, mode);
272 	}
273 	/**
274 	Sets the position of the specified node.
275 	*/
276 	void setNodePosition(in long type, in long id, in Vector2 position)
277 	{
278 		checkClassBinding!(typeof(this))();
279 		ptrcall!(void)(GDNativeClassBinding.setNodePosition, _godot_object, type, id, position);
280 	}
281 	/**
282 	The offset vector of the whole graph.
283 	*/
284 	@property Vector2 graphOffset()
285 	{
286 		return getGraphOffset();
287 	}
288 	/// ditto
289 	@property void graphOffset(Vector2 v)
290 	{
291 		setGraphOffset(v);
292 	}
293 }