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 glgdk.GLContext;
26 
27 private import glgdk.GLConfig;
28 private import glgdk.GLDrawable;
29 private import glgdk.GLDrawableIF;
30 private import glib.ConstructionException;
31 private import gobject.ObjectG;
32 private import gtkglc.glgdk;
33 public  import gtkglc.glgdktypes;
34 
35 
36 /** */
37 public class GLContext : ObjectG
38 {
39 	/** the main Gtk struct */
40 	protected GdkGLContext* gdkGLContext;
41 
42 	/** Get the main Gtk struct */
43 	public GdkGLContext* getGLContextStruct()
44 	{
45 		return gdkGLContext;
46 	}
47 
48 	/** the main Gtk struct as a void* */
49 	protected override void* getStruct()
50 	{
51 		return cast(void*)gdkGLContext;
52 	}
53 
54 	protected override void setStruct(GObject* obj)
55 	{
56 		gdkGLContext = cast(GdkGLContext*)obj;
57 		super.setStruct(obj);
58 	}
59 
60 	/**
61 	 * Sets our main struct and passes it to the parent class.
62 	 */
63 	public this (GdkGLContext* gdkGLContext, bool ownedRef = false)
64 	{
65 		this.gdkGLContext = gdkGLContext;
66 		super(cast(GObject*)gdkGLContext, ownedRef);
67 	}
68 
69 
70 	/** */
71 	public static GType getType()
72 	{
73 		return gdk_gl_context_get_type();
74 	}
75 
76 	/**
77 	 * Creates a new OpenGL rendering context.
78 	 *
79 	 * Params:
80 	 *     gldrawable = a #GdkGLDrawable.
81 	 *     shareList = the #GdkGLContext with which to share display lists and texture objects. NULL indicates that no sharing is to take place.
82 	 *     direct = whether rendering is to be done with a direct connection to the graphics system.
83 	 *     renderType = GDK_GL_RGBA_TYPE.
84 	 *
85 	 * Return: the new #GdkGLContext.
86 	 *
87 	 * Throws: ConstructionException GTK+ fails to create the object.
88 	 */
89 	public this(GLDrawableIF gldrawable, GLContext shareList, bool direct, int renderType)
90 	{
91 		auto p = gdk_gl_context_new((gldrawable is null) ? null : gldrawable.getGLDrawableStruct(), (shareList is null) ? null : shareList.getGLContextStruct(), direct, renderType);
92 		
93 		if(p is null)
94 		{
95 			throw new ConstructionException("null returned by new");
96 		}
97 		
98 		this(cast(GdkGLContext*) p, true);
99 	}
100 
101 	/**
102 	 * Returns the current #GdkGLContext.
103 	 *
104 	 * Return: the current #GdkGLContext or NULL if there is no current context.
105 	 */
106 	public static GLContext getCurrent()
107 	{
108 		auto p = gdk_gl_context_get_current();
109 		
110 		if(p is null)
111 		{
112 			return null;
113 		}
114 		
115 		return ObjectG.getDObject!(GLContext)(cast(GdkGLContext*) p);
116 	}
117 
118 	/**
119 	 * Releases the current #GdkGLContext.
120 	 */
121 	public static void releaseCurrent()
122 	{
123 		gdk_gl_context_release_current();
124 	}
125 
126 	/**
127 	 * Copy state from @src rendering context to @glcontext.
128 	 *
129 	 * @mask contains the bitwise-OR of the same symbolic names that are passed to
130 	 * the glPushAttrib() function. You can use GL_ALL_ATTRIB_BITS to copy all the
131 	 * rendering state information.
132 	 *
133 	 * Params:
134 	 *     src = the source context.
135 	 *     mask = which portions of @src state are to be copied to @glcontext.
136 	 *
137 	 * Return: FALSE if it fails, TRUE otherwise.
138 	 */
139 	public bool copy(GLContext src, ulong mask)
140 	{
141 		return gdk_gl_context_copy(gdkGLContext, (src is null) ? null : src.getGLContextStruct(), mask) != 0;
142 	}
143 
144 	/**
145 	 * Gets #GdkGLConfig with which the @glcontext is configured.
146 	 *
147 	 * Return: the #GdkGLConfig.
148 	 */
149 	public GLConfig getGlConfig()
150 	{
151 		auto p = gdk_gl_context_get_gl_config(gdkGLContext);
152 		
153 		if(p is null)
154 		{
155 			return null;
156 		}
157 		
158 		return ObjectG.getDObject!(GLConfig)(cast(GdkGLConfig*) p);
159 	}
160 
161 	/**
162 	 * Gets #GdkGLDrawable to which the @glcontext is bound.
163 	 *
164 	 * Return: the #GdkGLDrawable or NULL if no #GdkGLDrawable is bound.
165 	 */
166 	public GLDrawableIF getGlDrawable()
167 	{
168 		auto p = gdk_gl_context_get_gl_drawable(gdkGLContext);
169 		
170 		if(p is null)
171 		{
172 			return null;
173 		}
174 		
175 		return ObjectG.getDObject!(GLDrawable, GLDrawableIF)(cast(GdkGLDrawable*) p);
176 	}
177 
178 	/**
179 	 * Gets render_type of the @glcontext.
180 	 *
181 	 * Return: GDK_GL_RGBA_TYPE.
182 	 */
183 	public int getRenderType()
184 	{
185 		return gdk_gl_context_get_render_type(gdkGLContext);
186 	}
187 
188 	/**
189 	 * Gets #GdkGLContext with which the @glcontext shares the display lists and
190 	 * texture objects.
191 	 *
192 	 * Return: the #GdkGLContext.
193 	 */
194 	public GLContext getShareList()
195 	{
196 		auto p = gdk_gl_context_get_share_list(gdkGLContext);
197 		
198 		if(p is null)
199 		{
200 			return null;
201 		}
202 		
203 		return ObjectG.getDObject!(GLContext)(cast(GdkGLContext*) p);
204 	}
205 
206 	/**
207 	 * Returns whether the @glcontext is a direct rendering context.
208 	 *
209 	 * Return: TRUE if the @glcontext is a direct rendering contest.
210 	 */
211 	public bool isDirect()
212 	{
213 		return gdk_gl_context_is_direct(gdkGLContext) != 0;
214 	}
215 
216 	/** */
217 	public bool makeCurrent(GLDrawableIF draw, GLDrawableIF read)
218 	{
219 		return gdk_gl_context_make_current(gdkGLContext, (draw is null) ? null : draw.getGLDrawableStruct(), (read is null) ? null : read.getGLDrawableStruct()) != 0;
220 	}
221 }