I've no idea here...
[gtkD.git] / gtkD / srcgl / glgtk / GLCapability.d
blobac1a9801fb7f0c5753727bcd679195446c2e04c1
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 version(Tango) {
253 private import tango.core.Memory;
254 } else {
255 private import std.gc;
258 int configureFrame(GdkEventConfigure* event, Widget widget)
260 if ( event != null )
262 width = event.width;
263 height = event.height;
265 version(Tango)
267 GC.disable();
269 else
271 std.gc.disable();
274 //writefln("configureFrame 1");
275 //printf("GLCapabilityT.configureFrame \n" );
276 GLContext context = GLWidget.getGLContext(widget);
277 GLDrawable drawable = GLWidget.getGLDrawable(widget);
279 /*** OpenGL BEGIN ***/
280 if ( !drawable.glBegin(context) )
282 return false;
285 //writefln("configureFrame 2");
286 /*** do user actions ***/
287 int consumeEvent = typeof(this).resizeGL(event);
288 //printf("here\n");
289 //writefln("configureFrame 3");
291 /*** flush ***/
292 if ( drawable.isDoubleBuffered() )
294 //writefln("configureFrame 4");
295 drawable.swapBuffers();
296 //writefln("configureFrame 5");
298 else
300 //writefln("configureFrame 6");
301 glFlush ();
302 //writefln("configureFrame 7");
305 //writefln("configureFrame 8");
306 drawable.glEnd();
307 //writefln("configureFrame 9");
308 /*** OpenGL END ***/
309 version(Tango)
311 GC.enable();
313 else
315 std.gc.enable();
317 return consumeEvent;
320 void mapFrame(Widget widget)
322 //printf("GLCapabilityT.mapFrame \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 bool consumeEvent = typeof(this).onMap();
335 /*** flush ***/
336 if ( drawable.isDoubleBuffered() )
338 drawable.swapBuffers();
340 else
342 glFlush ();
345 drawable.glEnd();
346 /*** OpenGL END ***/
348 //return consumeEvent;
351 void unmapFrame(Widget widget)
353 //printf("GLCapabilityT.unmapFrame \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).onUnmap();
366 /*** flush ***/
367 if ( drawable.isDoubleBuffered() )
369 drawable.swapBuffers();
371 else
373 glFlush ();
376 drawable.glEnd();
377 /*** OpenGL END ***/
379 //return consumeEvent;
382 int visibilityFrame(GdkEventVisibility* event, Widget widget)
384 //printf("GLCapabilityT.visibilityFrame \n" );
385 GLContext context = GLWidget.getGLContext(widget);
386 GLDrawable drawable = GLWidget.getGLDrawable(widget);
388 /*** OpenGL BEGIN ***/
389 if ( !drawable.glBegin(context) )
391 return false;
394 /*** do user actions ***/
395 bool consumeEvent = typeof(this).onVisibility(event);
397 /*** flush ***/
398 if ( drawable.isDoubleBuffered() )
400 drawable.swapBuffers();
402 else
404 glFlush ();
407 drawable.glEnd();
408 /*** OpenGL END ***/
410 return consumeEvent;
413 bool onMap()
415 //printf("GLCapabilityT.map \n" );
416 return true;
419 bool onUnmap()
421 //printf("GLCapabilityT.unmap \n" );
422 return true;
425 bool onVisibility(GdkEventVisibility* event)
427 //printf("GLCapabilityT.visibility \n" );
428 return true;