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 * Makes the @context the current one. 274 * 275 * Since: 3.16 276 */ 277 public void makeCurrent() 278 { 279 gdk_gl_context_make_current(gdkGLContext); 280 } 281 282 /** 283 * Realizes the given #GdkGLContext. 284 * 285 * It is safe to call this function on a realized #GdkGLContext. 286 * 287 * Return: %TRUE if the context is realized 288 * 289 * Since: 3.16 290 * 291 * Throws: GException on failure. 292 */ 293 public bool realize() 294 { 295 GError* err = null; 296 297 auto p = gdk_gl_context_realize(gdkGLContext, &err) != 0; 298 299 if (err !is null) 300 { 301 throw new GException( new ErrorG(err) ); 302 } 303 304 return p; 305 } 306 307 /** 308 * Sets whether the #GdkGLContext should perform extra validations and 309 * run time checking. This is useful during development, but has 310 * additional overhead. 311 * 312 * The #GdkGLContext must not be realized or made current prior to 313 * calling this function. 314 * 315 * Params: 316 * enabled = whether to enable debugging in the context 317 * 318 * Since: 3.16 319 */ 320 public void setDebugEnabled(bool enabled) 321 { 322 gdk_gl_context_set_debug_enabled(gdkGLContext, enabled); 323 } 324 325 /** 326 * Sets whether the #GdkGLContext should be forward compatible. 327 * 328 * Forward compatibile contexts must not support OpenGL functionality that 329 * has been marked as deprecated in the requested version; non-forward 330 * compatible contexts, on the other hand, must support both deprecated and 331 * non deprecated functionality. 332 * 333 * The #GdkGLContext must not be realized or made current prior to calling 334 * this function. 335 * 336 * Params: 337 * compatible = whether the context should be forward compatible 338 * 339 * Since: 3.16 340 */ 341 public void setForwardCompatible(bool compatible) 342 { 343 gdk_gl_context_set_forward_compatible(gdkGLContext, compatible); 344 } 345 346 /** 347 * Sets the major and minor version of OpenGL to request. 348 * 349 * Setting @major and @minor to zero will use the default values. 350 * 351 * The #GdkGLContext must not be realized or made current prior to calling 352 * this function. 353 * 354 * Params: 355 * major = the major version to request 356 * minor = the minor version to request 357 * 358 * Since: 3.16 359 */ 360 public void setRequiredVersion(int major, int minor) 361 { 362 gdk_gl_context_set_required_version(gdkGLContext, major, minor); 363 } 364 }