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