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 * Retrieves the OpenGL version of the @context. 239 * 240 * The @context must be realized prior to calling this function. 241 * 242 * Params: 243 * major = return location for the major version 244 * minor = return location for the minor version 245 * 246 * Since: 3.16 247 */ 248 public void getVersion(out int major, out int minor) 249 { 250 gdk_gl_context_get_version(gdkGLContext, &major, &minor); 251 } 252 253 /** 254 * Retrieves the #GdkWindow used by the @context. 255 * 256 * Return: a #GdkWindow or %NULL 257 * 258 * Since: 3.16 259 */ 260 public Window getWindow() 261 { 262 auto p = gdk_gl_context_get_window(gdkGLContext); 263 264 if(p is null) 265 { 266 return null; 267 } 268 269 return ObjectG.getDObject!(Window)(cast(GdkWindow*) p); 270 } 271 272 /** 273 * Whether the #GdkGLContext is in legacy mode or not. 274 * 275 * The #GdkGLContext must be realized before calling this function. 276 * 277 * When realizing a GL context, GDK will try to use the OpenGL 3.2 core 278 * profile; this profile removes all the OpenGL API that was deprecated 279 * prior to the 3.2 version of the specification. If the realization is 280 * successful, this function will return %FALSE. 281 * 282 * If the underlying OpenGL implementation does not support core profiles, 283 * GDK will fall back to a pre-3.2 compatibility profile, and this function 284 * will return %TRUE. 285 * 286 * You can use the value returned by this function to decide which kind 287 * of OpenGL API to use, or whether to do extension discovery, or what 288 * kind of shader programs to load. 289 * 290 * Return: %TRUE if the GL context is in legacy mode 291 * 292 * Since: 3.20 293 */ 294 public bool isLegacy() 295 { 296 return gdk_gl_context_is_legacy(gdkGLContext) != 0; 297 } 298 299 /** 300 * Makes the @context the current one. 301 * 302 * Since: 3.16 303 */ 304 public void makeCurrent() 305 { 306 gdk_gl_context_make_current(gdkGLContext); 307 } 308 309 /** 310 * Realizes the given #GdkGLContext. 311 * 312 * It is safe to call this function on a realized #GdkGLContext. 313 * 314 * Return: %TRUE if the context is realized 315 * 316 * Since: 3.16 317 * 318 * Throws: GException on failure. 319 */ 320 public bool realize() 321 { 322 GError* err = null; 323 324 auto p = gdk_gl_context_realize(gdkGLContext, &err) != 0; 325 326 if (err !is null) 327 { 328 throw new GException( new ErrorG(err) ); 329 } 330 331 return p; 332 } 333 334 /** 335 * Sets whether the #GdkGLContext should perform extra validations and 336 * run time checking. This is useful during development, but has 337 * additional overhead. 338 * 339 * The #GdkGLContext must not be realized or made current prior to 340 * calling this function. 341 * 342 * Params: 343 * enabled = whether to enable debugging in the context 344 * 345 * Since: 3.16 346 */ 347 public void setDebugEnabled(bool enabled) 348 { 349 gdk_gl_context_set_debug_enabled(gdkGLContext, enabled); 350 } 351 352 /** 353 * Sets whether the #GdkGLContext should be forward compatible. 354 * 355 * Forward compatibile contexts must not support OpenGL functionality that 356 * has been marked as deprecated in the requested version; non-forward 357 * compatible contexts, on the other hand, must support both deprecated and 358 * non deprecated functionality. 359 * 360 * The #GdkGLContext must not be realized or made current prior to calling 361 * this function. 362 * 363 * Params: 364 * compatible = whether the context should be forward compatible 365 * 366 * Since: 3.16 367 */ 368 public void setForwardCompatible(bool compatible) 369 { 370 gdk_gl_context_set_forward_compatible(gdkGLContext, compatible); 371 } 372 373 /** 374 * Sets the major and minor version of OpenGL to request. 375 * 376 * Setting @major and @minor to zero will use the default values. 377 * 378 * The #GdkGLContext must not be realized or made current prior to calling 379 * this function. 380 * 381 * Params: 382 * major = the major version to request 383 * minor = the minor version to request 384 * 385 * Since: 3.16 386 */ 387 public void setRequiredVersion(int major, int minor) 388 { 389 gdk_gl_context_set_required_version(gdkGLContext, major, minor); 390 } 391 }