alternative to assert
[gtkD.git] / gtkD / srcgl / glgtk / GLCapability.d
blob2677ba599b80003b25a7455e477313340e1e10ef
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile =
26 * outPack = glgtk
27 * outFile = GLCapability
28 * strct =
29 * realStrct=
30 * ctorStrct=
31 * clss =
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * omit structs:
40 * omit prefixes:
41 * omit code:
42 * imports:
43 * structWrap:
44 * module aliases:
45 * local aliases:
48 module glgtk.GLCapability;
50 version(noAssert)
52 version(Tango)
54 import tango.io.Stdout; // use the tango loging?
58 private import gtkglc.glgtktypes;
60 private import gtkglc.glgtk;
67 /**
70 // SNEAKY MIXIN PROBLEM:
72 // These need to be public imports
73 // or GLCompatibility will not compile
74 // as a mixin in other modules!
76 // May as well be explicit about it:
79 public import std.stdio;
80 public import glgtk.GLWidget;
81 private import glgdk.GLDrawable;
82 public import gdk.Event;
83 public import gtkglc.gl;
86 template GLCapability()
89 GLfloat width = 0;
90 GLfloat height = 0;
92 GLfloat getGLWidth()
94 return width;
96 GLfloat getGLHeight()
98 return height;
103 * Sets the GL capabilities for the widget
105 bool setGLCapability(GLConfig glConfig = null, int renderType = GLRenderType.RGBA_TYPE)
107 if ( glConfig is null )
109 glConfig = new GLConfig(
110 GLConfigMode.MODE_RGB
111 | GLConfigMode.MODE_DEPTH
112 | GLConfigMode.MODE_DOUBLE,
113 GLConfigMode.MODE_RGB
114 | GLConfigMode.MODE_DEPTH
117 bool ok = setGLCapability(this, glConfig, null, true, renderType);
119 return ok;
123 * Set the GL capabilities for the widget
125 bool setGLCapability(Widget widget, GLConfig glConfig, GLContext shareList, bool direct, int renderType)
127 GLWidget.setGLCapability(widget, glConfig, shareList, direct, renderType);
129 addOnRealize(&realizeFrame);
130 addOnUnrealize(&realizeFrame);
131 addOnExpose(&exposeFrame);
132 addOnConfigure(&configureFrame);
133 addOnMap(&mapFrame);
134 addOnUnmap(&unmapFrame);
135 addOnVisibilityNotify(&visibilityFrame);
136 return true;
140 * The widget should use this method to redraw it self at any time
142 public bool glDrawFrame()
144 return glDrawFrame(this);
148 * The application should use this method to redraw the scene at any time
150 bool glDrawFrame(Widget widget)
152 //printf("GLCapabilityT.realizeFrame \n" );
153 GLContext context = GLWidget.getGLContext(widget);
154 GLDrawable drawable = GLWidget.getGLDrawable(widget);
156 /*** OpenGL BEGIN ***/
157 if ( !drawable.glBegin(context) )
159 return false;
162 /*** do user actions ***/
163 bool consumeEvent = typeof(this).drawGL(null);
165 /*** flush ***/
166 if ( drawable.isDoubleBuffered() )
168 drawable.swapBuffers();
170 else
172 glFlush ();
175 drawable.glEnd();
176 /*** OpenGL END ***/
177 return true;
181 bool alreadyRealized;
183 bool getAlreadyRealized()
185 return alreadyRealized;
188 void realizeFrame(Widget widget)
190 alreadyRealized = true;
192 //printf("GLCapabilityT.realizeFrame \n" );
193 GLContext context = GLWidget.getGLContext(widget);
194 GLDrawable drawable = GLWidget.getGLDrawable(widget);
196 /*** OpenGL BEGIN ***/
197 if ( !drawable.glBegin(context) )
199 return false;
202 /*** do user actions ***/
203 bool consumeEvent = typeof(this).initGL();
205 /*** flush ***/
206 if ( drawable.isDoubleBuffered() )
208 drawable.swapBuffers();
210 else
212 glFlush ();
215 drawable.glEnd();
216 /*** OpenGL END ***/
218 //return consumeEvent;
221 int exposeFrame(GdkEventExpose* event, Widget widget)
223 //printf("GLCapabilityT.exposeFrame exposeFrame\n" );
224 GLContext context = GLWidget.getGLContext(widget);
225 GLDrawable drawable = GLWidget.getGLDrawable(widget);
227 /*** OpenGL BEGIN ***/
228 if ( !drawable.glBegin(context) )
230 return false;
233 /*** do user actions ***/
234 int consumeEvent = typeof(this).drawGL(event);
236 /*** flush ***/
237 if ( drawable.isDoubleBuffered() )
239 drawable.swapBuffers();
241 else
243 glFlush ();
246 drawable.glEnd();
247 /*** OpenGL END ***/
249 return consumeEvent;
252 private import std.gc;
254 int configureFrame(GdkEventConfigure* event, Widget widget)
256 if ( event != null )
258 width = event.width;
259 height = event.height;
261 std.gc.disable();
262 //writefln("configureFrame 1");
263 //printf("GLCapabilityT.configureFrame \n" );
264 GLContext context = GLWidget.getGLContext(widget);
265 GLDrawable drawable = GLWidget.getGLDrawable(widget);
267 /*** OpenGL BEGIN ***/
268 if ( !drawable.glBegin(context) )
270 return false;
273 //writefln("configureFrame 2");
274 /*** do user actions ***/
275 int consumeEvent = typeof(this).resizeGL(event);
276 //printf("here\n");
277 //writefln("configureFrame 3");
279 /*** flush ***/
280 if ( drawable.isDoubleBuffered() )
282 //writefln("configureFrame 4");
283 drawable.swapBuffers();
284 //writefln("configureFrame 5");
286 else
288 //writefln("configureFrame 6");
289 glFlush ();
290 //writefln("configureFrame 7");
293 //writefln("configureFrame 8");
294 drawable.glEnd();
295 //writefln("configureFrame 9");
296 /*** OpenGL END ***/
298 std.gc.enable();
299 return consumeEvent;
302 void mapFrame(Widget widget)
304 //printf("GLCapabilityT.mapFrame \n" );
305 GLContext context = GLWidget.getGLContext(widget);
306 GLDrawable drawable = GLWidget.getGLDrawable(widget);
308 /*** OpenGL BEGIN ***/
309 if ( !drawable.glBegin(context) )
311 return false;
314 /*** do user actions ***/
315 bool consumeEvent = typeof(this).onMap();
317 /*** flush ***/
318 if ( drawable.isDoubleBuffered() )
320 drawable.swapBuffers();
322 else
324 glFlush ();
327 drawable.glEnd();
328 /*** OpenGL END ***/
330 //return consumeEvent;
333 void unmapFrame(Widget widget)
335 //printf("GLCapabilityT.unmapFrame \n" );
336 GLContext context = GLWidget.getGLContext(widget);
337 GLDrawable drawable = GLWidget.getGLDrawable(widget);
339 /*** OpenGL BEGIN ***/
340 if ( !drawable.glBegin(context) )
342 return false;
345 /*** do user actions ***/
346 bool consumeEvent = typeof(this).onUnmap();
348 /*** flush ***/
349 if ( drawable.isDoubleBuffered() )
351 drawable.swapBuffers();
353 else
355 glFlush ();
358 drawable.glEnd();
359 /*** OpenGL END ***/
361 //return consumeEvent;
364 int visibilityFrame(GdkEventVisibility* event, Widget widget)
366 //printf("GLCapabilityT.visibilityFrame \n" );
367 GLContext context = GLWidget.getGLContext(widget);
368 GLDrawable drawable = GLWidget.getGLDrawable(widget);
370 /*** OpenGL BEGIN ***/
371 if ( !drawable.glBegin(context) )
373 return false;
376 /*** do user actions ***/
377 bool consumeEvent = typeof(this).onVisibility(event);
379 /*** flush ***/
380 if ( drawable.isDoubleBuffered() )
382 drawable.swapBuffers();
384 else
386 glFlush ();
389 drawable.glEnd();
390 /*** OpenGL END ***/
392 return consumeEvent;
395 bool onMap()
397 //printf("GLCapabilityT.map \n" );
398 return true;
401 bool onUnmap()
403 //printf("GLCapabilityT.unmap \n" );
404 return true;
407 bool onVisibility(GdkEventVisibility* event)
409 //printf("GLCapabilityT.visibility \n" );
410 return true;