fakeglx.c revision 584b0879ac2ec2420ea6866e47eb90e1a980e758
1afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/*
2afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Mesa 3-D graphics library
349e80bf6b163310f7cd776261872201eea57053aBrian Paul * Version:  7.5
45e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
549e80bf6b163310f7cd776261872201eea57053aBrian Paul * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
649e80bf6b163310f7cd776261872201eea57053aBrian Paul * Copyright (C) 2009  VMware, Inc.   All Rights Reserved.
75e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
8afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Permission is hereby granted, free of charge, to any person obtaining a
9afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * copy of this software and associated documentation files (the "Software"),
10afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * to deal in the Software without restriction, including without limitation
11afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * and/or sell copies of the Software, and to permit persons to whom the
13afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Software is furnished to do so, subject to the following conditions:
145e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
15afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * The above copyright notice and this permission notice shall be included
16afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * in all copies or substantial portions of the Software.
175e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
18afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
25afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
26afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
27afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/*
2836cfa38760cc2bd91c08b66bb62c4b6cf9eb5454Brian Paul * This is an emulation of the GLX API which allows Mesa/GLX-based programs
2936cfa38760cc2bd91c08b66bb62c4b6cf9eb5454Brian Paul * to run on X servers which do not have the real GLX extension.
30afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *
31afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Thanks to the contributors:
32afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *
33ddf69f247fdb246b99ef6525fcfa6eda7b2e2aa7Brian Paul * Initial version:  Philip Brown (phil@bolthole.com)
34afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu)
35afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Further visual-handling refinements: Wolfram Gloger
36afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *    (wmglo@Dent.MED.Uni-Muenchen.DE).
37afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *
38afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Notes:
39afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *   Don't be fooled, stereo isn't supported yet.
40afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
41afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
42afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
43afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
44fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul#include "glxheader.h"
45426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul#include "glxapi.h"
46374e7fd6cc95d3d91629a6e1c951d77e8a29c31cBrian Paul#include "main/context.h"
47374e7fd6cc95d3d91629a6e1c951d77e8a29c31cBrian Paul#include "main/config.h"
48374e7fd6cc95d3d91629a6e1c951d77e8a29c31cBrian Paul#include "main/macros.h"
49374e7fd6cc95d3d91629a6e1c951d77e8a29c31cBrian Paul#include "main/imports.h"
50374e7fd6cc95d3d91629a6e1c951d77e8a29c31cBrian Paul#include "main/mtypes.h"
51374e7fd6cc95d3d91629a6e1c951d77e8a29c31cBrian Paul#include "main/version.h"
5271dea349d2be623b7819389428b0d6a124e8d184Brian Paul#include "xfonts.h"
53afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "xmesaP.h"
54afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
5570cf1f0cf83fc3f2df241cc638e23f8df3b89923Jouk Jansen#ifdef __VMS
5670cf1f0cf83fc3f2df241cc638e23f8df3b89923Jouk Jansen#define _mesa_sprintf sprintf
5770cf1f0cf83fc3f2df241cc638e23f8df3b89923Jouk Jansen#endif
58afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
5978fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul/* This indicates the client-side GLX API and GLX encoder version. */
6078fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul#define CLIENT_MAJOR_VERSION 1
61a573803ed3fe9ef6489f45bd4c5455b77cb33a43Brian Paul#define CLIENT_MINOR_VERSION 4  /* but don't have 1.3's pbuffers, etc yet */
6278fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul
6378fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul/* This indicates the server-side GLX decoder version.
64ba57e5297d60eef37e43dd4d7f10d1e62f5e97ceBrian Paul * GLX 1.4 indicates OpenGL 1.3 support
6578fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul */
6678fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul#define SERVER_MAJOR_VERSION 1
67ba57e5297d60eef37e43dd4d7f10d1e62f5e97ceBrian Paul#define SERVER_MINOR_VERSION 4
6878fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul
6978fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul/* This is appended onto the glXGetClient/ServerString version strings. */
702c5f93784ea1ba28ae15181917ff3e47656a93adBrian Paul#define MESA_GLX_VERSION "Mesa " MESA_VERSION_STRING
7178fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul
7278fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul/* Who implemented this GLX? */
7378fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul#define VENDOR "Brian Paul"
7478fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul
75e4656003caee346d9c4eb23256d73409271291a7Brian Paul#define EXTENSIONS \
76e4656003caee346d9c4eb23256d73409271291a7Brian Paul   "GLX_MESA_set_3dfx_mode " \
77e4656003caee346d9c4eb23256d73409271291a7Brian Paul   "GLX_MESA_copy_sub_buffer " \
78e4656003caee346d9c4eb23256d73409271291a7Brian Paul   "GLX_MESA_pixmap_colormap " \
79e4656003caee346d9c4eb23256d73409271291a7Brian Paul   "GLX_MESA_release_buffers " \
80e4656003caee346d9c4eb23256d73409271291a7Brian Paul   "GLX_ARB_get_proc_address " \
81fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   "GLX_EXT_texture_from_pixmap " \
82e4656003caee346d9c4eb23256d73409271291a7Brian Paul   "GLX_EXT_visual_info " \
83e4656003caee346d9c4eb23256d73409271291a7Brian Paul   "GLX_EXT_visual_rating " \
84ee061060826df059f0ddb904a2160ed610423579Brian Paul   /*"GLX_SGI_video_sync "*/ \
85e4656003caee346d9c4eb23256d73409271291a7Brian Paul   "GLX_SGIX_fbconfig " \
866d6efd605f662c1f07e183e58416db804f0a058fBrian Paul   "GLX_SGIX_pbuffer "
8743c9c2cfae458cf0d7618af5f25d57c0a5ebae08Brian Paul
887cf50e137da497a590ec9001a9918972a6246142Brian Paul/*
897cf50e137da497a590ec9001a9918972a6246142Brian Paul * Our fake GLX context will contain a "real" GLX context and an XMesa context.
907cf50e137da497a590ec9001a9918972a6246142Brian Paul *
917cf50e137da497a590ec9001a9918972a6246142Brian Paul * Note that a pointer to a __GLXcontext is a pointer to a fake_glx_context,
927cf50e137da497a590ec9001a9918972a6246142Brian Paul * and vice versa.
937cf50e137da497a590ec9001a9918972a6246142Brian Paul *
947cf50e137da497a590ec9001a9918972a6246142Brian Paul * We really just need this structure in order to make the libGL functions
957cf50e137da497a590ec9001a9918972a6246142Brian Paul * glXGetCurrentContext(), glXGetCurrentDrawable() and glXGetCurrentDisplay()
967cf50e137da497a590ec9001a9918972a6246142Brian Paul * work correctly.
977cf50e137da497a590ec9001a9918972a6246142Brian Paul */
987cf50e137da497a590ec9001a9918972a6246142Brian Paulstruct fake_glx_context {
997cf50e137da497a590ec9001a9918972a6246142Brian Paul   __GLXcontext glxContext;   /* this MUST be first! */
1007cf50e137da497a590ec9001a9918972a6246142Brian Paul   XMesaContext xmesaContext;
1017cf50e137da497a590ec9001a9918972a6246142Brian Paul};
10243c9c2cfae458cf0d7618af5f25d57c0a5ebae08Brian Paul
103afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
104afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1057cf50e137da497a590ec9001a9918972a6246142Brian Paul/**********************************************************************/
1067cf50e137da497a590ec9001a9918972a6246142Brian Paul/***                       GLX Visual Code                          ***/
1077cf50e137da497a590ec9001a9918972a6246142Brian Paul/**********************************************************************/
1087cf50e137da497a590ec9001a9918972a6246142Brian Paul
1097cf50e137da497a590ec9001a9918972a6246142Brian Paul#define DONT_CARE -1
1107cf50e137da497a590ec9001a9918972a6246142Brian Paul
111afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
11264034c4fb5c56f63d37faa6f64f3183ca106856aAlan Hourihanestatic XMesaVisual *VisualTable = NULL;
113afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtgstatic int NumVisuals = 0;
114afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
115afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
116afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/*
117afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * This struct and some code fragments borrowed
118afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * from Mark Kilgard's GLUT library.
119afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
120afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtgtypedef struct _OverlayInfo {
121afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg  /* Avoid 64-bit portability problems by being careful to use
122afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg     longs due to the way XGetWindowProperty is specified. Note
123afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg     that these parameters are passed as CARD32s over X
124afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg     protocol. */
125afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg  unsigned long overlay_visual;
126afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg  long transparent_type;
127afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg  long value;
128afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg  long layer;
129afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} OverlayInfo;
130afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
131afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
132afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
133afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* Macro to handle c_class vs class field name in XVisualInfo struct */
134afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#if defined(__cplusplus) || defined(c_plusplus)
135afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#define CLASS c_class
136afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#else
137afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#define CLASS class
138afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#endif
139afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
140afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
141afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
142afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/*
143afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Test if the given XVisualInfo is usable for Mesa rendering.
144afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
1457287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paulstatic GLboolean
1467287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paulis_usable_visual( XVisualInfo *vinfo )
147afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
148afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   switch (vinfo->CLASS) {
149afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case StaticGray:
150afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GrayScale:
151afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* Any StaticGray/GrayScale visual works in RGB or CI mode */
152afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return GL_TRUE;
153afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case StaticColor:
154afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case PseudoColor:
155afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 /* Any StaticColor/PseudoColor visual of at least 4 bits */
156afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 if (vinfo->depth>=4) {
157afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    return GL_TRUE;
158afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 }
159afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 else {
160afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    return GL_FALSE;
161afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 }
162afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case TrueColor:
163afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case DirectColor:
164afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 /* Any depth of TrueColor or DirectColor works in RGB mode */
165afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return GL_TRUE;
166afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      default:
167afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 /* This should never happen */
168afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return GL_FALSE;
169afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
170afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
171afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
172afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
173afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1741d97c277e0cb2b75559d495a58222f2511212a66Brian Paul/**
1751d97c277e0cb2b75559d495a58222f2511212a66Brian Paul * Get an array OverlayInfo records for specified screen.
1761d97c277e0cb2b75559d495a58222f2511212a66Brian Paul * \param dpy  the display
1771d97c277e0cb2b75559d495a58222f2511212a66Brian Paul * \param screen  screen number
1781d97c277e0cb2b75559d495a58222f2511212a66Brian Paul * \param numOverlays  returns numver of OverlayInfo records
1791d97c277e0cb2b75559d495a58222f2511212a66Brian Paul * \return  pointer to OverlayInfo array, free with XFree()
180afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
1811d97c277e0cb2b75559d495a58222f2511212a66Brian Paulstatic OverlayInfo *
1821d97c277e0cb2b75559d495a58222f2511212a66Brian PaulGetOverlayInfo(Display *dpy, int screen, int *numOverlays)
183afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
184afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   Atom overlayVisualsAtom;
185afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   Atom actualType;
1861d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   Status status;
1871d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   unsigned char *ovInfo;
188afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   unsigned long sizeData, bytesLeft;
1891d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   int actualFormat;
190afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
191afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /*
192afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    * The SERVER_OVERLAY_VISUALS property on the root window contains
193afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    * a list of overlay visuals.  Get that list now.
194afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    */
195afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True);
196afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (overlayVisualsAtom == None) {
197afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return 0;
198afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
199afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2001d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   status = XGetWindowProperty(dpy, RootWindow(dpy, screen),
201afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                               overlayVisualsAtom, 0L, (long) 10000, False,
202afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                               overlayVisualsAtom, &actualType, &actualFormat,
203afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                               &sizeData, &bytesLeft,
2041d97c277e0cb2b75559d495a58222f2511212a66Brian Paul                               &ovInfo);
205afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
206afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (status != Success || actualType != overlayVisualsAtom ||
207afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg       actualFormat != 32 || sizeData < 4) {
208afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      /* something went wrong */
2091d97c277e0cb2b75559d495a58222f2511212a66Brian Paul      XFree((void *) ovInfo);
2101d97c277e0cb2b75559d495a58222f2511212a66Brian Paul      *numOverlays = 0;
2111d97c277e0cb2b75559d495a58222f2511212a66Brian Paul      return NULL;
2121d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   }
2131d97c277e0cb2b75559d495a58222f2511212a66Brian Paul
2141d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   *numOverlays = sizeData / 4;
2151d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   return (OverlayInfo *) ovInfo;
2161d97c277e0cb2b75559d495a58222f2511212a66Brian Paul}
2171d97c277e0cb2b75559d495a58222f2511212a66Brian Paul
2181d97c277e0cb2b75559d495a58222f2511212a66Brian Paul
2191d97c277e0cb2b75559d495a58222f2511212a66Brian Paul
2201d97c277e0cb2b75559d495a58222f2511212a66Brian Paul/**
2211d97c277e0cb2b75559d495a58222f2511212a66Brian Paul * Return the level (overlay, normal, underlay) of a given XVisualInfo.
2221d97c277e0cb2b75559d495a58222f2511212a66Brian Paul * Input:  dpy - the X display
2231d97c277e0cb2b75559d495a58222f2511212a66Brian Paul *         vinfo - the XVisualInfo to test
2241d97c277e0cb2b75559d495a58222f2511212a66Brian Paul * Return:  level of the visual:
2251d97c277e0cb2b75559d495a58222f2511212a66Brian Paul *             0 = normal planes
2261d97c277e0cb2b75559d495a58222f2511212a66Brian Paul *            >0 = overlay planes
2271d97c277e0cb2b75559d495a58222f2511212a66Brian Paul *            <0 = underlay planes
2281d97c277e0cb2b75559d495a58222f2511212a66Brian Paul */
2291d97c277e0cb2b75559d495a58222f2511212a66Brian Paulstatic int
2301d97c277e0cb2b75559d495a58222f2511212a66Brian Paullevel_of_visual( Display *dpy, XVisualInfo *vinfo )
2311d97c277e0cb2b75559d495a58222f2511212a66Brian Paul{
2321d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   OverlayInfo *overlay_info;
2331d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   int numOverlaysPerScreen, i;
2341d97c277e0cb2b75559d495a58222f2511212a66Brian Paul
2351d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   overlay_info = GetOverlayInfo(dpy, vinfo->screen, &numOverlaysPerScreen);
2361d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   if (!overlay_info) {
237afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return 0;
238afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
239afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
240afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /* search the overlay visual list for the visual ID of interest */
2411d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   for (i = 0; i < numOverlaysPerScreen; i++) {
2421d97c277e0cb2b75559d495a58222f2511212a66Brian Paul      const OverlayInfo *ov = overlay_info + i;
2431d97c277e0cb2b75559d495a58222f2511212a66Brian Paul      if (ov->overlay_visual == vinfo->visualid) {
244afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* found the visual */
245afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         if (/*ov->transparent_type==1 &&*/ ov->layer!=0) {
246afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            int level = ov->layer;
247afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            XFree((void *) overlay_info);
248afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            return level;
249afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
250afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         else {
251afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            XFree((void *) overlay_info);
252afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            return 0;
253afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
254afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
255afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
256afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
257afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /* The visual ID was not found in the overlay list. */
258afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XFree((void *) overlay_info);
259afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   return 0;
260afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
261afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
262afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
263afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
264afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
265afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/*
266afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
267afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * configuration in our list of GLX visuals.
268afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
269afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtgstatic XMesaVisual
270afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtgsave_glx_visual( Display *dpy, XVisualInfo *vinfo,
271afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                 GLboolean rgbFlag, GLboolean alphaFlag, GLboolean dbFlag,
272afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                 GLboolean stereoFlag,
273afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                 GLint depth_size, GLint stencil_size,
274b2e460018375f699198073a6167e0ee96ba1d267Brian Paul                 GLint accumRedSize, GLint accumGreenSize,
275b2e460018375f699198073a6167e0ee96ba1d267Brian Paul                 GLint accumBlueSize, GLint accumAlphaSize,
276894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul                 GLint level, GLint numAuxBuffers )
277afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
278afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   GLboolean ximageFlag = GL_TRUE;
279afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XMesaVisual xmvis;
280afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   GLint i;
281afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   GLboolean comparePointers;
282afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
283afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (dbFlag) {
284afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      /* Check if the MESA_BACK_BUFFER env var is set */
285367d308b8267ad86cd7623590b7bfd4737b5fbf5Brian Paul      char *backbuffer = _mesa_getenv("MESA_BACK_BUFFER");
286afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (backbuffer) {
287afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         if (backbuffer[0]=='p' || backbuffer[0]=='P') {
288afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            ximageFlag = GL_FALSE;
289afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
290afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         else if (backbuffer[0]=='x' || backbuffer[0]=='X') {
291afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            ximageFlag = GL_TRUE;
292afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
293afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         else {
294d09a1d8b29ae5841ae39b5c24c3f4693dd750559Brian Paul            _mesa_warning(NULL, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
295afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
296afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
297afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
298afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
299da2f1e88bc63403a95b89706905c070b7c894863Brian   if (stereoFlag) {
300da2f1e88bc63403a95b89706905c070b7c894863Brian      /* stereo not supported */
301da2f1e88bc63403a95b89706905c070b7c894863Brian      return NULL;
302da2f1e88bc63403a95b89706905c070b7c894863Brian   }
303da2f1e88bc63403a95b89706905c070b7c894863Brian
304afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /* Comparing IDs uses less memory but sometimes fails. */
305afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /* XXX revisit this after 3.0 is finished. */
306367d308b8267ad86cd7623590b7bfd4737b5fbf5Brian Paul   if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
307afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      comparePointers = GL_TRUE;
308afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   else
309afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      comparePointers = GL_FALSE;
310afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
311a13331d59b535aa4a1ddad695420de5d6f814550Brian Paul   /* Force the visual to have an alpha channel */
312a13331d59b535aa4a1ddad695420de5d6f814550Brian Paul   if (rgbFlag && _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
313a13331d59b535aa4a1ddad695420de5d6f814550Brian Paul      alphaFlag = GL_TRUE;
314a13331d59b535aa4a1ddad695420de5d6f814550Brian Paul
315afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /* First check if a matching visual is already in the list */
316afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   for (i=0; i<NumVisuals; i++) {
317afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      XMesaVisual v = VisualTable[i];
318afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (v->display == dpy
319304d3aa9cb727eb4cd4797c33f8e13e5ac4285a9Ian Romanick          && v->mesa_visual.level == level
320894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul          && v->mesa_visual.numAuxBuffers == numAuxBuffers
321afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg          && v->ximage_flag == ximageFlag
3221832f1cc86758fdcbd122edd5bf9e7a29ccade20Brian Paul          && v->mesa_visual.rgbMode == rgbFlag
3231832f1cc86758fdcbd122edd5bf9e7a29ccade20Brian Paul          && v->mesa_visual.doubleBufferMode == dbFlag
3241832f1cc86758fdcbd122edd5bf9e7a29ccade20Brian Paul          && v->mesa_visual.stereoMode == stereoFlag
3251832f1cc86758fdcbd122edd5bf9e7a29ccade20Brian Paul          && (v->mesa_visual.alphaBits > 0) == alphaFlag
3261832f1cc86758fdcbd122edd5bf9e7a29ccade20Brian Paul          && (v->mesa_visual.depthBits >= depth_size || depth_size == 0)
3271832f1cc86758fdcbd122edd5bf9e7a29ccade20Brian Paul          && (v->mesa_visual.stencilBits >= stencil_size || stencil_size == 0)
3281832f1cc86758fdcbd122edd5bf9e7a29ccade20Brian Paul          && (v->mesa_visual.accumRedBits >= accumRedSize || accumRedSize == 0)
3291832f1cc86758fdcbd122edd5bf9e7a29ccade20Brian Paul          && (v->mesa_visual.accumGreenBits >= accumGreenSize || accumGreenSize == 0)
3301832f1cc86758fdcbd122edd5bf9e7a29ccade20Brian Paul          && (v->mesa_visual.accumBlueBits >= accumBlueSize || accumBlueSize == 0)
3311832f1cc86758fdcbd122edd5bf9e7a29ccade20Brian Paul          && (v->mesa_visual.accumAlphaBits >= accumAlphaSize || accumAlphaSize == 0)) {
332afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* now either compare XVisualInfo pointers or visual IDs */
333d0247f53aea8fa8677aadc8a00f75c8993be9ebcBrian Paul         if ((!comparePointers && v->visinfo->visualid == vinfo->visualid)
334afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg             || (comparePointers && v->vishandle == vinfo)) {
335afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            return v;
336afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
337afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
338afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
339afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
340afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /* Create a new visual and add it to the list. */
341afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
342c8735e8f8299676e443e6ca0ffd339ab94e013f9Brian Paul   xmvis = XMesaCreateVisual( dpy, vinfo, rgbFlag, alphaFlag, dbFlag,
343c8735e8f8299676e443e6ca0ffd339ab94e013f9Brian Paul                              stereoFlag, ximageFlag,
344c8735e8f8299676e443e6ca0ffd339ab94e013f9Brian Paul                              depth_size, stencil_size,
345c8735e8f8299676e443e6ca0ffd339ab94e013f9Brian Paul                              accumRedSize, accumBlueSize,
346c8735e8f8299676e443e6ca0ffd339ab94e013f9Brian Paul                              accumBlueSize, accumAlphaSize, 0, level,
347c8735e8f8299676e443e6ca0ffd339ab94e013f9Brian Paul                              GLX_NONE_EXT );
348afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (xmvis) {
349f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      /* Save a copy of the pointer now so we can find this visual again
350f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul       * if we need to search for it in find_glx_visual().
351f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul       */
352f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      xmvis->vishandle = vinfo;
35364034c4fb5c56f63d37faa6f64f3183ca106856aAlan Hourihane      /* Allocate more space for additional visual */
3549580179dfb42d5b81ff6ec9704b82a556c7f1229Brian Paul      VisualTable = (XMesaVisual *) _mesa_realloc( VisualTable,
35564034c4fb5c56f63d37faa6f64f3183ca106856aAlan Hourihane                                   sizeof(XMesaVisual) * NumVisuals,
356394fd40a536faade5ccfbbb1f2920394e89ad4aaBrian Paul                                   sizeof(XMesaVisual) * (NumVisuals + 1));
357f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      /* add xmvis to the list */
358afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      VisualTable[NumVisuals] = xmvis;
359afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      NumVisuals++;
3607287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul      /* XXX minor hack, because XMesaCreateVisual doesn't support an
3617287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul       * aux buffers parameter.
3627287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul       */
363894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul      xmvis->mesa_visual.numAuxBuffers = numAuxBuffers;
364afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
365afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   return xmvis;
366afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
367afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
368afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
369dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul/**
370dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul * Return the default number of bits for the Z buffer.
371dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul * If defined, use the MESA_GLX_DEPTH_BITS env var value.
372dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
373dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul * XXX probably do the same thing for stencil, accum, etc.
374dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul */
375dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paulstatic GLint
376dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Pauldefault_depth_bits(void)
377dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul{
378dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul   int zBits;
379dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul   const char *zEnv = _mesa_getenv("MESA_GLX_DEPTH_BITS");
380dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul   if (zEnv)
381dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul      zBits = _mesa_atoi(zEnv);
382dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul   else
383dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul      zBits = DEFAULT_SOFTWARE_DEPTH_BITS;
384dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul   return zBits;
385dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul}
386dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul
387978ef2bb6d9ca4996a24f95820a699e22c84f70bBrian Paulstatic GLint
388c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Pauldefault_alpha_bits(void)
389c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul{
390c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul   int aBits;
391c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul   const char *aEnv = _mesa_getenv("MESA_GLX_ALPHA_BITS");
392c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul   if (aEnv)
393c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul      aBits = _mesa_atoi(aEnv);
394c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul   else
395c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul      aBits = 0;
396c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul   return aBits;
397c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul}
398c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul
399c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paulstatic GLint
400978ef2bb6d9ca4996a24f95820a699e22c84f70bBrian Pauldefault_accum_bits(void)
401978ef2bb6d9ca4996a24f95820a699e22c84f70bBrian Paul{
402978ef2bb6d9ca4996a24f95820a699e22c84f70bBrian Paul   return 16;
403978ef2bb6d9ca4996a24f95820a699e22c84f70bBrian Paul}
404978ef2bb6d9ca4996a24f95820a699e22c84f70bBrian Paul
405dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul
406afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
407afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/*
408afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Create a GLX visual from a regular XVisualInfo.
409ed30dfa1264ec8875a3162c3c8778bc703bf11d5Brian Paul * This is called when Fake GLX is given an XVisualInfo which wasn't
410ed30dfa1264ec8875a3162c3c8778bc703bf11d5Brian Paul * returned by glXChooseVisual.  Since this is the first time we're
411ed30dfa1264ec8875a3162c3c8778bc703bf11d5Brian Paul * considering this visual we'll take a guess at reasonable values
412ed30dfa1264ec8875a3162c3c8778bc703bf11d5Brian Paul * for depth buffer size, stencil size, accum size, etc.
413ed30dfa1264ec8875a3162c3c8778bc703bf11d5Brian Paul * This is the best we can do with a client-side emulation of GLX.
414afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
415afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtgstatic XMesaVisual
416afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtgcreate_glx_visual( Display *dpy, XVisualInfo *visinfo )
417afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
418afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   int vislevel;
419dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul   GLint zBits = default_depth_bits();
420978ef2bb6d9ca4996a24f95820a699e22c84f70bBrian Paul   GLint accBits = default_accum_bits();
421c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul   GLboolean alphaFlag = default_alpha_bits() > 0;
422afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
423afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   vislevel = level_of_visual( dpy, visinfo );
424afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (vislevel) {
425afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      /* Configure this visual as a CI, single-buffered overlay */
426afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return save_glx_visual( dpy, visinfo,
427afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                              GL_FALSE,  /* rgb */
428afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                              GL_FALSE,  /* alpha */
429afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                              GL_FALSE,  /* double */
430afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                              GL_FALSE,  /* stereo */
431afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                              0,         /* depth bits */
432afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                              0,         /* stencil bits */
433b2e460018375f699198073a6167e0ee96ba1d267Brian Paul                              0,0,0,0,   /* accum bits */
434894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul                              vislevel,  /* level */
435894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul                              0          /* numAux */
436afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                            );
437afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
438afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   else if (is_usable_visual( visinfo )) {
439367d308b8267ad86cd7623590b7bfd4737b5fbf5Brian Paul      if (_mesa_getenv("MESA_GLX_FORCE_CI")) {
4408f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul         /* Configure this visual as a COLOR INDEX visual. */
4418f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul         return save_glx_visual( dpy, visinfo,
4428f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul                                 GL_FALSE,   /* rgb */
4438f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul                                 GL_FALSE,  /* alpha */
4448f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul                                 GL_TRUE,   /* double */
4458f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul                                 GL_FALSE,  /* stereo */
446dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul                                 zBits,
447e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul                                 STENCIL_BITS,
448e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul                                 0, 0, 0, 0, /* accum bits */
449894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul                                 0,         /* level */
450894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul                                 0          /* numAux */
4518f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul                               );
4528f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul      }
4538f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul      else {
4548f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul         /* Configure this visual as RGB, double-buffered, depth-buffered. */
4558f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul         /* This is surely wrong for some people's needs but what else */
4568f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul         /* can be done?  They should use glXChooseVisual(). */
4578f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul         return save_glx_visual( dpy, visinfo,
4588f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul                                 GL_TRUE,   /* rgb */
459c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul                                 alphaFlag, /* alpha */
4608f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul                                 GL_TRUE,   /* double */
4618f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul                                 GL_FALSE,  /* stereo */
462dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul                                 zBits,
463e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul                                 STENCIL_BITS,
464978ef2bb6d9ca4996a24f95820a699e22c84f70bBrian Paul                                 accBits, /* r */
465978ef2bb6d9ca4996a24f95820a699e22c84f70bBrian Paul                                 accBits, /* g */
466978ef2bb6d9ca4996a24f95820a699e22c84f70bBrian Paul                                 accBits, /* b */
467978ef2bb6d9ca4996a24f95820a699e22c84f70bBrian Paul                                 accBits, /* a */
468894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul                                 0,         /* level */
469894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul                                 0          /* numAux */
4708f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul                               );
4718f9a594ac8116ed5cab7f8eca14c17ec3e250dadBrian Paul      }
472afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
473afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   else {
474d09a1d8b29ae5841ae39b5c24c3f4693dd750559Brian Paul      _mesa_warning(NULL, "Mesa: error in glXCreateContext: bad visual\n");
475afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return NULL;
476afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
477afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
478afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
479afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
480afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
481afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/*
482afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Find the GLX visual associated with an XVisualInfo.
483afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
484afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtgstatic XMesaVisual
485afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtgfind_glx_visual( Display *dpy, XVisualInfo *vinfo )
486afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
487afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   int i;
488afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
489f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul   /* try to match visual id */
490afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   for (i=0;i<NumVisuals;i++) {
491f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      if (VisualTable[i]->display==dpy
492f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul          && VisualTable[i]->visinfo->visualid == vinfo->visualid) {
493afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return VisualTable[i];
494afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
495afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
496f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul
497f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul   /* if that fails, try to match pointers */
498afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   for (i=0;i<NumVisuals;i++) {
499f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      if (VisualTable[i]->display==dpy && VisualTable[i]->vishandle==vinfo) {
500afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return VisualTable[i];
501afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
502afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
503f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul
504afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   return NULL;
505afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
506afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
507afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
508afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
5091d97c277e0cb2b75559d495a58222f2511212a66Brian Paul/**
510afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Return the transparent pixel value for a GLX visual.
511afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Input:  glxvis - the glx_visual
512afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Return:  a pixel value or -1 if no transparent pixel
513afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
5147287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paulstatic int
5157287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paultransparent_pixel( XMesaVisual glxvis )
516afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
517afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   Display *dpy = glxvis->display;
518afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XVisualInfo *vinfo = glxvis->visinfo;
5191d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   OverlayInfo *overlay_info;
5201d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   int numOverlaysPerScreen, i;
521afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
5221d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   overlay_info = GetOverlayInfo(dpy, vinfo->screen, &numOverlaysPerScreen);
5231d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   if (!overlay_info) {
524afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return -1;
525afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
526afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
5271d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   for (i = 0; i < numOverlaysPerScreen; i++) {
5281d97c277e0cb2b75559d495a58222f2511212a66Brian Paul      const OverlayInfo *ov = overlay_info + i;
5291d97c277e0cb2b75559d495a58222f2511212a66Brian Paul      if (ov->overlay_visual == vinfo->visualid) {
530afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* found it! */
5311d97c277e0cb2b75559d495a58222f2511212a66Brian Paul         if (ov->transparent_type == 0) {
532afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            /* type 0 indicates no transparency */
533afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            XFree((void *) overlay_info);
534afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            return -1;
535afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
536afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         else {
537afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            /* ov->value is the transparent pixel */
538afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            XFree((void *) overlay_info);
539afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            return ov->value;
540afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
541afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
542afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
543afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
544afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /* The visual ID was not found in the overlay list. */
545afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XFree((void *) overlay_info);
546afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   return -1;
547afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
548afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
549afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
550afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
5511d97c277e0cb2b75559d495a58222f2511212a66Brian Paul/**
552afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Try to get an X visual which matches the given arguments.
553afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
5547287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paulstatic XVisualInfo *
5557287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paulget_visual( Display *dpy, int scr, unsigned int depth, int xclass )
556afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
557afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XVisualInfo temp, *vis;
558afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   long mask;
559afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   int n;
560afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   unsigned int default_depth;
561afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   int default_class;
562afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
563afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   mask = VisualScreenMask | VisualDepthMask | VisualClassMask;
564afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   temp.screen = scr;
565afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   temp.depth = depth;
566afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   temp.CLASS = xclass;
567afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
568afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   default_depth = DefaultDepth(dpy,scr);
569afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   default_class = DefaultVisual(dpy,scr)->CLASS;
570afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
571afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (depth==default_depth && xclass==default_class) {
572afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      /* try to get root window's visual */
573afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      temp.visualid = DefaultVisual(dpy,scr)->visualid;
574afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      mask |= VisualIDMask;
575afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
576afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
577afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   vis = XGetVisualInfo( dpy, mask, &temp, &n );
578afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
579afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
580afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    * An SGI Infinite Reality system, for example, can have 30bpp pixels:
581afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    * 10 bits per color channel.  Mesa's limited to a max of 8 bits/channel.
582afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    */
583afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) {
58471dea349d2be623b7819389428b0d6a124e8d184Brian Paul      if (_mesa_bitcount((GLuint) vis->red_mask  ) <= 8 &&
58571dea349d2be623b7819389428b0d6a124e8d184Brian Paul          _mesa_bitcount((GLuint) vis->green_mask) <= 8 &&
58671dea349d2be623b7819389428b0d6a124e8d184Brian Paul          _mesa_bitcount((GLuint) vis->blue_mask ) <= 8) {
587afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return vis;
588afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
589afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      else {
590afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         XFree((void *) vis);
591afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return NULL;
592afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
593afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
594afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
595afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   return vis;
596afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
597afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
598afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
599afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
600afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/*
601afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Retrieve the value of the given environment variable and find
602afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * the X visual which matches it.
603afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Input:  dpy - the display
604afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *         screen - the screen number
605afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *         varname - the name of the environment variable
606afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Return:  an XVisualInfo pointer to NULL if error.
607afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
6087287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paulstatic XVisualInfo *
6097287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paulget_env_visual(Display *dpy, int scr, const char *varname)
610afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
611afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   char value[100], type[100];
612afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   int depth, xclass = -1;
613afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XVisualInfo *vis;
614afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
615367d308b8267ad86cd7623590b7bfd4737b5fbf5Brian Paul   if (!_mesa_getenv( varname )) {
616afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return NULL;
617afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
618afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
619367d308b8267ad86cd7623590b7bfd4737b5fbf5Brian Paul   _mesa_strncpy( value, _mesa_getenv(varname), 100 );
620afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   value[99] = 0;
621afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
622afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   sscanf( value, "%s %d", type, &depth );
623afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
624367d308b8267ad86cd7623590b7bfd4737b5fbf5Brian Paul   if (_mesa_strcmp(type,"TrueColor")==0)          xclass = TrueColor;
625367d308b8267ad86cd7623590b7bfd4737b5fbf5Brian Paul   else if (_mesa_strcmp(type,"DirectColor")==0)   xclass = DirectColor;
626367d308b8267ad86cd7623590b7bfd4737b5fbf5Brian Paul   else if (_mesa_strcmp(type,"PseudoColor")==0)   xclass = PseudoColor;
627367d308b8267ad86cd7623590b7bfd4737b5fbf5Brian Paul   else if (_mesa_strcmp(type,"StaticColor")==0)   xclass = StaticColor;
628367d308b8267ad86cd7623590b7bfd4737b5fbf5Brian Paul   else if (_mesa_strcmp(type,"GrayScale")==0)     xclass = GrayScale;
629367d308b8267ad86cd7623590b7bfd4737b5fbf5Brian Paul   else if (_mesa_strcmp(type,"StaticGray")==0)    xclass = StaticGray;
630afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
631afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (xclass>-1 && depth>0) {
632afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      vis = get_visual( dpy, scr, depth, xclass );
633afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (vis) {
634afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return vis;
635afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
636afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
637afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
6382ad5921cf3c9737796c3485bd5b9f738fb4a3cb9Brian Paul   _mesa_warning(NULL, "GLX unable to find visual class=%s, depth=%d.",
6392ad5921cf3c9737796c3485bd5b9f738fb4a3cb9Brian Paul                 type, depth);
640d09a1d8b29ae5841ae39b5c24c3f4693dd750559Brian Paul
641afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   return NULL;
642afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
643afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
644afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
645afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
646afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/*
647afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
648afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Input:  dpy, screen - X display and screen number
649afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *         rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode
650afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *         min_depth - minimum visual depth
651afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *         preferred_class - preferred GLX visual class or DONT_CARE
652afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Return:  pointer to an XVisualInfo or NULL.
653afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
6547287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paulstatic XVisualInfo *
6557287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paulchoose_x_visual( Display *dpy, int screen, GLboolean rgba, int min_depth,
6567287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul                 int preferred_class )
657afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
658afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XVisualInfo *vis;
659db6aa58267cad3f502f03ab80b9deb6b75320a91Brian Paul   int xclass, visclass = 0;
660afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   int depth;
661afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
662afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (rgba) {
663afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      Atom hp_cr_maps = XInternAtom(dpy, "_HP_RGB_SMOOTH_MAP_LIST", True);
664afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      /* First see if the MESA_RGB_VISUAL env var is defined */
665afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      vis = get_env_visual( dpy, screen, "MESA_RGB_VISUAL" );
666afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (vis) {
667afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return vis;
668afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
669afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      /* Otherwise, search for a suitable visual */
670afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (preferred_class==DONT_CARE) {
671afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         for (xclass=0;xclass<6;xclass++) {
672afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            switch (xclass) {
673afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               case 0:  visclass = TrueColor;    break;
674afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               case 1:  visclass = DirectColor;  break;
675afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               case 2:  visclass = PseudoColor;  break;
676afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               case 3:  visclass = StaticColor;  break;
677afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               case 4:  visclass = GrayScale;    break;
678afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               case 5:  visclass = StaticGray;   break;
679afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
680afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            if (min_depth==0) {
681afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               /* start with shallowest */
682afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               for (depth=0;depth<=32;depth++) {
683afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                  if (visclass==TrueColor && depth==8 && !hp_cr_maps) {
684afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                     /* Special case:  try to get 8-bit PseudoColor before */
685afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                     /* 8-bit TrueColor */
686afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                     vis = get_visual( dpy, screen, 8, PseudoColor );
687afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                     if (vis) {
688afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                        return vis;
689afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                     }
690afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                  }
691afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                  vis = get_visual( dpy, screen, depth, visclass );
692afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                  if (vis) {
693afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                     return vis;
694afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                  }
695afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               }
696afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
697afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            else {
698afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               /* start with deepest */
699afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               for (depth=32;depth>=min_depth;depth--) {
700afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                  if (visclass==TrueColor && depth==8 && !hp_cr_maps) {
701afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                     /* Special case:  try to get 8-bit PseudoColor before */
702afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                     /* 8-bit TrueColor */
703afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                     vis = get_visual( dpy, screen, 8, PseudoColor );
704afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                     if (vis) {
705afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                        return vis;
706afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                     }
707afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                  }
708afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                  vis = get_visual( dpy, screen, depth, visclass );
709afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                  if (vis) {
710afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                     return vis;
711afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                  }
712afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               }
713afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
714afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
715afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
716afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      else {
717afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* search for a specific visual class */
718afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         switch (preferred_class) {
719afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case GLX_TRUE_COLOR_EXT:    visclass = TrueColor;    break;
720afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case GLX_DIRECT_COLOR_EXT:  visclass = DirectColor;  break;
721afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case GLX_PSEUDO_COLOR_EXT:  visclass = PseudoColor;  break;
722afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case GLX_STATIC_COLOR_EXT:  visclass = StaticColor;  break;
723afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case GLX_GRAY_SCALE_EXT:    visclass = GrayScale;    break;
724afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case GLX_STATIC_GRAY_EXT:   visclass = StaticGray;   break;
725afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            default:   return NULL;
726afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
727afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         if (min_depth==0) {
728afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            /* start with shallowest */
729afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            for (depth=0;depth<=32;depth++) {
730afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               vis = get_visual( dpy, screen, depth, visclass );
731afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               if (vis) {
732afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                  return vis;
733afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               }
734afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
735afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
736afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         else {
737afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            /* start with deepest */
738afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            for (depth=32;depth>=min_depth;depth--) {
739afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               vis = get_visual( dpy, screen, depth, visclass );
740afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               if (vis) {
741afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                  return vis;
742afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               }
743afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
744afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
745afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
746afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
747afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   else {
748afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      /* First see if the MESA_CI_VISUAL env var is defined */
749afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      vis = get_env_visual( dpy, screen, "MESA_CI_VISUAL" );
750afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (vis) {
751afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return vis;
752afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
753afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      /* Otherwise, search for a suitable visual, starting with shallowest */
754afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (preferred_class==DONT_CARE) {
755afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         for (xclass=0;xclass<4;xclass++) {
756afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            switch (xclass) {
757afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               case 0:  visclass = PseudoColor;  break;
758afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               case 1:  visclass = StaticColor;  break;
759afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               case 2:  visclass = GrayScale;    break;
760afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               case 3:  visclass = StaticGray;   break;
761afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
762afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            /* try 8-bit up through 16-bit */
763afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            for (depth=8;depth<=16;depth++) {
764afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               vis = get_visual( dpy, screen, depth, visclass );
765afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               if (vis) {
766afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                  return vis;
767afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               }
768afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
769afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            /* try min_depth up to 8-bit */
770afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            for (depth=min_depth;depth<8;depth++) {
771afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               vis = get_visual( dpy, screen, depth, visclass );
772afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               if (vis) {
773afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                  return vis;
774afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               }
775afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
776afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
777afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
778afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      else {
779afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* search for a specific visual class */
780afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         switch (preferred_class) {
781afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case GLX_TRUE_COLOR_EXT:    visclass = TrueColor;    break;
782afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case GLX_DIRECT_COLOR_EXT:  visclass = DirectColor;  break;
783afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case GLX_PSEUDO_COLOR_EXT:  visclass = PseudoColor;  break;
784afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case GLX_STATIC_COLOR_EXT:  visclass = StaticColor;  break;
785afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case GLX_GRAY_SCALE_EXT:    visclass = GrayScale;    break;
786afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case GLX_STATIC_GRAY_EXT:   visclass = StaticGray;   break;
787afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            default:   return NULL;
788afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
789afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* try 8-bit up through 16-bit */
790afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         for (depth=8;depth<=16;depth++) {
791afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            vis = get_visual( dpy, screen, depth, visclass );
792afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            if (vis) {
793afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               return vis;
794afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
795afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
796afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* try min_depth up to 8-bit */
797afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         for (depth=min_depth;depth<8;depth++) {
798afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            vis = get_visual( dpy, screen, depth, visclass );
799afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            if (vis) {
800afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               return vis;
801afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
802afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
803afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
804afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
805afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
806afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /* didn't find a visual */
807afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   return NULL;
808afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
809afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
810afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
811afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
812afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/*
813afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Find the deepest X over/underlay visual of at least min_depth.
814afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Input:  dpy, screen - X display and screen number
815afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *         level - the over/underlay level
816afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *         trans_type - transparent pixel type: GLX_NONE_EXT,
817afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *                      GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
818afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *                      or DONT_CARE
819afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *         trans_value - transparent pixel value or DONT_CARE
820afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *         min_depth - minimum visual depth
821afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg *         preferred_class - preferred GLX visual class or DONT_CARE
822afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Return:  pointer to an XVisualInfo or NULL.
823afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
8247287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paulstatic XVisualInfo *
8257287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paulchoose_x_overlay_visual( Display *dpy, int scr, GLboolean rgbFlag,
8267287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul                         int level, int trans_type, int trans_value,
8277287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul                         int min_depth, int preferred_class )
828afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
829afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   OverlayInfo *overlay_info;
830afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   int numOverlaysPerScreen;
831afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   int i;
832afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XVisualInfo *deepvis;
833afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   int deepest;
834afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
835afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /*DEBUG int tt, tv; */
836afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
837afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   switch (preferred_class) {
838afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_TRUE_COLOR_EXT:    preferred_class = TrueColor;    break;
839afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_DIRECT_COLOR_EXT:  preferred_class = DirectColor;  break;
840afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_PSEUDO_COLOR_EXT:  preferred_class = PseudoColor;  break;
841afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_STATIC_COLOR_EXT:  preferred_class = StaticColor;  break;
842afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_GRAY_SCALE_EXT:    preferred_class = GrayScale;    break;
843afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_STATIC_GRAY_EXT:   preferred_class = StaticGray;   break;
844afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      default:                    preferred_class = DONT_CARE;
845afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
846afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
8471d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   overlay_info = GetOverlayInfo(dpy, scr, &numOverlaysPerScreen);
8481d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   if (!overlay_info) {
849afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return NULL;
850afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
851afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
852afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /* Search for the deepest overlay which satisifies all criteria. */
853afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   deepest = min_depth;
854afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   deepvis = NULL;
855afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
8561d97c277e0cb2b75559d495a58222f2511212a66Brian Paul   for (i = 0; i < numOverlaysPerScreen; i++) {
8571d97c277e0cb2b75559d495a58222f2511212a66Brian Paul      const OverlayInfo *ov = overlay_info + i;
858afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      XVisualInfo *vislist, vistemplate;
859afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      int count;
860afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
861afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (ov->layer!=level) {
862afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* failed overlay level criteria */
863afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         continue;
864afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
865afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (!(trans_type==DONT_CARE
866afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            || (trans_type==GLX_TRANSPARENT_INDEX_EXT
867afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                && ov->transparent_type>0)
868afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            || (trans_type==GLX_NONE_EXT && ov->transparent_type==0))) {
869afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* failed transparent pixel type criteria */
870afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         continue;
871afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
872afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (trans_value!=DONT_CARE && trans_value!=ov->value) {
873afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* failed transparent pixel value criteria */
874afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         continue;
875afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
876afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
877afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      /* get XVisualInfo and check the depth */
878afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      vistemplate.visualid = ov->overlay_visual;
879afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      vistemplate.screen = scr;
880afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      vislist = XGetVisualInfo( dpy, VisualIDMask | VisualScreenMask,
881afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg                                &vistemplate, &count );
882afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
883afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (count!=1) {
884afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* something went wrong */
885afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         continue;
886afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
887afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (preferred_class!=DONT_CARE && preferred_class!=vislist->CLASS) {
888afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* wrong visual class */
889afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         continue;
890afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
891afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
89242f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul      /* if RGB was requested, make sure we have True/DirectColor */
89342f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul      if (rgbFlag && vislist->CLASS != TrueColor
89442f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul          && vislist->CLASS != DirectColor)
89542f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul         continue;
89642f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul
89742f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul      /* if CI was requested, make sure we have a color indexed visual */
89842f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul      if (!rgbFlag
89942f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul          && (vislist->CLASS == TrueColor || vislist->CLASS == DirectColor))
90042f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul         continue;
90142f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul
902afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (deepvis==NULL || vislist->depth > deepest) {
903afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* YES!  found a satisfactory visual */
904afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         if (deepvis) {
90580af3614d88c0cac160e787de7f34b37e96cb626Brian Paul            XFree( deepvis );
906afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
907afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         deepest = vislist->depth;
908afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         deepvis = vislist;
909afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* DEBUG  tt = ov->transparent_type;*/
910afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* DEBUG  tv = ov->value; */
911afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
912afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
913afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
914afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/*DEBUG
915afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (deepvis) {
916afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      printf("chose 0x%x:  layer=%d depth=%d trans_type=%d trans_value=%d\n",
917afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg             deepvis->visualid, level, deepvis->depth, tt, tv );
918afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
919afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg*/
920afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   return deepvis;
921afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
922afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
923afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
9247cf50e137da497a590ec9001a9918972a6246142Brian Paul/**********************************************************************/
9256c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul/***             Display-related functions                          ***/
9266c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul/**********************************************************************/
9276c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul
9286c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul
9296c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul/**
9306c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul * Free all XMesaVisuals which are associated with the given display.
9316c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul */
9326c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paulstatic void
9336c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Pauldestroy_visuals_on_display(Display *dpy)
9346c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul{
9356c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   int i;
9366c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   for (i = 0; i < NumVisuals; i++) {
9376c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul      if (VisualTable[i]->display == dpy) {
9386c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul         /* remove this visual */
9396c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul         int j;
9406c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul         free(VisualTable[i]);
9416c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul         for (j = i; j < NumVisuals - 1; j++)
9426c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul            VisualTable[j] = VisualTable[j + 1];
9436c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul         NumVisuals--;
9446c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul      }
9456c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   }
9466c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul}
9476c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul
9486c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul
9496c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul/**
9506c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul * Called from XCloseDisplay() to let us free our display-related data.
9516c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul */
9526c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paulstatic int
9536c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paulclose_display_callback(Display *dpy, XExtCodes *codes)
9546c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul{
9556c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   destroy_visuals_on_display(dpy);
9566c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   xmesa_destroy_buffers_on_display(dpy);
9576c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   return 0;
9586c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul}
9596c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul
9606c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul
9616c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul/**
9626c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul * Look for the named extension on given display and return a pointer
9636c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul * to the _XExtension data, or NULL if extension not found.
9646c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul */
9656c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paulstatic _XExtension *
9666c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paullookup_extension(Display *dpy, const char *extName)
9676c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul{
9686c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   _XExtension *ext;
9696c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   for (ext = dpy->ext_procs; ext; ext = ext->next) {
97052e36cd8d9a727d786c2db14ae8291d48fad8e47Brian Paul      if (ext->name && strcmp(ext->name, extName) == 0) {
9716c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul         return ext;
9726c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul      }
9736c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   }
9746c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   return NULL;
9756c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul}
9766c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul
9776c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul
9786c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul/**
9796c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul * Whenever we're given a new Display pointer, call this function to
9806c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul * register our close_display_callback function.
9816c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul */
9826c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paulstatic void
9836c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paulregister_with_display(Display *dpy)
9846c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul{
9856c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   const char *extName = "MesaGLX";
9866c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   _XExtension *ext;
9876c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul
9886c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   ext = lookup_extension(dpy, extName);
9896c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   if (!ext) {
9906c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul      XExtCodes *c = XAddExtension(dpy);
9916c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul      ext = dpy->ext_procs;  /* new extension is at head of list */
9926c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul      assert(c->extension == ext->codes.extension);
9936c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul      ext->name = _mesa_strdup(extName);
9946c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul      ext->close_display = close_display_callback;
9956c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   }
9966c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul}
9976c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul
9986c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul
9996c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul/**********************************************************************/
10007cf50e137da497a590ec9001a9918972a6246142Brian Paul/***                  Begin Fake GLX API Functions                  ***/
10017cf50e137da497a590ec9001a9918972a6246142Brian Paul/**********************************************************************/
10027cf50e137da497a590ec9001a9918972a6246142Brian Paul
1003afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1004ba0fe1832e3573c7ec872ba9bfb1cf1773e384c6Brian Paul/**
1005ba0fe1832e3573c7ec872ba9bfb1cf1773e384c6Brian Paul * Helper used by glXChooseVisual and glXChooseFBConfig.
1006ba0fe1832e3573c7ec872ba9bfb1cf1773e384c6Brian Paul * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
1007ba0fe1832e3573c7ec872ba9bfb1cf1773e384c6Brian Paul * the later.
1008ba0fe1832e3573c7ec872ba9bfb1cf1773e384c6Brian Paul * In either case, the attribute list is terminated with the value 'None'.
1009ba0fe1832e3573c7ec872ba9bfb1cf1773e384c6Brian Paul */
10107287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paulstatic XMesaVisual
10111f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paulchoose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig )
1012afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
10131f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul   const GLboolean rgbModeDefault = fbConfig;
10143265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   const int *parselist;
1015afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XVisualInfo *vis;
1016afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   int min_ci = 0;
1017afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   int min_red=0, min_green=0, min_blue=0;
1018b3063ac398b72e6a4fd2015d4e220495b9779294Brian Paul   GLboolean rgb_flag = rgbModeDefault;
1019afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   GLboolean alpha_flag = GL_FALSE;
1020afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   GLboolean double_flag = GL_FALSE;
1021afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   GLboolean stereo_flag = GL_FALSE;
1022afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   GLint depth_size = 0;
1023afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   GLint stencil_size = 0;
1024b2e460018375f699198073a6167e0ee96ba1d267Brian Paul   GLint accumRedSize = 0;
1025b2e460018375f699198073a6167e0ee96ba1d267Brian Paul   GLint accumGreenSize = 0;
1026b2e460018375f699198073a6167e0ee96ba1d267Brian Paul   GLint accumBlueSize = 0;
1027b2e460018375f699198073a6167e0ee96ba1d267Brian Paul   GLint accumAlphaSize = 0;
1028afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   int level = 0;
1029afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   int visual_type = DONT_CARE;
1030afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   int trans_type = DONT_CARE;
1031afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   int trans_value = DONT_CARE;
1032e1210b176926349b258c7ec77b7f36716025c82aBrian Paul   GLint caveat = DONT_CARE;
10333265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   XMesaVisual xmvis = NULL;
10343a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul   int desiredVisualID = -1;
1035894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul   int numAux = 0;
1036afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1037afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   parselist = list;
1038afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1039afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   while (*parselist) {
1040afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1041afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      switch (*parselist) {
1042afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_USE_GL:
10431f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            if (fbConfig) {
10441f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul               /* invalid token */
10451f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul               return NULL;
10461f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            }
10471f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            else {
10481f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul               /* skip */
10491f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul               parselist++;
10501f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            }
1051afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    break;
1052afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_BUFFER_SIZE:
1053afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    parselist++;
1054afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    min_ci = *parselist++;
1055afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    break;
1056afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_LEVEL:
1057afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    parselist++;
1058afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            level = *parselist++;
1059afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    break;
1060afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_RGBA:
10611f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            if (fbConfig) {
10621f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul               /* invalid token */
10631f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul               return NULL;
10641f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            }
10651f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            else {
10661f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul               rgb_flag = GL_TRUE;
10671f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul               parselist++;
10681f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            }
1069afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    break;
1070afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_DOUBLEBUFFER:
10711f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            parselist++;
10721f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            if (fbConfig) {
10731f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul               double_flag = *parselist++;
10741f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            }
10751f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            else {
10761f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul               double_flag = GL_TRUE;
10771f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            }
1078afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    break;
1079afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_STEREO:
10801f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            parselist++;
10811f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            if (fbConfig) {
10821f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul               stereo_flag = *parselist++;
10831f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            }
10841f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            else {
10851f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul               stereo_flag = GL_TRUE;
10861f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            }
1087da2f1e88bc63403a95b89706905c070b7c894863Brian            break;
1088afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_AUX_BUFFERS:
1089afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    parselist++;
1090894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul            numAux = *parselist++;
1091894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul            if (numAux > MAX_AUX_BUFFERS)
1092894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul               return NULL;
1093afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    break;
1094afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_RED_SIZE:
1095afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    parselist++;
1096afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    min_red = *parselist++;
1097afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    break;
1098afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_GREEN_SIZE:
1099afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    parselist++;
1100afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    min_green = *parselist++;
1101afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    break;
1102afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_BLUE_SIZE:
1103afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    parselist++;
1104afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    min_blue = *parselist++;
1105afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    break;
1106afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_ALPHA_SIZE:
1107afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    parselist++;
1108afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            {
1109afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               GLint size = *parselist++;
1110c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul               alpha_flag = size ? GL_TRUE : GL_FALSE;
1111afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
1112afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    break;
1113afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_DEPTH_SIZE:
1114afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    parselist++;
1115afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    depth_size = *parselist++;
1116afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    break;
1117afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_STENCIL_SIZE:
1118afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    parselist++;
1119afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    stencil_size = *parselist++;
1120afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    break;
1121afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_ACCUM_RED_SIZE:
1122b2e460018375f699198073a6167e0ee96ba1d267Brian Paul	    parselist++;
1123b2e460018375f699198073a6167e0ee96ba1d267Brian Paul            {
1124b2e460018375f699198073a6167e0ee96ba1d267Brian Paul               GLint size = *parselist++;
1125b2e460018375f699198073a6167e0ee96ba1d267Brian Paul               accumRedSize = MAX2( accumRedSize, size );
1126b2e460018375f699198073a6167e0ee96ba1d267Brian Paul            }
1127b2e460018375f699198073a6167e0ee96ba1d267Brian Paul            break;
1128afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_ACCUM_GREEN_SIZE:
1129b2e460018375f699198073a6167e0ee96ba1d267Brian Paul	    parselist++;
1130b2e460018375f699198073a6167e0ee96ba1d267Brian Paul            {
1131b2e460018375f699198073a6167e0ee96ba1d267Brian Paul               GLint size = *parselist++;
1132b2e460018375f699198073a6167e0ee96ba1d267Brian Paul               accumGreenSize = MAX2( accumGreenSize, size );
1133b2e460018375f699198073a6167e0ee96ba1d267Brian Paul            }
1134b2e460018375f699198073a6167e0ee96ba1d267Brian Paul            break;
1135afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_ACCUM_BLUE_SIZE:
1136b2e460018375f699198073a6167e0ee96ba1d267Brian Paul	    parselist++;
1137b2e460018375f699198073a6167e0ee96ba1d267Brian Paul            {
1138b2e460018375f699198073a6167e0ee96ba1d267Brian Paul               GLint size = *parselist++;
1139b2e460018375f699198073a6167e0ee96ba1d267Brian Paul               accumBlueSize = MAX2( accumBlueSize, size );
1140b2e460018375f699198073a6167e0ee96ba1d267Brian Paul            }
1141b2e460018375f699198073a6167e0ee96ba1d267Brian Paul            break;
1142afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case GLX_ACCUM_ALPHA_SIZE:
1143afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    parselist++;
1144afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            {
1145afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               GLint size = *parselist++;
1146b2e460018375f699198073a6167e0ee96ba1d267Brian Paul               accumAlphaSize = MAX2( accumAlphaSize, size );
1147afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
1148afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    break;
1149afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1150afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /*
1151afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg          * GLX_EXT_visual_info extension
1152afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg          */
1153afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         case GLX_X_VISUAL_TYPE_EXT:
1154afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            parselist++;
1155afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            visual_type = *parselist++;
1156afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            break;
1157afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         case GLX_TRANSPARENT_TYPE_EXT:
1158afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            parselist++;
1159afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            trans_type = *parselist++;
1160afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            break;
1161afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1162afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            parselist++;
1163afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            trans_value = *parselist++;
1164afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            break;
1165afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         case GLX_TRANSPARENT_RED_VALUE_EXT:
1166afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1167afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1168afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1169afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    /* ignore */
1170afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    parselist++;
1171afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    parselist++;
1172afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    break;
11735e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen
1174e1210b176926349b258c7ec77b7f36716025c82aBrian Paul         /*
1175e1210b176926349b258c7ec77b7f36716025c82aBrian Paul          * GLX_EXT_visual_info extension
1176e1210b176926349b258c7ec77b7f36716025c82aBrian Paul          */
1177e1210b176926349b258c7ec77b7f36716025c82aBrian Paul         case GLX_VISUAL_CAVEAT_EXT:
1178e1210b176926349b258c7ec77b7f36716025c82aBrian Paul            parselist++;
1179e1210b176926349b258c7ec77b7f36716025c82aBrian Paul            caveat = *parselist++; /* ignored for now */
1180e1210b176926349b258c7ec77b7f36716025c82aBrian Paul            break;
1181e1210b176926349b258c7ec77b7f36716025c82aBrian Paul
11823265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         /*
118366ab7271016615cf485fb0b71832833d2e0f99a7Brian Paul          * GLX_ARB_multisample
118466ab7271016615cf485fb0b71832833d2e0f99a7Brian Paul          */
118566ab7271016615cf485fb0b71832833d2e0f99a7Brian Paul         case GLX_SAMPLE_BUFFERS_ARB:
118666ab7271016615cf485fb0b71832833d2e0f99a7Brian Paul         case GLX_SAMPLES_ARB:
1187e903f51bc43fde1f61a779fd8017c96a651781acBrian Paul	    parselist++;
1188e903f51bc43fde1f61a779fd8017c96a651781acBrian Paul	    if (*parselist++ != 0)
1189e903f51bc43fde1f61a779fd8017c96a651781acBrian Paul	       /* ms not supported */
1190e903f51bc43fde1f61a779fd8017c96a651781acBrian Paul	       return NULL;
1191e903f51bc43fde1f61a779fd8017c96a651781acBrian Paul	    break;
119266ab7271016615cf485fb0b71832833d2e0f99a7Brian Paul
119366ab7271016615cf485fb0b71832833d2e0f99a7Brian Paul         /*
11943265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul          * FBConfig attribs.
11953265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul          */
11963265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         case GLX_RENDER_TYPE:
1197dfb6c56ed85d7b11b6e7e9b0a5ec7eddb1162510Brian Paul            if (!fbConfig)
1198dfb6c56ed85d7b11b6e7e9b0a5ec7eddb1162510Brian Paul               return NULL;
11993265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            parselist++;
1200584b0879ac2ec2420ea6866e47eb90e1a980e758Brian Paul            if (*parselist & GLX_RGBA_BIT) {
12013265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul               rgb_flag = GL_TRUE;
12023265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            }
1203584b0879ac2ec2420ea6866e47eb90e1a980e758Brian Paul            else if (*parselist & GLX_COLOR_INDEX_BIT) {
12043265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul               rgb_flag = GL_FALSE;
12053265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            }
12063265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            else if (*parselist == 0) {
12073265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul               rgb_flag = GL_TRUE;
12083265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            }
12093265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            parselist++;
12103265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            break;
12113265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         case GLX_DRAWABLE_TYPE:
1212dfb6c56ed85d7b11b6e7e9b0a5ec7eddb1162510Brian Paul            if (!fbConfig)
1213dfb6c56ed85d7b11b6e7e9b0a5ec7eddb1162510Brian Paul               return NULL;
12143265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            parselist++;
12153265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            if (*parselist & ~(GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT)) {
12163265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul               return NULL; /* bad bit */
12173265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            }
12183265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            parselist++;
12193265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            break;
12203a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul         case GLX_FBCONFIG_ID:
1221dfb6c56ed85d7b11b6e7e9b0a5ec7eddb1162510Brian Paul            if (!fbConfig)
1222dfb6c56ed85d7b11b6e7e9b0a5ec7eddb1162510Brian Paul               return NULL;
12233a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul            parselist++;
1224dfb6c56ed85d7b11b6e7e9b0a5ec7eddb1162510Brian Paul            desiredVisualID = *parselist++;
1225dfb6c56ed85d7b11b6e7e9b0a5ec7eddb1162510Brian Paul            break;
1226dfb6c56ed85d7b11b6e7e9b0a5ec7eddb1162510Brian Paul         case GLX_X_RENDERABLE:
1227dfb6c56ed85d7b11b6e7e9b0a5ec7eddb1162510Brian Paul            if (!fbConfig)
1228dfb6c56ed85d7b11b6e7e9b0a5ec7eddb1162510Brian Paul               return NULL;
1229dfb6c56ed85d7b11b6e7e9b0a5ec7eddb1162510Brian Paul            parselist += 2;
1230dfb6c56ed85d7b11b6e7e9b0a5ec7eddb1162510Brian Paul            /* ignore */
12313a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul            break;
12323265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul
1233fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian#ifdef GLX_EXT_texture_from_pixmap
1234fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         case GLX_BIND_TO_TEXTURE_RGB_EXT:
1235fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            parselist++; /*skip*/
1236fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            break;
1237fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         case GLX_BIND_TO_TEXTURE_RGBA_EXT:
1238fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            parselist++; /*skip*/
1239fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            break;
1240fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
1241fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            parselist++; /*skip*/
1242fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            break;
1243fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
1244fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            parselist++;
1245fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            if (*parselist & ~(GLX_TEXTURE_1D_BIT_EXT |
1246fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian                               GLX_TEXTURE_2D_BIT_EXT |
1247fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian                               GLX_TEXTURE_RECTANGLE_BIT_EXT)) {
1248fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian               /* invalid bit */
1249fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian               return NULL;
1250fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            }
1251fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            break;
1252fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         case GLX_Y_INVERTED_EXT:
1253fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            parselist++; /*skip*/
1254fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            break;
1255fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian#endif
1256fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian
1257afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 case None:
12583a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul            /* end of list */
1259afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    break;
12603265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul
1261afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 default:
1262afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    /* undefined attribute */
12632ad5921cf3c9737796c3485bd5b9f738fb4a3cb9Brian Paul            _mesa_warning(NULL, "unexpected attrib 0x%x in choose_visual()",
12642ad5921cf3c9737796c3485bd5b9f738fb4a3cb9Brian Paul                          *parselist);
1265afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    return NULL;
1266afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
1267afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1268afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1269b305028464f02947c0cce0476af0e35f4ed1fafaBrian Paul   (void) caveat;
1270b305028464f02947c0cce0476af0e35f4ed1fafaBrian Paul
1271afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /*
1272afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    * Since we're only simulating the GLX extension this function will never
1273afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    * find any real GL visuals.  Instead, all we can do is try to find an RGB
1274afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    * or CI visual of appropriate depth.  Other requested attributes such as
1275afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    * double buffering, depth buffer, etc. will be associated with the X
1276afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    * visual and stored in the VisualTable[].
1277afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg    */
12783a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul   if (desiredVisualID != -1) {
12793a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul      /* try to get a specific visual, by visualID */
12803a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul      XVisualInfo temp;
12813a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul      int n;
12823a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul      temp.visualid = desiredVisualID;
12833a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul      temp.screen = screen;
12843a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul      vis = XGetVisualInfo(dpy, VisualIDMask | VisualScreenMask, &temp, &n);
12853a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul      if (vis) {
12863a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul         /* give the visual some useful GLX attributes */
12873a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul         double_flag = GL_TRUE;
12883a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul         if (vis->depth > 8)
12893a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul            rgb_flag = GL_TRUE;
1290dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul         depth_size = default_depth_bits();
12913a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul         stencil_size = STENCIL_BITS;
12923a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul         /* XXX accum??? */
12933a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul      }
12943a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul   }
12953a99674980c1fd76649ac48a95402bedc75a5e46Brian Paul   else if (level==0) {
1296afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      /* normal color planes */
1297afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (rgb_flag) {
1298afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* Get an RGB visual */
1299afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         int min_rgb = min_red + min_green + min_blue;
1300afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         if (min_rgb>1 && min_rgb<8) {
1301afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            /* a special case to be sure we can get a monochrome visual */
1302afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            min_rgb = 1;
1303afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
1304afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         vis = choose_x_visual( dpy, screen, rgb_flag, min_rgb, visual_type );
1305afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
1306afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      else {
1307afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* Get a color index visual */
1308afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         vis = choose_x_visual( dpy, screen, rgb_flag, min_ci, visual_type );
1309b2e460018375f699198073a6167e0ee96ba1d267Brian Paul         accumRedSize = accumGreenSize = accumBlueSize = accumAlphaSize = 0;
1310afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
1311afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1312afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   else {
1313afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      /* over/underlay planes */
131442f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul      if (rgb_flag) {
131542f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul         /* rgba overlay */
131642f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul         int min_rgb = min_red + min_green + min_blue;
131742f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul         if (min_rgb>1 && min_rgb<8) {
131842f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul            /* a special case to be sure we can get a monochrome visual */
131942f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul            min_rgb = 1;
132042f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul         }
132142f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul         vis = choose_x_overlay_visual( dpy, screen, rgb_flag, level,
132242f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul                              trans_type, trans_value, min_rgb, visual_type );
132342f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul      }
132442f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul      else {
132542f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul         /* color index overlay */
132642f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul         vis = choose_x_overlay_visual( dpy, screen, rgb_flag, level,
132742f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul                              trans_type, trans_value, min_ci, visual_type );
132842f252fc06e6fd0bb8c95cb9d238c1416b5d50e7Brian Paul      }
1329afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1330afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1331afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (vis) {
1332ed30dfa1264ec8875a3162c3c8778bc703bf11d5Brian Paul      /* Note: we're not exactly obeying the glXChooseVisual rules here.
1333ed30dfa1264ec8875a3162c3c8778bc703bf11d5Brian Paul       * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
13342c7e6334ec81c2fab2cce9e0fe52cd30256e37eaBrian Paul       * largest depth buffer size, which is 32bits/value.  Instead, we
1335ed30dfa1264ec8875a3162c3c8778bc703bf11d5Brian Paul       * return 16 to maintain performance with earlier versions of Mesa.
1336ed30dfa1264ec8875a3162c3c8778bc703bf11d5Brian Paul       */
13372c7e6334ec81c2fab2cce9e0fe52cd30256e37eaBrian Paul      if (depth_size > 24)
13389e4e3adcf82a72e9a74f21b492fbf5552ebfd47fBrian Paul         depth_size = 32;
1339ed30dfa1264ec8875a3162c3c8778bc703bf11d5Brian Paul      else if (depth_size > 16)
1340ed30dfa1264ec8875a3162c3c8778bc703bf11d5Brian Paul         depth_size = 24;
1341dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul      else if (depth_size > 0) {
1342dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul         depth_size = default_depth_bits();
1343dfa5c2bfbbba1e24829582863caeafd97f124d5eBrian Paul      }
13442c7e6334ec81c2fab2cce9e0fe52cd30256e37eaBrian Paul
1345c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul      if (!alpha_flag) {
1346c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul         alpha_flag = default_alpha_bits() > 0;
1347c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul      }
1348c12ee99d119debe1a421a77c1cc6d99d958ae94bBrian Paul
1349ed30dfa1264ec8875a3162c3c8778bc703bf11d5Brian Paul      /* we only support one size of stencil and accum buffers. */
1350ed30dfa1264ec8875a3162c3c8778bc703bf11d5Brian Paul      if (stencil_size > 0)
1351ed30dfa1264ec8875a3162c3c8778bc703bf11d5Brian Paul         stencil_size = STENCIL_BITS;
13526d62d7f32189d6a7b053420d16495217dc62f66fBrian Paul      if (accumRedSize > 0 || accumGreenSize > 0 || accumBlueSize > 0 ||
13536d62d7f32189d6a7b053420d16495217dc62f66fBrian Paul          accumAlphaSize > 0) {
1354978ef2bb6d9ca4996a24f95820a699e22c84f70bBrian Paul         accumRedSize =
1355978ef2bb6d9ca4996a24f95820a699e22c84f70bBrian Paul         accumGreenSize =
1356978ef2bb6d9ca4996a24f95820a699e22c84f70bBrian Paul         accumBlueSize = default_accum_bits();
1357978ef2bb6d9ca4996a24f95820a699e22c84f70bBrian Paul         accumAlphaSize = alpha_flag ? accumRedSize : 0;
13586d62d7f32189d6a7b053420d16495217dc62f66fBrian Paul      }
13596d62d7f32189d6a7b053420d16495217dc62f66fBrian Paul
13603265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      xmvis = save_glx_visual( dpy, vis, rgb_flag, alpha_flag, double_flag,
13613265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul                               stereo_flag, depth_size, stencil_size,
13623265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul                               accumRedSize, accumGreenSize,
1363894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul                               accumBlueSize, accumAlphaSize, level, numAux );
1364afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1365afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
13663265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   return xmvis;
1367afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1368afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1369afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
13703265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paulstatic XVisualInfo *
13713265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian PaulFake_glXChooseVisual( Display *dpy, int screen, int *list )
13723265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul{
13736c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   XMesaVisual xmvis;
13746c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul
13756c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   /* register ourselves as an extension on this display */
13766c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   register_with_display(dpy);
13776c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul
13786c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul   xmvis = choose_visual(dpy, screen, list, GL_FALSE);
1379f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul   if (xmvis) {
1380f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul#if 0
1381f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      return xmvis->vishandle;
1382f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul#else
1383f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      /* create a new vishandle - the cached one may be stale */
13844039cb8ca82d59451a6de8902fe35e693cdca3baBrian Paul      xmvis->vishandle = (XVisualInfo *) _mesa_malloc(sizeof(XVisualInfo));
1385f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      if (xmvis->vishandle) {
1386f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul         _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
1387f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      }
13883265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      return xmvis->vishandle;
1389f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul#endif
1390f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul   }
13913265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   else
13923265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      return NULL;
13933265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul}
1394afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1395afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
139649e80bf6b163310f7cd776261872201eea57053aBrian Paul/**
139749e80bf6b163310f7cd776261872201eea57053aBrian Paul * Init basic fields of a new fake_glx_context.
139849e80bf6b163310f7cd776261872201eea57053aBrian Paul */
139949e80bf6b163310f7cd776261872201eea57053aBrian Paulstatic void
140049e80bf6b163310f7cd776261872201eea57053aBrian Paulinit_glx_context(struct fake_glx_context *glxCtx, Display *dpy)
140149e80bf6b163310f7cd776261872201eea57053aBrian Paul{
1402c35a5aeb706d33b9c09b5a12bbbeae0f109885c9Brian Paul   /* Always return True.  See if anyone's confused... */
1403c35a5aeb706d33b9c09b5a12bbbeae0f109885c9Brian Paul   GLboolean direct = GL_TRUE;
1404c35a5aeb706d33b9c09b5a12bbbeae0f109885c9Brian Paul
140549e80bf6b163310f7cd776261872201eea57053aBrian Paul   glxCtx->xmesaContext->direct = direct;
140649e80bf6b163310f7cd776261872201eea57053aBrian Paul   glxCtx->glxContext.isDirect = direct;
140749e80bf6b163310f7cd776261872201eea57053aBrian Paul   glxCtx->glxContext.currentDpy = dpy;
140849e80bf6b163310f7cd776261872201eea57053aBrian Paul   glxCtx->glxContext.xid = (XID) glxCtx;  /* self pointer */
140949e80bf6b163310f7cd776261872201eea57053aBrian Paul
141049e80bf6b163310f7cd776261872201eea57053aBrian Paul   assert((void *) glxCtx == (void *) &(glxCtx->glxContext));
141149e80bf6b163310f7cd776261872201eea57053aBrian Paul}
141249e80bf6b163310f7cd776261872201eea57053aBrian Paul
141349e80bf6b163310f7cd776261872201eea57053aBrian Paul
141449e80bf6b163310f7cd776261872201eea57053aBrian Paul
1415426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic GLXContext
1416426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXCreateContext( Display *dpy, XVisualInfo *visinfo,
1417426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul                       GLXContext share_list, Bool direct )
1418afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
1419e4656003caee346d9c4eb23256d73409271291a7Brian Paul   XMesaVisual xmvis;
14207cf50e137da497a590ec9001a9918972a6246142Brian Paul   struct fake_glx_context *glxCtx;
14215e1680ce1d8296b2182e8909856927bbeddf3b95Brian Paul   struct fake_glx_context *shareCtx = (struct fake_glx_context *) share_list;
142299aab341998e84d9fa208c525cae8021b3845812Brian Paul
142399aab341998e84d9fa208c525cae8021b3845812Brian Paul   if (!dpy || !visinfo)
142499aab341998e84d9fa208c525cae8021b3845812Brian Paul      return 0;
142599aab341998e84d9fa208c525cae8021b3845812Brian Paul
14267cf50e137da497a590ec9001a9918972a6246142Brian Paul   glxCtx = CALLOC_STRUCT(fake_glx_context);
14277cf50e137da497a590ec9001a9918972a6246142Brian Paul   if (!glxCtx)
14287cf50e137da497a590ec9001a9918972a6246142Brian Paul      return 0;
1429afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1430afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /* deallocate unused windows/buffers */
14316c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul#if 0
1432afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XMesaGarbageCollect();
14336c06ce281aa7a7e20eab1934f573bc5c673d41cbBrian Paul#endif
1434afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1435e4656003caee346d9c4eb23256d73409271291a7Brian Paul   xmvis = find_glx_visual( dpy, visinfo );
1436e4656003caee346d9c4eb23256d73409271291a7Brian Paul   if (!xmvis) {
1437afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      /* This visual wasn't found with glXChooseVisual() */
1438e4656003caee346d9c4eb23256d73409271291a7Brian Paul      xmvis = create_glx_visual( dpy, visinfo );
1439e4656003caee346d9c4eb23256d73409271291a7Brian Paul      if (!xmvis) {
1440afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* unusable visual */
14410c54e47c0e93f725b8bc028b0d4614011dbe3fefBrian Paul         _mesa_free(glxCtx);
1442afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return NULL;
1443afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
1444afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1445afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1446e4656003caee346d9c4eb23256d73409271291a7Brian Paul   glxCtx->xmesaContext = XMesaCreateContext(xmvis,
14475e1680ce1d8296b2182e8909856927bbeddf3b95Brian Paul                                   shareCtx ? shareCtx->xmesaContext : NULL);
14487cf50e137da497a590ec9001a9918972a6246142Brian Paul   if (!glxCtx->xmesaContext) {
14490c54e47c0e93f725b8bc028b0d4614011dbe3fefBrian Paul      _mesa_free(glxCtx);
14507cf50e137da497a590ec9001a9918972a6246142Brian Paul      return NULL;
1451afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
14527cf50e137da497a590ec9001a9918972a6246142Brian Paul
145349e80bf6b163310f7cd776261872201eea57053aBrian Paul   init_glx_context(glxCtx, dpy);
14547cf50e137da497a590ec9001a9918972a6246142Brian Paul
14557cf50e137da497a590ec9001a9918972a6246142Brian Paul   return (GLXContext) glxCtx;
1456afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1457afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1458afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
14597cf50e137da497a590ec9001a9918972a6246142Brian Paul/* XXX these may have to be removed due to thread-safety issues. */
1460afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtgstatic GLXContext MakeCurrent_PrevContext = 0;
1461086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paulstatic GLXDrawable MakeCurrent_PrevDrawable = 0;
1462086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paulstatic GLXDrawable MakeCurrent_PrevReadable = 0;
1463086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paulstatic XMesaBuffer MakeCurrent_PrevDrawBuffer = 0;
1464086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paulstatic XMesaBuffer MakeCurrent_PrevReadBuffer = 0;
1465afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
14667cf50e137da497a590ec9001a9918972a6246142Brian Paul
1467086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul/* GLX 1.3 and later */
1468426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic Bool
1469426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
14707a1f3a37a10b162b067239dafa19fc6865a41f14Keith Whitwell                            GLXDrawable read, GLXContext ctx )
1471086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul{
14727cf50e137da497a590ec9001a9918972a6246142Brian Paul   struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
14737cf50e137da497a590ec9001a9918972a6246142Brian Paul
14747a1f3a37a10b162b067239dafa19fc6865a41f14Keith Whitwell   if (ctx && draw && read) {
1475086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      XMesaBuffer drawBuffer, readBuffer;
14767cf50e137da497a590ec9001a9918972a6246142Brian Paul      XMesaContext xmctx = glxCtx->xmesaContext;
1477086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul
1478086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
14797a1f3a37a10b162b067239dafa19fc6865a41f14Keith Whitwell      if (ctx == MakeCurrent_PrevContext
14807a1f3a37a10b162b067239dafa19fc6865a41f14Keith Whitwell          && draw == MakeCurrent_PrevDrawable) {
1481086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul         drawBuffer = MakeCurrent_PrevDrawBuffer;
1482086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      }
1483086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      else {
1484086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul         drawBuffer = XMesaFindBuffer( dpy, draw );
1485086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      }
1486086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      if (!drawBuffer) {
1487086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul         /* drawable must be a new window! */
14886aa5668871e7f366b33e85fabc72885fc269a7d4George Sapountzis         drawBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, draw );
1489086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul         if (!drawBuffer) {
1490086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul            /* Out of memory, or context/drawable depth mismatch */
1491086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul            return False;
1492086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul         }
14936aa5668871e7f366b33e85fabc72885fc269a7d4George Sapountzis#ifdef FX
14946aa5668871e7f366b33e85fabc72885fc269a7d4George Sapountzis         FXcreateContext( xmctx->xm_visual, draw, xmctx, drawBuffer );
14956aa5668871e7f366b33e85fabc72885fc269a7d4George Sapountzis#endif
1496086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      }
1497086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul
1498086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
14997a1f3a37a10b162b067239dafa19fc6865a41f14Keith Whitwell      if (ctx == MakeCurrent_PrevContext
1500086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul          && read == MakeCurrent_PrevReadable) {
1501086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul         readBuffer = MakeCurrent_PrevReadBuffer;
1502086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      }
1503086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      else {
1504086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul         readBuffer = XMesaFindBuffer( dpy, read );
1505086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      }
1506086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      if (!readBuffer) {
1507086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul         /* drawable must be a new window! */
15086aa5668871e7f366b33e85fabc72885fc269a7d4George Sapountzis         readBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, read );
1509086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul         if (!readBuffer) {
1510086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul            /* Out of memory, or context/drawable depth mismatch */
1511086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul            return False;
1512086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul         }
15136aa5668871e7f366b33e85fabc72885fc269a7d4George Sapountzis#ifdef FX
15146aa5668871e7f366b33e85fabc72885fc269a7d4George Sapountzis         FXcreateContext( xmctx->xm_visual, read, xmctx, readBuffer );
15156aa5668871e7f366b33e85fabc72885fc269a7d4George Sapountzis#endif
1516086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      }
1517086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul
15187a1f3a37a10b162b067239dafa19fc6865a41f14Keith Whitwell      MakeCurrent_PrevContext = ctx;
1519086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      MakeCurrent_PrevDrawable = draw;
1520086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      MakeCurrent_PrevReadable = read;
1521086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      MakeCurrent_PrevDrawBuffer = drawBuffer;
1522086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      MakeCurrent_PrevReadBuffer = readBuffer;
1523086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul
1524086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      /* Now make current! */
15257cf50e137da497a590ec9001a9918972a6246142Brian Paul      if (XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer)) {
152612c1bee87fcc3a0912685bb6e83447972e5de64eBrian Paul         ((__GLXcontext *) ctx)->currentDpy = dpy;
152712c1bee87fcc3a0912685bb6e83447972e5de64eBrian Paul         ((__GLXcontext *) ctx)->currentDrawable = draw;
152812c1bee87fcc3a0912685bb6e83447972e5de64eBrian Paul         ((__GLXcontext *) ctx)->currentReadable = read;
15297cf50e137da497a590ec9001a9918972a6246142Brian Paul         return True;
15307cf50e137da497a590ec9001a9918972a6246142Brian Paul      }
15317cf50e137da497a590ec9001a9918972a6246142Brian Paul      else {
15327cf50e137da497a590ec9001a9918972a6246142Brian Paul         return False;
15337cf50e137da497a590ec9001a9918972a6246142Brian Paul      }
1534086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul   }
15357a1f3a37a10b162b067239dafa19fc6865a41f14Keith Whitwell   else if (!ctx && !draw && !read) {
1536086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      /* release current context w/out assigning new one. */
1537086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      XMesaMakeCurrent( NULL, NULL );
1538086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      MakeCurrent_PrevContext = 0;
1539086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      MakeCurrent_PrevDrawable = 0;
1540086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      MakeCurrent_PrevReadable = 0;
1541086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      MakeCurrent_PrevDrawBuffer = 0;
1542086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      MakeCurrent_PrevReadBuffer = 0;
1543086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      return True;
1544086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul   }
1545086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul   else {
1546086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      /* The args must either all be non-zero or all zero.
1547086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul       * This is an error.
1548086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul       */
1549086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul      return False;
1550086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul   }
1551086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul}
1552086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul
1553086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul
1554426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic Bool
1555426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
1556426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
1557426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   return Fake_glXMakeContextCurrent( dpy, drawable, drawable, ctx );
1558426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
1559426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
1560426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
1561426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic GLXPixmap
1562426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap )
1563afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
1564afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XMesaVisual v;
1565afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XMesaBuffer b;
1566afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1567afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   v = find_glx_visual( dpy, visinfo );
1568afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (!v) {
1569afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      v = create_glx_visual( dpy, visinfo );
1570afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (!v) {
1571afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* unusable visual */
1572afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return 0;
1573afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
1574afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1575afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1576afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1577afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (!b) {
1578afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return 0;
1579afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1580e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul   return b->frontxrb->pixmap;
1581afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1582afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1583afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1584b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_MESA_pixmap_colormap ***/
1585b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul
1586426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic GLXPixmap
1587426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
1588426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul                             Pixmap pixmap, Colormap cmap )
1589afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
1590afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XMesaVisual v;
1591afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XMesaBuffer b;
1592afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1593afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   v = find_glx_visual( dpy, visinfo );
1594afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (!v) {
1595afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      v = create_glx_visual( dpy, visinfo );
1596afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      if (!v) {
1597afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* unusable visual */
1598afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return 0;
1599afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      }
1600afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1601afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1602afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   b = XMesaCreatePixmapBuffer( v, pixmap, cmap );
1603afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (!b) {
1604afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return 0;
1605afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1606e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul   return b->frontxrb->pixmap;
1607afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1608afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1609afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1610426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic void
1611426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
1612afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
1613afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XMesaBuffer b = XMesaFindBuffer(dpy, pixmap);
1614afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (b) {
1615afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      XMesaDestroyBuffer(b);
1616afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1617367d308b8267ad86cd7623590b7bfd4737b5fbf5Brian Paul   else if (_mesa_getenv("MESA_DEBUG")) {
1618d09a1d8b29ae5841ae39b5c24c3f4693dd750559Brian Paul      _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1619afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1620afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1621afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1622afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1623426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic void
1624426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
16253994b77bab8c62a4c1a4dffdfba233ef46662b99Brian Paul                     unsigned long mask )
1626afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
162783b820aa98931ef30fa73c72b2a96fe23885955eBrian Paul   struct fake_glx_context *fakeSrc = (struct fake_glx_context *) src;
162883b820aa98931ef30fa73c72b2a96fe23885955eBrian Paul   struct fake_glx_context *fakeDst = (struct fake_glx_context *) dst;
162983b820aa98931ef30fa73c72b2a96fe23885955eBrian Paul   XMesaContext xm_src = fakeSrc->xmesaContext;
163083b820aa98931ef30fa73c72b2a96fe23885955eBrian Paul   XMesaContext xm_dst = fakeDst->xmesaContext;
1631afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   (void) dpy;
163268edf28df68701ac429e53c0fd6dbb70b39c3fd0Brian Paul   if (MakeCurrent_PrevContext == src) {
163368edf28df68701ac429e53c0fd6dbb70b39c3fd0Brian Paul      _mesa_Flush();
163468edf28df68701ac429e53c0fd6dbb70b39c3fd0Brian Paul   }
16351e24d3318df57b36e3b68695ff64b4b8bd822c9eBrian Paul   _mesa_copy_context( &(xm_src->mesa), &(xm_dst->mesa), (GLuint) mask );
1636afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1637afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1638afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1639426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic Bool
1640426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXQueryExtension( Display *dpy, int *errorb, int *event )
1641afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
1642afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /* Mesa's GLX isn't really an X extension but we try to act like one. */
1643afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   (void) dpy;
1644afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   (void) errorb;
1645afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   (void) event;
1646afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   return True;
1647afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1648afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1649afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1650e7b16b74bf5d13331b5a88bbbbb9096560297b63Brian Paulextern void _kw_ungrab_all( Display *dpy );
1651afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtgvoid _kw_ungrab_all( Display *dpy )
1652afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
1653afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XUngrabPointer( dpy, CurrentTime );
1654afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XUngrabKeyboard( dpy, CurrentTime );
1655afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1656afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1657afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1658426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic void
1659426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXDestroyContext( Display *dpy, GLXContext ctx )
1660afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
16617cf50e137da497a590ec9001a9918972a6246142Brian Paul   struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
1662afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   (void) dpy;
1663afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   MakeCurrent_PrevContext = 0;
1664afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   MakeCurrent_PrevDrawable = 0;
1665086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul   MakeCurrent_PrevReadable = 0;
1666086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul   MakeCurrent_PrevDrawBuffer = 0;
1667086a151f942b2bcd8b9fbc56255e45b8c89b705eBrian Paul   MakeCurrent_PrevReadBuffer = 0;
16687cf50e137da497a590ec9001a9918972a6246142Brian Paul   XMesaDestroyContext( glxCtx->xmesaContext );
1669afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XMesaGarbageCollect();
16700c54e47c0e93f725b8bc028b0d4614011dbe3fefBrian Paul   _mesa_free(glxCtx);
1671afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1672afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1673afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1674426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic Bool
1675426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXIsDirect( Display *dpy, GLXContext ctx )
1676afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
16777cf50e137da497a590ec9001a9918972a6246142Brian Paul   struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
1678afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   (void) dpy;
16797cf50e137da497a590ec9001a9918972a6246142Brian Paul   return glxCtx->xmesaContext->direct;
1680afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1681afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1682afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1683afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1684426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic void
1685426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXSwapBuffers( Display *dpy, GLXDrawable drawable )
1686afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
1687afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1688afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1689afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (buffer) {
1690afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      XMesaSwapBuffers(buffer);
1691afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1692367d308b8267ad86cd7623590b7bfd4737b5fbf5Brian Paul   else if (_mesa_getenv("MESA_DEBUG")) {
1693ba0fe1832e3573c7ec872ba9bfb1cf1773e384c6Brian Paul      _mesa_warning(NULL, "glXSwapBuffers: invalid drawable 0x%x\n",
1694ba0fe1832e3573c7ec872ba9bfb1cf1773e384c6Brian Paul                    (int) drawable);
1695afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1696afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1697afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1698afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
16994c07bd5709830bd11cb29d4d8b8a56e757dc0365Brian Paul
1700b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_MESA_copy_sub_buffer ***/
1701b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul
1702426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic void
1703426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable,
1704426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul                           int x, int y, int width, int height )
1705afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
1706afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1707afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (buffer) {
1708afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      XMesaCopySubBuffer(buffer, x, y, width, height);
1709afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1710367d308b8267ad86cd7623590b7bfd4737b5fbf5Brian Paul   else if (_mesa_getenv("MESA_DEBUG")) {
1711d09a1d8b29ae5841ae39b5c24c3f4693dd750559Brian Paul      _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1712afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
1713afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1714afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1715afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1716426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic Bool
1717426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXQueryVersion( Display *dpy, int *maj, int *min )
1718afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
1719afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   (void) dpy;
1720afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   /* Return GLX version, not Mesa version */
172178fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul   assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION);
172278fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul   *maj = CLIENT_MAJOR_VERSION;
172378fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul   *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION );
1724afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   return True;
1725afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1726afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1727afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1728afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/*
1729afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Query the GLX attributes of the given XVisualInfo.
1730afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
1731426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic int
1732e4656003caee346d9c4eb23256d73409271291a7Brian Paulget_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig )
1733afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
1734e4656003caee346d9c4eb23256d73409271291a7Brian Paul   ASSERT(xmvis);
1735afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   switch(attrib) {
1736afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_USE_GL:
17371f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul         if (fbconfig)
17381f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            return GLX_BAD_ATTRIBUTE;
1739afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         *value = (int) True;
1740afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return 0;
1741afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_BUFFER_SIZE:
1742e4656003caee346d9c4eb23256d73409271291a7Brian Paul	 *value = xmvis->visinfo->depth;
1743afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return 0;
1744afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_LEVEL:
1745304d3aa9cb727eb4cd4797c33f8e13e5ac4285a9Ian Romanick	 *value = xmvis->mesa_visual.level;
1746afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return 0;
1747afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_RGBA:
17481f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul         if (fbconfig)
17491f98ee90228aa56df207cdbd223bb4b8c0bb15d9Brian Paul            return GLX_BAD_ATTRIBUTE;
1750e4656003caee346d9c4eb23256d73409271291a7Brian Paul	 if (xmvis->mesa_visual.rgbMode) {
1751afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    *value = True;
1752afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 }
1753afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 else {
1754afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	    *value = False;
1755afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 }
1756afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return 0;
1757afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_DOUBLEBUFFER:
1758e4656003caee346d9c4eb23256d73409271291a7Brian Paul	 *value = (int) xmvis->mesa_visual.doubleBufferMode;
1759afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return 0;
1760afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_STEREO:
1761e4656003caee346d9c4eb23256d73409271291a7Brian Paul	 *value = (int) xmvis->mesa_visual.stereoMode;
1762afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return 0;
1763afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_AUX_BUFFERS:
1764894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul	 *value = xmvis->mesa_visual.numAuxBuffers;
1765afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return 0;
1766afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_RED_SIZE:
1767e4656003caee346d9c4eb23256d73409271291a7Brian Paul         *value = xmvis->mesa_visual.redBits;
1768afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return 0;
1769afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_GREEN_SIZE:
1770e4656003caee346d9c4eb23256d73409271291a7Brian Paul         *value = xmvis->mesa_visual.greenBits;
1771afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return 0;
1772afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_BLUE_SIZE:
1773e4656003caee346d9c4eb23256d73409271291a7Brian Paul         *value = xmvis->mesa_visual.blueBits;
1774afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return 0;
1775afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_ALPHA_SIZE:
1776e4656003caee346d9c4eb23256d73409271291a7Brian Paul         *value = xmvis->mesa_visual.alphaBits;
1777afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return 0;
1778afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_DEPTH_SIZE:
1779e4656003caee346d9c4eb23256d73409271291a7Brian Paul         *value = xmvis->mesa_visual.depthBits;
1780afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return 0;
1781afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_STENCIL_SIZE:
1782e4656003caee346d9c4eb23256d73409271291a7Brian Paul	 *value = xmvis->mesa_visual.stencilBits;
1783afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return 0;
1784afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_ACCUM_RED_SIZE:
1785e4656003caee346d9c4eb23256d73409271291a7Brian Paul	 *value = xmvis->mesa_visual.accumRedBits;
1786b2e460018375f699198073a6167e0ee96ba1d267Brian Paul	 return 0;
1787afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_ACCUM_GREEN_SIZE:
1788e4656003caee346d9c4eb23256d73409271291a7Brian Paul	 *value = xmvis->mesa_visual.accumGreenBits;
1789b2e460018375f699198073a6167e0ee96ba1d267Brian Paul	 return 0;
1790afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_ACCUM_BLUE_SIZE:
1791e4656003caee346d9c4eb23256d73409271291a7Brian Paul	 *value = xmvis->mesa_visual.accumBlueBits;
1792afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return 0;
1793afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_ACCUM_ALPHA_SIZE:
1794e4656003caee346d9c4eb23256d73409271291a7Brian Paul         *value = xmvis->mesa_visual.accumAlphaBits;
1795afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return 0;
1796afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1797afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      /*
1798afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg       * GLX_EXT_visual_info extension
1799afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg       */
1800afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_X_VISUAL_TYPE_EXT:
1801e4656003caee346d9c4eb23256d73409271291a7Brian Paul         switch (xmvis->visinfo->CLASS) {
1802afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case StaticGray:   *value = GLX_STATIC_GRAY_EXT;   return 0;
1803afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case GrayScale:    *value = GLX_GRAY_SCALE_EXT;    return 0;
1804afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case StaticColor:  *value = GLX_STATIC_GRAY_EXT;   return 0;
1805afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case PseudoColor:  *value = GLX_PSEUDO_COLOR_EXT;  return 0;
1806afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case TrueColor:    *value = GLX_TRUE_COLOR_EXT;    return 0;
1807afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            case DirectColor:  *value = GLX_DIRECT_COLOR_EXT;  return 0;
1808afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
1809afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return 0;
1810afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_TRANSPARENT_TYPE_EXT:
1811304d3aa9cb727eb4cd4797c33f8e13e5ac4285a9Ian Romanick         if (xmvis->mesa_visual.level==0) {
1812afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            /* normal planes */
1813afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            *value = GLX_NONE_EXT;
1814afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
1815304d3aa9cb727eb4cd4797c33f8e13e5ac4285a9Ian Romanick         else if (xmvis->mesa_visual.level>0) {
1816afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            /* overlay */
1817e4656003caee346d9c4eb23256d73409271291a7Brian Paul            if (xmvis->mesa_visual.rgbMode) {
1818afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               *value = GLX_TRANSPARENT_RGB_EXT;
1819afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
1820afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            else {
1821afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               *value = GLX_TRANSPARENT_INDEX_EXT;
1822afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
1823afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
1824304d3aa9cb727eb4cd4797c33f8e13e5ac4285a9Ian Romanick         else if (xmvis->mesa_visual.level<0) {
1825afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            /* underlay */
1826afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            *value = GLX_NONE_EXT;
1827afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
1828afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return 0;
1829afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1830afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         {
1831e4656003caee346d9c4eb23256d73409271291a7Brian Paul            int pixel = transparent_pixel( xmvis );
1832afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            if (pixel>=0) {
1833afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg               *value = pixel;
1834afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            }
1835afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg            /* else undefined */
1836afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         }
1837afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return 0;
1838afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_TRANSPARENT_RED_VALUE_EXT:
1839afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* undefined */
1840afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return 0;
1841afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1842afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* undefined */
1843afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return 0;
1844afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1845afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* undefined */
1846afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return 0;
1847afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1848afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         /* undefined */
1849afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return 0;
1850afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1851afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      /*
1852b2e460018375f699198073a6167e0ee96ba1d267Brian Paul       * GLX_EXT_visual_info extension
1853b2e460018375f699198073a6167e0ee96ba1d267Brian Paul       */
1854b2e460018375f699198073a6167e0ee96ba1d267Brian Paul      case GLX_VISUAL_CAVEAT_EXT:
1855fc68be6b111473a0bf8f991468f973bb9dd275f4Brian Paul         /* test for zero, just in case */
1856304d3aa9cb727eb4cd4797c33f8e13e5ac4285a9Ian Romanick         if (xmvis->mesa_visual.visualRating > 0)
1857304d3aa9cb727eb4cd4797c33f8e13e5ac4285a9Ian Romanick            *value = xmvis->mesa_visual.visualRating;
1858962f4269153ba954e137aab94ff4eaad4a7b02aeBrian Paul         else
1859962f4269153ba954e137aab94ff4eaad4a7b02aeBrian Paul            *value = GLX_NONE_EXT;
1860962f4269153ba954e137aab94ff4eaad4a7b02aeBrian Paul         return 0;
1861b2e460018375f699198073a6167e0ee96ba1d267Brian Paul
1862b2e460018375f699198073a6167e0ee96ba1d267Brian Paul      /*
186366ab7271016615cf485fb0b71832833d2e0f99a7Brian Paul       * GLX_ARB_multisample
1864afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg       */
186566ab7271016615cf485fb0b71832833d2e0f99a7Brian Paul      case GLX_SAMPLE_BUFFERS_ARB:
18663265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         *value = 0;
18673265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         return 0;
186866ab7271016615cf485fb0b71832833d2e0f99a7Brian Paul      case GLX_SAMPLES_ARB:
18693265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         *value = 0;
18703265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         return 0;
18713265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul
18723265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      /*
18733265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul       * For FBConfigs:
18743265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul       */
18753265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      case GLX_SCREEN_EXT:
18763265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         if (!fbconfig)
18773265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            return GLX_BAD_ATTRIBUTE;
1878e4656003caee346d9c4eb23256d73409271291a7Brian Paul         *value = xmvis->visinfo->screen;
18793265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         break;
18803265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      case GLX_DRAWABLE_TYPE: /*SGIX too */
18813265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         if (!fbconfig)
18823265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            return GLX_BAD_ATTRIBUTE;
18833265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         *value = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
18843265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         break;
18853265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      case GLX_RENDER_TYPE_SGIX:
18863265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         if (!fbconfig)
18873265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            return GLX_BAD_ATTRIBUTE;
1888e4656003caee346d9c4eb23256d73409271291a7Brian Paul         if (xmvis->mesa_visual.rgbMode)
18893265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            *value = GLX_RGBA_BIT;
18903265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         else
18913265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            *value = GLX_COLOR_INDEX_BIT;
18923265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         break;
18933265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      case GLX_X_RENDERABLE_SGIX:
18943265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         if (!fbconfig)
18953265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            return GLX_BAD_ATTRIBUTE;
18963265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         *value = True; /* XXX really? */
18973265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         break;
18983265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      case GLX_FBCONFIG_ID_SGIX:
18993265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         if (!fbconfig)
19003265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            return GLX_BAD_ATTRIBUTE;
1901f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul         *value = xmvis->visinfo->visualid;
19023265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         break;
19033265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      case GLX_MAX_PBUFFER_WIDTH:
19043265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         if (!fbconfig)
19053265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            return GLX_BAD_ATTRIBUTE;
19063265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         /* XXX or MAX_WIDTH? */
1907f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul         *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen);
19083265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         break;
19093265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      case GLX_MAX_PBUFFER_HEIGHT:
19103265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         if (!fbconfig)
19113265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            return GLX_BAD_ATTRIBUTE;
1912f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul         *value = DisplayHeight(xmvis->display, xmvis->visinfo->screen);
19133265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         break;
19143265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      case GLX_MAX_PBUFFER_PIXELS:
19153265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         if (!fbconfig)
19163265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            return GLX_BAD_ATTRIBUTE;
1917f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul         *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen) *
1918f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul                  DisplayHeight(xmvis->display, xmvis->visinfo->screen);
19193265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         break;
19203265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      case GLX_VISUAL_ID:
19213265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         if (!fbconfig)
19223265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            return GLX_BAD_ATTRIBUTE;
1923f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul         *value = xmvis->visinfo->visualid;
19243265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         break;
19253265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul
1926fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian#ifdef GLX_EXT_texture_from_pixmap
1927fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      case GLX_BIND_TO_TEXTURE_RGB_EXT:
1928fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         *value = True; /*XXX*/
1929fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         break;
1930fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      case GLX_BIND_TO_TEXTURE_RGBA_EXT:
1931fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         /* XXX review */
1932fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         *value = xmvis->mesa_visual.alphaBits > 0 ? True : False;
1933fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         break;
1934fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
1935fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         *value = True; /*XXX*/
1936fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         break;
1937fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
1938fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         *value = (GLX_TEXTURE_1D_BIT_EXT |
1939fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian                   GLX_TEXTURE_2D_BIT_EXT |
1940fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian                   GLX_TEXTURE_RECTANGLE_BIT_EXT); /*XXX*/
1941fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         break;
1942fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      case GLX_Y_INVERTED_EXT:
1943a10ba38df7ac80e36db15aaae9f78e7223b2bfaeBrian         *value = True; /*XXX*/
1944fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         break;
1945fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian#endif
1946fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian
1947afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      default:
1948afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return GLX_BAD_ATTRIBUTE;
1949afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
19503265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   return Success;
1951afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1952afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1953afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
19543265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paulstatic int
19553265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian PaulFake_glXGetConfig( Display *dpy, XVisualInfo *visinfo,
19563265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul                   int attrib, int *value )
19573265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul{
1958e4656003caee346d9c4eb23256d73409271291a7Brian Paul   XMesaVisual xmvis;
1959ba0fe1832e3573c7ec872ba9bfb1cf1773e384c6Brian Paul   int k;
1960379641956d134b8dc761b6411d7c4dca8f94a092Brian Paul   if (!dpy || !visinfo)
1961a9a1c3f20f2d6aad4afc47cf2b29c5393fddb6b6Brian Paul      return GLX_BAD_ATTRIBUTE;
1962a9a1c3f20f2d6aad4afc47cf2b29c5393fddb6b6Brian Paul
1963e4656003caee346d9c4eb23256d73409271291a7Brian Paul   xmvis = find_glx_visual( dpy, visinfo );
1964e4656003caee346d9c4eb23256d73409271291a7Brian Paul   if (!xmvis) {
19653265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      /* this visual wasn't obtained with glXChooseVisual */
1966e4656003caee346d9c4eb23256d73409271291a7Brian Paul      xmvis = create_glx_visual( dpy, visinfo );
1967e4656003caee346d9c4eb23256d73409271291a7Brian Paul      if (!xmvis) {
19683265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul	 /* this visual can't be used for GL rendering */
19693265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul	 if (attrib==GLX_USE_GL) {
19703265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul	    *value = (int) False;
19713265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul	    return 0;
19723265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul	 }
19733265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul	 else {
19743265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul	    return GLX_BAD_VISUAL;
19753265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul	 }
19763265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      }
19773265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   }
19783265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul
1979ba0fe1832e3573c7ec872ba9bfb1cf1773e384c6Brian Paul   k = get_config(xmvis, attrib, value, GL_FALSE);
1980ba0fe1832e3573c7ec872ba9bfb1cf1773e384c6Brian Paul   return k;
19813265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul}
19823265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul
1983afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1984426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic void
1985426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXWaitGL( void )
1986afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
1987afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XMesaContext xmesa = XMesaGetCurrentContext();
1988afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XMesaFlush( xmesa );
1989afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1990afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1991afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1992afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1993426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic void
1994426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXWaitX( void )
1995afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
1996afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XMesaContext xmesa = XMesaGetCurrentContext();
1997afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   XMesaFlush( xmesa );
1998afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
1999afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2000afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2001e4656003caee346d9c4eb23256d73409271291a7Brian Paulstatic const char *
2002e4656003caee346d9c4eb23256d73409271291a7Brian Paulget_extensions( void )
200343c9c2cfae458cf0d7618af5f25d57c0a5ebae08Brian Paul{
2004d60009bd6dba15d094b0d0bcb8180b7a2e1c1708George Sapountzis#ifdef FX
2005d60009bd6dba15d094b0d0bcb8180b7a2e1c1708George Sapountzis   const char *fx = _mesa_getenv("MESA_GLX_FX");
2006d60009bd6dba15d094b0d0bcb8180b7a2e1c1708George Sapountzis   if (fx && fx[0] != 'd') {
2007d60009bd6dba15d094b0d0bcb8180b7a2e1c1708George Sapountzis      return EXTENSIONS;
2008d60009bd6dba15d094b0d0bcb8180b7a2e1c1708George Sapountzis   }
2009d60009bd6dba15d094b0d0bcb8180b7a2e1c1708George Sapountzis#endif
2010e4656003caee346d9c4eb23256d73409271291a7Brian Paul   return EXTENSIONS + 23; /* skip "GLX_MESA_set_3dfx_mode" */
201143c9c2cfae458cf0d7618af5f25d57c0a5ebae08Brian Paul}
2012afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2013afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2014afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2015afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* GLX 1.1 and later */
2016426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic const char *
2017426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXQueryExtensionsString( Display *dpy, int screen )
2018afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
2019afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   (void) dpy;
2020afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   (void) screen;
202143c9c2cfae458cf0d7618af5f25d57c0a5ebae08Brian Paul   return get_extensions();
2022afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
2023afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2024afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2025afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2026afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* GLX 1.1 and later */
2027426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic const char *
2028426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXQueryServerString( Display *dpy, int screen, int name )
2029afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
203078fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul   static char version[1000];
20312ad5921cf3c9737796c3485bd5b9f738fb4a3cb9Brian Paul   _mesa_sprintf(version, "%d.%d %s",
20322ad5921cf3c9737796c3485bd5b9f738fb4a3cb9Brian Paul                 SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, MESA_GLX_VERSION);
2033afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2034afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   (void) dpy;
2035afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   (void) screen;
2036afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2037afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   switch (name) {
2038afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_EXTENSIONS:
203943c9c2cfae458cf0d7618af5f25d57c0a5ebae08Brian Paul         return get_extensions();
2040afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_VENDOR:
204178fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul	 return VENDOR;
2042afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_VERSION:
2043afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return version;
2044afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      default:
2045afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return NULL;
2046afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
2047afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
2048afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2049afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2050afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2051afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* GLX 1.1 and later */
2052426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic const char *
2053426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXGetClientString( Display *dpy, int name )
2054afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
205578fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul   static char version[1000];
20562ad5921cf3c9737796c3485bd5b9f738fb4a3cb9Brian Paul   _mesa_sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION,
20572ad5921cf3c9737796c3485bd5b9f738fb4a3cb9Brian Paul                 CLIENT_MINOR_VERSION, MESA_GLX_VERSION);
2058afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2059afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   (void) dpy;
2060afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2061afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   switch (name) {
2062afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_EXTENSIONS:
206343c9c2cfae458cf0d7618af5f25d57c0a5ebae08Brian Paul         return get_extensions();
2064afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_VENDOR:
206578fc78e0f68a20ae90f3d4aaf361751a9185a0b9Brian Paul	 return VENDOR;
2066afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      case GLX_VERSION:
2067afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg	 return version;
2068afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      default:
2069afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg         return NULL;
2070afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
2071afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
2072afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2073afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2074afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2075426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul/*
2076426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul * GLX 1.3 and later
2077426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul */
2078426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
20797d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul
2080426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic int
2081426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
2082426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul                           int attribute, int *value )
2083426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
20843265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   XMesaVisual v = (XMesaVisual) config;
2085426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   (void) dpy;
2086426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   (void) config;
20877d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul
20887d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   if (!dpy || !config || !value)
20897d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      return -1;
20907d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul
20913265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   return get_config(v, attribute, value, GL_TRUE);
2092426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
2093426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2094426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
20955605798e56ca6e9f968623f33b58ee7ca90594afBrian Paulstatic GLXFBConfig *
20965605798e56ca6e9f968623f33b58ee7ca90594afBrian PaulFake_glXGetFBConfigs( Display *dpy, int screen, int *nelements )
20975605798e56ca6e9f968623f33b58ee7ca90594afBrian Paul{
20983265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   XVisualInfo *visuals, visTemplate;
20993265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   const long visMask = VisualScreenMask;
21003265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   int i;
21013265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul
21023265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   /* Get list of all X visuals */
21033265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   visTemplate.screen = screen;
21043265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   visuals = XGetVisualInfo(dpy, visMask, &visTemplate, nelements);
21053265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   if (*nelements > 0) {
21063265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      XMesaVisual *results;
21074039cb8ca82d59451a6de8902fe35e693cdca3baBrian Paul      results = (XMesaVisual *) _mesa_malloc(*nelements * sizeof(XMesaVisual));
21083265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      if (!results) {
21093265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         *nelements = 0;
21103265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         return NULL;
21113265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      }
21123265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      for (i = 0; i < *nelements; i++) {
21133265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         results[i] = create_glx_visual(dpy, visuals + i);
21143265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      }
21153265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      return (GLXFBConfig *) results;
21163265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   }
21173265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   return NULL;
21185605798e56ca6e9f968623f33b58ee7ca90594afBrian Paul}
21195605798e56ca6e9f968623f33b58ee7ca90594afBrian Paul
21205605798e56ca6e9f968623f33b58ee7ca90594afBrian Paul
2121481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paulstatic GLXFBConfig *
2122481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian PaulFake_glXChooseFBConfig( Display *dpy, int screen,
2123481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul                        const int *attribList, int *nitems )
2124481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul{
2125481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul   XMesaVisual xmvis;
2126481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul
2127481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul   if (!attribList || !attribList[0]) {
2128481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul      /* return list of all configs (per GLX_SGIX_fbconfig spec) */
2129481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul      return Fake_glXGetFBConfigs(dpy, screen, nitems);
2130481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul   }
2131481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul
2132481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul   xmvis = choose_visual(dpy, screen, attribList, GL_TRUE);
2133481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul   if (xmvis) {
2134481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul      GLXFBConfig *config = (GLXFBConfig *) _mesa_malloc(sizeof(XMesaVisual));
2135481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul      if (!config) {
2136481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul         *nitems = 0;
2137481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul         return NULL;
2138481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul      }
2139481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul      *nitems = 1;
2140481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul      config[0] = (GLXFBConfig) xmvis;
2141481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul      return (GLXFBConfig *) config;
2142481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul   }
2143481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul   else {
2144481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul      *nitems = 0;
2145481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul      return NULL;
2146481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul   }
2147481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul}
2148481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul
2149481bdd383ac309cda8e471215b8fd3d6b5fa8cadBrian Paul
2150426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic XVisualInfo *
2151426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
2152426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
21537d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   if (dpy && config) {
2154f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      XMesaVisual xmvis = (XMesaVisual) config;
2155f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul#if 0
2156f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      return xmvis->vishandle;
2157f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul#else
2158f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      /* create a new vishandle - the cached one may be stale */
21594039cb8ca82d59451a6de8902fe35e693cdca3baBrian Paul      xmvis->vishandle = (XVisualInfo *) _mesa_malloc(sizeof(XVisualInfo));
2160f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      if (xmvis->vishandle) {
2161f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul         _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
2162f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      }
2163f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      return xmvis->vishandle;
2164f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul#endif
21657d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   }
21667d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   else {
21677d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      return NULL;
21687d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   }
2169426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
2170426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2171426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2172426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic GLXWindow
2173426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXCreateWindow( Display *dpy, GLXFBConfig config, Window win,
2174426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul                      const int *attribList )
2175426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
2176529614cd1a1e426ca7ad019795a6b72ad51cd9e6Brian Paul   XMesaVisual xmvis = (XMesaVisual) config;
2177529614cd1a1e426ca7ad019795a6b72ad51cd9e6Brian Paul   XMesaBuffer xmbuf;
2178529614cd1a1e426ca7ad019795a6b72ad51cd9e6Brian Paul   if (!xmvis)
2179529614cd1a1e426ca7ad019795a6b72ad51cd9e6Brian Paul      return 0;
2180529614cd1a1e426ca7ad019795a6b72ad51cd9e6Brian Paul
21816aa5668871e7f366b33e85fabc72885fc269a7d4George Sapountzis   xmbuf = XMesaCreateWindowBuffer(xmvis, win);
2182529614cd1a1e426ca7ad019795a6b72ad51cd9e6Brian Paul   if (!xmbuf)
2183529614cd1a1e426ca7ad019795a6b72ad51cd9e6Brian Paul      return 0;
2184529614cd1a1e426ca7ad019795a6b72ad51cd9e6Brian Paul
21856aa5668871e7f366b33e85fabc72885fc269a7d4George Sapountzis#ifdef FX
21866aa5668871e7f366b33e85fabc72885fc269a7d4George Sapountzis   /* XXX this will segfault if actually called */
21876aa5668871e7f366b33e85fabc72885fc269a7d4George Sapountzis   FXcreateContext(xmvis, win, NULL, xmbuf);
21886aa5668871e7f366b33e85fabc72885fc269a7d4George Sapountzis#endif
21896aa5668871e7f366b33e85fabc72885fc269a7d4George Sapountzis
2190426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   (void) dpy;
21917d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   (void) attribList;  /* Ignored in GLX 1.3 */
21927d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul
21937d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   return win;  /* A hack for now */
2194426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
2195426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2196426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2197426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic void
2198426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXDestroyWindow( Display *dpy, GLXWindow window )
2199426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
22007d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable) window);
22017d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   if (b)
22027d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      XMesaDestroyBuffer(b);
22037d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   /* don't destroy X window */
2204426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
2205426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2206426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
22077d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul/* XXX untested */
2208426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic GLXPixmap
2209426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap,
2210426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul                      const int *attribList )
2211426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
22127d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   XMesaVisual v = (XMesaVisual) config;
22137d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   XMesaBuffer b;
2214fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   const int *attr;
2215fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   int target = 0, format = 0, mipmap = 0;
2216fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   int value;
22177d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul
22187d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   if (!dpy || !config || !pixmap)
22197d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      return 0;
22207d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul
2221d18c57aaeac37cde0cb551191ecd3c3a56a0ffbaBrian Paul   for (attr = attribList; attr && *attr; attr++) {
2222fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      switch (*attr) {
2223fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      case GLX_TEXTURE_FORMAT_EXT:
2224fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         attr++;
2225fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         switch (*attr) {
2226fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         case GLX_TEXTURE_FORMAT_NONE_EXT:
2227fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         case GLX_TEXTURE_FORMAT_RGB_EXT:
2228fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         case GLX_TEXTURE_FORMAT_RGBA_EXT:
2229fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            format = *attr;
2230fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            break;
2231fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         default:
2232fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            /* error */
2233fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            return 0;
2234fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         }
2235fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         break;
2236fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      case GLX_TEXTURE_TARGET_EXT:
2237fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         attr++;
2238fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         switch (*attr) {
2239fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         case GLX_TEXTURE_1D_EXT:
2240fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         case GLX_TEXTURE_2D_EXT:
2241fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         case GLX_TEXTURE_RECTANGLE_EXT:
2242fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            target = *attr;
2243fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            break;
2244fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         default:
2245fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            /* error */
2246fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            return 0;
2247fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         }
2248fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         break;
2249fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      case GLX_MIPMAP_TEXTURE_EXT:
2250fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         attr++;
2251fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         if (*attr)
2252fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian            mipmap = 1;
2253fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         break;
2254fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      default:
2255fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         /* error */
2256fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         return 0;
2257fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      }
2258fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   }
2259fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian
2260fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   if (format == GLX_TEXTURE_FORMAT_RGB_EXT) {
2261fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      if (get_config(v, GLX_BIND_TO_TEXTURE_RGB_EXT,
2262fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian                     &value, GL_TRUE) != Success
2263fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian          || !value) {
2264fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         return 0; /* error! */
2265fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      }
2266fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   }
2267fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   else if (format == GLX_TEXTURE_FORMAT_RGBA_EXT) {
2268fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      if (get_config(v, GLX_BIND_TO_TEXTURE_RGBA_EXT,
2269fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian                     &value, GL_TRUE) != Success
2270fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian          || !value) {
2271fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         return 0; /* error! */
2272fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      }
2273fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   }
2274fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   if (mipmap) {
2275fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      if (get_config(v, GLX_BIND_TO_MIPMAP_TEXTURE_EXT,
2276fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian                     &value, GL_TRUE) != Success
2277fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian          || !value) {
2278fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         return 0; /* error! */
2279fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      }
2280fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   }
2281fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   if (target == GLX_TEXTURE_1D_EXT) {
2282fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
2283fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian                     &value, GL_TRUE) != Success
2284fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian          || (value & GLX_TEXTURE_1D_BIT_EXT) == 0) {
2285fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         return 0; /* error! */
2286fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      }
2287fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   }
2288fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   else if (target == GLX_TEXTURE_2D_EXT) {
2289fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
2290fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian                     &value, GL_TRUE) != Success
2291fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian          || (value & GLX_TEXTURE_2D_BIT_EXT) == 0) {
2292fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         return 0; /* error! */
2293fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      }
2294fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   }
2295fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   if (target == GLX_TEXTURE_RECTANGLE_EXT) {
2296fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
2297fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian                     &value, GL_TRUE) != Success
2298fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian          || (value & GLX_TEXTURE_RECTANGLE_BIT_EXT) == 0) {
2299fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         return 0; /* error! */
2300fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      }
2301fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   }
2302fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian
2303fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   if (format || target || mipmap) {
2304fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      /* texture from pixmap */
2305fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      b = XMesaCreatePixmapTextureBuffer(v, pixmap, 0, format, target, mipmap);
2306fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   }
2307fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   else {
2308fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
2309fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   }
23107d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   if (!b) {
23117d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      return 0;
23127d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   }
23137d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul
23147d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   return pixmap;
2315426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
2316426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2317426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2318426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic void
2319426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
2320426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
23217d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable)pixmap);
23227d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   if (b)
23237d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      XMesaDestroyBuffer(b);
23247d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   /* don't destroy X pixmap */
2325426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
2326426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2327426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2328426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic GLXPbuffer
2329426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXCreatePbuffer( Display *dpy, GLXFBConfig config,
2330426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul                       const int *attribList )
2331426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
23323265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   XMesaVisual xmvis = (XMesaVisual) config;
23333265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   XMesaBuffer xmbuf;
23347d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   const int *attrib;
23357d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   int width = 0, height = 0;
23367d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
23377d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul
2338426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   (void) dpy;
23397d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul
23403265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   for (attrib = attribList; *attrib; attrib++) {
23417d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      switch (*attrib) {
23427d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul         case GLX_PBUFFER_WIDTH:
23433265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            attrib++;
23443265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            width = *attrib;
23457d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul            break;
23467d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul         case GLX_PBUFFER_HEIGHT:
23473265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            attrib++;
23483265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            height = *attrib;
23497d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul            break;
23507d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul         case GLX_PRESERVED_CONTENTS:
23513265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            attrib++;
23523265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            preserveContents = *attrib; /* ignored */
23537d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul            break;
23547d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul         case GLX_LARGEST_PBUFFER:
23553265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            attrib++;
23563265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            useLargest = *attrib; /* ignored */
23577d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul            break;
23587d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul         default:
23597d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul            return 0;
23607d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      }
23617d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   }
23627d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul
2363b305028464f02947c0cce0476af0e35f4ed1fafaBrian Paul   /* not used at this time */
2364b305028464f02947c0cce0476af0e35f4ed1fafaBrian Paul   (void) useLargest;
2365b305028464f02947c0cce0476af0e35f4ed1fafaBrian Paul   (void) preserveContents;
2366b305028464f02947c0cce0476af0e35f4ed1fafaBrian Paul
23677d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   if (width == 0 || height == 0)
23687d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      return 0;
23697d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul
23703265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2371e4656003caee346d9c4eb23256d73409271291a7Brian Paul   /* A GLXPbuffer handle must be an X Drawable because that's what
2372e4656003caee346d9c4eb23256d73409271291a7Brian Paul    * glXMakeCurrent takes.
2373e4656003caee346d9c4eb23256d73409271291a7Brian Paul    */
2374dd1a9f75dc1d29e3383f27aaa1cf024c83e5c8e2Brian Paul   if (xmbuf)
2375dd1a9f75dc1d29e3383f27aaa1cf024c83e5c8e2Brian Paul      return (GLXPbuffer) xmbuf->frontxrb->pixmap;
2376dd1a9f75dc1d29e3383f27aaa1cf024c83e5c8e2Brian Paul   else
2377dd1a9f75dc1d29e3383f27aaa1cf024c83e5c8e2Brian Paul      return 0;
2378426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
2379426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2380426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2381426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic void
2382426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
2383426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
2384e4656003caee346d9c4eb23256d73409271291a7Brian Paul   XMesaBuffer b = XMesaFindBuffer(dpy, pbuf);
2385e4656003caee346d9c4eb23256d73409271291a7Brian Paul   if (b) {
2386e4656003caee346d9c4eb23256d73409271291a7Brian Paul      XMesaDestroyBuffer(b);
2387e4656003caee346d9c4eb23256d73409271291a7Brian Paul   }
2388426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
2389426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2390426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2391426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic void
2392426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
2393426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul                       unsigned int *value )
2394426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
2395e4656003caee346d9c4eb23256d73409271291a7Brian Paul   XMesaBuffer xmbuf = XMesaFindBuffer(dpy, draw);
2396e4656003caee346d9c4eb23256d73409271291a7Brian Paul   if (!xmbuf)
2397e4656003caee346d9c4eb23256d73409271291a7Brian Paul      return;
23987d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul
23997d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   switch (attribute) {
24007d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      case GLX_WIDTH:
240129926a11b16ec7a235947d95e9a46777605dd30eBrian Paul         *value = xmbuf->mesa_buffer.Width;
2402e4656003caee346d9c4eb23256d73409271291a7Brian Paul         break;
24037d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      case GLX_HEIGHT:
240429926a11b16ec7a235947d95e9a46777605dd30eBrian Paul         *value = xmbuf->mesa_buffer.Height;
2405e4656003caee346d9c4eb23256d73409271291a7Brian Paul         break;
24067d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      case GLX_PRESERVED_CONTENTS:
2407e4656003caee346d9c4eb23256d73409271291a7Brian Paul         *value = True;
2408e4656003caee346d9c4eb23256d73409271291a7Brian Paul         break;
24097d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      case GLX_LARGEST_PBUFFER:
241029926a11b16ec7a235947d95e9a46777605dd30eBrian Paul         *value = xmbuf->mesa_buffer.Width * xmbuf->mesa_buffer.Height;
2411e4656003caee346d9c4eb23256d73409271291a7Brian Paul         break;
24127d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      case GLX_FBCONFIG_ID:
2413f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul         *value = xmbuf->xm_visual->visinfo->visualid;
24147d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul         return;
2415fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian#ifdef GLX_EXT_texture_from_pixmap
2416fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      case GLX_TEXTURE_FORMAT_EXT:
2417fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         *value = xmbuf->TextureFormat;
2418fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         break;
2419fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      case GLX_TEXTURE_TARGET_EXT:
2420fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         *value = xmbuf->TextureTarget;
2421fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         break;
2422fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      case GLX_MIPMAP_TEXTURE_EXT:
2423fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         *value = xmbuf->TextureMipmap;
2424fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         break;
2425fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian#endif
2426fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian
24277d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      default:
2428fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian         return; /* raise BadValue error */
24297d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   }
2430426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
2431426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2432426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2433426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic GLXContext
2434426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXCreateNewContext( Display *dpy, GLXFBConfig config,
2435426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul                          int renderType, GLXContext shareList, Bool direct )
2436426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
2437f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul   struct fake_glx_context *glxCtx;
2438f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul   struct fake_glx_context *shareCtx = (struct fake_glx_context *) shareList;
2439f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul   XMesaVisual xmvis = (XMesaVisual) config;
24407d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul
24417d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   if (!dpy || !config ||
24427d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul       (renderType != GLX_RGBA_TYPE && renderType != GLX_COLOR_INDEX_TYPE))
24437d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      return 0;
24447d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul
2445f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul   glxCtx = CALLOC_STRUCT(fake_glx_context);
2446f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul   if (!glxCtx)
2447f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      return 0;
2448f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul
2449f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul   /* deallocate unused windows/buffers */
2450f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul   XMesaGarbageCollect();
2451f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul
2452f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul   glxCtx->xmesaContext = XMesaCreateContext(xmvis,
2453f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul                                   shareCtx ? shareCtx->xmesaContext : NULL);
2454f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul   if (!glxCtx->xmesaContext) {
24550c54e47c0e93f725b8bc028b0d4614011dbe3fefBrian Paul      _mesa_free(glxCtx);
2456f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      return NULL;
2457f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul   }
2458f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul
245949e80bf6b163310f7cd776261872201eea57053aBrian Paul   init_glx_context(glxCtx, dpy);
2460f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul
2461f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul   return (GLXContext) glxCtx;
2462426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
2463426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2464426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2465426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic int
2466426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
2467426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
2468e4656003caee346d9c4eb23256d73409271291a7Brian Paul   struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
2469e4656003caee346d9c4eb23256d73409271291a7Brian Paul   XMesaContext xmctx = glxCtx->xmesaContext;
2470e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2471426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   (void) dpy;
2472426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   (void) ctx;
24737d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul
24747d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   switch (attribute) {
24757d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   case GLX_FBCONFIG_ID:
2476f104619b8f6ece7a60aa365c859b03fbc1d74592Brian Paul      *value = xmctx->xm_visual->visinfo->visualid;
2477e4656003caee346d9c4eb23256d73409271291a7Brian Paul      break;
24787d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   case GLX_RENDER_TYPE:
2479e4656003caee346d9c4eb23256d73409271291a7Brian Paul      if (xmctx->xm_visual->mesa_visual.rgbMode)
248086ee448047e4f7be722b69da5296ccafc2307145Brian Paul         *value = GLX_RGBA_TYPE;
2481e4656003caee346d9c4eb23256d73409271291a7Brian Paul      else
248286ee448047e4f7be722b69da5296ccafc2307145Brian Paul         *value = GLX_COLOR_INDEX_TYPE;
2483e4656003caee346d9c4eb23256d73409271291a7Brian Paul      break;
24847d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   case GLX_SCREEN:
24857d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      *value = 0;
24867d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      return Success;
24877d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   default:
24887d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul      return GLX_BAD_ATTRIBUTE;
24897d5656bee7d3e0c4ba54005c7af6f59f4bf8aea0Brian Paul   }
2490e4656003caee346d9c4eb23256d73409271291a7Brian Paul   return 0;
2491426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
2492426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2493426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2494426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic void
2495426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask )
2496426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
2497e4656003caee346d9c4eb23256d73409271291a7Brian Paul   XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2498e4656003caee346d9c4eb23256d73409271291a7Brian Paul   if (xmbuf)
2499e4656003caee346d9c4eb23256d73409271291a7Brian Paul      xmbuf->selectedEvents = mask;
2500426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
2501426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2502426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2503426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic void
2504426cb9f58f194a1e30e0908e8fc971bdcae06960Brian PaulFake_glXGetSelectedEvent( Display *dpy, GLXDrawable drawable,
2505426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul                          unsigned long *mask )
2506426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
2507e4656003caee346d9c4eb23256d73409271291a7Brian Paul   XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2508e4656003caee346d9c4eb23256d73409271291a7Brian Paul   if (xmbuf)
2509e4656003caee346d9c4eb23256d73409271291a7Brian Paul      *mask = xmbuf->selectedEvents;
2510e4656003caee346d9c4eb23256d73409271291a7Brian Paul   else
2511e4656003caee346d9c4eb23256d73409271291a7Brian Paul      *mask = 0;
2512426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
2513b82d993b03320818f88f792a9e713f7ed491bfcbBrian Paul
2514b82d993b03320818f88f792a9e713f7ed491bfcbBrian Paul
2515b82d993b03320818f88f792a9e713f7ed491bfcbBrian Paul
2516b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_SGI_swap_control ***/
2517783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2518783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic int
2519783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXSwapIntervalSGI(int interval)
2520783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2521783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) interval;
2522783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return 0;
2523783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2524783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2525783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2526783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2527b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_SGI_video_sync ***/
2528783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2529ee061060826df059f0ddb904a2160ed610423579Brian Paulstatic unsigned int FrameCounter = 0;
2530ee061060826df059f0ddb904a2160ed610423579Brian Paul
2531783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic int
2532783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXGetVideoSyncSGI(unsigned int *count)
2533783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2534ee061060826df059f0ddb904a2160ed610423579Brian Paul   /* this is a bogus implementation */
2535ee061060826df059f0ddb904a2160ed610423579Brian Paul   *count = FrameCounter++;
2536783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return 0;
2537783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2538783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2539783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic int
2540783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
2541783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2542ee061060826df059f0ddb904a2160ed610423579Brian Paul   if (divisor <= 0 || remainder < 0)
2543ee061060826df059f0ddb904a2160ed610423579Brian Paul      return GLX_BAD_VALUE;
2544ee061060826df059f0ddb904a2160ed610423579Brian Paul   /* this is a bogus implementation */
2545ee061060826df059f0ddb904a2160ed610423579Brian Paul   FrameCounter++;
2546ee061060826df059f0ddb904a2160ed610423579Brian Paul   while (FrameCounter % divisor != remainder)
2547ee061060826df059f0ddb904a2160ed610423579Brian Paul      FrameCounter++;
2548ee061060826df059f0ddb904a2160ed610423579Brian Paul   *count = FrameCounter;
2549783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return 0;
2550783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2551783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2552783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2553783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2554b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_SGI_make_current_read ***/
2555783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2556426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic Bool
2557783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
2558afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
2559a078d75a27b99252ede6520e24b145106ab98aa2Brian Paul   return Fake_glXMakeContextCurrent( dpy, draw, read, ctx );
2560afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
2561783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
25627cf50e137da497a590ec9001a9918972a6246142Brian Paul/* not used
2563783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic GLXDrawable
2564b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian PaulFake_glXGetCurrentReadDrawableSGI(void)
2565783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2566783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return 0;
2567783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
25687cf50e137da497a590ec9001a9918972a6246142Brian Paul*/
2569afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2570afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
2571b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_SGIX_video_source ***/
2572b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul#if defined(_VL_H)
25734c07bd5709830bd11cb29d4d8b8a56e757dc0365Brian Paul
2574783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic GLXVideoSourceSGIX
2575783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode)
2576afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
2577783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2578783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) screen;
2579783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) server;
2580783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) path;
2581783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) nodeClass;
2582783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) drainNode;
2583783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return 0;
2584783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2585783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2586783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic void
2587783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src)
2588783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2589783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2590783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) src;
2591afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
2592783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
25934c07bd5709830bd11cb29d4d8b8a56e757dc0365Brian Paul#endif
25944c07bd5709830bd11cb29d4d8b8a56e757dc0365Brian Paul
259589a42b7e736bd9b0ab090906cab0cd047a6ec12eBrian Paul
2596b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_EXT_import_context ***/
259789a42b7e736bd9b0ab090906cab0cd047a6ec12eBrian Paul
2598783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic void
2599783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXFreeContextEXT(Display *dpy, GLXContext context)
2600783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2601783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2602783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) context;
2603783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2604426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2605783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic GLXContextID
2606783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXGetContextIDEXT(const GLXContext context)
2607783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2608783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) context;
2609783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return 0;
2610783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2611783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2612783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic GLXContext
2613783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXImportContextEXT(Display *dpy, GLXContextID contextID)
2614783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2615783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2616783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) contextID;
2617783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return 0;
2618783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2619426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2620426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic int
2621783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute, int *value)
2622426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
2623783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2624783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) context;
2625783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) attribute;
2626783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) value;
2627426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   return 0;
2628426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
2629426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2630783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2631783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2632b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_SGIX_fbconfig ***/
2633426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2634426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paulstatic int
2635783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value)
2636783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
26373265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   return Fake_glXGetFBConfigAttrib(dpy, config, attribute, value);
2638783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2639783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2640783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic GLXFBConfigSGIX *
2641783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list, int *nelements)
2642783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
26433265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   return (GLXFBConfig *) Fake_glXChooseFBConfig(dpy, screen, attrib_list, nelements);
2644783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2645783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2646e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2647783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic GLXPixmap
2648783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap)
2649783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2650e4656003caee346d9c4eb23256d73409271291a7Brian Paul   XMesaVisual xmvis = (XMesaVisual) config;
2651e4656003caee346d9c4eb23256d73409271291a7Brian Paul   XMesaBuffer xmbuf = XMesaCreatePixmapBuffer(xmvis, pixmap, 0);
2652e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul   return xmbuf->frontxrb->pixmap; /* need to return an X ID */
2653783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2654783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2655e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2656783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic GLXContext
2657783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct)
2658783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2659e4656003caee346d9c4eb23256d73409271291a7Brian Paul   XMesaVisual xmvis = (XMesaVisual) config;
2660e4656003caee346d9c4eb23256d73409271291a7Brian Paul   struct fake_glx_context *glxCtx;
2661e4656003caee346d9c4eb23256d73409271291a7Brian Paul   struct fake_glx_context *shareCtx = (struct fake_glx_context *) share_list;
2662e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2663e4656003caee346d9c4eb23256d73409271291a7Brian Paul   glxCtx = CALLOC_STRUCT(fake_glx_context);
2664e4656003caee346d9c4eb23256d73409271291a7Brian Paul   if (!glxCtx)
2665e4656003caee346d9c4eb23256d73409271291a7Brian Paul      return 0;
2666e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2667e4656003caee346d9c4eb23256d73409271291a7Brian Paul   /* deallocate unused windows/buffers */
2668e4656003caee346d9c4eb23256d73409271291a7Brian Paul   XMesaGarbageCollect();
2669e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2670e4656003caee346d9c4eb23256d73409271291a7Brian Paul   glxCtx->xmesaContext = XMesaCreateContext(xmvis,
2671e4656003caee346d9c4eb23256d73409271291a7Brian Paul                                   shareCtx ? shareCtx->xmesaContext : NULL);
2672e4656003caee346d9c4eb23256d73409271291a7Brian Paul   if (!glxCtx->xmesaContext) {
26730c54e47c0e93f725b8bc028b0d4614011dbe3fefBrian Paul      _mesa_free(glxCtx);
2674e4656003caee346d9c4eb23256d73409271291a7Brian Paul      return NULL;
2675e4656003caee346d9c4eb23256d73409271291a7Brian Paul   }
2676e4656003caee346d9c4eb23256d73409271291a7Brian Paul
267749e80bf6b163310f7cd776261872201eea57053aBrian Paul   init_glx_context(glxCtx, dpy);
2678e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2679e4656003caee346d9c4eb23256d73409271291a7Brian Paul   return (GLXContext) glxCtx;
2680783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2681783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2682e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2683783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic XVisualInfo *
2684783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config)
2685783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
26863265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   return Fake_glXGetVisualFromFBConfig(dpy, config);
2687783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2688783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2689e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2690783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic GLXFBConfigSGIX
2691783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis)
2692426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
2693e4656003caee346d9c4eb23256d73409271291a7Brian Paul   XMesaVisual xmvis = find_glx_visual(dpy, vis);
2694e4656003caee346d9c4eb23256d73409271291a7Brian Paul   if (!xmvis) {
2695e4656003caee346d9c4eb23256d73409271291a7Brian Paul      /* This visual wasn't found with glXChooseVisual() */
2696e4656003caee346d9c4eb23256d73409271291a7Brian Paul      xmvis = create_glx_visual(dpy, vis);
2697e4656003caee346d9c4eb23256d73409271291a7Brian Paul   }
2698e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2699e4656003caee346d9c4eb23256d73409271291a7Brian Paul   return (GLXFBConfigSGIX) xmvis;
2700426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
2701426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2702426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2703426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
2704b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_SGIX_pbuffer ***/
2705783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2706783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic GLXPbufferSGIX
27073265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian PaulFake_glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config,
27083265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul                             unsigned int width, unsigned int height,
27093265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul                             int *attribList)
2710783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
27113265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   XMesaVisual xmvis = (XMesaVisual) config;
27123265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   XMesaBuffer xmbuf;
27133265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   const int *attrib;
27143265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
27153265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul
2716783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
27173265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul
271811b3028e7ba2fc3b985ab84d7227c290608f83f6Brian Paul   for (attrib = attribList; attrib && *attrib; attrib++) {
27193265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      switch (*attrib) {
27203265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         case GLX_PRESERVED_CONTENTS_SGIX:
27213265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            attrib++;
27223265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            preserveContents = *attrib; /* ignored */
27233265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            break;
27243265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         case GLX_LARGEST_PBUFFER_SGIX:
27253265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            attrib++;
27263265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            useLargest = *attrib; /* ignored */
27273265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            break;
27283265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul         default:
27293265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul            return 0;
27303265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul      }
27313265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   }
27323265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul
2733b305028464f02947c0cce0476af0e35f4ed1fafaBrian Paul   /* not used at this time */
2734b305028464f02947c0cce0476af0e35f4ed1fafaBrian Paul   (void) useLargest;
2735b305028464f02947c0cce0476af0e35f4ed1fafaBrian Paul   (void) preserveContents;
2736b305028464f02947c0cce0476af0e35f4ed1fafaBrian Paul
27373265fe5f8e47bfa42dd9e5e4a0e717816ad058a0Brian Paul   xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2738e4656003caee346d9c4eb23256d73409271291a7Brian Paul   /* A GLXPbuffer handle must be an X Drawable because that's what
2739e4656003caee346d9c4eb23256d73409271291a7Brian Paul    * glXMakeCurrent takes.
2740e4656003caee346d9c4eb23256d73409271291a7Brian Paul    */
2741e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul   return (GLXPbuffer) xmbuf->frontxrb->pixmap;
2742783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2743783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2744e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2745783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic void
2746783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf)
2747783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2748e4656003caee346d9c4eb23256d73409271291a7Brian Paul   XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2749e4656003caee346d9c4eb23256d73409271291a7Brian Paul   if (xmbuf) {
2750e4656003caee346d9c4eb23256d73409271291a7Brian Paul      XMesaDestroyBuffer(xmbuf);
2751e4656003caee346d9c4eb23256d73409271291a7Brian Paul   }
2752783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2753783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2754e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2755783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic int
2756783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value)
2757783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2758e4656003caee346d9c4eb23256d73409271291a7Brian Paul   const XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2759e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2760e4656003caee346d9c4eb23256d73409271291a7Brian Paul   if (!xmbuf) {
2761e4656003caee346d9c4eb23256d73409271291a7Brian Paul      /* Generate GLXBadPbufferSGIX for bad pbuffer */
2762e4656003caee346d9c4eb23256d73409271291a7Brian Paul      return 0;
2763e4656003caee346d9c4eb23256d73409271291a7Brian Paul   }
2764e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2765e4656003caee346d9c4eb23256d73409271291a7Brian Paul   switch (attribute) {
2766e4656003caee346d9c4eb23256d73409271291a7Brian Paul      case GLX_PRESERVED_CONTENTS_SGIX:
2767e4656003caee346d9c4eb23256d73409271291a7Brian Paul         *value = True;
2768e4656003caee346d9c4eb23256d73409271291a7Brian Paul         break;
2769e4656003caee346d9c4eb23256d73409271291a7Brian Paul      case GLX_LARGEST_PBUFFER_SGIX:
277029926a11b16ec7a235947d95e9a46777605dd30eBrian Paul         *value = xmbuf->mesa_buffer.Width * xmbuf->mesa_buffer.Height;
2771e4656003caee346d9c4eb23256d73409271291a7Brian Paul         break;
2772e4656003caee346d9c4eb23256d73409271291a7Brian Paul      case GLX_WIDTH_SGIX:
277329926a11b16ec7a235947d95e9a46777605dd30eBrian Paul         *value = xmbuf->mesa_buffer.Width;
2774e4656003caee346d9c4eb23256d73409271291a7Brian Paul         break;
2775e4656003caee346d9c4eb23256d73409271291a7Brian Paul      case GLX_HEIGHT_SGIX:
277629926a11b16ec7a235947d95e9a46777605dd30eBrian Paul         *value = xmbuf->mesa_buffer.Height;
2777e4656003caee346d9c4eb23256d73409271291a7Brian Paul         break;
2778e4656003caee346d9c4eb23256d73409271291a7Brian Paul      case GLX_EVENT_MASK_SGIX:
2779e4656003caee346d9c4eb23256d73409271291a7Brian Paul         *value = 0;  /* XXX might be wrong */
2780e4656003caee346d9c4eb23256d73409271291a7Brian Paul         break;
2781e4656003caee346d9c4eb23256d73409271291a7Brian Paul      default:
2782e4656003caee346d9c4eb23256d73409271291a7Brian Paul         *value = 0;
2783e4656003caee346d9c4eb23256d73409271291a7Brian Paul   }
2784783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return 0;
2785783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2786783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2787e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2788783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic void
2789783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask)
2790783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2791e4656003caee346d9c4eb23256d73409271291a7Brian Paul   XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2792e4656003caee346d9c4eb23256d73409271291a7Brian Paul   if (xmbuf) {
2793e4656003caee346d9c4eb23256d73409271291a7Brian Paul      /* Note: we'll never generate clobber events */
2794e4656003caee346d9c4eb23256d73409271291a7Brian Paul      xmbuf->selectedEvents = mask;
2795e4656003caee346d9c4eb23256d73409271291a7Brian Paul   }
2796783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2797783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2798e4656003caee346d9c4eb23256d73409271291a7Brian Paul
2799783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic void
2800783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long *mask)
2801783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2802e4656003caee346d9c4eb23256d73409271291a7Brian Paul   XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2803e4656003caee346d9c4eb23256d73409271291a7Brian Paul   if (xmbuf) {
2804e4656003caee346d9c4eb23256d73409271291a7Brian Paul      *mask = xmbuf->selectedEvents;
2805e4656003caee346d9c4eb23256d73409271291a7Brian Paul   }
2806e4656003caee346d9c4eb23256d73409271291a7Brian Paul   else {
2807e4656003caee346d9c4eb23256d73409271291a7Brian Paul      *mask = 0;
2808e4656003caee346d9c4eb23256d73409271291a7Brian Paul   }
2809783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2810783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2811783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2812783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2813b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_SGI_cushion ***/
2814783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2815783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic void
2816783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXCushionSGI(Display *dpy, Window win, float cushion)
2817783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2818783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2819783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) win;
2820783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) cushion;
2821783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2822783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2823783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2824783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2825b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_SGIX_video_resize ***/
2826783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2827783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic int
2828783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXBindChannelToWindowSGIX(Display *dpy, int screen, int channel , Window window)
2829783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2830783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2831783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) screen;
2832783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) channel;
2833783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) window;
2834783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return 0;
2835783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2836783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2837783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic int
2838783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXChannelRectSGIX(Display *dpy, int screen, int channel, int x, int y, int w, int h)
2839783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2840783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2841783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) screen;
2842783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) channel;
2843783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) x;
2844783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) y;
2845783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) w;
2846783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) h;
2847783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return 0;
2848783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2849783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2850783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic int
2851783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXQueryChannelRectSGIX(Display *dpy, int screen, int channel, int *x, int *y, int *w, int *h)
2852783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2853783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2854783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) screen;
2855783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) channel;
2856783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) x;
2857783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) y;
2858783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) w;
2859783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) h;
2860783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return 0;
2861783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2862783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2863783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic int
2864783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel, int *dx, int *dy, int *dw, int *dh)
2865783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2866783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2867783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) screen;
2868783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) channel;
2869783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dx;
2870783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dy;
2871783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dw;
2872783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dh;
2873783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return 0;
2874783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2875783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2876783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic int
2877783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype)
2878783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2879783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2880783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) screen;
2881783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) channel;
2882783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) synctype;
2883783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return 0;
2884783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2885783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2886783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2887783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2888b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_SGIX_dmbuffer **/
2889783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2890b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul#if defined(_DM_BUFFER_H_)
2891783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic Bool
2892783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer)
2893783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2894783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2895783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) pbuffer;
2896783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) params;
2897783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dmbuffer;
2898783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return False;
2899783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2900783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul#endif
2901783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2902783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2903b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_SGIX_swap_group ***/
2904783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2905783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic void
2906783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, GLXDrawable member)
2907783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2908783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2909783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) drawable;
2910783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) member;
2911783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2912783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2913783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2914783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2915b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_SGIX_swap_barrier ***/
2916783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2917783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic void
2918783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, int barrier)
2919783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2920783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2921783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) drawable;
2922783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) barrier;
2923783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2924783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2925783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic Bool
2926783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
2927783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2928783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2929783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) screen;
2930783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) max;
2931783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return False;
2932783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2933783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2934783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2935783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2936b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_SUN_get_transparent_index ***/
2937783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2938783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic Status
2939783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay, long *pTransparent)
2940783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2941783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) dpy;
2942783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) overlay;
2943783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) underlay;
2944783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   (void) pTransparent;
2945783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return 0;
2946783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2947783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2948783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2949783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2950b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_MESA_release_buffers ***/
2951b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul
2952783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul/*
2953783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul * Release the depth, stencil, accum buffers attached to a GLXDrawable
2954783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul * (a window or pixmap) prior to destroying the GLXDrawable.
2955783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul */
2956783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic Bool
2957783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
2958783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2959783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   XMesaBuffer b = XMesaFindBuffer(dpy, d);
2960783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   if (b) {
2961783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul      XMesaDestroyBuffer(b);
2962783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul      return True;
2963783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   }
2964783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return False;
2965783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2966783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2967783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2968783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2969b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_MESA_set_3dfx_mode ***/
2970b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul
2971783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paulstatic Bool
2972783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian PaulFake_glXSet3DfxModeMESA( int mode )
2973783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul{
2974783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   return XMesaSetFXmode( mode );
2975783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul}
2976783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2977783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
2978783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
29793c5bfac63bcbc4028c552fe74d904e6a3416ff36Brian Paul/*** GLX_NV_vertex_array range ***/
29808fefafa2200d3ea44ec46592b190654a10685b46Brian Paulstatic void *
29818fefafa2200d3ea44ec46592b190654a10685b46Brian PaulFake_glXAllocateMemoryNV( GLsizei size,
29828fefafa2200d3ea44ec46592b190654a10685b46Brian Paul                          GLfloat readFrequency,
29838fefafa2200d3ea44ec46592b190654a10685b46Brian Paul                          GLfloat writeFrequency,
29848fefafa2200d3ea44ec46592b190654a10685b46Brian Paul                          GLfloat priority )
29858fefafa2200d3ea44ec46592b190654a10685b46Brian Paul{
29868fefafa2200d3ea44ec46592b190654a10685b46Brian Paul   (void) size;
29878fefafa2200d3ea44ec46592b190654a10685b46Brian Paul   (void) readFrequency;
29888fefafa2200d3ea44ec46592b190654a10685b46Brian Paul   (void) writeFrequency;
29898fefafa2200d3ea44ec46592b190654a10685b46Brian Paul   (void) priority;
29908fefafa2200d3ea44ec46592b190654a10685b46Brian Paul   return NULL;
29918fefafa2200d3ea44ec46592b190654a10685b46Brian Paul}
29928fefafa2200d3ea44ec46592b190654a10685b46Brian Paul
29938fefafa2200d3ea44ec46592b190654a10685b46Brian Paul
29948fefafa2200d3ea44ec46592b190654a10685b46Brian Paulstatic void
29958fefafa2200d3ea44ec46592b190654a10685b46Brian PaulFake_glXFreeMemoryNV( GLvoid *pointer )
29968fefafa2200d3ea44ec46592b190654a10685b46Brian Paul{
29978fefafa2200d3ea44ec46592b190654a10685b46Brian Paul   (void) pointer;
29988fefafa2200d3ea44ec46592b190654a10685b46Brian Paul}
29998fefafa2200d3ea44ec46592b190654a10685b46Brian Paul
30008fefafa2200d3ea44ec46592b190654a10685b46Brian Paul
30013c5bfac63bcbc4028c552fe74d904e6a3416ff36Brian Paul/*** GLX_MESA_agp_offset ***/
3002d6113fc20d68f5720740b89c594227d0312bab3eBrian Paul
3003d6113fc20d68f5720740b89c594227d0312bab3eBrian Paulstatic GLuint
3004d6113fc20d68f5720740b89c594227d0312bab3eBrian PaulFake_glXGetAGPOffsetMESA( const GLvoid *pointer )
3005d6113fc20d68f5720740b89c594227d0312bab3eBrian Paul{
3006d6113fc20d68f5720740b89c594227d0312bab3eBrian Paul   (void) pointer;
3007d6113fc20d68f5720740b89c594227d0312bab3eBrian Paul   return ~0;
3008d6113fc20d68f5720740b89c594227d0312bab3eBrian Paul}
3009d6113fc20d68f5720740b89c594227d0312bab3eBrian Paul
3010d6113fc20d68f5720740b89c594227d0312bab3eBrian Paul
3011fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian/*** GLX_EXT_texture_from_pixmap ***/
3012fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian
3013fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrianstatic void
3014fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrianFake_glXBindTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer,
3015fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian                        const int *attrib_list)
3016fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian{
3017fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   XMesaBuffer b = XMesaFindBuffer(dpy, drawable);
3018fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   if (b)
3019fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      XMesaBindTexImage(dpy, b, buffer, attrib_list);
3020fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian}
3021fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian
3022fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrianstatic void
3023fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrianFake_glXReleaseTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer)
3024fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian{
3025fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   XMesaBuffer b = XMesaFindBuffer(dpy, drawable);
3026fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   if (b)
3027fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian      XMesaReleaseTexImage(dpy, b, buffer);
3028fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian}
3029fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian
3030fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian
30317287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul/* silence warning */
3032e7b16b74bf5d13331b5a88bbbbb9096560297b63Brian Paulextern struct _glxapi_table *_mesa_GetGLXDispatchTable(void);
30337287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul
30347287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul
30357287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul/**
30367287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul * Create a new GLX API dispatch table with its function pointers
30377287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul * initialized to point to Mesa's "fake" GLX API functions.
30387287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul * Note: there's a similar function (_real_GetGLXDispatchTable) that
30397287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul * returns a new dispatch table with all pointers initalized to point
30407287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul * to "real" GLX functions (which understand GLX wire protocol, etc).
30417287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul */
30427287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paulstruct _glxapi_table *
30437287bbf4fc7c52da2aa31cae897ed70deda645bbBrian Paul_mesa_GetGLXDispatchTable(void)
3044426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul{
3045426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   static struct _glxapi_table glx;
3046426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
3047426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   /* be sure our dispatch table size <= libGL's table */
3048426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   {
304901915e90e6912f06d43d443a09157f7bbc96ddc5Brian Paul      GLuint size = sizeof(struct _glxapi_table) / sizeof(void *);
3050426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul      (void) size;
3051426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul      assert(_glxapi_get_dispatch_table_size() >= size);
3052426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   }
3053426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
3054426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   /* initialize the whole table to no-ops */
3055426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   _glxapi_set_no_op_table(&glx);
3056426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
3057426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   /* now initialize the table with the functions I implement */
3058426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.ChooseVisual = Fake_glXChooseVisual;
3059426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.CopyContext = Fake_glXCopyContext;
3060426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.CreateContext = Fake_glXCreateContext;
3061426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.CreateGLXPixmap = Fake_glXCreateGLXPixmap;
3062426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.DestroyContext = Fake_glXDestroyContext;
3063426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.DestroyGLXPixmap = Fake_glXDestroyGLXPixmap;
3064426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.GetConfig = Fake_glXGetConfig;
3065426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
3066426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
3067426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.IsDirect = Fake_glXIsDirect;
3068426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.MakeCurrent = Fake_glXMakeCurrent;
3069426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.QueryExtension = Fake_glXQueryExtension;
3070426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.QueryVersion = Fake_glXQueryVersion;
3071426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.SwapBuffers = Fake_glXSwapBuffers;
3072426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.UseXFont = Fake_glXUseXFont;
3073426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.WaitGL = Fake_glXWaitGL;
3074426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.WaitX = Fake_glXWaitX;
3075426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
3076b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_VERSION_1_1 ***/
3077426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.GetClientString = Fake_glXGetClientString;
3078426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.QueryExtensionsString = Fake_glXQueryExtensionsString;
3079426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.QueryServerString = Fake_glXQueryServerString;
3080426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
3081b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_VERSION_1_2 ***/
3082426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
3083426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
3084b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_VERSION_1_3 ***/
3085426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.ChooseFBConfig = Fake_glXChooseFBConfig;
3086426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.CreateNewContext = Fake_glXCreateNewContext;
3087426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.CreatePbuffer = Fake_glXCreatePbuffer;
3088426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.CreatePixmap = Fake_glXCreatePixmap;
3089426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.CreateWindow = Fake_glXCreateWindow;
3090426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.DestroyPbuffer = Fake_glXDestroyPbuffer;
3091426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.DestroyPixmap = Fake_glXDestroyPixmap;
3092426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.DestroyWindow = Fake_glXDestroyWindow;
3093426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
3094426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.GetFBConfigAttrib = Fake_glXGetFBConfigAttrib;
309571dea349d2be623b7819389428b0d6a124e8d184Brian Paul   glx.GetFBConfigs = Fake_glXGetFBConfigs;
3096426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.GetSelectedEvent = Fake_glXGetSelectedEvent;
3097426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.GetVisualFromFBConfig = Fake_glXGetVisualFromFBConfig;
3098426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.MakeContextCurrent = Fake_glXMakeContextCurrent;
3099426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.QueryContext = Fake_glXQueryContext;
3100426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.QueryDrawable = Fake_glXQueryDrawable;
3101426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.SelectEvent = Fake_glXSelectEvent;
3102426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
3103b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_SGI_swap_control ***/
3104783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.SwapIntervalSGI = Fake_glXSwapIntervalSGI;
3105783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
3106b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_SGI_video_sync ***/
3107426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.GetVideoSyncSGI = Fake_glXGetVideoSyncSGI;
3108426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.WaitVideoSyncSGI = Fake_glXWaitVideoSyncSGI;
3109426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
3110b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_SGI_make_current_read ***/
3111783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.MakeCurrentReadSGI = Fake_glXMakeCurrentReadSGI;
31127cf50e137da497a590ec9001a9918972a6246142Brian Paul   /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
3113783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
3114b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul/*** GLX_SGIX_video_source ***/
3115b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul#if defined(_VL_H)
3116783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.CreateGLXVideoSourceSGIX = Fake_glXCreateGLXVideoSourceSGIX;
3117783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.DestroyGLXVideoSourceSGIX = Fake_glXDestroyGLXVideoSourceSGIX;
3118783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul#endif
3119783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
3120b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_EXT_import_context ***/
3121783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.FreeContextEXT = Fake_glXFreeContextEXT;
3122783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.GetContextIDEXT = Fake_glXGetContextIDEXT;
31237cf50e137da497a590ec9001a9918972a6246142Brian Paul   /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
3124783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.ImportContextEXT = Fake_glXImportContextEXT;
3125783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.QueryContextInfoEXT = Fake_glXQueryContextInfoEXT;
31264536021a62e02fceaa6e8eb889b0f61743109cc4Brian Paul
3127b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_SGIX_fbconfig ***/
3128783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.GetFBConfigAttribSGIX = Fake_glXGetFBConfigAttribSGIX;
3129783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.ChooseFBConfigSGIX = Fake_glXChooseFBConfigSGIX;
3130783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.CreateGLXPixmapWithConfigSGIX = Fake_glXCreateGLXPixmapWithConfigSGIX;
3131783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.CreateContextWithConfigSGIX = Fake_glXCreateContextWithConfigSGIX;
3132783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.GetVisualFromFBConfigSGIX = Fake_glXGetVisualFromFBConfigSGIX;
3133783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.GetFBConfigFromVisualSGIX = Fake_glXGetFBConfigFromVisualSGIX;
3134783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
3135b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_SGIX_pbuffer ***/
3136783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.CreateGLXPbufferSGIX = Fake_glXCreateGLXPbufferSGIX;
3137783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.DestroyGLXPbufferSGIX = Fake_glXDestroyGLXPbufferSGIX;
3138783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.QueryGLXPbufferSGIX = Fake_glXQueryGLXPbufferSGIX;
3139783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.SelectEventSGIX = Fake_glXSelectEventSGIX;
3140783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.GetSelectedEventSGIX = Fake_glXGetSelectedEventSGIX;
3141783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
3142b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_SGI_cushion ***/
3143783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.CushionSGI = Fake_glXCushionSGI;
3144783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
3145b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_SGIX_video_resize ***/
3146783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.BindChannelToWindowSGIX = Fake_glXBindChannelToWindowSGIX;
3147783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.ChannelRectSGIX = Fake_glXChannelRectSGIX;
3148783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.QueryChannelRectSGIX = Fake_glXQueryChannelRectSGIX;
3149783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.QueryChannelDeltasSGIX = Fake_glXQueryChannelDeltasSGIX;
3150783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.ChannelRectSyncSGIX = Fake_glXChannelRectSyncSGIX;
3151783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
3152b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_SGIX_dmbuffer **/
3153b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul#if defined(_DM_BUFFER_H_)
3154783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.AssociateDMPbufferSGIX = NULL;
3155783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul#endif
3156783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
3157b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_SGIX_swap_group ***/
3158783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.JoinSwapGroupSGIX = Fake_glXJoinSwapGroupSGIX;
3159783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
3160b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_SGIX_swap_barrier ***/
3161783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.BindSwapBarrierSGIX = Fake_glXBindSwapBarrierSGIX;
3162783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.QueryMaxSwapBarriersSGIX = Fake_glXQueryMaxSwapBarriersSGIX;
3163783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul
3164b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_SUN_get_transparent_index ***/
3165783d7dfcbf40f727c85915b3e5ea5ff6682eaa48Brian Paul   glx.GetTransparentIndexSUN = Fake_glXGetTransparentIndexSUN;
31664536021a62e02fceaa6e8eb889b0f61743109cc4Brian Paul
3167b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_MESA_copy_sub_buffer ***/
3168426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.CopySubBufferMESA = Fake_glXCopySubBufferMESA;
3169426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
3170b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_MESA_release_buffers ***/
3171426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.ReleaseBuffersMESA = Fake_glXReleaseBuffersMESA;
3172426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
3173b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_MESA_pixmap_colormap ***/
3174426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.CreateGLXPixmapMESA = Fake_glXCreateGLXPixmapMESA;
3175426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
3176b0bb4f6226a18e0a6eb40046c7f7b5a841c75edaBrian Paul   /*** GLX_MESA_set_3dfx_mode ***/
3177426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   glx.Set3DfxModeMESA = Fake_glXSet3DfxModeMESA;
3178426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul
3179d6113fc20d68f5720740b89c594227d0312bab3eBrian Paul   /*** GLX_NV_vertex_array_range ***/
31808fefafa2200d3ea44ec46592b190654a10685b46Brian Paul   glx.AllocateMemoryNV = Fake_glXAllocateMemoryNV;
31818fefafa2200d3ea44ec46592b190654a10685b46Brian Paul   glx.FreeMemoryNV = Fake_glXFreeMemoryNV;
31828fefafa2200d3ea44ec46592b190654a10685b46Brian Paul
3183d6113fc20d68f5720740b89c594227d0312bab3eBrian Paul   /*** GLX_MESA_agp_offset ***/
3184d6113fc20d68f5720740b89c594227d0312bab3eBrian Paul   glx.GetAGPOffsetMESA = Fake_glXGetAGPOffsetMESA;
3185d6113fc20d68f5720740b89c594227d0312bab3eBrian Paul
3186fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   /*** GLX_EXT_texture_from_pixmap ***/
3187fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   glx.BindTexImageEXT = Fake_glXBindTexImageEXT;
3188fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian   glx.ReleaseTexImageEXT = Fake_glXReleaseTexImageEXT;
3189fd54564f78d4aeae2c39ada7502ec659c14b3ecaBrian
3190426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul   return &glx;
3191426cb9f58f194a1e30e0908e8fc971bdcae06960Brian Paul}
3192