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 124 public static GType getType() 125 { 126 return gdk_gl_context_get_type(); 127 } 128 129 /** 130 * Clears the current #GdkGLContext. 131 * 132 * Any OpenGL call after this function returns will be ignored 133 * until gdk_gl_context_make_current() is called. 134 * 135 * Since: 3.16 136 */ 137 public static void clearCurrent() 138 { 139 gdk_gl_context_clear_current(); 140 } 141 142 /** 143 * Retrieves the current #GdkGLContext. 144 * 145 * Return: the current #GdkGLContext, or %NULL 146 * 147 * Since: 3.16 148 */ 149 public static GLContext getCurrent() 150 { 151 auto p = gdk_gl_context_get_current(); 152 153 if(p is null) 154 { 155 return null; 156 } 157 158 return ObjectG.getDObject!(GLContext)(cast(GdkGLContext*) p); 159 } 160 161 /** 162 * Retrieves the value set using gdk_gl_context_set_debug_enabled(). 163 * 164 * Return: %TRUE if debugging is enabled 165 * 166 * Since: 3.16 167 */ 168 public bool getDebugEnabled() 169 { 170 return gdk_gl_context_get_debug_enabled(gdkGLContext) != 0; 171 } 172 173 /** 174 * Retrieves the #GdkDisplay the @context is created for 175 * 176 * Return: a #GdkDisplay or %NULL 177 * 178 * Since: 3.16 179 */ 180 public Display getDisplay() 181 { 182 auto p = gdk_gl_context_get_display(gdkGLContext); 183 184 if(p is null) 185 { 186 return null; 187 } 188 189 return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p); 190 } 191 192 /** 193 * Retrieves the value set using gdk_gl_context_set_forward_compatible(). 194 * 195 * Return: %TRUE if the context should be forward compatible 196 * 197 * Since: 3.16 198 */ 199 public bool getForwardCompatible() 200 { 201 return gdk_gl_context_get_forward_compatible(gdkGLContext) != 0; 202 } 203 204 /** 205 * Retrieves the major and minor version requested by calling 206 * gdk_gl_context_set_required_version(). 207 * 208 * Params: 209 * major = return location for the major version to request 210 * minor = return location for the minor version to request 211 * 212 * Since: 3.16 213 */ 214 public void getRequiredVersion(out int major, out int minor) 215 { 216 gdk_gl_context_get_required_version(gdkGLContext, &major, &minor); 217 } 218 219 /** 220 * Retrieves the #GdkGLContext that this @context share data with. 221 * 222 * Return: a #GdkGLContext or %NULL 223 * 224 * Since: 3.16 225 */ 226 public GLContext getSharedContext() 227 { 228 auto p = gdk_gl_context_get_shared_context(gdkGLContext); 229 230 if(p is null) 231 { 232 return null; 233 } 234 235 return ObjectG.getDObject!(GLContext)(cast(GdkGLContext*) p); 236 } 237 238 /** 239 * Retrieves the OpenGL version of the @context. 240 * 241 * The @context must be realized prior to calling this function. 242 * 243 * Params: 244 * major = return location for the major version 245 * minor = return location for the minor version 246 * 247 * Since: 3.16 248 */ 249 public void getVersion(out int major, out int minor) 250 { 251 gdk_gl_context_get_version(gdkGLContext, &major, &minor); 252 } 253 254 /** 255 * Retrieves the #GdkWindow used by the @context. 256 * 257 * Return: a #GdkWindow or %NULL 258 * 259 * Since: 3.16 260 */ 261 public Window getWindow() 262 { 263 auto p = gdk_gl_context_get_window(gdkGLContext); 264 265 if(p is null) 266 { 267 return null; 268 } 269 270 return ObjectG.getDObject!(Window)(cast(GdkWindow*) p); 271 } 272 273 /** 274 * Makes the @context the current one. 275 * 276 * Since: 3.16 277 */ 278 public void makeCurrent() 279 { 280 gdk_gl_context_make_current(gdkGLContext); 281 } 282 283 /** 284 * Realizes the given #GdkGLContext. 285 * 286 * It is safe to call this function on a realized #GdkGLContext. 287 * 288 * Return: %TRUE if the context is realized 289 * 290 * Since: 3.16 291 * 292 * Throws: GException on failure. 293 */ 294 public bool realize() 295 { 296 GError* err = null; 297 298 auto p = gdk_gl_context_realize(gdkGLContext, &err) != 0; 299 300 if (err !is null) 301 { 302 throw new GException( new ErrorG(err) ); 303 } 304 305 return p; 306 } 307 308 /** 309 * Sets whether the #GdkGLContext should perform extra validations and 310 * run time checking. This is useful during development, but has 311 * additional overhead. 312 * 313 * The #GdkGLContext must not be realized or made current prior to 314 * calling this function. 315 * 316 * Params: 317 * enabled = whether to enable debugging in the context 318 * 319 * Since: 3.16 320 */ 321 public void setDebugEnabled(bool enabled) 322 { 323 gdk_gl_context_set_debug_enabled(gdkGLContext, enabled); 324 } 325 326 /** 327 * Sets whether the #GdkGLContext should be forward compatible. 328 * 329 * Forward compatibile contexts must not support OpenGL functionality that 330 * has been marked as deprecated in the requested version; non-forward 331 * compatible contexts, on the other hand, must support both deprecated and 332 * non deprecated functionality. 333 * 334 * The #GdkGLContext must not be realized or made current prior to calling 335 * this function. 336 * 337 * Params: 338 * compatible = whether the context should be forward compatible 339 * 340 * Since: 3.16 341 */ 342 public void setForwardCompatible(bool compatible) 343 { 344 gdk_gl_context_set_forward_compatible(gdkGLContext, compatible); 345 } 346 347 /** 348 * Sets the major and minor version of OpenGL to request. 349 * 350 * Setting @major and @minor to zero will use the default values. 351 * 352 * The #GdkGLContext must not be realized or made current prior to calling 353 * this function. 354 * 355 * Params: 356 * major = the major version to request 357 * minor = the minor version to request 358 * 359 * Since: 3.16 360 */ 361 public void setRequiredVersion(int major, int minor) 362 { 363 gdk_gl_context_set_required_version(gdkGLContext, major, minor); 364 } 365 }