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