home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / mesa / src / glxapi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-31  |  7.3 KB  |  361 lines

  1. /* $Id: glxapi.c,v 1.1 1997/05/24 12:10:09 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.3
  6.  * Copyright (C) 1995-1997  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: glxapi.c,v $
  26.  * Revision 1.1  1997/05/24 12:10:09  brianp
  27.  * Initial revision
  28.  *
  29.  */
  30.  
  31.  
  32. /*
  33.  * GLX API functions which either call fake or real GLX implementations
  34.  *
  35.  * To enable real GLX encoding the REALGLX preprocessor symbol should be
  36.  * defined on the command line.
  37.  */
  38.  
  39.  
  40.  
  41. #include <X11/Xlib.h>
  42. #include <X11/Xutil.h>
  43. #include "GL/glx.h"
  44. #include "fakeglx.h"
  45. #include "realglx.h"
  46.  
  47.  
  48. #ifdef REALGLX
  49. static Display *CurrentDisplay = NULL;
  50. #endif
  51.  
  52.  
  53. /*
  54.  * This functions determines whether a call to a glX*() function should
  55.  * be routed to the "fake" (Mesa) or "real" (GLX-encoder) functions.
  56.  * Input:  dpy - the X display.
  57.  * Return:   GL_TRUE if the given display supports the real GLX extension,
  58.  *           GL_FALSE otherwise.
  59.  */
  60. static GLboolean display_has_glx( Display *dpy )
  61. {
  62.    /* TODO: we should use a lookup table to avoid calling XQueryExtension
  63.     * every time.
  64.     */
  65.    int ignore;
  66.    if (XQueryExtension( dpy, "GLX", &ignore, &ignore, &ignore )) {
  67.       return GL_TRUE;
  68.    }
  69.    else {
  70.       return GL_FALSE;
  71.    }
  72. }
  73.  
  74.  
  75.  
  76. XVisualInfo *glXChooseVisual( Display *dpy, int screen, int *list )
  77. {
  78. #ifdef REALGLX
  79.    if (display_has_glx(dpy))
  80.       return Real_glXChooseVisual( dpy, screen, list );
  81.    else
  82. #endif
  83.       return Fake_glXChooseVisual( dpy, screen, list );
  84. }
  85.  
  86.  
  87.  
  88. int glXGetConfig( Display *dpy, XVisualInfo *visinfo, int attrib, int *value )
  89. {
  90. #ifdef REALGLX
  91.    if (display_has_glx(dpy))
  92.       return Real_glXGetConfig( dpy, visinfo, attrib, value );
  93.    else
  94. #endif
  95.       return Fake_glXGetConfig( dpy, visinfo, attrib, value );
  96. }
  97.  
  98.  
  99.  
  100. GLXContext glXCreateContext( Display *dpy, XVisualInfo *visinfo,
  101.                  GLXContext shareList, Bool direct )
  102. {
  103. #ifdef REALGLX
  104.    if (display_has_glx(dpy))
  105.       return Real_glXCreateContext( dpy, visinfo, shareList, direct );
  106.    else
  107. #endif
  108.       return Fake_glXCreateContext( dpy, visinfo, shareList, direct );
  109. }
  110.  
  111.  
  112.  
  113. void glXDestroyContext( Display *dpy, GLXContext ctx )
  114. {
  115. #ifdef REALGLX
  116.    if (display_has_glx(dpy))
  117.       Real_glXDestroyContext( dpy, ctx );
  118.    else
  119. #endif
  120.       Fake_glXDestroyContext( dpy, ctx );
  121. }
  122.  
  123.  
  124.  
  125. void glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
  126.              GLuint mask )
  127. {
  128. #ifdef REALGLX
  129.    if (display_has_glx(dpy))
  130.       Real_glXCopyContext( dpy, src, dst, mask );
  131.    else
  132. #endif
  133.       Fake_glXCopyContext( dpy, src, dst, mask );
  134. }
  135.  
  136.  
  137.  
  138. Bool glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
  139. {
  140. #ifdef REALGLX
  141.    if (display_has_glx(dpy)) {
  142.       if (Real_glXMakeCurrent( dpy, drawable, ctx )) {
  143.          CurrentDisplay = dpy;
  144.          return True;
  145.       }
  146.       else {
  147.          return False;
  148.       }
  149.    }
  150.    else {
  151.       if (Fake_glXMakeCurrent( dpy, drawable, ctx )) {
  152.          CurrentDisplay = dpy;
  153.          return True;
  154.       }
  155.       else {
  156.          return False;
  157.       }
  158.    }
  159. #else
  160.    return Fake_glXMakeCurrent( dpy, drawable, ctx );
  161. #endif
  162. }
  163.  
  164.  
  165.  
  166. GLXContext glXGetCurrentContext( void )
  167. {
  168. #ifdef REALGLX
  169.    if (display_has_glx(CurrentDisplay))
  170.       return Real_glXGetCurrentContext();
  171.    else
  172. #endif
  173.       return Fake_glXGetCurrentContext();
  174. }
  175.  
  176.  
  177.  
  178. GLXDrawable glXGetCurrentDrawable( void )
  179. {
  180. #ifdef REALGLX
  181.    if (display_has_glx(CurrentDisplay))
  182.       return Real_glXGetCurrentDrawable();
  183.    else
  184. #endif
  185.       return Fake_glXGetCurrentDrawable();
  186. }
  187.  
  188.  
  189.  
  190. GLXPixmap glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo,
  191.                               Pixmap pixmap )
  192. {
  193. #ifdef REALGLX
  194.    if (display_has_glx(dpy))
  195.       return Real_glXCreateGLXPixmap( dpy, visinfo, pixmap );
  196.    else
  197. #endif
  198.       return Fake_glXCreateGLXPixmap( dpy, visinfo, pixmap );
  199. }
  200.  
  201.  
  202. void glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
  203. {
  204. #ifdef REALGLX
  205.    if (display_has_glx(dpy))
  206.       Real_glXDestroyGLXPixmap( dpy, pixmap );
  207.    else
  208. #endif
  209.       Fake_glXDestroyGLXPixmap( dpy, pixmap );
  210. }
  211.  
  212.  
  213.  
  214. Bool glXQueryExtension( Display *dpy, int *errorb, int *event )
  215. {
  216. #ifdef REALGLX
  217.    if (display_has_glx(dpy))
  218.       return Real_glXQueryExtension( dpy, errorb, event );
  219.    else
  220. #endif
  221.       return Fake_glXQueryExtension( dpy, errorb, event );
  222. }
  223.  
  224.  
  225.  
  226. Bool glXIsDirect( Display *dpy, GLXContext ctx )
  227. {
  228. #ifdef REALGLX
  229.    if (display_has_glx(dpy))
  230.       return Real_glXIsDirect( dpy, ctx );
  231.    else
  232. #endif
  233.       return Fake_glXIsDirect( dpy, ctx );
  234. }
  235.  
  236.  
  237.  
  238. void glXSwapBuffers( Display *dpy, GLXDrawable drawable )
  239. {
  240. #ifdef REALGLX
  241.    if (display_has_glx(dpy))
  242.       Real_glXSwapBuffers( dpy, drawable );
  243.    else
  244. #endif
  245.       Fake_glXSwapBuffers( dpy, drawable );
  246. }
  247.  
  248.  
  249.  
  250. Bool glXQueryVersion( Display *dpy, int *maj, int *min )
  251. {
  252. #ifdef REALGLX
  253.    if (display_has_glx(dpy))
  254.       return Real_glXQueryVersion( dpy, maj, min );
  255.    else
  256. #endif
  257.       return Fake_glXQueryVersion( dpy, maj, min );
  258. }
  259.  
  260.  
  261.  
  262. void glXUseXFont( Font font, int first, int count, int listBase )
  263. {
  264. #ifdef REALGLX
  265.    if (display_has_glx(CurrentDisplay))
  266.       Real_glXUseXFont( font, first, count, listBase );
  267.    else
  268. #endif
  269.       Fake_glXUseXFont( font, first, count, listBase );
  270. }
  271.  
  272.  
  273. void glXWaitGL( void )
  274. {
  275. #ifdef REALGLX
  276.    if (display_has_glx(CurrentDisplay))
  277.       Real_glXWaitGL();
  278.    else
  279. #endif
  280.       Fake_glXWaitGL();
  281. }
  282.  
  283.  
  284.  
  285. void glXWaitX( void )
  286. {
  287. #ifdef REALGLX
  288.    if (display_has_glx(CurrentDisplay))
  289.       Real_glXWaitX();
  290.    else
  291. #endif
  292.       Fake_glXWaitX();
  293. }
  294.  
  295.  
  296.  
  297. /* GLX 1.1 and later */
  298. const char *glXQueryExtensionsString( Display *dpy, int screen )
  299. {
  300. #ifdef REALGLX
  301.    if (display_has_glx(dpy))
  302.       return Real_glXQueryExtensionsString( dpy, screen );
  303.    else
  304. #endif
  305.       return Fake_glXQueryExtensionsString( dpy, screen );
  306. }
  307.  
  308.  
  309.  
  310. /* GLX 1.1 and later */
  311. const char *glXQueryServerString( Display *dpy, int screen, int name )
  312. {
  313. #ifdef REALGLX
  314.    if (display_has_glx(dpy))
  315.       return Real_glXQueryServerString( dpy, screen, name );
  316.    else
  317. #endif
  318.       return Fake_glXQueryServerString( dpy, screen, name );
  319. }
  320.  
  321.  
  322.  
  323. /* GLX 1.1 and later */
  324. const char *glXGetClientString( Display *dpy, int name )
  325. {
  326. #ifdef REALGLX
  327.    if (display_has_glx(dpy))
  328.       return Real_glXGetClientString( dpy, name );
  329.    else
  330. #endif
  331.       return Fake_glXGetClientString( dpy, name );
  332. }
  333.  
  334.  
  335.  
  336. #ifdef GLX_MESA_release_buffers
  337. Bool glXReleaseBuffersMESA( Display *dpy, Window w )
  338. {
  339. #ifdef REALGLX
  340.    if (display_has_glx(dpy))
  341.       return GL_FALSE;
  342.    else
  343. #endif
  344.       return Fake_glXReleaseBuffersMESA( dpy, w );
  345. }
  346. #endif
  347.  
  348.  
  349. #ifdef GLX_MESA_pixmap_colormap
  350. GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
  351.                                   Pixmap pixmap, Colormap cmap )
  352. {
  353. #ifdef REALGLX
  354.    if (display_has_glx(dpy))
  355.       return 0;
  356.    else
  357. #endif
  358.       return Fake_glXCreateGLXPixmapMESA( dpy, visinfo, pixmap, cmap );
  359. }
  360. #endif
  361.