1 /* $Id: glxapi.c,v 1.7 1999/11/25 17:37:49 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
32 * GLX API functions which either call fake or real GLX implementations
34 * To enable real GLX encoding the REALGLX preprocessor symbol should be
35 * defined on the command line.
45 #include <X11/Xutil.h>
52 static Display
*CurrentDisplay
= NULL
;
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,
63 static GLboolean
display_has_glx( Display
*dpy
)
65 /* TODO: we should use a lookup table to avoid calling XQueryExtension
69 if (XQueryExtension( dpy
, "GLX", &ignore
, &ignore
, &ignore
)) {
79 XVisualInfo
*glXChooseVisual( Display
*dpy
, int screen
, int *list
)
82 if (display_has_glx(dpy
))
83 return Real_glXChooseVisual( dpy
, screen
, list
);
86 return Fake_glXChooseVisual( dpy
, screen
, list
);
91 int glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
, int attrib
, int *value
)
94 if (display_has_glx(dpy
))
95 return Real_glXGetConfig( dpy
, visinfo
, attrib
, value
);
98 return Fake_glXGetConfig( dpy
, visinfo
, attrib
, value
);
103 GLXContext
glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
104 GLXContext shareList
, Bool direct
)
107 if (display_has_glx(dpy
))
108 return Real_glXCreateContext( dpy
, visinfo
, shareList
, direct
);
111 return Fake_glXCreateContext( dpy
, visinfo
, shareList
, direct
);
116 void glXDestroyContext( Display
*dpy
, GLXContext ctx
)
119 if (display_has_glx(dpy
))
120 Real_glXDestroyContext( dpy
, ctx
);
123 Fake_glXDestroyContext( dpy
, ctx
);
128 void glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
132 if (display_has_glx(dpy
))
133 Real_glXCopyContext( dpy
, src
, dst
, mask
);
136 Fake_glXCopyContext( dpy
, src
, dst
, mask
);
141 Bool
glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
144 if (display_has_glx(dpy
)) {
145 if (Real_glXMakeCurrent( dpy
, drawable
, ctx
)) {
146 CurrentDisplay
= dpy
;
154 if (Fake_glXMakeCurrent( dpy
, drawable
, ctx
)) {
155 CurrentDisplay
= dpy
;
163 return Fake_glXMakeCurrent( dpy
, drawable
, ctx
);
169 GLXContext
glXGetCurrentContext( void )
172 if (display_has_glx(CurrentDisplay
))
173 return Real_glXGetCurrentContext();
176 return Fake_glXGetCurrentContext();
181 GLXDrawable
glXGetCurrentDrawable( void )
184 if (display_has_glx(CurrentDisplay
))
185 return Real_glXGetCurrentDrawable();
188 return Fake_glXGetCurrentDrawable();
193 GLXPixmap
glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
,
197 if (display_has_glx(dpy
))
198 return Real_glXCreateGLXPixmap( dpy
, visinfo
, pixmap
);
201 return Fake_glXCreateGLXPixmap( dpy
, visinfo
, pixmap
);
205 void glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
208 if (display_has_glx(dpy
))
209 Real_glXDestroyGLXPixmap( dpy
, pixmap
);
212 Fake_glXDestroyGLXPixmap( dpy
, pixmap
);
217 Bool
glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
220 if (display_has_glx(dpy
))
221 return Real_glXQueryExtension( dpy
, errorb
, event
);
224 return Fake_glXQueryExtension( dpy
, errorb
, event
);
229 Bool
glXIsDirect( Display
*dpy
, GLXContext ctx
)
232 if (display_has_glx(dpy
))
233 return Real_glXIsDirect( dpy
, ctx
);
236 return Fake_glXIsDirect( dpy
, ctx
);
241 void glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
244 if (display_has_glx(dpy
))
245 Real_glXSwapBuffers( dpy
, drawable
);
248 Fake_glXSwapBuffers( dpy
, drawable
);
253 void glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
254 int x
, int y
, int width
, int height
)
257 /* can't implement! */
260 Fake_glXCopySubBufferMESA( dpy
, drawable
, x
, y
, width
, height
);
265 Bool
glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
268 if (display_has_glx(dpy
))
269 return Real_glXQueryVersion( dpy
, maj
, min
);
272 return Fake_glXQueryVersion( dpy
, maj
, min
);
277 void glXUseXFont( Font font
, int first
, int count
, int listBase
)
280 if (display_has_glx(CurrentDisplay
))
281 Real_glXUseXFont( font
, first
, count
, listBase
);
284 Fake_glXUseXFont( font
, first
, count
, listBase
);
288 void glXWaitGL( void )
291 if (display_has_glx(CurrentDisplay
))
300 void glXWaitX( void )
303 if (display_has_glx(CurrentDisplay
))
312 /* GLX 1.1 and later */
313 const char *glXQueryExtensionsString( Display
*dpy
, int screen
)
316 if (display_has_glx(dpy
))
317 return Real_glXQueryExtensionsString( dpy
, screen
);
320 return Fake_glXQueryExtensionsString( dpy
, screen
);
325 /* GLX 1.1 and later */
326 const char *glXQueryServerString( Display
*dpy
, int screen
, int name
)
329 if (display_has_glx(dpy
))
330 return Real_glXQueryServerString( dpy
, screen
, name
);
333 return Fake_glXQueryServerString( dpy
, screen
, name
);
338 /* GLX 1.1 and later */
339 const char *glXGetClientString( Display
*dpy
, int name
)
342 if (display_has_glx(dpy
))
343 return Real_glXGetClientString( dpy
, name
);
346 return Fake_glXGetClientString( dpy
, name
);
351 /* GLX 1.2 and later */
352 Display
*glXGetCurrentDisplay( void )
355 if (display_has_glx(dpy
))
356 return Real_glXGetCurrentDisplay();
359 return Fake_glXGetCurrentDisplay();
366 * XXX these are just no-op stubs for now.
368 GLXFBConfig
glXChooseFBConfig( Display
*dpy
, int screen
,
369 const int *attribList
, int *nitems
)
379 int glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
380 int attribute
, int *value
)
390 XVisualInfo
*glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
398 GLXWindow
glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
399 const int *attribList
)
409 void glXDestroyWindow( Display
*dpy
, GLXWindow window
)
417 GLXPixmap
glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
418 const int *attribList
)
428 void glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
436 GLXPbuffer
glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
437 const int *attribList
)
446 void glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
453 void glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
454 unsigned int *value
)
463 GLXContext
glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
464 int renderType
, GLXContext shareList
,
476 Bool
glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
, GLXDrawable read
,
480 if (display_has_glx(dpy
))
481 return Real_glXMakeContextCurrent(dpy
, draw
, read
, ctx
);
484 return Fake_glXMakeContextCurrent(dpy
, draw
, read
, ctx
);
488 GLXDrawable
glXGetCurrentReadDrawable( void )
491 if (display_has_glx(dpy
))
492 return Real_glXGetCurrentReadDrawable();
495 return Fake_glXGetCurrentReadDrawable();
499 int glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
509 void glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
517 void glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
518 unsigned long *mask
)
528 #ifdef GLX_MESA_release_buffers
529 Bool
glXReleaseBuffersMESA( Display
*dpy
, Window w
)
532 if (display_has_glx(dpy
))
536 return Fake_glXReleaseBuffersMESA( dpy
, w
);
541 #ifdef GLX_MESA_pixmap_colormap
542 GLXPixmap
glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
543 Pixmap pixmap
, Colormap cmap
)
546 if (display_has_glx(dpy
))
550 return Fake_glXCreateGLXPixmapMESA( dpy
, visinfo
, pixmap
, cmap
);
556 #ifdef GLX_SGI_video_sync
559 * This function doesn't really do anything. But, at least one
560 * application uses the function so this stub is useful.
562 int glXGetVideoSyncSGI(unsigned int *count
)
564 static unsigned int counter
= 0;
571 * Again, this is really just a stub function.
573 int glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
575 static unsigned int counter
= 0;
576 while (counter
% divisor
!= remainder
)
586 #ifdef GLX_MESA_set_3dfx_mode
587 GLboolean
glXSet3DfxModeMESA( GLint mode
)
592 return Fake_glXSet3DfxModeMESA( mode
);
599 #if 0 /* spec for this not finalized yet */
600 void (*glXGetProcAddressEXT( const GLubyte
*procName
))()
605 return Fake_glXGetProcAddress( procName
);