annotate dwt/opengl/GLCanvas.d @ 259:c0d810de7093

Update SWT 3.4M7 to 3.4
author Frank Benoit <benoit@tionex.de>
date Sun, 29 Jun 2008 14:33:38 +0200
parents 384b3a0c9cd7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
174
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
1 /*******************************************************************************
259
c0d810de7093 Update SWT 3.4M7 to 3.4
Frank Benoit <benoit@tionex.de>
parents: 174
diff changeset
2 * Copyright (c) 2000, 2008 IBM Corporation and others.
174
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
7 *
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
8 * Contributors:
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
10 * Port to the D Programming Language:
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
11 * John Reimer <terminal.node@gmail.com>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
12 *******************************************************************************/
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
13
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
14 module dwt.opengl.GLCanvas;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
15
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
16 import dwt.DWT;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
17 import dwt.DWTException;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
18 import dwt.graphics.Rectangle;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
19
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
20 import dwt.internal.gtk.OS;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
21 import dwt.internal.c.glx;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
22 import dwt.internal.c.gdk : GdkWindowAttr, GdkDrawable;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
23 import dwt.internal.c.Xutil : XVisualInfo;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
24
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
25 import dwt.internal.opengl.glx.GLX;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
26
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
27 import dwt.widgets.Canvas;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
28 import dwt.widgets.Composite;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
29 import dwt.widgets.Event;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
30 import dwt.widgets.Listener;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
31
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
32 import dwt.opengl.GLData;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
33
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
34 /**
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
35 * GLCanvas is a widget capable of displaying OpenGL content.
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
36 *
259
c0d810de7093 Update SWT 3.4M7 to 3.4
Frank Benoit <benoit@tionex.de>
parents: 174
diff changeset
37 * @see GLData
c0d810de7093 Update SWT 3.4M7 to 3.4
Frank Benoit <benoit@tionex.de>
parents: 174
diff changeset
38 * @see <a href="http://www.eclipse.org/swt/snippets/#opengl">OpenGL snippets</a>
c0d810de7093 Update SWT 3.4M7 to 3.4
Frank Benoit <benoit@tionex.de>
parents: 174
diff changeset
39 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
c0d810de7093 Update SWT 3.4M7 to 3.4
Frank Benoit <benoit@tionex.de>
parents: 174
diff changeset
40 *
174
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
41 * @since 3.2
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
42 */
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
43
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
44 public class GLCanvas : Canvas {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
45 void* context;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
46 uint xWindow;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
47 GdkDrawable* glWindow;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
48 XVisualInfo vinfo;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
49 static const int MAX_ATTRIBUTES = 32;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
50
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
51 /**
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
52 * Create a GLCanvas widget using the attributes described in the GLData
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
53 * object provided.
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
54 *
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
55 * @param parent a composite widget
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
56 * @param style the bitwise OR'ing of widget styles
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
57 * @param data the requested attributes of the GLCanvas
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
58 *
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
59 * @exception IllegalArgumentException
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
60 * <ul><li>ERROR_NULL_ARGUMENT when the data is null
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
61 * <li>ERROR_UNSUPPORTED_DEPTH when the requested attributes cannot be provided</ul>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
62 * </ul>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
63 */
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
64 public this (Composite parent, int style, GLData data) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
65 super (parent, style);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
66 if (data is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
67 int[MAX_ATTRIBUTES] glxAttrib;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
68 int pos = 0;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
69 glxAttrib [pos++] = GLX.GLX_RGBA;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
70 if (data.doubleBuffer) glxAttrib [pos++] = GLX.GLX_DOUBLEBUFFER;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
71 if (data.stereo) glxAttrib [pos++] = GLX.GLX_STEREO;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
72 if (data.redSize > 0) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
73 glxAttrib [pos++] = GLX.GLX_RED_SIZE;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
74 glxAttrib [pos++] = data.redSize;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
75 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
76 if (data.greenSize > 0) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
77 glxAttrib [pos++] = GLX.GLX_GREEN_SIZE;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
78 glxAttrib [pos++] = data.greenSize;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
79 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
80 if (data.blueSize > 0) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
81 glxAttrib [pos++] = GLX.GLX_BLUE_SIZE;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
82 glxAttrib [pos++] = data.blueSize;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
83 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
84 if (data.alphaSize > 0) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
85 glxAttrib [pos++] = GLX.GLX_ALPHA_SIZE;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
86 glxAttrib [pos++] = data.alphaSize;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
87 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
88 if (data.depthSize > 0) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
89 glxAttrib [pos++] = GLX.GLX_DEPTH_SIZE;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
90 glxAttrib [pos++] = data.depthSize;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
91 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
92 if (data.stencilSize > 0) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
93 glxAttrib [pos++] = GLX.GLX_STENCIL_SIZE;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
94 glxAttrib [pos++] = data.stencilSize;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
95 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
96 if (data.accumRedSize > 0) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
97 glxAttrib [pos++] = GLX.GLX_ACCUM_RED_SIZE;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
98 glxAttrib [pos++] = data.accumRedSize;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
99 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
100 if (data.accumGreenSize > 0) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
101 glxAttrib [pos++] = GLX.GLX_ACCUM_GREEN_SIZE;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
102 glxAttrib [pos++] = data.accumGreenSize;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
103 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
104 if (data.accumBlueSize > 0) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
105 glxAttrib [pos++] = GLX.GLX_ACCUM_BLUE_SIZE;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
106 glxAttrib [pos++] = data.accumBlueSize;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
107 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
108 if (data.accumAlphaSize > 0) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
109 glxAttrib [pos++] = GLX.GLX_ACCUM_ALPHA_SIZE;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
110 glxAttrib [pos++] = data.accumAlphaSize;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
111 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
112 if (data.sampleBuffers > 0) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
113 glxAttrib [pos++] = GLX.GLX_SAMPLE_BUFFERS;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
114 glxAttrib [pos++] = data.sampleBuffers;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
115 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
116 if (data.samples > 0) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
117 glxAttrib [pos++] = GLX.GLX_SAMPLES;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
118 glxAttrib [pos++] = data.samples;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
119 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
120 glxAttrib [pos++] = 0;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
121 OS.gtk_widget_realize (handle);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
122 auto window = OS.GTK_WIDGET_WINDOW (handle);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
123 auto xDisplay = OS.gdk_x11_drawable_get_xdisplay (window);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
124 auto infoPtr = GLX.glXChooseVisual (xDisplay, OS.XDefaultScreen (xDisplay), glxAttrib.ptr);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
125 if (infoPtr is null) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
126 dispose ();
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
127 DWT.error (DWT.ERROR_UNSUPPORTED_DEPTH);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
128 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
129
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
130 vinfo = *infoPtr;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
131 //tango.stdc.string.memmove (vinfo, infoPtr, XVisualInfo.sizeof);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
132 OS.XFree (infoPtr);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
133 auto screen = OS.gdk_screen_get_default ();
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
134 auto gdkvisual = OS.gdk_x11_screen_lookup_visual (screen, vinfo.visualid);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
135 //FIXME- share lists
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
136 //context = GLX.glXCreateContext (xDisplay, info, share is null ? 0 : share.context, true);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
137 context = GLX.glXCreateContext (xDisplay, &vinfo, null, true);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
138 if (context is null)
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
139 DWT.error (DWT.ERROR_NO_HANDLES);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
140 GdkWindowAttr attrs;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
141 attrs.width = 1;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
142 attrs.height = 1;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
143 attrs.event_mask = OS.GDK_KEY_PRESS_MASK | OS.GDK_KEY_RELEASE_MASK |
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
144 OS.GDK_FOCUS_CHANGE_MASK | OS.GDK_POINTER_MOTION_MASK |
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
145 OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK |
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
146 OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK |
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
147 OS.GDK_EXPOSURE_MASK | OS.GDK_VISIBILITY_NOTIFY_MASK |
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
148 OS.GDK_POINTER_MOTION_HINT_MASK;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
149 attrs.window_type = OS.GDK_WINDOW_CHILD;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
150 attrs.visual = gdkvisual;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
151 glWindow = OS.gdk_window_new (window, &attrs, OS.GDK_WA_VISUAL);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
152 OS.gdk_window_set_user_data ( glWindow, cast(void*) handle);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
153 if ((style & DWT.NO_BACKGROUND) !is 0)
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
154 OS.gdk_window_set_back_pixmap (window, null, false);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
155 xWindow = OS.gdk_x11_drawable_get_xid ( glWindow );
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
156 OS.gdk_window_show (glWindow);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
157
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
158 Listener listener = new class() Listener {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
159 public void handleEvent (Event event) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
160 switch (event.type) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
161 case DWT.Paint:
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
162 /**
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
163 * Bug in MESA. MESA does some nasty sort of polling to try
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
164 * to ensure that their buffer sizes match the current X state.
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
165 * This state can be updated using glViewport().
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
166 * FIXME: There has to be a better way of doing this.
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
167 */
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
168 int[4] viewport;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
169 GLX.glGetIntegerv (GLX.GL_VIEWPORT, viewport);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
170 GLX.glViewport (viewport [0],viewport [1],viewport [2],viewport [3]);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
171 break;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
172 case DWT.Resize:
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
173 Rectangle clientArea = getClientArea();
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
174 OS.gdk_window_move (glWindow, clientArea.x, clientArea.y);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
175 OS.gdk_window_resize (glWindow, clientArea.width, clientArea.height);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
176 break;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
177 case DWT.Dispose:
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
178 auto window = OS.GTK_WIDGET_WINDOW (handle);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
179 auto xDisplay = OS.gdk_x11_drawable_get_xdisplay (window);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
180 if (context !is null) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
181 if (GLX.glXGetCurrentContext () is context) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
182 GLX.glXMakeCurrent (xDisplay, 0, null);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
183 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
184 GLX.glXDestroyContext (xDisplay, context);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
185 context = null;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
186 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
187 if (glWindow !is null) {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
188 OS.gdk_window_destroy (glWindow);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
189 glWindow = null;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
190 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
191 break;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
192 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
193 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
194 };
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
195 addListener (DWT.Resize, listener);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
196 addListener (DWT.Paint, listener);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
197 addListener (DWT.Dispose, listener);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
198 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
199
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
200 /**
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
201 * Returns a GLData object describing the created context.
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
202 *
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
203 * @return GLData description of the OpenGL context attributes
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
204 * @exception DWTException <ul>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
205 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
206 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
207 * </ul>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
208 */
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
209 public GLData getGLData () {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
210 checkWidget ();
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
211 auto window = OS.GTK_WIDGET_WINDOW (handle);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
212 auto xDisplay = OS.gdk_x11_drawable_get_xdisplay (window);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
213 GLData data = new GLData ();
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
214 int [1] value;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
215 GLX.glXGetConfig (xDisplay, &vinfo, GLX.GLX_DOUBLEBUFFER, value);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
216 data.doubleBuffer = value [0] !is 0;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
217 GLX.glXGetConfig (xDisplay, &vinfo, GLX.GLX_STEREO, value);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
218 data.stereo = value [0] !is 0;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
219 GLX.glXGetConfig (xDisplay, &vinfo, GLX.GLX_RED_SIZE, value);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
220 data.redSize = value [0];
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
221 GLX.glXGetConfig (xDisplay, &vinfo, GLX.GLX_GREEN_SIZE, value);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
222 data.greenSize = value [0];
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
223 GLX.glXGetConfig (xDisplay, &vinfo, GLX.GLX_BLUE_SIZE, value);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
224 data.blueSize = value [0];
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
225 GLX.glXGetConfig (xDisplay, &vinfo, GLX.GLX_ALPHA_SIZE, value);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
226 data.alphaSize = value [0];
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
227 GLX.glXGetConfig (xDisplay, &vinfo, GLX.GLX_DEPTH_SIZE, value);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
228 data.depthSize = value [0];
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
229 GLX.glXGetConfig (xDisplay, &vinfo, GLX.GLX_STENCIL_SIZE, value);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
230 data.stencilSize = value [0];
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
231 GLX.glXGetConfig (xDisplay, &vinfo, GLX.GLX_ACCUM_RED_SIZE, value);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
232 data.accumRedSize = value [0];
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
233 GLX.glXGetConfig (xDisplay, &vinfo, GLX.GLX_ACCUM_GREEN_SIZE, value);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
234 data.accumGreenSize = value [0];
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
235 GLX.glXGetConfig (xDisplay, &vinfo, GLX.GLX_ACCUM_BLUE_SIZE, value);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
236 data.accumBlueSize = value [0];
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
237 GLX.glXGetConfig (xDisplay, &vinfo, GLX.GLX_ACCUM_ALPHA_SIZE, value);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
238 data.accumAlphaSize = value [0];
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
239 GLX.glXGetConfig (xDisplay, &vinfo, GLX.GLX_SAMPLE_BUFFERS, value);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
240 data.sampleBuffers = value [0];
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
241 GLX.glXGetConfig (xDisplay, &vinfo, GLX.GLX_SAMPLES, value);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
242 data.samples = value [0];
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
243 return data;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
244 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
245
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
246 /**
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
247 * Returns a bool indicating whether the receiver's OpenGL context
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
248 * is the current context.
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
249 *
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
250 * @return true if the receiver holds the current OpenGL context,
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
251 * false otherwise
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
252 * @exception DWTException <ul>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
253 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
254 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
255 * </ul>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
256 */
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
257 public bool isCurrent () {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
258 checkWidget ();
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
259 return (GLX.glXGetCurrentContext () is context);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
260 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
261
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
262 /**
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
263 * Sets the OpenGL context associated with this GLCanvas to be the
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
264 * current GL context.
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
265 *
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
266 * @exception DWTException <ul>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
267 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
268 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
269 * </ul>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
270 */
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
271 public void setCurrent () {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
272 checkWidget ();
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
273 if (GLX.glXGetCurrentContext () is context) return;
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
274 auto window = OS.GTK_WIDGET_WINDOW (handle);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
275 auto xDisplay = OS.gdk_x11_drawable_get_xdisplay (window);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
276 GLX.glXMakeCurrent (xDisplay, xWindow, context);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
277 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
278
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
279 /**
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
280 * Swaps the front and back color buffers.
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
281 *
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
282 * @exception DWTException <ul>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
283 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
284 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
285 * </ul>
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
286 */
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
287 public void swapBuffers () {
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
288 checkWidget ();
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
289 auto window = OS.GTK_WIDGET_WINDOW (handle);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
290 auto xDisplay = OS.gdk_x11_drawable_get_xdisplay (window);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
291 GLX.glXSwapBuffers (xDisplay, xWindow);
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
292 }
384b3a0c9cd7 Add OpenGL/Derelict support to Linux DWT
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
293 }