added GLX 1.3 functions
[mesa.git] / src / mesa / drivers / x11 / glxapi.c
1 /* $Id: glxapi.c,v 1.6 1999/11/23 19:54:27 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.1
6 *
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28
29
30
31 /*
32 * GLX API functions which either call fake or real GLX implementations
33 *
34 * To enable real GLX encoding the REALGLX preprocessor symbol should be
35 * defined on the command line.
36 */
37
38
39
40 #ifdef HAVE_CONFIG_H
41 #include "conf.h"
42 #endif
43
44 #include <X11/Xlib.h>
45 #include <X11/Xutil.h>
46 #include "GL/glx.h"
47 #include "fakeglx.h"
48 #include "realglx.h"
49
50
51 #ifdef REALGLX
52 static Display *CurrentDisplay = NULL;
53 #endif
54
55
56 /*
57 * This functions determines whether a call to a glX*() function should
58 * be routed to the "fake" (Mesa) or "real" (GLX-encoder) functions.
59 * Input: dpy - the X display.
60 * Return: GL_TRUE if the given display supports the real GLX extension,
61 * GL_FALSE otherwise.
62 */
63 static GLboolean display_has_glx( Display *dpy )
64 {
65 /* TODO: we should use a lookup table to avoid calling XQueryExtension
66 * every time.
67 */
68 int ignore;
69 if (XQueryExtension( dpy, "GLX", &ignore, &ignore, &ignore )) {
70 return GL_TRUE;
71 }
72 else {
73 return GL_FALSE;
74 }
75 }
76
77
78
79 XVisualInfo *glXChooseVisual( Display *dpy, int screen, int *list )
80 {
81 #ifdef REALGLX
82 if (display_has_glx(dpy))
83 return Real_glXChooseVisual( dpy, screen, list );
84 else
85 #endif
86 return Fake_glXChooseVisual( dpy, screen, list );
87 }
88
89
90
91 int glXGetConfig( Display *dpy, XVisualInfo *visinfo, int attrib, int *value )
92 {
93 #ifdef REALGLX
94 if (display_has_glx(dpy))
95 return Real_glXGetConfig( dpy, visinfo, attrib, value );
96 else
97 #endif
98 return Fake_glXGetConfig( dpy, visinfo, attrib, value );
99 }
100
101
102
103 GLXContext glXCreateContext( Display *dpy, XVisualInfo *visinfo,
104 GLXContext shareList, Bool direct )
105 {
106 #ifdef REALGLX
107 if (display_has_glx(dpy))
108 return Real_glXCreateContext( dpy, visinfo, shareList, direct );
109 else
110 #endif
111 return Fake_glXCreateContext( dpy, visinfo, shareList, direct );
112 }
113
114
115
116 void glXDestroyContext( Display *dpy, GLXContext ctx )
117 {
118 #ifdef REALGLX
119 if (display_has_glx(dpy))
120 Real_glXDestroyContext( dpy, ctx );
121 else
122 #endif
123 Fake_glXDestroyContext( dpy, ctx );
124 }
125
126
127
128 void glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
129 GLuint mask )
130 {
131 #ifdef REALGLX
132 if (display_has_glx(dpy))
133 Real_glXCopyContext( dpy, src, dst, mask );
134 else
135 #endif
136 Fake_glXCopyContext( dpy, src, dst, mask );
137 }
138
139
140
141 Bool glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
142 {
143 #ifdef REALGLX
144 if (display_has_glx(dpy)) {
145 if (Real_glXMakeCurrent( dpy, drawable, ctx )) {
146 CurrentDisplay = dpy;
147 return True;
148 }
149 else {
150 return False;
151 }
152 }
153 else {
154 if (Fake_glXMakeCurrent( dpy, drawable, ctx )) {
155 CurrentDisplay = dpy;
156 return True;
157 }
158 else {
159 return False;
160 }
161 }
162 #else
163 return Fake_glXMakeCurrent( dpy, drawable, ctx );
164 #endif
165 }
166
167
168
169 GLXContext glXGetCurrentContext( void )
170 {
171 #ifdef REALGLX
172 if (display_has_glx(CurrentDisplay))
173 return Real_glXGetCurrentContext();
174 else
175 #endif
176 return Fake_glXGetCurrentContext();
177 }
178
179
180
181 GLXDrawable glXGetCurrentDrawable( void )
182 {
183 #ifdef REALGLX
184 if (display_has_glx(CurrentDisplay))
185 return Real_glXGetCurrentDrawable();
186 else
187 #endif
188 return Fake_glXGetCurrentDrawable();
189 }
190
191
192
193 GLXPixmap glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo,
194 Pixmap pixmap )
195 {
196 #ifdef REALGLX
197 if (display_has_glx(dpy))
198 return Real_glXCreateGLXPixmap( dpy, visinfo, pixmap );
199 else
200 #endif
201 return Fake_glXCreateGLXPixmap( dpy, visinfo, pixmap );
202 }
203
204
205 void glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
206 {
207 #ifdef REALGLX
208 if (display_has_glx(dpy))
209 Real_glXDestroyGLXPixmap( dpy, pixmap );
210 else
211 #endif
212 Fake_glXDestroyGLXPixmap( dpy, pixmap );
213 }
214
215
216
217 Bool glXQueryExtension( Display *dpy, int *errorb, int *event )
218 {
219 #ifdef REALGLX
220 if (display_has_glx(dpy))
221 return Real_glXQueryExtension( dpy, errorb, event );
222 else
223 #endif
224 return Fake_glXQueryExtension( dpy, errorb, event );
225 }
226
227
228
229 Bool glXIsDirect( Display *dpy, GLXContext ctx )
230 {
231 #ifdef REALGLX
232 if (display_has_glx(dpy))
233 return Real_glXIsDirect( dpy, ctx );
234 else
235 #endif
236 return Fake_glXIsDirect( dpy, ctx );
237 }
238
239
240
241 void glXSwapBuffers( Display *dpy, GLXDrawable drawable )
242 {
243 #ifdef REALGLX
244 if (display_has_glx(dpy))
245 Real_glXSwapBuffers( dpy, drawable );
246 else
247 #endif
248 Fake_glXSwapBuffers( dpy, drawable );
249 }
250
251
252
253 void glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable,
254 int x, int y, int width, int height )
255 {
256 #ifdef REALGLX
257 /* can't implement! */
258 return;
259 #endif
260 Fake_glXCopySubBufferMESA( dpy, drawable, x, y, width, height );
261 }
262
263
264
265 Bool glXQueryVersion( Display *dpy, int *maj, int *min )
266 {
267 #ifdef REALGLX
268 if (display_has_glx(dpy))
269 return Real_glXQueryVersion( dpy, maj, min );
270 else
271 #endif
272 return Fake_glXQueryVersion( dpy, maj, min );
273 }
274
275
276
277 void glXUseXFont( Font font, int first, int count, int listBase )
278 {
279 #ifdef REALGLX
280 if (display_has_glx(CurrentDisplay))
281 Real_glXUseXFont( font, first, count, listBase );
282 else
283 #endif
284 Fake_glXUseXFont( font, first, count, listBase );
285 }
286
287
288 void glXWaitGL( void )
289 {
290 #ifdef REALGLX
291 if (display_has_glx(CurrentDisplay))
292 Real_glXWaitGL();
293 else
294 #endif
295 Fake_glXWaitGL();
296 }
297
298
299
300 void glXWaitX( void )
301 {
302 #ifdef REALGLX
303 if (display_has_glx(CurrentDisplay))
304 Real_glXWaitX();
305 else
306 #endif
307 Fake_glXWaitX();
308 }
309
310
311
312 /* GLX 1.1 and later */
313 const char *glXQueryExtensionsString( Display *dpy, int screen )
314 {
315 #ifdef REALGLX
316 if (display_has_glx(dpy))
317 return Real_glXQueryExtensionsString( dpy, screen );
318 else
319 #endif
320 return Fake_glXQueryExtensionsString( dpy, screen );
321 }
322
323
324
325 /* GLX 1.1 and later */
326 const char *glXQueryServerString( Display *dpy, int screen, int name )
327 {
328 #ifdef REALGLX
329 if (display_has_glx(dpy))
330 return Real_glXQueryServerString( dpy, screen, name );
331 else
332 #endif
333 return Fake_glXQueryServerString( dpy, screen, name );
334 }
335
336
337
338 /* GLX 1.1 and later */
339 const char *glXGetClientString( Display *dpy, int name )
340 {
341 #ifdef REALGLX
342 if (display_has_glx(dpy))
343 return Real_glXGetClientString( dpy, name );
344 else
345 #endif
346 return Fake_glXGetClientString( dpy, name );
347 }
348
349
350
351 /* GLX 1.2 and later */
352 Display *glXGetCurrentDisplay( void )
353 {
354 #ifdef REALGLX
355 if (display_has_glx(dpy))
356 return Real_glXGetCurrentDisplay();
357 else
358 #endif
359 return Fake_glXGetCurrentDisplay();
360 }
361
362
363
364 /*
365 * GLX 1.3 and later
366 * XXX these are just no-op stubs for now.
367 */
368 GLXFBConfig glXChooseFBConfig( Display *dpy, int screen,
369 const int *attribList, int *nitems )
370 {
371 (void) dpy;
372 (void) screen;
373 (void) attribList;
374 (void) nitems;
375 return 0;
376 }
377
378
379 int glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
380 int attribute, int *value )
381 {
382 (void) dpy;
383 (void) config;
384 (void) attribute;
385 (void) value;
386 return 0;
387 }
388
389
390 XVisualInfo *glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
391 {
392 (void) dpy;
393 (void) config;
394 return 0;
395 }
396
397
398 GLXWindow glXCreateWindow( Display *dpy, GLXFBConfig config, Window win,
399 const int *attribList )
400 {
401 (void) dpy;
402 (void) config;
403 (void) win;
404 (void) attribList;
405 return 0;
406 }
407
408
409 void glXDestroyWindow( Display *dpy, GLXWindow window )
410 {
411 (void) dpy;
412 (void) window;
413 return;
414 }
415
416
417 GLXPixmap glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap,
418 const int *attribList )
419 {
420 (void) dpy;
421 (void) config;
422 (void) pixmap;
423 (void) attribList;
424 return 0;
425 }
426
427
428 void glXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
429 {
430 (void) dpy;
431 (void) pixmap;
432 return;
433 }
434
435
436 GLXPbuffer glXCreatePbuffer( Display *dpy, GLXFBConfig config,
437 const int *attribList )
438 {
439 (void) dpy;
440 (void) config;
441 (void) attribList;
442 return 0;
443 }
444
445
446 void glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
447 {
448 (void) dpy;
449 (void) pbuf;
450 }
451
452
453 void glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
454 unsigned int *value )
455 {
456 (void) dpy;
457 (void) draw;
458 (void) attribute;
459 (void) value;
460 }
461
462
463 GLXContext glXCreateNewContext( Display *dpy, GLXFBConfig config,
464 int renderType, GLXContext shareList,
465 Bool direct )
466 {
467 (void) dpy;
468 (void) config;
469 (void) renderType;
470 (void) shareList;
471 (void) direct;
472 return 0;
473 }
474
475
476 Bool glXMakeContextCurrent( Display *dpy, GLXDrawable draw, GLXDrawable read,
477 GLXContext ctx )
478 {
479 (void) dpy;
480 (void) draw;
481 (void) read;
482 (void) ctx;
483 return 0;
484 }
485
486
487 GLXDrawable glXGetCurrentReadDrawable( void )
488 {
489 return 0;
490 }
491
492
493 int glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
494 {
495 (void) dpy;
496 (void) ctx;
497 (void) attribute;
498 (void) value;
499 return 0;
500 }
501
502
503 void glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask )
504 {
505 (void) dpy;
506 (void) drawable;
507 (void) mask;
508 }
509
510
511 void glXGetSelectedEvent( Display *dpy, GLXDrawable drawable,
512 unsigned long *mask )
513 {
514 (void) dpy;
515 (void) drawable;
516 (void) mask;
517 }
518
519
520
521
522 #ifdef GLX_MESA_release_buffers
523 Bool glXReleaseBuffersMESA( Display *dpy, Window w )
524 {
525 #ifdef REALGLX
526 if (display_has_glx(dpy))
527 return GL_FALSE;
528 else
529 #endif
530 return Fake_glXReleaseBuffersMESA( dpy, w );
531 }
532 #endif
533
534
535 #ifdef GLX_MESA_pixmap_colormap
536 GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
537 Pixmap pixmap, Colormap cmap )
538 {
539 #ifdef REALGLX
540 if (display_has_glx(dpy))
541 return 0;
542 else
543 #endif
544 return Fake_glXCreateGLXPixmapMESA( dpy, visinfo, pixmap, cmap );
545 }
546 #endif
547
548
549
550 #ifdef GLX_SGI_video_sync
551
552 /*
553 * This function doesn't really do anything. But, at least one
554 * application uses the function so this stub is useful.
555 */
556 int glXGetVideoSyncSGI(unsigned int *count)
557 {
558 static unsigned int counter = 0;
559 *count = counter++;
560 return 0;
561 }
562
563
564 /*
565 * Again, this is really just a stub function.
566 */
567 int glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
568 {
569 static unsigned int counter = 0;
570 while (counter % divisor != remainder)
571 counter++;
572 *count = counter;
573 return 0;
574 }
575
576 #endif
577
578
579
580 #ifdef GLX_MESA_set_3dfx_mode
581 GLboolean glXSet3DfxModeMESA( GLint mode )
582 {
583 #ifdef REALGLX
584 return GL_FALSE;
585 #else
586 return Fake_glXSet3DfxModeMESA( mode );
587 #endif
588 }
589 #endif
590
591
592
593 #if 0 /* spec for this not finalized yet */
594 void (*glXGetProcAddressEXT( const GLubyte *procName ))()
595 {
596 #ifdef REALGLX
597 return NULL;
598 #else
599 return Fake_glXGetProcAddress( procName );
600 #endif
601 }
602 #endif