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