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(bool transferOwnership = false)
96 	{
97 		if (transferOwnership)
98 			ownedRef = false;
99 		return gdkGLContext;
100 	}
101 
102 	/** the main Gtk struct as a void* */
103 	protected override void* getStruct()
104 	{
105 		return cast(void*)gdkGLContext;
106 	}
107 
108 	protected override void setStruct(GObject* obj)
109 	{
110 		gdkGLContext = cast(GdkGLContext*)obj;
111 		super.setStruct(obj);
112 	}
113 
114 	/**
115 	 * Sets our main struct and passes it to the parent class.
116 	 */
117 	public this (GdkGLContext* gdkGLContext, bool ownedRef = false)
118 	{
119 		this.gdkGLContext = gdkGLContext;
120 		super(cast(GObject*)gdkGLContext, ownedRef);
121 	}
122 
123 
124 	/** */
125 	public static GType getType()
126 	{
127 		return gdk_gl_context_get_type();
128 	}
129 
130 	/**
131 	 * Clears the current #GdkGLContext.
132 	 *
133 	 * Any OpenGL call after this function returns will be ignored
134 	 * until gdk_gl_context_make_current() is called.
135 	 *
136 	 * Since: 3.16
137 	 */
138 	public static void clearCurrent()
139 	{
140 		gdk_gl_context_clear_current();
141 	}
142 
143 	/**
144 	 * Retrieves the current #GdkGLContext.
145 	 *
146 	 * Returns: the current #GdkGLContext, or %NULL
147 	 *
148 	 * Since: 3.16
149 	 */
150 	public static GLContext getCurrent()
151 	{
152 		auto p = gdk_gl_context_get_current();
153 		
154 		if(p is null)
155 		{
156 			return null;
157 		}
158 		
159 		return ObjectG.getDObject!(GLContext)(cast(GdkGLContext*) p);
160 	}
161 
162 	/**
163 	 * Retrieves the value set using gdk_gl_context_set_debug_enabled().
164 	 *
165 	 * Returns: %TRUE if debugging is enabled
166 	 *
167 	 * Since: 3.16
168 	 */
169 	public bool getDebugEnabled()
170 	{
171 		return gdk_gl_context_get_debug_enabled(gdkGLContext) != 0;
172 	}
173 
174 	/**
175 	 * Retrieves the #GdkDisplay the @context is created for
176 	 *
177 	 * Returns: a #GdkDisplay or %NULL
178 	 *
179 	 * Since: 3.16
180 	 */
181 	public Display getDisplay()
182 	{
183 		auto p = gdk_gl_context_get_display(gdkGLContext);
184 		
185 		if(p is null)
186 		{
187 			return null;
188 		}
189 		
190 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p);
191 	}
192 
193 	/**
194 	 * Retrieves the value set using gdk_gl_context_set_forward_compatible().
195 	 *
196 	 * Returns: %TRUE if the context should be forward compatible
197 	 *
198 	 * Since: 3.16
199 	 */
200 	public bool getForwardCompatible()
201 	{
202 		return gdk_gl_context_get_forward_compatible(gdkGLContext) != 0;
203 	}
204 
205 	/**
206 	 * Retrieves the major and minor version requested by calling
207 	 * gdk_gl_context_set_required_version().
208 	 *
209 	 * Params:
210 	 *     major = return location for the major version to request
211 	 *     minor = return location for the minor version to request
212 	 *
213 	 * Since: 3.16
214 	 */
215 	public void getRequiredVersion(out int major, out int minor)
216 	{
217 		gdk_gl_context_get_required_version(gdkGLContext, &major, &minor);
218 	}
219 
220 	/**
221 	 * Retrieves the #GdkGLContext that this @context share data with.
222 	 *
223 	 * Returns: a #GdkGLContext or %NULL
224 	 *
225 	 * Since: 3.16
226 	 */
227 	public GLContext getSharedContext()
228 	{
229 		auto p = gdk_gl_context_get_shared_context(gdkGLContext);
230 		
231 		if(p is null)
232 		{
233 			return null;
234 		}
235 		
236 		return ObjectG.getDObject!(GLContext)(cast(GdkGLContext*) p);
237 	}
238 
239 	/**
240 	 * Checks whether the @context is using an OpenGL or OpenGL ES profile.
241 	 *
242 	 * Returns: %TRUE if the #GdkGLContext is using an OpenGL ES profile
243 	 *
244 	 * Since: 3.22
245 	 */
246 	public bool getUseEs()
247 	{
248 		return gdk_gl_context_get_use_es(gdkGLContext) != 0;
249 	}
250 
251 	/**
252 	 * Retrieves the OpenGL version of the @context.
253 	 *
254 	 * The @context must be realized prior to calling this function.
255 	 *
256 	 * Params:
257 	 *     major = return location for the major version
258 	 *     minor = return location for the minor version
259 	 *
260 	 * Since: 3.16
261 	 */
262 	public void getVersion(out int major, out int minor)
263 	{
264 		gdk_gl_context_get_version(gdkGLContext, &major, &minor);
265 	}
266 
267 	/**
268 	 * Retrieves the #GdkWindow used by the @context.
269 	 *
270 	 * Returns: a #GdkWindow or %NULL
271 	 *
272 	 * Since: 3.16
273 	 */
274 	public Window getWindow()
275 	{
276 		auto p = gdk_gl_context_get_window(gdkGLContext);
277 		
278 		if(p is null)
279 		{
280 			return null;
281 		}
282 		
283 		return ObjectG.getDObject!(Window)(cast(GdkWindow*) p);
284 	}
285 
286 	/**
287 	 * Whether the #GdkGLContext is in legacy mode or not.
288 	 *
289 	 * The #GdkGLContext must be realized before calling this function.
290 	 *
291 	 * When realizing a GL context, GDK will try to use the OpenGL 3.2 core
292 	 * profile; this profile removes all the OpenGL API that was deprecated
293 	 * prior to the 3.2 version of the specification. If the realization is
294 	 * successful, this function will return %FALSE.
295 	 *
296 	 * If the underlying OpenGL implementation does not support core profiles,
297 	 * GDK will fall back to a pre-3.2 compatibility profile, and this function
298 	 * will return %TRUE.
299 	 *
300 	 * You can use the value returned by this function to decide which kind
301 	 * of OpenGL API to use, or whether to do extension discovery, or what
302 	 * kind of shader programs to load.
303 	 *
304 	 * Returns: %TRUE if the GL context is in legacy mode
305 	 *
306 	 * Since: 3.20
307 	 */
308 	public bool isLegacy()
309 	{
310 		return gdk_gl_context_is_legacy(gdkGLContext) != 0;
311 	}
312 
313 	/**
314 	 * Makes the @context the current one.
315 	 *
316 	 * Since: 3.16
317 	 */
318 	public void makeCurrent()
319 	{
320 		gdk_gl_context_make_current(gdkGLContext);
321 	}
322 
323 	/**
324 	 * Realizes the given #GdkGLContext.
325 	 *
326 	 * It is safe to call this function on a realized #GdkGLContext.
327 	 *
328 	 * Returns: %TRUE if the context is realized
329 	 *
330 	 * Since: 3.16
331 	 *
332 	 * Throws: GException on failure.
333 	 */
334 	public bool realize()
335 	{
336 		GError* err = null;
337 		
338 		auto p = gdk_gl_context_realize(gdkGLContext, &err) != 0;
339 		
340 		if (err !is null)
341 		{
342 			throw new GException( new ErrorG(err) );
343 		}
344 		
345 		return p;
346 	}
347 
348 	/**
349 	 * Sets whether the #GdkGLContext should perform extra validations and
350 	 * run time checking. This is useful during development, but has
351 	 * additional overhead.
352 	 *
353 	 * The #GdkGLContext must not be realized or made current prior to
354 	 * calling this function.
355 	 *
356 	 * Params:
357 	 *     enabled = whether to enable debugging in the context
358 	 *
359 	 * Since: 3.16
360 	 */
361 	public void setDebugEnabled(bool enabled)
362 	{
363 		gdk_gl_context_set_debug_enabled(gdkGLContext, enabled);
364 	}
365 
366 	/**
367 	 * Sets whether the #GdkGLContext should be forward compatible.
368 	 *
369 	 * Forward compatibile contexts must not support OpenGL functionality that
370 	 * has been marked as deprecated in the requested version; non-forward
371 	 * compatible contexts, on the other hand, must support both deprecated and
372 	 * non deprecated functionality.
373 	 *
374 	 * The #GdkGLContext must not be realized or made current prior to calling
375 	 * this function.
376 	 *
377 	 * Params:
378 	 *     compatible = whether the context should be forward compatible
379 	 *
380 	 * Since: 3.16
381 	 */
382 	public void setForwardCompatible(bool compatible)
383 	{
384 		gdk_gl_context_set_forward_compatible(gdkGLContext, compatible);
385 	}
386 
387 	/**
388 	 * Sets the major and minor version of OpenGL to request.
389 	 *
390 	 * Setting @major and @minor to zero will use the default values.
391 	 *
392 	 * The #GdkGLContext must not be realized or made current prior to calling
393 	 * this function.
394 	 *
395 	 * Params:
396 	 *     major = the major version to request
397 	 *     minor = the minor version to request
398 	 *
399 	 * Since: 3.16
400 	 */
401 	public void setRequiredVersion(int major, int minor)
402 	{
403 		gdk_gl_context_set_required_version(gdkGLContext, major, minor);
404 	}
405 
406 	/**
407 	 * Requests that GDK create a OpenGL ES context instead of an OpenGL one,
408 	 * if the platform and windowing system allows it.
409 	 *
410 	 * The @context must not have been realized.
411 	 *
412 	 * By default, GDK will attempt to automatically detect whether the
413 	 * underlying GL implementation is OpenGL or OpenGL ES once the @context
414 	 * is realized.
415 	 *
416 	 * You should check the return value of gdk_gl_context_get_use_es() after
417 	 * calling gdk_gl_context_realize() to decide whether to use the OpenGL or
418 	 * OpenGL ES API, extensions, or shaders.
419 	 *
420 	 * Params:
421 	 *     useEs = whether the context should use OpenGL ES instead of OpenGL,
422 	 *         or -1 to allow auto-detection
423 	 *
424 	 * Since: 3.22
425 	 */
426 	public void setUseEs(int useEs)
427 	{
428 		gdk_gl_context_set_use_es(gdkGLContext, useEs);
429 	}
430 }