added GLX_MESA_set_3dfx_mode. clean-up of glXGetProcAddress
[mesa.git] / src / mesa / drivers / x11 / glxapi.c
1 /* $Id: glxapi.c,v 1.3 1999/09/16 15:54:21 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 #ifdef GLX_MESA_release_buffers
352 Bool glXReleaseBuffersMESA( Display *dpy, Window w )
353 {
354 #ifdef REALGLX
355 if (display_has_glx(dpy))
356 return GL_FALSE;
357 else
358 #endif
359 return Fake_glXReleaseBuffersMESA( dpy, w );
360 }
361 #endif
362
363
364 #ifdef GLX_MESA_pixmap_colormap
365 GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
366 Pixmap pixmap, Colormap cmap )
367 {
368 #ifdef REALGLX
369 if (display_has_glx(dpy))
370 return 0;
371 else
372 #endif
373 return Fake_glXCreateGLXPixmapMESA( dpy, visinfo, pixmap, cmap );
374 }
375 #endif
376
377
378
379 #ifdef GLX_SGI_video_sync
380
381 /*
382 * This function doesn't really do anything. But, at least one
383 * application uses the function so this stub is useful.
384 */
385 int glXGetVideoSyncSGI(unsigned int *count)
386 {
387 static unsigned int counter = 0;
388 *count = counter++;
389 return 0;
390 }
391
392
393 /*
394 * Again, this is really just a stub function.
395 */
396 int glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
397 {
398 static unsigned int counter = 0;
399 while (counter % divisor != remainder)
400 counter++;
401 *count = counter;
402 return 0;
403 }
404
405 #endif
406
407
408
409 #ifdef GLX_MESA_set_3dfx_mode
410 GLboolean glXSet3DfxModeMESA( GLint mode )
411 {
412 #ifdef REALGLX
413 return GL_FALSE;
414 #else
415 return Fake_glXSet3DfxModeMESA( mode );
416 #endif
417 }
418 #endif
419
420
421
422 #ifdef GLX_EXT_get_proc_address
423 void (*glXGetProcAddressEXT( const GLubyte *procName ))()
424 {
425 #ifdef REALGLX
426 return NULL;
427 #else
428 return Fake_glXGetProcAddress( procName );
429 #endif
430 }
431 #endif