1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gsk.GLShaderNode;
26 
27 private import glib.Bytes;
28 private import glib.ConstructionException;
29 private import gobject.ObjectG;
30 private import graphene.Rect;
31 private import gsk.GLShader;
32 private import gsk.RenderNode;
33 private import gsk.c.functions;
34 public  import gsk.c.types;
35 
36 
37 /**
38  * A render node using a GL shader when drawing its children nodes.
39  */
40 public class GLShaderNode : RenderNode
41 {
42 	/** the main Gtk struct */
43 	protected GskGLShaderNode* gskGLShaderNode;
44 
45 	/** Get the main Gtk struct */
46 	public GskGLShaderNode* getGLShaderNodeStruct(bool transferOwnership = false)
47 	{
48 		if (transferOwnership)
49 			ownedRef = false;
50 		return gskGLShaderNode;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected override void* getStruct()
55 	{
56 		return cast(void*)gskGLShaderNode;
57 	}
58 
59 	/**
60 	 * Sets our main struct and passes it to the parent class.
61 	 */
62 	public this (GskGLShaderNode* gskGLShaderNode, bool ownedRef = false)
63 	{
64 		this.gskGLShaderNode = gskGLShaderNode;
65 		super(cast(GskRenderNode*)gskGLShaderNode, ownedRef);
66 	}
67 
68 
69 	/** */
70 	public static GType getType()
71 	{
72 		return gsk_gl_shader_node_get_type();
73 	}
74 
75 	/**
76 	 * Creates a `GskRenderNode` that will render the given @shader into the
77 	 * area given by @bounds.
78 	 *
79 	 * The @args is a block of data to use for uniform input, as per types and
80 	 * offsets defined by the @shader. Normally this is generated by
81 	 * [method@Gsk.GLShader.format_args] or [struct@Gsk.ShaderArgsBuilder].
82 	 *
83 	 * See [class@Gsk.GLShader] for details about how the shader should be written.
84 	 *
85 	 * All the children will be rendered into textures (if they aren't already
86 	 * `GskTextureNodes`, which will be used directly). These textures will be
87 	 * sent as input to the shader.
88 	 *
89 	 * If the renderer doesn't support GL shaders, or if there is any problem
90 	 * when compiling the shader, then the node will draw pink. You should use
91 	 * [method@Gsk.GLShader.compile] to ensure the @shader will work for the
92 	 * renderer before using it.
93 	 *
94 	 * Params:
95 	 *     shader = the #GskGLShader
96 	 *     bounds = the rectangle to render the shader into
97 	 *     args = Arguments for the uniforms
98 	 *     children = array of child nodes, these will
99 	 *         be rendered to textures and used as input.
100 	 *
101 	 * Returns: A new `GskRenderNode`
102 	 *
103 	 * Throws: ConstructionException GTK+ fails to create the object.
104 	 */
105 	public this(GLShader shader, Rect bounds, Bytes args, RenderNode[] children)
106 	{
107 		GskRenderNode*[] childrenArray = new GskRenderNode*[children.length];
108 		for ( int i = 0; i < children.length; i++ )
109 		{
110 			childrenArray[i] = children[i].getRenderNodeStruct();
111 		}
112 
113 		auto __p = gsk_gl_shader_node_new((shader is null) ? null : shader.getGLShaderStruct(), (bounds is null) ? null : bounds.getRectStruct(), (args is null) ? null : args.getBytesStruct(), childrenArray.ptr, cast(uint)children.length);
114 
115 		if(__p is null)
116 		{
117 			throw new ConstructionException("null returned by new");
118 		}
119 
120 		this(cast(GskGLShaderNode*) __p);
121 	}
122 
123 	/**
124 	 * Gets args for the node.
125 	 *
126 	 * Returns: A #GBytes with the uniform arguments
127 	 */
128 	public Bytes getArgs()
129 	{
130 		auto __p = gsk_gl_shader_node_get_args(cast(GskRenderNode*)gskGLShaderNode);
131 
132 		if(__p is null)
133 		{
134 			return null;
135 		}
136 
137 		return new Bytes(cast(GBytes*) __p);
138 	}
139 
140 	/**
141 	 * Gets one of the children.
142 	 *
143 	 * Params:
144 	 *     idx = the position of the child to get
145 	 *
146 	 * Returns: the @idx'th child of @node
147 	 */
148 	public RenderNode getChild(uint idx)
149 	{
150 		auto __p = gsk_gl_shader_node_get_child(cast(GskRenderNode*)gskGLShaderNode, idx);
151 
152 		if(__p is null)
153 		{
154 			return null;
155 		}
156 
157 		return ObjectG.getDObject!(RenderNode)(cast(GskRenderNode*) __p);
158 	}
159 
160 	/**
161 	 * Returns the number of children
162 	 *
163 	 * Returns: The number of children
164 	 */
165 	public uint getNChildren()
166 	{
167 		return gsk_gl_shader_node_get_n_children(cast(GskRenderNode*)gskGLShaderNode);
168 	}
169 
170 	/**
171 	 * Gets shader code for the node.
172 	 *
173 	 * Returns: the #GskGLShader shader
174 	 */
175 	public GLShader getShader()
176 	{
177 		auto __p = gsk_gl_shader_node_get_shader(cast(GskRenderNode*)gskGLShaderNode);
178 
179 		if(__p is null)
180 		{
181 			return null;
182 		}
183 
184 		return ObjectG.getDObject!(GLShader)(cast(GskGLShader*) __p);
185 	}
186 }