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 gdk.GLContext;
26 
27 private import gdk.Display;
28 private import gdk.Window;
29 private import glib.ErrorG;
30 private import glib.GException;
31 private import gobject.ObjectG;
32 private import gtkc.gdk;
33 public  import gtkc.gdktypes;
34 
35 
36 /**
37  * #GdkGLContext is an object representing the platform-specific
38  * OpenGL drawing context.
39  * 
40  * #GdkGLContexts are created for a #GdkWindow using
41  * gdk_window_create_gl_context(), and the context will match
42  * the #GdkVisual of the window.
43  * 
44  * A #GdkGLContext is not tied to any particular normal framebuffer.
45  * For instance, it cannot draw to the #GdkWindow back buffer. The GDK
46  * repaint system is in full control of the painting to that. Instead,
47  * you can create render buffers or textures and use gdk_cairo_draw_from_gl()
48  * in the draw function of your widget to draw them. Then GDK will handle
49  * the integration of your rendering with that of other widgets.
50  * 
51  * Support for #GdkGLContext is platform-specific, context creation
52  * can fail, returning %NULL context.
53  * 
54  * A #GdkGLContext has to be made "current" in order to start using
55  * it, otherwise any OpenGL call will be ignored.
56  * 
57  * ## Creating a new OpenGL context ##
58  * 
59  * In order to create a new #GdkGLContext instance you need a
60  * #GdkWindow, which you typically get during the realize call
61  * of a widget.
62  * 
63  * A #GdkGLContext is not realized until either gdk_gl_context_make_current(),
64  * or until it is realized using gdk_gl_context_realize(). It is possible to
65  * specify details of the GL context like the OpenGL version to be used, or
66  * whether the GL context should have extra state validation enabled after
67  * calling gdk_window_create_gl_context() by calling gdk_gl_context_realize().
68  * If the realization fails you have the option to change the settings of the
69  * #GdkGLContext and try again.
70  * 
71  * ## Using a GdkGLContext ##
72  * 
73  * You will need to make the #GdkGLContext the current context
74  * before issuing OpenGL calls; the system sends OpenGL commands to
75  * whichever context is current. It is possible to have multiple
76  * contexts, so you always need to ensure that the one which you
77  * want to draw with is the current one before issuing commands:
78  * 
79  * |[<!-- language="C" -->
80  * gdk_gl_context_make_current (context);
81  * ]|
82  * 
83  * You can now perform your drawing using OpenGL commands.
84  * 
85  * You can check which #GdkGLContext is the current one by using
86  * gdk_gl_context_get_current(); you can also unset any #GdkGLContext
87  * that is currently set by calling gdk_gl_context_clear_current().
88  */
89 public class GLContext : ObjectG
90 {
91 	/** the main Gtk struct */
92 	protected GdkGLContext* gdkGLContext;
93 
94 	/** Get the main Gtk struct */
95 	public GdkGLContext* getGLContextStruct()
96 	{
97 		return gdkGLContext;
98 	}
99 
100 	/** the main Gtk struct as a void* */
101 	protected override void* getStruct()
102 	{
103 		return cast(void*)gdkGLContext;
104 	}
105 
106 	protected override void setStruct(GObject* obj)
107 	{
108 		gdkGLContext = cast(GdkGLContext*)obj;
109 		super.setStruct(obj);
110 	}
111 
112 	/**
113 	 * Sets our main struct and passes it to the parent class.
114 	 */
115 	public this (GdkGLContext* gdkGLContext, bool ownedRef = false)
116 	{
117 		this.gdkGLContext = gdkGLContext;
118 		super(cast(GObject*)gdkGLContext, ownedRef);
119 	}
120 
121 
122 	/** */
123 	public static GType getType()
124 	{
125 		return gdk_gl_context_get_type();
126 	}
127 
128 	/**
129 	 * Clears the current #GdkGLContext.
130 	 *
131 	 * Any OpenGL call after this function returns will be ignored
132 	 * until gdk_gl_context_make_current() is called.
133 	 *
134 	 * Since: 3.16
135 	 */
136 	public static void clearCurrent()
137 	{
138 		gdk_gl_context_clear_current();
139 	}
140 
141 	/**
142 	 * Retrieves the current #GdkGLContext.
143 	 *
144 	 * Return: the current #GdkGLContext, or %NULL
145 	 *
146 	 * Since: 3.16
147 	 */
148 	public static GLContext getCurrent()
149 	{
150 		auto p = gdk_gl_context_get_current();
151 		
152 		if(p is null)
153 		{
154 			return null;
155 		}
156 		
157 		return ObjectG.getDObject!(GLContext)(cast(GdkGLContext*) p);
158 	}
159 
160 	/**
161 	 * Retrieves the value set using gdk_gl_context_set_debug_enabled().
162 	 *
163 	 * Return: %TRUE if debugging is enabled
164 	 *
165 	 * Since: 3.16
166 	 */
167 	public bool getDebugEnabled()
168 	{
169 		return gdk_gl_context_get_debug_enabled(gdkGLContext) != 0;
170 	}
171 
172 	/**
173 	 * Retrieves the #GdkDisplay the @context is created for
174 	 *
175 	 * Return: a #GdkDisplay or %NULL
176 	 *
177 	 * Since: 3.16
178 	 */
179 	public Display getDisplay()
180 	{
181 		auto p = gdk_gl_context_get_display(gdkGLContext);
182 		
183 		if(p is null)
184 		{
185 			return null;
186 		}
187 		
188 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p);
189 	}
190 
191 	/**
192 	 * Retrieves the value set using gdk_gl_context_set_forward_compatible().
193 	 *
194 	 * Return: %TRUE if the context should be forward compatible
195 	 *
196 	 * Since: 3.16
197 	 */
198 	public bool getForwardCompatible()
199 	{
200 		return gdk_gl_context_get_forward_compatible(gdkGLContext) != 0;
201 	}
202 
203 	/**
204 	 * Retrieves the major and minor version requested by calling
205 	 * gdk_gl_context_set_required_version().
206 	 *
207 	 * Params:
208 	 *     major = return location for the major version to request
209 	 *     minor = return location for the minor version to request
210 	 *
211 	 * Since: 3.16
212 	 */
213 	public void getRequiredVersion(out int major, out int minor)
214 	{
215 		gdk_gl_context_get_required_version(gdkGLContext, &major, &minor);
216 	}
217 
218 	/**
219 	 * Retrieves the #GdkGLContext that this @context share data with.
220 	 *
221 	 * Return: a #GdkGLContext or %NULL
222 	 *
223 	 * Since: 3.16
224 	 */
225 	public GLContext getSharedContext()
226 	{
227 		auto p = gdk_gl_context_get_shared_context(gdkGLContext);
228 		
229 		if(p is null)
230 		{
231 			return null;
232 		}
233 		
234 		return ObjectG.getDObject!(GLContext)(cast(GdkGLContext*) p);
235 	}
236 
237 	/**
238 	 * Checks whether the @context is using an OpenGL or OpenGL ES profile.
239 	 *
240 	 * Return: %TRUE if the #GdkGLContext is using an OpenGL ES profile
241 	 *
242 	 * Since: 3.22
243 	 */
244 	public bool getUseEs()
245 	{
246 		return gdk_gl_context_get_use_es(gdkGLContext) != 0;
247 	}
248 
249 	/**
250 	 * Retrieves the OpenGL version of the @context.
251 	 *
252 	 * The @context must be realized prior to calling this function.
253 	 *
254 	 * Params:
255 	 *     major = return location for the major version
256 	 *     minor = return location for the minor version
257 	 *
258 	 * Since: 3.16
259 	 */
260 	public void getVersion(out int major, out int minor)
261 	{
262 		gdk_gl_context_get_version(gdkGLContext, &major, &minor);
263 	}
264 
265 	/**
266 	 * Retrieves the #GdkWindow used by the @context.
267 	 *
268 	 * Return: a #GdkWindow or %NULL
269 	 *
270 	 * Since: 3.16
271 	 */
272 	public Window getWindow()
273 	{
274 		auto p = gdk_gl_context_get_window(gdkGLContext);
275 		
276 		if(p is null)
277 		{
278 			return null;
279 		}
280 		
281 		return ObjectG.getDObject!(Window)(cast(GdkWindow*) p);
282 	}
283 
284 	/**
285 	 * Whether the #GdkGLContext is in legacy mode or not.
286 	 *
287 	 * The #GdkGLContext must be realized before calling this function.
288 	 *
289 	 * When realizing a GL context, GDK will try to use the OpenGL 3.2 core
290 	 * profile; this profile removes all the OpenGL API that was deprecated
291 	 * prior to the 3.2 version of the specification. If the realization is
292 	 * successful, this function will return %FALSE.
293 	 *
294 	 * If the underlying OpenGL implementation does not support core profiles,
295 	 * GDK will fall back to a pre-3.2 compatibility profile, and this function
296 	 * will return %TRUE.
297 	 *
298 	 * You can use the value returned by this function to decide which kind
299 	 * of OpenGL API to use, or whether to do extension discovery, or what
300 	 * kind of shader programs to load.
301 	 *
302 	 * Return: %TRUE if the GL context is in legacy mode
303 	 *
304 	 * Since: 3.20
305 	 */
306 	public bool isLegacy()
307 	{
308 		return gdk_gl_context_is_legacy(gdkGLContext) != 0;
309 	}
310 
311 	/**
312 	 * Makes the @context the current one.
313 	 *
314 	 * Since: 3.16
315 	 */
316 	public void makeCurrent()
317 	{
318 		gdk_gl_context_make_current(gdkGLContext);
319 	}
320 
321 	/**
322 	 * Realizes the given #GdkGLContext.
323 	 *
324 	 * It is safe to call this function on a realized #GdkGLContext.
325 	 *
326 	 * Return: %TRUE if the context is realized
327 	 *
328 	 * Since: 3.16
329 	 *
330 	 * Throws: GException on failure.
331 	 */
332 	public bool realize()
333 	{
334 		GError* err = null;
335 		
336 		auto p = gdk_gl_context_realize(gdkGLContext, &err) != 0;
337 		
338 		if (err !is null)
339 		{
340 			throw new GException( new ErrorG(err) );
341 		}
342 		
343 		return p;
344 	}
345 
346 	/**
347 	 * Sets whether the #GdkGLContext should perform extra validations and
348 	 * run time checking. This is useful during development, but has
349 	 * additional overhead.
350 	 *
351 	 * The #GdkGLContext must not be realized or made current prior to
352 	 * calling this function.
353 	 *
354 	 * Params:
355 	 *     enabled = whether to enable debugging in the context
356 	 *
357 	 * Since: 3.16
358 	 */
359 	public void setDebugEnabled(bool enabled)
360 	{
361 		gdk_gl_context_set_debug_enabled(gdkGLContext, enabled);
362 	}
363 
364 	/**
365 	 * Sets whether the #GdkGLContext should be forward compatible.
366 	 *
367 	 * Forward compatibile contexts must not support OpenGL functionality that
368 	 * has been marked as deprecated in the requested version; non-forward
369 	 * compatible contexts, on the other hand, must support both deprecated and
370 	 * non deprecated functionality.
371 	 *
372 	 * The #GdkGLContext must not be realized or made current prior to calling
373 	 * this function.
374 	 *
375 	 * Params:
376 	 *     compatible = whether the context should be forward compatible
377 	 *
378 	 * Since: 3.16
379 	 */
380 	public void setForwardCompatible(bool compatible)
381 	{
382 		gdk_gl_context_set_forward_compatible(gdkGLContext, compatible);
383 	}
384 
385 	/**
386 	 * Sets the major and minor version of OpenGL to request.
387 	 *
388 	 * Setting @major and @minor to zero will use the default values.
389 	 *
390 	 * The #GdkGLContext must not be realized or made current prior to calling
391 	 * this function.
392 	 *
393 	 * Params:
394 	 *     major = the major version to request
395 	 *     minor = the minor version to request
396 	 *
397 	 * Since: 3.16
398 	 */
399 	public void setRequiredVersion(int major, int minor)
400 	{
401 		gdk_gl_context_set_required_version(gdkGLContext, major, minor);
402 	}
403 
404 	/**
405 	 * Requests that GDK create a OpenGL ES context instead of an OpenGL one,
406 	 * if the platform and windowing system allows it.
407 	 *
408 	 * The @context must not have been realized.
409 	 *
410 	 * By default, GDK will attempt to automatically detect whether the
411 	 * underlying GL implementation is OpenGL or OpenGL ES once the @context
412 	 * is realized.
413 	 *
414 	 * You should check the return value of gdk_gl_context_get_use_es() after
415 	 * calling gdk_gl_context_realize() to decide whether to use the OpenGL or
416 	 * OpenGL ES API, extensions, or shaders.
417 	 *
418 	 * Params:
419 	 *     useEs = whether the context should use OpenGL ES instead of OpenGL,
420 	 *         or -1 to allow auto-detection
421 	 *
422 	 * Since: 3.22
423 	 */
424 	public void setUseEs(int useEs)
425 	{
426 		gdk_gl_context_set_use_es(gdkGLContext, useEs);
427 	}
428 }