alternative to assert
[gtkD.git] / srcgl / glgtk / GLCapability.d
blobb9c909f8886f7a4748ff7bdb69249fff54c55ee9
1 /*
2 * This file is part of duit.
4 * duit 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 * duit 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 duit; 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 * local aliases:
47 module glgtk.GLCapability;
49 private import glgtk.glgtktypes;
51 private import lib.glgtk;
54 /**
57 // SNEAKY MIXIN PROBLEM:
59 // These need to be public imports
60 // or GLCompatibility will not compile
61 // as a mixin in other modules!
63 // May as well be explicit about it:
66 public import std.stdio;
67 public import glgtk.GLWidget;
68 private import glgdk.GLDrawable;
69 public import gdk.Event;
70 public import lib.gl;
73 template GLCapability()
76 GLfloat width = 0;
77 GLfloat height = 0;
79 GLfloat getGLWidth()
81 return width;
83 GLfloat getGLHeight()
85 return height;
89 /**
90 * Sets the GL capabilities for the widget
92 bit setGLCapability(GLConfig glConfig = null, int renderType = GLRenderType.RGBA_TYPE)
94 if ( glConfig is null )
96 glConfig = new GLConfig(
97 GLConfigMode.MODE_RGB
98 | GLConfigMode.MODE_DEPTH
99 | GLConfigMode.MODE_DOUBLE,
100 GLConfigMode.MODE_RGB
101 | GLConfigMode.MODE_DEPTH
104 bit ok = setGLCapability(this, glConfig, null, true, renderType);
106 return ok;
110 * Set the GL capabilities for the widget
112 bit setGLCapability(Widget widget, GLConfig glConfig, GLContext shareList, bit direct, int renderType)
114 GLWidget.setGLCapability(widget, glConfig, shareList, direct, renderType);
116 addOnRealize(&realizeFrame);
117 addOnUnrealize(&realizeFrame);
118 addOnExpose(&exposeFrame);
119 addOnConfigure(&configureFrame);
120 addOnMap(&mapFrame);
121 addOnUnmap(&unmapFrame);
122 addOnVisibilityNotify(&visibilityFrame);
123 return true;
127 * The widget should use this method to redraw it self at any time
129 public bit glDrawFrame()
131 return glDrawFrame(this);
135 * The application should use this method to redraw the scene at any time
137 bit glDrawFrame(Widget widget)
139 //printf("GLCapabilityT.realizeFrame \n" );
140 GLContext context = GLWidget.getGLContext(widget);
141 GLDrawable drawable = GLWidget.getGLDrawable(widget);
143 /*** OpenGL BEGIN ***/
144 if ( !drawable.glBegin(context) )
146 return false;
149 /*** do user actions ***/
150 bit consumeEvent = typeof(this).drawGL(null);
152 /*** flush ***/
153 if ( drawable.isDoubleBuffered() )
155 drawable.swapBuffers();
157 else
159 glFlush ();
162 drawable.glEnd();
163 /*** OpenGL END ***/
164 return true;
168 bool alreadyRealized;
170 bool getAlreadyRealized()
172 return alreadyRealized;
175 void realizeFrame(Widget widget)
177 alreadyRealized = true;
179 //printf("GLCapabilityT.realizeFrame \n" );
180 GLContext context = GLWidget.getGLContext(widget);
181 GLDrawable drawable = GLWidget.getGLDrawable(widget);
183 /*** OpenGL BEGIN ***/
184 if ( !drawable.glBegin(context) )
186 return false;
189 /*** do user actions ***/
190 bit consumeEvent = typeof(this).initGL();
192 /*** flush ***/
193 if ( drawable.isDoubleBuffered() )
195 drawable.swapBuffers();
197 else
199 glFlush ();
202 drawable.glEnd();
203 /*** OpenGL END ***/
205 //return consumeEvent;
208 int exposeFrame(GdkEventExpose* event, Widget widget)
210 //printf("GLCapabilityT.exposeFrame exposeFrame\n" );
211 GLContext context = GLWidget.getGLContext(widget);
212 GLDrawable drawable = GLWidget.getGLDrawable(widget);
214 /*** OpenGL BEGIN ***/
215 if ( !drawable.glBegin(context) )
217 return false;
220 /*** do user actions ***/
221 int consumeEvent = typeof(this).drawGL(event);
223 /*** flush ***/
224 if ( drawable.isDoubleBuffered() )
226 drawable.swapBuffers();
228 else
230 glFlush ();
233 drawable.glEnd();
234 /*** OpenGL END ***/
236 return consumeEvent;
239 private import std.gc;
241 int configureFrame(GdkEventConfigure* event, Widget widget)
243 if ( event != null )
245 width = event.width;
246 height = event.height;
248 std.gc.disable();
249 //writefln("configureFrame 1");
250 //printf("GLCapabilityT.configureFrame \n" );
251 GLContext context = GLWidget.getGLContext(widget);
252 GLDrawable drawable = GLWidget.getGLDrawable(widget);
254 /*** OpenGL BEGIN ***/
255 if ( !drawable.glBegin(context) )
257 return false;
260 //writefln("configureFrame 2");
261 /*** do user actions ***/
262 int consumeEvent = typeof(this).resizeGL(event);
263 //printf("here\n");
264 //writefln("configureFrame 3");
266 /*** flush ***/
267 if ( drawable.isDoubleBuffered() )
269 //writefln("configureFrame 4");
270 drawable.swapBuffers();
271 //writefln("configureFrame 5");
273 else
275 //writefln("configureFrame 6");
276 glFlush ();
277 //writefln("configureFrame 7");
280 //writefln("configureFrame 8");
281 drawable.glEnd();
282 //writefln("configureFrame 9");
283 /*** OpenGL END ***/
285 std.gc.enable();
286 return consumeEvent;
289 void mapFrame(Widget widget)
291 //printf("GLCapabilityT.mapFrame \n" );
292 GLContext context = GLWidget.getGLContext(widget);
293 GLDrawable drawable = GLWidget.getGLDrawable(widget);
295 /*** OpenGL BEGIN ***/
296 if ( !drawable.glBegin(context) )
298 return false;
301 /*** do user actions ***/
302 bit consumeEvent = typeof(this).onMap();
304 /*** flush ***/
305 if ( drawable.isDoubleBuffered() )
307 drawable.swapBuffers();
309 else
311 glFlush ();
314 drawable.glEnd();
315 /*** OpenGL END ***/
317 //return consumeEvent;
320 void unmapFrame(Widget widget)
322 //printf("GLCapabilityT.unmapFrame \n" );
323 GLContext context = GLWidget.getGLContext(widget);
324 GLDrawable drawable = GLWidget.getGLDrawable(widget);
326 /*** OpenGL BEGIN ***/
327 if ( !drawable.glBegin(context) )
329 return false;
332 /*** do user actions ***/
333 bit consumeEvent = typeof(this).onUnmap();
335 /*** flush ***/
336 if ( drawable.isDoubleBuffered() )
338 drawable.swapBuffers();
340 else
342 glFlush ();
345 drawable.glEnd();
346 /*** OpenGL END ***/
348 //return consumeEvent;
351 int visibilityFrame(GdkEventVisibility* event, Widget widget)
353 //printf("GLCapabilityT.visibilityFrame \n" );
354 GLContext context = GLWidget.getGLContext(widget);
355 GLDrawable drawable = GLWidget.getGLDrawable(widget);
357 /*** OpenGL BEGIN ***/
358 if ( !drawable.glBegin(context) )
360 return false;
363 /*** do user actions ***/
364 bool consumeEvent = typeof(this).onVisibility(event);
366 /*** flush ***/
367 if ( drawable.isDoubleBuffered() )
369 drawable.swapBuffers();
371 else
373 glFlush ();
376 drawable.glEnd();
377 /*** OpenGL END ***/
379 return consumeEvent;
382 bit onMap()
384 //printf("GLCapabilityT.map \n" );
385 return true;
388 bit onUnmap()
390 //printf("GLCapabilityT.unmap \n" );
391 return true;
394 bool onVisibility(GdkEventVisibility* event)
396 //printf("GLCapabilityT.visibility \n" );
397 return true;