1 module glx.glx;
2 
3 version(linux):
4 extern(C):
5 
6 private import x11.X;
7 private import x11.Xlib;
8 private import x11.Xutil;
9 private import opengl.gl2;
10 
11 private import glx.glxint;
12 
13 version = GLX_VERSION_1_1;
14 version = GLX_VERSION_1_2;
15 version = GLX_VERSION_1_3;
16 version = GLX_VERSION_1_4;
17 
18 immutable string GLX_EXTENSION_NAME = "GLX";
19 
20 /*
21  * Error codes returned by glXGetConfig:
22  */
23 enum
24 {
25 	GLX_USE_GL = 1,
26 	GLX_BUFFER_SIZE = 2,
27 	GLX_LEVEL = 3,
28 	GLX_RGBA = 4,
29 	GLX_DOUBLEBUFFER = 5,
30 	GLX_STEREO = 6,
31 	GLX_AUX_BUFFERS = 7,
32 	GLX_RED_SIZE = 8,
33 	GLX_GREEN_SIZE = 9,
34 	GLX_BLUE_SIZE = 10,
35 	GLX_ALPHA_SIZE = 11,
36 	GLX_DEPTH_SIZE = 12,
37 	GLX_STENCIL_SIZE = 13,
38 	GLX_ACCUM_RED_SIZE = 14,
39 	GLX_ACCUM_GREEN_SIZE = 15,
40 	GLX_ACCUM_BLUE_SIZE	= 16,
41 	GLX_ACCUM_ALPHA_SIZE = 17
42 }
43 
44 /*
45  * Error codes returned by glXGetConfig:
46  */
47 enum
48 {
49 	GLX_BAD_SCREEN = 1,
50 	GLX_BAD_ATTRIBUTE = 2,
51 	GLX_NO_EXTENSION = 3,
52 	GLX_BAD_VISUAL = 4,
53 	GLX_BAD_CONTEXT = 5,
54 	GLX_BAD_VALUE = 6,
55 	GLX_BAD_ENUM = 7
56 }
57 
58 /*
59  * GLX 1.1 and later:
60  */
61 enum
62 {
63 	GLX_VENDOR = 1,
64 	GLX_VERSION = 2,
65 	GLX_EXTENSIONS  = 3
66 }
67 
68 /*
69  * GLX 1.3 and later:
70  */
71 enum
72 {
73 	GLX_CONFIG_CAVEAT = 0x20,
74 	GLX_DONT_CARE = 0xFFFFFFFF,
75 	GLX_X_VISUAL_TYPE = 0x22,
76 	GLX_TRANSPARENT_TYPE = 0x23,
77 	GLX_TRANSPARENT_INDEX_VALUE = 0x24,
78 	GLX_TRANSPARENT_RED_VALUE = 0x25,
79 	GLX_TRANSPARENT_GREEN_VALUE = 0x26,
80 	GLX_TRANSPARENT_BLUE_VALUE = 0x27,
81 	GLX_TRANSPARENT_ALPHA_VALUE = 0x28,
82 	GLX_WINDOW_BIT = 0x00000001,
83 	GLX_PIXMAP_BIT = 0x00000002,
84 	GLX_PBUFFER_BIT = 0x00000004,
85 	GLX_AUX_BUFFERS_BIT	= 0x00000010,
86 	GLX_FRONT_LEFT_BUFFER_BIT = 0x00000001,
87 	GLX_FRONT_RIGHT_BUFFER_BIT = 0x00000002,
88 	GLX_BACK_LEFT_BUFFER_BIT = 0x00000004,
89 	GLX_BACK_RIGHT_BUFFER_BIT = 0x00000008,
90 	GLX_DEPTH_BUFFER_BIT = 0x00000020,
91 	GLX_STENCIL_BUFFER_BIT = 0x00000040,
92 	GLX_ACCUM_BUFFER_BIT = 0x00000080,
93 	GLX_NONE = 0x8000,
94 	GLX_SLOW_CONFIG = 0x8001,
95 	GLX_TRUE_COLOR = 0x8002,
96 	GLX_DIRECT_COLOR = 0x8003,
97 	GLX_PSEUDO_COLOR = 0x8004,
98 	GLX_STATIC_COLOR = 0x8005,
99 	GLX_GRAY_SCALE = 0x8006,
100 	GLX_STATIC_GRAY = 0x8007,
101 	GLX_TRANSPARENT_RGB	= 0x8008,
102 	GLX_TRANSPARENT_INDEX = 0x8009,
103 	GLX_VISUAL_ID = 0x800B,
104 	GLX_SCREEN = 0x800C,
105 	GLX_NON_CONFORMANT_CONFIG = 0x800D,
106 	GLX_DRAWABLE_TYPE = 0x8010,
107 	GLX_RENDER_TYPE = 0x8011,
108 	GLX_X_RENDERABLE = 0x8012,
109 	GLX_FBCONFIG_ID = 0x8013,
110 	GLX_RGBA_TYPE = 0x8014,
111 	GLX_COLOR_INDEX_TYPE = 0x8015,
112 	GLX_MAX_PBUFFER_WIDTH = 0x8016,
113 	GLX_MAX_PBUFFER_HEIGHT = 0x8017,
114 	GLX_MAX_PBUFFER_PIXELS = 0x8018,
115 	GLX_PRESERVED_CONTENTS = 0x801B,
116 	GLX_LARGEST_PBUFFER = 0x801C,
117 	GLX_WIDTH = 0x801D,
118 	GLX_HEIGHT = 0x801E,
119 	GLX_EVENT_MASK = 0x801F,
120 	GLX_DAMAGED = 0x8020,
121 	GLX_SAVED = 0x8021,
122 	GLX_WINDOW = 0x8022,
123 	GLX_PBUFFER = 0x8023,
124 	GLX_PBUFFER_HEIGHT = 0x8040,
125 	GLX_PBUFFER_WIDTH = 0x8041,
126 	GLX_RGBA_BIT = 0x00000001,
127 	GLX_COLOR_INDEX_BIT = 0x00000002,
128 	GLX_PBUFFER_CLOBBER_MASK = 0x08000000,
129 }
130 
131 /*
132  * GLX 1.4 and later:
133  */
134 enum
135 {
136 	GLX_SAMPLE_BUFFERS = 0x186a0, /*100000*/
137 	GLX_SAMPLES = 0x186a1 /*100001*/
138 }
139 
140 // It's supposed to be an alias to __GLXcontextRec*, but I have no clue where the hell it is
141 // Running grep over my include folder didn't do much so I temporarily made it alias void*
142 // If somebody knows a solution to this please let me now or fix this
143 alias GLXContext = void*;
144 alias GLXPixmap = XID;
145 alias GLXDrawable = XID;
146 /* GLX 1.3 and later */
147 alias GLXFBConfig = __GLXFBConfigRec*;
148 alias GLXFBConfigID = XID;
149 alias GLXContextID = XID;
150 alias GLXWindow = XID;
151 alias GLXPbuffer = XID;
152 
153 /*
154 ** Events.
155 ** __GLX_NUMBER_EVENTS is set to 17 to account for the BufferClobberSGIX
156 **  event - this helps initialization if the server supports the pbuffer
157 **  extension and the client doesn't.
158 */
159 immutable GLX_PbufferClobber = 0;
160 immutable GLX_BufferSwapComplete = 1;
161 
162 immutable __GLX_NUMBER_EVENTS = 17;
163 
164 extern XVisualInfo* glXChooseVisual( Display *dpy, int screen,
165 				     int *attribList );
166 
167 extern GLXContext glXCreateContext( Display *dpy, XVisualInfo *vis,
168 				    GLXContext shareList, bool direct );
169 
170 extern void glXDestroyContext( Display *dpy, GLXContext ctx );
171 
172 extern bool glXMakeCurrent( Display *dpy, GLXDrawable drawable,
173 			    GLXContext ctx);
174 
175 extern void glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
176 			    ulong mask );
177 
178 extern void glXSwapBuffers( Display *dpy, GLXDrawable drawable );
179 
180 extern GLXPixmap glXCreateGLXPixmap( Display *dpy, XVisualInfo *visual,
181 				     Pixmap pixmap );
182 
183 extern void glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap );
184 
185 extern bool glXQueryExtension( Display *dpy, int *errorb, int *event );
186 
187 extern bool glXQueryVersion( Display *dpy, int *maj, int *min );
188 
189 extern bool glXIsDirect( Display *dpy, GLXContext ctx );
190 
191 extern int glXGetConfig( Display *dpy, XVisualInfo *visual,
192 			 int attrib, int *value );
193 
194 extern GLXContext glXGetCurrentContext();
195 
196 extern GLXDrawable glXGetCurrentDrawable();
197 
198 extern void glXWaitGL();
199 
200 extern void glXWaitX();
201 
202 extern void glXUseXFont( Font font, int first, int count, int list );
203 
204 /* GLX 1.1 and later */
205 extern const(char*) glXQueryExtensionsString( Display *dpy, int screen );
206 
207 extern const(char*) glXQueryServerString( Display *dpy, int screen, int name );
208 
209 extern const(char*) glXGetClientString( Display *dpy, int name );
210 
211 
212 /* GLX 1.2 and later */
213 extern Display *glXGetCurrentDisplay();
214 
215 
216 /* GLX 1.3 and later */
217 extern GLXFBConfig *glXChooseFBConfig( Display *dpy, int screen,
218                                        const int *attribList, int *nitems );
219 
220 extern int glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
221                                  int attribute, int *value );
222 
223 extern GLXFBConfig *glXGetFBConfigs( Display *dpy, int screen,
224                                      int *nelements );
225 
226 extern XVisualInfo *glXGetVisualFromFBConfig( Display *dpy,
227                                               GLXFBConfig config );
228 
229 extern GLXWindow glXCreateWindow( Display *dpy, GLXFBConfig config,
230                                   Window win, const int *attribList );
231 
232 extern void glXDestroyWindow( Display *dpy, GLXWindow window );
233 
234 extern GLXPixmap glXCreatePixmap( Display *dpy, GLXFBConfig config,
235                                   Pixmap pixmap, const int *attribList );
236 
237 extern void glXDestroyPixmap( Display *dpy, GLXPixmap pixmap );
238 
239 extern GLXPbuffer glXCreatePbuffer( Display *dpy, GLXFBConfig config,
240                                     const int *attribList );
241 
242 extern void glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf );
243 
244 extern void glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
245                               uint *value );
246 
247 extern GLXContext glXCreateNewContext( Display *dpy, GLXFBConfig config,
248                                        int renderType, GLXContext shareList,
249                                        Bool direct );
250 
251 extern Bool glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
252                                    GLXDrawable read, GLXContext ctx );
253 
254 extern GLXDrawable glXGetCurrentReadDrawable();
255 
256 extern int glXQueryContext( Display *dpy, GLXContext ctx, int attribute,
257                             int *value );
258 
259 extern void glXSelectEvent( Display *dpy, GLXDrawable drawable,
260                             ulong mask );
261 
262 extern void glXGetSelectedEvent( Display *dpy, GLXDrawable drawable,
263                                  ulong *mask );
264 
265 /* GLX 1.3 function pointer typedefs */
266 alias PFNGLXGETFBCONFIGSPROC = GLXFBConfig* function(Display *dpy, int screen, int *nelements);
267 alias PFNGLXCHOOSEFBCONFIGPROC = GLXFBConfig* function(Display *dpy, int screen, const int *attrib_list, int *nelements);
268 alias PFNGLXGETFBCONFIGATTRIBPROC = int function(Display *dpy, GLXFBConfig config, int attribute, int *value);
269 alias PFNGLXGETVISUALFROMFBCONFIGPROC = XVisualInfo* function(Display *dpy, GLXFBConfig config);
270 alias PFNGLXCREATEWINDOWPROC = GLXWindow function(Display *dpy, GLXFBConfig config, Window win, const int *attrib_list);
271 alias PFNGLXDESTROYWINDOWPROC = void function(Display *dpy, GLXWindow win);
272 alias PFNGLXCREATEPIXMAPPROC = GLXPixmap function(Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list);
273 alias PFNGLXDESTROYPIXMAPPROC = void function(Display *dpy, GLXPixmap pixmap);
274 alias PFNGLXCREATEPBUFFERPROC = GLXPbuffer function(Display *dpy, GLXFBConfig config, const int *attrib_list);
275 alias PFNGLXDESTROYPBUFFERPROC = void function(Display *dpy, GLXPbuffer pbuf);
276 alias PFNGLXQUERYDRAWABLEPROC = void function(Display *dpy, GLXDrawable draw, int attribute, uint *value);
277 alias PFNGLXCREATENEWCONTEXTPROC = GLXContext function(Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct);
278 alias PFNGLXMAKECONTEXTCURRENTPROC = bool function(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx);
279 alias PFNGLXGETCURRENTREADDRAWABLEPROC = GLXDrawable function();
280 alias PFNGLXGETCURRENTDISPLAYPROC = Display* function();
281 alias PFNGLXQUERYCONTEXTPROC = int function(Display *dpy, GLXContext ctx, int attribute, int *value);
282 alias PFNGLXSELECTEVENTPROC = void function(Display *dpy, GLXDrawable draw, ulong event_mask);
283 alias PFNGLXGETSELECTEDEVENTPROC = void function(Display *dpy, GLXDrawable draw, ulong *event_mask);
284 
285 /*
286  * ARB 2. GLX_ARB_get_proc_address
287  */
288 version = GLX_ARB_get_proc_address;
289 
290 alias __GLXextFuncPtr = void function();
291 extern __GLXextFuncPtr glXGetProcAddressARB (const GLubyte *);
292 
293 
294 /* GLX 1.4 and later */
295 extern void function() glXGetProcAddress(const GLubyte *procname);
296 
297 void function() glXGetProcAddressS(const string procName)
298 {
299 	return glXGetProcAddress((cast(ubyte[])procName).ptr);
300 }
301 
302 /* GLX 1.4 function pointer typedefs */
303 alias PFNGLXGETPROCADDRESSPROC = __GLXextFuncPtr function(const GLubyte *procName);
304 
305 
306 /**
307  ** The following aren't in glxext.h yet.
308  **/
309 
310 
311 /*
312  * ???. GLX_NV_vertex_array_range
313  */
314 version = GLX_NV_vertex_array_range;
315 
316 extern void *glXAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
317 extern void glXFreeMemoryNV(GLvoid *pointer);
318 alias PFNGLXALLOCATEMEMORYNVPROC = void* function(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
319 alias PFNGLXFREEMEMORYNVPROC = void function(GLvoid *pointer);
320 
321 
322 /*
323  * ARB ?. GLX_ARB_render_texture
324  * XXX This was never finalized!
325  */
326 version = GLX_ARB_render_texture;
327 
328 extern bool glXBindTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer);
329 extern bool glXReleaseTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer);
330 extern bool glXDrawableAttribARB(Display *dpy, GLXDrawable draw, const int *attribList);
331 
332 
333 /*
334  * #?. GLX_MESA_swap_frame_usage
335  */
336 version = GLX_MESA_swap_frame_usage;
337 
338 extern int glXGetFrameUsageMESA(Display *dpy, GLXDrawable drawable, float *usage);
339 extern int glXBeginFrameTrackingMESA(Display *dpy, GLXDrawable drawable);
340 extern int glXEndFrameTrackingMESA(Display *dpy, GLXDrawable drawable);
341 extern int glXQueryFrameTrackingMESA(Display *dpy, GLXDrawable drawable, long *swapCount, long *missedFrames, float *lastMissedUsage);
342 
343 alias PFNGLXGETFRAMEUSAGEMESAPROC = int function(Display *dpy, GLXDrawable drawable, float *usage);
344 alias PFNGLXBEGINFRAMETRACKINGMESAPROC = int function(Display *dpy, GLXDrawable drawable);
345 alias PFNGLXENDFRAMETRACKINGMESAPROC = int function(Display *dpy, GLXDrawable drawable);
346 alias PFNGLXQUERYFRAMETRACKINGMESAPROC = int function(Display *dpy, GLXDrawable drawable, long *swapCount, long *missedFrames, float *lastMissedUsage);
347 
348 
349 /*
350  * #?. GLX_MESA_swap_control
351  */
352 version = GLX_MESA_swap_control;
353 
354 extern int glXSwapIntervalMESA(uint interval);
355 extern int glXGetSwapIntervalMESA();
356 
357 alias PFNGLXSWAPINTERVALMESAPROC = int function(uint interval);
358 alias PFNGLXGETSWAPINTERVALMESAPROC = int function();
359 
360 
361 /*** Should these go here, or in another header? */
362 /*
363 ** GLX Events
364 */
365 struct GLXPbufferClobberEvent
366 {
367     int event_type;		/* GLX_DAMAGED or GLX_SAVED */
368     int draw_type;		/* GLX_WINDOW or GLX_PBUFFER */
369     ulong serial;	/* # of last request processed by server */
370     bool send_event;		/* true if this came for SendEvent request */
371     Display *display;		/* display the event was read from */
372     GLXDrawable drawable;	/* XID of Drawable */
373     uint buffer_mask;	/* mask indicating which buffers are affected */
374     uint aux_buffer;	/* which aux buffer was affected */
375     int x, y;
376     int width, height;
377     int count;			/* if nonzero, at least this many more */
378 }
379 
380 struct GLXBufferSwapComplete
381 {
382     int type;
383     ulong serial;	/* # of last request processed by server */
384     bool send_event;		/* true if this came from a SendEvent request */
385     Display *display;		/* Display the event was read from */
386     Drawable drawable;	/* drawable on which event was requested in event mask */
387     int event_type;
388     long ust;
389     long msc;
390     long sbc;
391 }
392 
393 union __GLXEvent
394 {
395     GLXPbufferClobberEvent glxpbufferclobber;
396     GLXBufferSwapComplete glxbufferswapcomplete;
397     long[24] pad;
398 }
399 
400 alias GLXEvent = __GLXEvent;