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