1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  * Port to the D Programming Language:
11  *     John Reimer <terminal.node@gmail.com>
12  *******************************************************************************/
13 module org.eclipse.swt.internal.opengl.glx.GLX;
14 
15 import java.lang.all;
16 
17 version(Tango){
18     import tango.stdc.stdint;
19 } else { // Phobos
20     import std.stdint;
21 }
22 
23 import org.eclipse.swt.internal.Library;
24 import org.eclipse.swt.internal.Platform;
25 import org.eclipse.swt.internal.c.X;
26 import org.eclipse.swt.internal.c.Xutil;
27 import org.eclipse.swt.internal.c.glx;
28 
29 public class GLX : Platform {
30 
31     /*
32     ** Visual Config Attributes (glXGetConfig, glXGetFBConfigAttrib)
33     */
34 
35     enum {
36         GLX_USE_GL              = 1,    /* support GLX rendering */
37         GLX_BUFFER_SIZE         = 2,    /* depth of the color buffer */
38         GLX_LEVEL               = 3,    /* level in plane stacking */
39         GLX_RGBA                = 4,    /* true if RGBA mode */
40         GLX_DOUBLEBUFFER        = 5,    /* double buffering supported */
41         GLX_STEREO              = 6,    /* stereo buffering supported */
42         GLX_AUX_BUFFERS         = 7,    /* number of aux buffers */
43         GLX_RED_SIZE            = 8,    /* number of red component bits */
44         GLX_GREEN_SIZE          = 9,    /* number of green component bits */
45         GLX_BLUE_SIZE           = 10,   /* number of blue component bits */
46         GLX_ALPHA_SIZE          = 11,   /* number of alpha component bits */
47         GLX_DEPTH_SIZE          = 12,   /* number of depth bits */
48         GLX_STENCIL_SIZE        = 13,   /* number of stencil bits */
49         GLX_ACCUM_RED_SIZE      = 14,   /* number of red accum bits */
50         GLX_ACCUM_GREEN_SIZE    = 15,   /* number of green accum bits */
51         GLX_ACCUM_BLUE_SIZE     = 16,   /* number of blue accum bits */
52         GLX_ACCUM_ALPHA_SIZE    = 17,   /* number of alpha accum bits */
53     /*
54     ** FBConfig-specific attributes
55     */
56         GLX_X_VISUAL_TYPE       = 0x22,
57         GLX_CONFIG_CAVEAT       = 0x20, /* Like visual_info VISUAL_CAVEAT_EXT */
58         GLX_TRANSPARENT_TYPE    = 0x23,
59         GLX_TRANSPARENT_INDEX_VALUE = 0x24,
60         GLX_TRANSPARENT_RED_VALUE   = 0x25,
61         GLX_TRANSPARENT_GREEN_VALUE = 0x26,
62         GLX_TRANSPARENT_BLUE_VALUE  = 0x27,
63         GLX_TRANSPARENT_ALPHA_VALUE = 0x28,
64         GLX_DRAWABLE_TYPE       = 0x8010,
65         GLX_RENDER_TYPE         = 0x8011,
66         GLX_X_RENDERABLE        = 0x8012,
67         GLX_FBCONFIG_ID         = 0x8013,
68         GLX_MAX_PBUFFER_WIDTH   = 0x8016,
69         GLX_MAX_PBUFFER_HEIGHT  = 0x8017,
70         GLX_MAX_PBUFFER_PIXELS  = 0x8018,
71         GLX_VISUAL_ID           = 0x800B,
72     
73     /*
74     ** Error return values from glXGetConfig.  Success is indicated by
75     ** a value of 0.
76     */
77         GLX_BAD_SCREEN      = 1,    /* screen # is bad */
78         GLX_BAD_ATTRIBUTE   = 2,    /* attribute to get is bad */
79         GLX_NO_EXTENSION    = 3,    /* no glx extension on server */
80         GLX_BAD_VISUAL      = 4,    /* visual # not known by GLX */
81         GLX_BAD_CONTEXT     = 5,    /* returned only by import_context EXT? */
82         GLX_BAD_VALUE       = 6,    /* returned only by glXSwapIntervalSGI? */
83         GLX_BAD_ENUM        = 7,    /* unused? */
84     
85     /* FBConfig attribute values */
86     
87     /*
88     ** Generic "don't care" value for glX ChooseFBConfig attributes (except
89     ** GLX_LEVEL)
90     */
91         GLX_DONT_CARE           = 0xFFFFFFFF,
92     
93     /* GLX_RENDER_TYPE bits */
94         GLX_RGBA_BIT            = 0x00000001,
95         GLX_COLOR_INDEX_BIT     = 0x00000002,
96     
97     /* GLX_DRAWABLE_TYPE bits */
98         GLX_WINDOW_BIT          = 0x00000001,
99         GLX_PIXMAP_BIT          = 0x00000002,
100         GLX_PBUFFER_BIT         = 0x00000004,
101     
102     /* GLX_CONFIG_CAVEAT attribute values */
103         GLX_NONE                = 0x8000,
104         GLX_SLOW_CONFIG         = 0x8001,
105         GLX_NON_CONFORMANT_CONFIG   = 0x800D,
106     
107     /* GLX_X_VISUAL_TYPE attribute values */
108         GLX_TRUE_COLOR          = 0x8002,
109         GLX_DIRECT_COLOR        = 0x8003,
110         GLX_PSEUDO_COLOR        = 0x8004,
111         GLX_STATIC_COLOR        = 0x8005,
112         GLX_GRAY_SCALE          = 0x8006,
113         GLX_STATIC_GRAY         = 0x8007,
114     
115     /* GLX_TRANSPARENT_TYPE attribute values */
116     /*     GLX_NONE            0x8000 */
117         GLX_TRANSPARENT_RGB     = 0x8008,
118         GLX_TRANSPARENT_INDEX   = 0x8009,
119     
120     /* glXCreateGLXPbuffer attributes */
121         GLX_PRESERVED_CONTENTS  = 0x801B,
122         GLX_LARGEST_PBUFFER     = 0x801C,
123         GLX_PBUFFER_HEIGHT      = 0x8040,   /* New for GLX 1.3 */
124         GLX_PBUFFER_WIDTH       = 0x8041,   /* New for GLX 1.3 */
125     
126     /* glXQueryGLXPBuffer attributes */
127         GLX_WIDTH       = 0x801D,
128         GLX_HEIGHT      = 0x801E,
129         GLX_EVENT_MASK  = 0x801F,
130     
131     /* glXCreateNewContext render_type attribute values */
132         GLX_RGBA_TYPE           = 0x8014,
133         GLX_COLOR_INDEX_TYPE    = 0x8015,
134     
135     /* glXQueryContext attributes */
136     /*     GLX_FBCONFIG_ID        0x8013 */
137     /*     GLX_RENDER_TYPE        0x8011 */
138         GLX_SCREEN          = 0x800C,
139     
140     /* glXSelectEvent event mask bits */
141         GLX_PBUFFER_CLOBBER_MASK    = 0x08000000,
142     
143     /* GLXPbufferClobberEvent event_type values */
144         GLX_DAMAGED         = 0x8020,
145         GLX_SAVED           = 0x8021,
146     
147     /* GLXPbufferClobberEvent draw_type values */
148         GLX_WINDOW          = 0x8022,
149         GLX_PBUFFER         = 0x8023,
150     
151     /* GLXPbufferClobberEvent buffer_mask bits */
152         GLX_FRONT_LEFT_BUFFER_BIT   = 0x00000001,
153         GLX_FRONT_RIGHT_BUFFER_BIT  = 0x00000002,
154         GLX_BACK_LEFT_BUFFER_BIT    = 0x00000004,
155         GLX_BACK_RIGHT_BUFFER_BIT   = 0x00000008,
156         GLX_AUX_BUFFERS_BIT     = 0x00000010,
157         GLX_DEPTH_BUFFER_BIT        = 0x00000020,
158         GLX_STENCIL_BUFFER_BIT      = 0x00000040,
159         GLX_ACCUM_BUFFER_BIT        = 0x00000080,
160     
161     /*
162     ** Extension return values from glXGetConfig.  These are also
163     ** accepted as parameter values for glXChooseVisual.
164     */
165     
166         GLX_X_VISUAL_TYPE_EXT = 0x22,   /* visual_info extension type */
167         GLX_TRANSPARENT_TYPE_EXT = 0x23,    /* visual_info extension */
168         GLX_TRANSPARENT_INDEX_VALUE_EXT = 0x24, /* visual_info extension */
169         GLX_TRANSPARENT_RED_VALUE_EXT   = 0x25, /* visual_info extension */
170         GLX_TRANSPARENT_GREEN_VALUE_EXT = 0x26, /* visual_info extension */
171         GLX_TRANSPARENT_BLUE_VALUE_EXT  = 0x27, /* visual_info extension */
172         GLX_TRANSPARENT_ALPHA_VALUE_EXT = 0x28, /* visual_info extension */
173     
174     /* Property values for visual_type */
175         GLX_TRUE_COLOR_EXT  = 0x8002,
176         GLX_DIRECT_COLOR_EXT    = 0x8003,
177         GLX_PSEUDO_COLOR_EXT    = 0x8004,
178         GLX_STATIC_COLOR_EXT    = 0x8005,
179         GLX_GRAY_SCALE_EXT  = 0x8006,
180         GLX_STATIC_GRAY_EXT = 0x8007,
181     
182     /* Property values for transparent pixel */
183         GLX_NONE_EXT        = 0x8000,
184         GLX_TRANSPARENT_RGB_EXT     = 0x8008,
185         GLX_TRANSPARENT_INDEX_EXT   = 0x8009,
186     
187     /* Property values for visual_rating */
188         GLX_VISUAL_CAVEAT_EXT       = 0x20,  /* visual_rating extension type */
189         GLX_SLOW_VISUAL_EXT     = 0x8001,
190         GLX_NON_CONFORMANT_VISUAL_EXT   = 0x800D,
191     
192     /*
193     ** Names for attributes to glXGetClientString.
194     */
195         GLX_VENDOR      = 0x1,
196         GLX_VERSION     = 0x2,
197         GLX_EXTENSIONS  = 0x3,
198     
199     /*
200     ** Names for attributes to glXQueryContextInfoEXT.
201     */
202         GLX_SHARE_CONTEXT_EXT = 0x800A, /* id of share context */
203         GLX_VISUAL_ID_EXT = 0x800B, /* id of context's visual */
204         GLX_SCREEN_EXT = 0x800C,    /* screen number */
205     
206     /*
207     * GLX 1.4 
208     */
209         GLX_SAMPLE_BUFFERS = 100000,
210         GLX_SAMPLES = 100001,
211 
212     /*
213     * GL bits 
214     */
215         GL_VIEWPORT = 0x0BA2
216     }
217 
218     static this() {
219         org.eclipse.swt.internal.c.glx.loadLib();
220     }
221     
222     static void glGetIntegerv( GLenum pname, GLint[] params ) 
223     {
224         lock.lock();
225         scope(exit) lock.unlock();
226         return dwt_glGetIntegerv (pname, params.ptr );
227     }
228 
229     static void glViewport( GLint x, GLint y, GLsizei width, GLsizei height ) 
230     {
231         lock.lock();
232         scope(exit) lock.unlock();
233         return dwt_glViewport( x, y, width, height );
234     }
235 
236     static XVisualInfo* glXChooseVisual( void* dpy, GLint screen, GLint* attribList ) 
237     {
238         lock.lock();
239         scope(exit) lock.unlock();
240         return dwt_glXChooseVisual( dpy, screen, attribList );
241     }
242 
243     static void glXCopyContext( void* dpy, void* src, void* dst, GLulong mask ) 
244     {
245         lock.lock();
246         scope(exit) lock.unlock();
247         dwt_glXCopyContext(dpy, src, dst, mask);
248     }
249 
250     static void* glXCreateContext( void* dpy, XVisualInfo* vis, void* shareList, Bool direct ) 
251     {
252         lock.lock();
253         scope(exit) lock.unlock();        
254         return dwt_glXCreateContext(dpy, vis, shareList, direct);
255     }
256 
257     final GLXPixmap glXCreateGLXPixmap( void* dpy, XVisualInfo* vis , Pixmap pixmap ) 
258     {
259         lock.lock();
260         scope(exit) lock.unlock();
261         return dwt_glXCreateGLXPixmap(dpy, vis, pixmap);
262     }
263 
264     static void glXDestroyContext( void* dpy, void* ctx ) 
265     {
266         lock.lock();
267         scope(exit) lock.unlock();
268         dwt_glXDestroyContext(dpy, ctx);
269     }
270 
271     static void glXDestroyGLXPixmap( void* dpy, GLXPixmap pix ) 
272     {
273         lock.lock();
274         scope(exit) lock.unlock();
275         dwt_glXDestroyGLXPixmap(dpy, pix);
276     }
277 
278     static char* glXGetClientString( void* dpy, GLint name ) 
279     {
280         lock.lock();
281         scope(exit) lock.unlock();
282         return dwt_glXGetClientString(dpy, name);
283     }
284 
285     static GLint glXGetConfig( void* dpy, XVisualInfo* vis, GLint attrib, GLint[] value ) 
286     {
287         lock.lock();
288         scope(exit) lock.unlock();
289         return dwt_glXGetConfig(dpy, vis, attrib, value.ptr);
290     }
291 
292     static void* glXGetCurrentContext() 
293     {
294         lock.lock();
295         scope(exit) lock.unlock();
296         return dwt_glXGetCurrentContext();
297     }
298 
299     static GLXDrawable glXGetCurrentDrawable() 
300     {
301         lock.lock();
302         scope(exit) lock.unlock();
303         return dwt_glXGetCurrentDrawable();
304     }
305 
306     static Bool glXIsDirect( void* dpy, void* ctx ) 
307     {
308         lock.lock();
309         scope(exit) lock.unlock();    
310         return dwt_glXIsDirect(dpy, ctx);
311     }
312 
313     static Bool glXMakeCurrent( void* dpy, GLXDrawable drawable, void* ctx) 
314     {
315         lock.lock();
316         scope(exit) lock.unlock();
317         return dwt_glXMakeCurrent(dpy, drawable, ctx);
318     }
319 
320     static Bool glXQueryExtension( void* dpy, GLint[] errorBase, GLint[] eventBase) 
321     {
322         lock.lock();
323         scope(exit) lock.unlock(); 
324         return dwt_glXQueryExtension(dpy, errorBase.ptr, eventBase.ptr);
325     }
326 
327     static char* glXQueryExtensionsString( void* dpy, GLint screen) 
328     {
329         lock.lock();
330         scope(exit) lock.unlock();
331         return dwt_glXQueryExtensionsString(dpy, screen);
332     }
333 
334     static char* glXQueryServerString( void* dpy, GLint screen, GLint name ) 
335     {
336         lock.lock();
337         scope(exit) lock.unlock();
338         return dwt_glXQueryServerString(dpy, screen, name);
339     }
340 
341     static Bool glXQueryVersion( void* dpy, GLint[] major, GLint[] minor ) 
342     {
343         lock.lock();
344         scope(exit) lock.unlock();
345         return dwt_glXQueryVersion(dpy, major.ptr, minor.ptr);
346     }
347 
348     static void glXSwapBuffers( void* dpy, GLXDrawable drawable ) 
349     {
350         lock.lock();
351         scope(exit) lock.unlock();
352         dwt_glXSwapBuffers(dpy, drawable);
353     }
354 
355     static void glXWaitGL() 
356     {
357         lock.lock();
358         scope(exit) lock.unlock();
359         dwt_glXWaitGL();
360     }
361 
362     static void glXWaitX() 
363     {
364         lock.lock();
365         scope(exit) lock.unlock();
366         dwt_glXWaitX();
367     }
368 }