1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Mesa 3-D graphics library
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
5bf215546Sopenharmony_ci * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
6bf215546Sopenharmony_ci *
7bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
8bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
9bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
10bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
12bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included
15bf215546Sopenharmony_ci * in all copies or substantial portions of the Software.
16bf215546Sopenharmony_ci *
17bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
24bf215546Sopenharmony_ci */
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci/**
28bf215546Sopenharmony_ci * "Fake" GLX API implemented in terms of the XMesa*() functions.
29bf215546Sopenharmony_ci */
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci#define GLX_GLXEXT_PROTOTYPES
34bf215546Sopenharmony_ci#include "GL/glx.h"
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci#include <stdio.h>
37bf215546Sopenharmony_ci#include <string.h>
38bf215546Sopenharmony_ci#include <X11/Xmd.h>
39bf215546Sopenharmony_ci#include <GL/glxproto.h>
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ci#include "xm_api.h"
42bf215546Sopenharmony_ci#include "main/errors.h"
43bf215546Sopenharmony_ci#include "main/config.h"
44bf215546Sopenharmony_ci#include "util/u_math.h"
45bf215546Sopenharmony_ci#include "util/u_memory.h"
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci/* An "Atrribs/Attribs" typo was fixed in glxproto.h in Nov 2014.
48bf215546Sopenharmony_ci * This is in case we don't have the updated header.
49bf215546Sopenharmony_ci */
50bf215546Sopenharmony_ci#if !defined(X_GLXCreateContextAttribsARB) && \
51bf215546Sopenharmony_ci     defined(X_GLXCreateContextAtrribsARB)
52bf215546Sopenharmony_ci#define X_GLXCreateContextAttribsARB X_GLXCreateContextAtrribsARB
53bf215546Sopenharmony_ci#endif
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci/* This indicates the client-side GLX API and GLX encoder version. */
56bf215546Sopenharmony_ci#define CLIENT_MAJOR_VERSION 1
57bf215546Sopenharmony_ci#define CLIENT_MINOR_VERSION 4  /* but don't have 1.3's pbuffers, etc yet */
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci/* This indicates the server-side GLX decoder version.
60bf215546Sopenharmony_ci * GLX 1.4 indicates OpenGL 1.3 support
61bf215546Sopenharmony_ci */
62bf215546Sopenharmony_ci#define SERVER_MAJOR_VERSION 1
63bf215546Sopenharmony_ci#define SERVER_MINOR_VERSION 4
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ci/* Who implemented this GLX? */
66bf215546Sopenharmony_ci#define VENDOR "Brian Paul"
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci#define EXTENSIONS \
69bf215546Sopenharmony_ci   "GLX_MESA_copy_sub_buffer " \
70bf215546Sopenharmony_ci   "GLX_MESA_pixmap_colormap " \
71bf215546Sopenharmony_ci   "GLX_MESA_release_buffers " \
72bf215546Sopenharmony_ci   "GLX_ARB_create_context " \
73bf215546Sopenharmony_ci   "GLX_ARB_create_context_profile " \
74bf215546Sopenharmony_ci   "GLX_ARB_get_proc_address " \
75bf215546Sopenharmony_ci   "GLX_EXT_create_context_es_profile " \
76bf215546Sopenharmony_ci   "GLX_EXT_create_context_es2_profile " \
77bf215546Sopenharmony_ci   "GLX_EXT_texture_from_pixmap " \
78bf215546Sopenharmony_ci   "GLX_EXT_visual_info " \
79bf215546Sopenharmony_ci   "GLX_EXT_visual_rating " \
80bf215546Sopenharmony_ci   /*"GLX_SGI_video_sync "*/ \
81bf215546Sopenharmony_ci   "GLX_SGIX_fbconfig " \
82bf215546Sopenharmony_ci   "GLX_SGIX_pbuffer "
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ci#define DEFAULT_DIRECT GL_TRUE
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci/** XXX this could be based on gallium's max texture size */
88bf215546Sopenharmony_ci#define PBUFFER_MAX_SIZE 16384
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ci/**
92bf215546Sopenharmony_ci * The GLXContext typedef is defined as a pointer to this structure.
93bf215546Sopenharmony_ci */
94bf215546Sopenharmony_cistruct __GLXcontextRec
95bf215546Sopenharmony_ci{
96bf215546Sopenharmony_ci   Display *currentDpy;
97bf215546Sopenharmony_ci   GLboolean isDirect;
98bf215546Sopenharmony_ci   GLXDrawable currentDrawable;
99bf215546Sopenharmony_ci   GLXDrawable currentReadable;
100bf215546Sopenharmony_ci   XID xid;
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_ci   XMesaContext xmesaContext;
103bf215546Sopenharmony_ci};
104bf215546Sopenharmony_ci
105bf215546Sopenharmony_ci
106bf215546Sopenharmony_cithread_local GLXContext ContextTSD;
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_ci/** Set current context for calling thread */
109bf215546Sopenharmony_cistatic void
110bf215546Sopenharmony_ciSetCurrentContext(GLXContext c)
111bf215546Sopenharmony_ci{
112bf215546Sopenharmony_ci   ContextTSD = c;
113bf215546Sopenharmony_ci}
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ci/** Get current context for calling thread */
116bf215546Sopenharmony_cistatic GLXContext
117bf215546Sopenharmony_ciGetCurrentContext(void)
118bf215546Sopenharmony_ci{
119bf215546Sopenharmony_ci   return ContextTSD;
120bf215546Sopenharmony_ci}
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ci
124bf215546Sopenharmony_ci/**********************************************************************/
125bf215546Sopenharmony_ci/***                       GLX Visual Code                          ***/
126bf215546Sopenharmony_ci/**********************************************************************/
127bf215546Sopenharmony_ci
128bf215546Sopenharmony_ci#define DONT_CARE -1
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_ci
131bf215546Sopenharmony_cistatic XMesaVisual *VisualTable = NULL;
132bf215546Sopenharmony_cistatic int NumVisuals = 0;
133bf215546Sopenharmony_ci
134bf215546Sopenharmony_ci
135bf215546Sopenharmony_ci
136bf215546Sopenharmony_ci/* Macro to handle c_class vs class field name in XVisualInfo struct */
137bf215546Sopenharmony_ci#if defined(__cplusplus) || defined(c_plusplus)
138bf215546Sopenharmony_ci#define CLASS c_class
139bf215546Sopenharmony_ci#else
140bf215546Sopenharmony_ci#define CLASS class
141bf215546Sopenharmony_ci#endif
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_ci
144bf215546Sopenharmony_ci
145bf215546Sopenharmony_ci/*
146bf215546Sopenharmony_ci * Test if the given XVisualInfo is usable for Mesa rendering.
147bf215546Sopenharmony_ci */
148bf215546Sopenharmony_cistatic GLboolean
149bf215546Sopenharmony_ciis_usable_visual( XVisualInfo *vinfo )
150bf215546Sopenharmony_ci{
151bf215546Sopenharmony_ci   switch (vinfo->CLASS) {
152bf215546Sopenharmony_ci      case StaticGray:
153bf215546Sopenharmony_ci      case GrayScale:
154bf215546Sopenharmony_ci         /* Any StaticGray/GrayScale visual works in RGB or CI mode */
155bf215546Sopenharmony_ci         return GL_TRUE;
156bf215546Sopenharmony_ci      case StaticColor:
157bf215546Sopenharmony_ci      case PseudoColor:
158bf215546Sopenharmony_ci	 /* Any StaticColor/PseudoColor visual of at least 4 bits */
159bf215546Sopenharmony_ci	 if (vinfo->depth>=4) {
160bf215546Sopenharmony_ci	    return GL_TRUE;
161bf215546Sopenharmony_ci	 }
162bf215546Sopenharmony_ci	 else {
163bf215546Sopenharmony_ci	    return GL_FALSE;
164bf215546Sopenharmony_ci	 }
165bf215546Sopenharmony_ci      case TrueColor:
166bf215546Sopenharmony_ci      case DirectColor:
167bf215546Sopenharmony_ci	 /* Any depth of TrueColor or DirectColor works in RGB mode */
168bf215546Sopenharmony_ci	 return GL_TRUE;
169bf215546Sopenharmony_ci      default:
170bf215546Sopenharmony_ci	 /* This should never happen */
171bf215546Sopenharmony_ci	 return GL_FALSE;
172bf215546Sopenharmony_ci   }
173bf215546Sopenharmony_ci}
174bf215546Sopenharmony_ci
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_ci/*
177bf215546Sopenharmony_ci * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
178bf215546Sopenharmony_ci * configuration in our list of GLX visuals.
179bf215546Sopenharmony_ci */
180bf215546Sopenharmony_cistatic XMesaVisual
181bf215546Sopenharmony_cisave_glx_visual( Display *dpy, XVisualInfo *vinfo,
182bf215546Sopenharmony_ci                 GLboolean rgbFlag, GLboolean alphaFlag, GLboolean dbFlag,
183bf215546Sopenharmony_ci                 GLboolean stereoFlag,
184bf215546Sopenharmony_ci                 GLint depth_size, GLint stencil_size,
185bf215546Sopenharmony_ci                 GLint accumRedSize, GLint accumGreenSize,
186bf215546Sopenharmony_ci                 GLint accumBlueSize, GLint accumAlphaSize,
187bf215546Sopenharmony_ci                 GLint level, GLint numAuxBuffers, GLuint num_samples )
188bf215546Sopenharmony_ci{
189bf215546Sopenharmony_ci   GLboolean ximageFlag = GL_TRUE;
190bf215546Sopenharmony_ci   XMesaVisual xmvis;
191bf215546Sopenharmony_ci   GLint i;
192bf215546Sopenharmony_ci   GLboolean comparePointers;
193bf215546Sopenharmony_ci
194bf215546Sopenharmony_ci   if (!rgbFlag)
195bf215546Sopenharmony_ci      return NULL;
196bf215546Sopenharmony_ci
197bf215546Sopenharmony_ci   if (dbFlag) {
198bf215546Sopenharmony_ci      /* Check if the MESA_BACK_BUFFER env var is set */
199bf215546Sopenharmony_ci      char *backbuffer = getenv("MESA_BACK_BUFFER");
200bf215546Sopenharmony_ci      if (backbuffer) {
201bf215546Sopenharmony_ci         if (backbuffer[0]=='p' || backbuffer[0]=='P') {
202bf215546Sopenharmony_ci            ximageFlag = GL_FALSE;
203bf215546Sopenharmony_ci         }
204bf215546Sopenharmony_ci         else if (backbuffer[0]=='x' || backbuffer[0]=='X') {
205bf215546Sopenharmony_ci            ximageFlag = GL_TRUE;
206bf215546Sopenharmony_ci         }
207bf215546Sopenharmony_ci         else {
208bf215546Sopenharmony_ci            _mesa_warning(NULL, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
209bf215546Sopenharmony_ci         }
210bf215546Sopenharmony_ci      }
211bf215546Sopenharmony_ci   }
212bf215546Sopenharmony_ci
213bf215546Sopenharmony_ci   if (stereoFlag) {
214bf215546Sopenharmony_ci      /* stereo not supported */
215bf215546Sopenharmony_ci      return NULL;
216bf215546Sopenharmony_ci   }
217bf215546Sopenharmony_ci
218bf215546Sopenharmony_ci   if (stencil_size > 0 && depth_size > 0)
219bf215546Sopenharmony_ci      depth_size = 24;
220bf215546Sopenharmony_ci
221bf215546Sopenharmony_ci   /* Comparing IDs uses less memory but sometimes fails. */
222bf215546Sopenharmony_ci   /* XXX revisit this after 3.0 is finished. */
223bf215546Sopenharmony_ci   if (getenv("MESA_GLX_VISUAL_HACK"))
224bf215546Sopenharmony_ci      comparePointers = GL_TRUE;
225bf215546Sopenharmony_ci   else
226bf215546Sopenharmony_ci      comparePointers = GL_FALSE;
227bf215546Sopenharmony_ci
228bf215546Sopenharmony_ci   /* Force the visual to have an alpha channel */
229bf215546Sopenharmony_ci   if (rgbFlag && getenv("MESA_GLX_FORCE_ALPHA"))
230bf215546Sopenharmony_ci      alphaFlag = GL_TRUE;
231bf215546Sopenharmony_ci
232bf215546Sopenharmony_ci   /* First check if a matching visual is already in the list */
233bf215546Sopenharmony_ci   for (i=0; i<NumVisuals; i++) {
234bf215546Sopenharmony_ci      XMesaVisual v = VisualTable[i];
235bf215546Sopenharmony_ci      if (v->display == dpy
236bf215546Sopenharmony_ci          && v->mesa_visual.samples == num_samples
237bf215546Sopenharmony_ci          && v->ximage_flag == ximageFlag
238bf215546Sopenharmony_ci          && v->mesa_visual.doubleBufferMode == dbFlag
239bf215546Sopenharmony_ci          && v->mesa_visual.stereoMode == stereoFlag
240bf215546Sopenharmony_ci          && (v->mesa_visual.alphaBits > 0) == alphaFlag
241bf215546Sopenharmony_ci          && (v->mesa_visual.depthBits >= depth_size || depth_size == 0)
242bf215546Sopenharmony_ci          && (v->mesa_visual.stencilBits >= stencil_size || stencil_size == 0)
243bf215546Sopenharmony_ci          && (v->mesa_visual.accumRedBits >= accumRedSize || accumRedSize == 0)
244bf215546Sopenharmony_ci          && (v->mesa_visual.accumGreenBits >= accumGreenSize || accumGreenSize == 0)
245bf215546Sopenharmony_ci          && (v->mesa_visual.accumBlueBits >= accumBlueSize || accumBlueSize == 0)
246bf215546Sopenharmony_ci          && (v->mesa_visual.accumAlphaBits >= accumAlphaSize || accumAlphaSize == 0)) {
247bf215546Sopenharmony_ci         /* now either compare XVisualInfo pointers or visual IDs */
248bf215546Sopenharmony_ci         if ((!comparePointers && v->visinfo->visualid == vinfo->visualid)
249bf215546Sopenharmony_ci             || (comparePointers && v->vishandle == vinfo)) {
250bf215546Sopenharmony_ci            return v;
251bf215546Sopenharmony_ci         }
252bf215546Sopenharmony_ci      }
253bf215546Sopenharmony_ci   }
254bf215546Sopenharmony_ci
255bf215546Sopenharmony_ci   /* Create a new visual and add it to the list. */
256bf215546Sopenharmony_ci
257bf215546Sopenharmony_ci   xmvis = XMesaCreateVisual( dpy, vinfo, rgbFlag, alphaFlag, dbFlag,
258bf215546Sopenharmony_ci                              stereoFlag, ximageFlag,
259bf215546Sopenharmony_ci                              depth_size, stencil_size,
260bf215546Sopenharmony_ci                              accumRedSize, accumBlueSize,
261bf215546Sopenharmony_ci                              accumBlueSize, accumAlphaSize, num_samples, level,
262bf215546Sopenharmony_ci                              GLX_NONE_EXT );
263bf215546Sopenharmony_ci   if (xmvis) {
264bf215546Sopenharmony_ci      /* Save a copy of the pointer now so we can find this visual again
265bf215546Sopenharmony_ci       * if we need to search for it in find_glx_visual().
266bf215546Sopenharmony_ci       */
267bf215546Sopenharmony_ci      xmvis->vishandle = vinfo;
268bf215546Sopenharmony_ci      /* Allocate more space for additional visual */
269bf215546Sopenharmony_ci      VisualTable = realloc(VisualTable, sizeof(XMesaVisual) * (NumVisuals + 1));
270bf215546Sopenharmony_ci      /* add xmvis to the list */
271bf215546Sopenharmony_ci      VisualTable[NumVisuals] = xmvis;
272bf215546Sopenharmony_ci      NumVisuals++;
273bf215546Sopenharmony_ci   }
274bf215546Sopenharmony_ci   return xmvis;
275bf215546Sopenharmony_ci}
276bf215546Sopenharmony_ci
277bf215546Sopenharmony_ci
278bf215546Sopenharmony_ci/**
279bf215546Sopenharmony_ci * Return the default number of bits for the Z buffer.
280bf215546Sopenharmony_ci * If defined, use the MESA_GLX_DEPTH_BITS env var value.
281bf215546Sopenharmony_ci * Otherwise, use 24.
282bf215546Sopenharmony_ci * XXX probably do the same thing for stencil, accum, etc.
283bf215546Sopenharmony_ci */
284bf215546Sopenharmony_cistatic GLint
285bf215546Sopenharmony_cidefault_depth_bits(void)
286bf215546Sopenharmony_ci{
287bf215546Sopenharmony_ci   int zBits;
288bf215546Sopenharmony_ci   const char *zEnv = getenv("MESA_GLX_DEPTH_BITS");
289bf215546Sopenharmony_ci   if (zEnv)
290bf215546Sopenharmony_ci      zBits = atoi(zEnv);
291bf215546Sopenharmony_ci   else
292bf215546Sopenharmony_ci      zBits = 24;
293bf215546Sopenharmony_ci   return zBits;
294bf215546Sopenharmony_ci}
295bf215546Sopenharmony_ci
296bf215546Sopenharmony_cistatic GLint
297bf215546Sopenharmony_cidefault_alpha_bits(void)
298bf215546Sopenharmony_ci{
299bf215546Sopenharmony_ci   int aBits;
300bf215546Sopenharmony_ci   const char *aEnv = getenv("MESA_GLX_ALPHA_BITS");
301bf215546Sopenharmony_ci   if (aEnv)
302bf215546Sopenharmony_ci      aBits = atoi(aEnv);
303bf215546Sopenharmony_ci   else
304bf215546Sopenharmony_ci      aBits = 0;
305bf215546Sopenharmony_ci   return aBits;
306bf215546Sopenharmony_ci}
307bf215546Sopenharmony_ci
308bf215546Sopenharmony_cistatic GLint
309bf215546Sopenharmony_cidefault_accum_bits(void)
310bf215546Sopenharmony_ci{
311bf215546Sopenharmony_ci   return 16;
312bf215546Sopenharmony_ci}
313bf215546Sopenharmony_ci
314bf215546Sopenharmony_ci
315bf215546Sopenharmony_ci
316bf215546Sopenharmony_ci/*
317bf215546Sopenharmony_ci * Create a GLX visual from a regular XVisualInfo.
318bf215546Sopenharmony_ci * This is called when Fake GLX is given an XVisualInfo which wasn't
319bf215546Sopenharmony_ci * returned by glXChooseVisual.  Since this is the first time we're
320bf215546Sopenharmony_ci * considering this visual we'll take a guess at reasonable values
321bf215546Sopenharmony_ci * for depth buffer size, stencil size, accum size, etc.
322bf215546Sopenharmony_ci * This is the best we can do with a client-side emulation of GLX.
323bf215546Sopenharmony_ci */
324bf215546Sopenharmony_cistatic XMesaVisual
325bf215546Sopenharmony_cicreate_glx_visual( Display *dpy, XVisualInfo *visinfo )
326bf215546Sopenharmony_ci{
327bf215546Sopenharmony_ci   GLint zBits = default_depth_bits();
328bf215546Sopenharmony_ci   GLint accBits = default_accum_bits();
329bf215546Sopenharmony_ci   GLboolean alphaFlag = default_alpha_bits() > 0;
330bf215546Sopenharmony_ci
331bf215546Sopenharmony_ci   if (is_usable_visual( visinfo )) {
332bf215546Sopenharmony_ci      /* Configure this visual as RGB, double-buffered, depth-buffered. */
333bf215546Sopenharmony_ci      /* This is surely wrong for some people's needs but what else */
334bf215546Sopenharmony_ci      /* can be done?  They should use glXChooseVisual(). */
335bf215546Sopenharmony_ci      return save_glx_visual( dpy, visinfo,
336bf215546Sopenharmony_ci                              GL_TRUE,   /* rgb */
337bf215546Sopenharmony_ci                              alphaFlag, /* alpha */
338bf215546Sopenharmony_ci                              GL_TRUE,   /* double */
339bf215546Sopenharmony_ci                              GL_FALSE,  /* stereo */
340bf215546Sopenharmony_ci                              zBits,
341bf215546Sopenharmony_ci                              8,       /* stencil bits */
342bf215546Sopenharmony_ci                              accBits, /* r */
343bf215546Sopenharmony_ci                              accBits, /* g */
344bf215546Sopenharmony_ci                              accBits, /* b */
345bf215546Sopenharmony_ci                              accBits, /* a */
346bf215546Sopenharmony_ci                              0,         /* level */
347bf215546Sopenharmony_ci                              0,         /* numAux */
348bf215546Sopenharmony_ci                              0          /* numSamples */
349bf215546Sopenharmony_ci         );
350bf215546Sopenharmony_ci   }
351bf215546Sopenharmony_ci   else {
352bf215546Sopenharmony_ci      _mesa_warning(NULL, "Mesa: error in glXCreateContext: bad visual\n");
353bf215546Sopenharmony_ci      return NULL;
354bf215546Sopenharmony_ci   }
355bf215546Sopenharmony_ci}
356bf215546Sopenharmony_ci
357bf215546Sopenharmony_ci
358bf215546Sopenharmony_ci
359bf215546Sopenharmony_ci/*
360bf215546Sopenharmony_ci * Find the GLX visual associated with an XVisualInfo.
361bf215546Sopenharmony_ci */
362bf215546Sopenharmony_cistatic XMesaVisual
363bf215546Sopenharmony_cifind_glx_visual( Display *dpy, XVisualInfo *vinfo )
364bf215546Sopenharmony_ci{
365bf215546Sopenharmony_ci   int i;
366bf215546Sopenharmony_ci
367bf215546Sopenharmony_ci   /* try to match visual id */
368bf215546Sopenharmony_ci   for (i=0;i<NumVisuals;i++) {
369bf215546Sopenharmony_ci      if (VisualTable[i]->display==dpy
370bf215546Sopenharmony_ci          && VisualTable[i]->visinfo->visualid == vinfo->visualid) {
371bf215546Sopenharmony_ci         return VisualTable[i];
372bf215546Sopenharmony_ci      }
373bf215546Sopenharmony_ci   }
374bf215546Sopenharmony_ci
375bf215546Sopenharmony_ci   /* if that fails, try to match pointers */
376bf215546Sopenharmony_ci   for (i=0;i<NumVisuals;i++) {
377bf215546Sopenharmony_ci      if (VisualTable[i]->display==dpy && VisualTable[i]->vishandle==vinfo) {
378bf215546Sopenharmony_ci         return VisualTable[i];
379bf215546Sopenharmony_ci      }
380bf215546Sopenharmony_ci   }
381bf215546Sopenharmony_ci
382bf215546Sopenharmony_ci   return NULL;
383bf215546Sopenharmony_ci}
384bf215546Sopenharmony_ci
385bf215546Sopenharmony_ci
386bf215546Sopenharmony_ci/**
387bf215546Sopenharmony_ci * Try to get an X visual which matches the given arguments.
388bf215546Sopenharmony_ci */
389bf215546Sopenharmony_cistatic XVisualInfo *
390bf215546Sopenharmony_ciget_visual( Display *dpy, int scr, unsigned int depth, int xclass )
391bf215546Sopenharmony_ci{
392bf215546Sopenharmony_ci   XVisualInfo temp, *vis;
393bf215546Sopenharmony_ci   long mask;
394bf215546Sopenharmony_ci   int n;
395bf215546Sopenharmony_ci   unsigned int default_depth;
396bf215546Sopenharmony_ci   int default_class;
397bf215546Sopenharmony_ci
398bf215546Sopenharmony_ci   mask = VisualScreenMask | VisualDepthMask | VisualClassMask;
399bf215546Sopenharmony_ci   temp.screen = scr;
400bf215546Sopenharmony_ci   temp.depth = depth;
401bf215546Sopenharmony_ci   temp.CLASS = xclass;
402bf215546Sopenharmony_ci
403bf215546Sopenharmony_ci   default_depth = DefaultDepth(dpy,scr);
404bf215546Sopenharmony_ci   default_class = DefaultVisual(dpy,scr)->CLASS;
405bf215546Sopenharmony_ci
406bf215546Sopenharmony_ci   if (depth==default_depth && xclass==default_class) {
407bf215546Sopenharmony_ci      /* try to get root window's visual */
408bf215546Sopenharmony_ci      temp.visualid = DefaultVisual(dpy,scr)->visualid;
409bf215546Sopenharmony_ci      mask |= VisualIDMask;
410bf215546Sopenharmony_ci   }
411bf215546Sopenharmony_ci
412bf215546Sopenharmony_ci   vis = XGetVisualInfo( dpy, mask, &temp, &n );
413bf215546Sopenharmony_ci
414bf215546Sopenharmony_ci   /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
415bf215546Sopenharmony_ci    * An SGI Infinite Reality system, for example, can have 30bpp pixels:
416bf215546Sopenharmony_ci    * 10 bits per color channel.  Mesa's limited to a max of 8 bits/channel.
417bf215546Sopenharmony_ci    */
418bf215546Sopenharmony_ci   if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) {
419bf215546Sopenharmony_ci      if (util_bitcount((GLuint) vis->red_mask  ) <= 8 &&
420bf215546Sopenharmony_ci          util_bitcount((GLuint) vis->green_mask) <= 8 &&
421bf215546Sopenharmony_ci          util_bitcount((GLuint) vis->blue_mask ) <= 8) {
422bf215546Sopenharmony_ci         return vis;
423bf215546Sopenharmony_ci      }
424bf215546Sopenharmony_ci      else {
425bf215546Sopenharmony_ci         free((void *) vis);
426bf215546Sopenharmony_ci         return NULL;
427bf215546Sopenharmony_ci      }
428bf215546Sopenharmony_ci   }
429bf215546Sopenharmony_ci
430bf215546Sopenharmony_ci   return vis;
431bf215546Sopenharmony_ci}
432bf215546Sopenharmony_ci
433bf215546Sopenharmony_ci
434bf215546Sopenharmony_ci/*
435bf215546Sopenharmony_ci * Retrieve the value of the given environment variable and find
436bf215546Sopenharmony_ci * the X visual which matches it.
437bf215546Sopenharmony_ci * Input:  dpy - the display
438bf215546Sopenharmony_ci *         screen - the screen number
439bf215546Sopenharmony_ci *         varname - the name of the environment variable
440bf215546Sopenharmony_ci * Return:  an XVisualInfo pointer to NULL if error.
441bf215546Sopenharmony_ci */
442bf215546Sopenharmony_cistatic XVisualInfo *
443bf215546Sopenharmony_ciget_env_visual(Display *dpy, int scr, const char *varname)
444bf215546Sopenharmony_ci{
445bf215546Sopenharmony_ci   char value[100], type[100];
446bf215546Sopenharmony_ci   int depth, xclass = -1;
447bf215546Sopenharmony_ci   XVisualInfo *vis;
448bf215546Sopenharmony_ci
449bf215546Sopenharmony_ci   if (!getenv( varname )) {
450bf215546Sopenharmony_ci      return NULL;
451bf215546Sopenharmony_ci   }
452bf215546Sopenharmony_ci
453bf215546Sopenharmony_ci   strncpy( value, getenv(varname), 100 );
454bf215546Sopenharmony_ci   value[99] = 0;
455bf215546Sopenharmony_ci
456bf215546Sopenharmony_ci   sscanf( value, "%s %d", type, &depth );
457bf215546Sopenharmony_ci
458bf215546Sopenharmony_ci   if (strcmp(type,"TrueColor")==0)          xclass = TrueColor;
459bf215546Sopenharmony_ci   else if (strcmp(type,"DirectColor")==0)   xclass = DirectColor;
460bf215546Sopenharmony_ci   else if (strcmp(type,"PseudoColor")==0)   xclass = PseudoColor;
461bf215546Sopenharmony_ci   else if (strcmp(type,"StaticColor")==0)   xclass = StaticColor;
462bf215546Sopenharmony_ci   else if (strcmp(type,"GrayScale")==0)     xclass = GrayScale;
463bf215546Sopenharmony_ci   else if (strcmp(type,"StaticGray")==0)    xclass = StaticGray;
464bf215546Sopenharmony_ci
465bf215546Sopenharmony_ci   if (xclass>-1 && depth>0) {
466bf215546Sopenharmony_ci      vis = get_visual( dpy, scr, depth, xclass );
467bf215546Sopenharmony_ci      if (vis) {
468bf215546Sopenharmony_ci	 return vis;
469bf215546Sopenharmony_ci      }
470bf215546Sopenharmony_ci   }
471bf215546Sopenharmony_ci
472bf215546Sopenharmony_ci   _mesa_warning(NULL, "GLX unable to find visual class=%s, depth=%d.",
473bf215546Sopenharmony_ci                 type, depth);
474bf215546Sopenharmony_ci
475bf215546Sopenharmony_ci   return NULL;
476bf215546Sopenharmony_ci}
477bf215546Sopenharmony_ci
478bf215546Sopenharmony_ci
479bf215546Sopenharmony_ci
480bf215546Sopenharmony_ci/*
481bf215546Sopenharmony_ci * Select an X visual which satisfies the RGBA flag and minimum depth.
482bf215546Sopenharmony_ci * Input:  dpy,
483bf215546Sopenharmony_ci *         screen - X display and screen number
484bf215546Sopenharmony_ci *         min_depth - minimum visual depth
485bf215546Sopenharmony_ci *         preferred_class - preferred GLX visual class or DONT_CARE
486bf215546Sopenharmony_ci * Return:  pointer to an XVisualInfo or NULL.
487bf215546Sopenharmony_ci */
488bf215546Sopenharmony_cistatic XVisualInfo *
489bf215546Sopenharmony_cichoose_x_visual( Display *dpy, int screen, int min_depth,
490bf215546Sopenharmony_ci                 int preferred_class )
491bf215546Sopenharmony_ci{
492bf215546Sopenharmony_ci   XVisualInfo *vis;
493bf215546Sopenharmony_ci   int xclass, visclass = 0;
494bf215546Sopenharmony_ci   int depth;
495bf215546Sopenharmony_ci
496bf215546Sopenharmony_ci   /* First see if the MESA_RGB_VISUAL env var is defined */
497bf215546Sopenharmony_ci   vis = get_env_visual( dpy, screen, "MESA_RGB_VISUAL" );
498bf215546Sopenharmony_ci   if (vis) {
499bf215546Sopenharmony_ci      return vis;
500bf215546Sopenharmony_ci   }
501bf215546Sopenharmony_ci   /* Otherwise, search for a suitable visual */
502bf215546Sopenharmony_ci   if (preferred_class==DONT_CARE) {
503bf215546Sopenharmony_ci      for (xclass=0;xclass<6;xclass++) {
504bf215546Sopenharmony_ci         switch (xclass) {
505bf215546Sopenharmony_ci         case 0:  visclass = TrueColor;    break;
506bf215546Sopenharmony_ci         case 1:  visclass = DirectColor;  break;
507bf215546Sopenharmony_ci         case 2:  visclass = PseudoColor;  break;
508bf215546Sopenharmony_ci         case 3:  visclass = StaticColor;  break;
509bf215546Sopenharmony_ci         case 4:  visclass = GrayScale;    break;
510bf215546Sopenharmony_ci         case 5:  visclass = StaticGray;   break;
511bf215546Sopenharmony_ci         }
512bf215546Sopenharmony_ci         if (min_depth==0) {
513bf215546Sopenharmony_ci            /* start with shallowest */
514bf215546Sopenharmony_ci            for (depth=0;depth<=32;depth++) {
515bf215546Sopenharmony_ci               if (visclass==TrueColor && depth==8) {
516bf215546Sopenharmony_ci                  /* Special case:  try to get 8-bit PseudoColor before */
517bf215546Sopenharmony_ci                  /* 8-bit TrueColor */
518bf215546Sopenharmony_ci                  vis = get_visual( dpy, screen, 8, PseudoColor );
519bf215546Sopenharmony_ci                  if (vis) {
520bf215546Sopenharmony_ci                     return vis;
521bf215546Sopenharmony_ci                  }
522bf215546Sopenharmony_ci               }
523bf215546Sopenharmony_ci               vis = get_visual( dpy, screen, depth, visclass );
524bf215546Sopenharmony_ci               if (vis) {
525bf215546Sopenharmony_ci                  return vis;
526bf215546Sopenharmony_ci               }
527bf215546Sopenharmony_ci            }
528bf215546Sopenharmony_ci         }
529bf215546Sopenharmony_ci         else {
530bf215546Sopenharmony_ci            /* start with deepest */
531bf215546Sopenharmony_ci            for (depth=32;depth>=min_depth;depth--) {
532bf215546Sopenharmony_ci               if (visclass==TrueColor && depth==8) {
533bf215546Sopenharmony_ci                  /* Special case:  try to get 8-bit PseudoColor before */
534bf215546Sopenharmony_ci                  /* 8-bit TrueColor */
535bf215546Sopenharmony_ci                  vis = get_visual( dpy, screen, 8, PseudoColor );
536bf215546Sopenharmony_ci                  if (vis) {
537bf215546Sopenharmony_ci                     return vis;
538bf215546Sopenharmony_ci                  }
539bf215546Sopenharmony_ci               }
540bf215546Sopenharmony_ci               vis = get_visual( dpy, screen, depth, visclass );
541bf215546Sopenharmony_ci               if (vis) {
542bf215546Sopenharmony_ci                  return vis;
543bf215546Sopenharmony_ci               }
544bf215546Sopenharmony_ci            }
545bf215546Sopenharmony_ci         }
546bf215546Sopenharmony_ci      }
547bf215546Sopenharmony_ci   }
548bf215546Sopenharmony_ci   else {
549bf215546Sopenharmony_ci      /* search for a specific visual class */
550bf215546Sopenharmony_ci      switch (preferred_class) {
551bf215546Sopenharmony_ci      case GLX_TRUE_COLOR_EXT:    visclass = TrueColor;    break;
552bf215546Sopenharmony_ci      case GLX_DIRECT_COLOR_EXT:  visclass = DirectColor;  break;
553bf215546Sopenharmony_ci      case GLX_PSEUDO_COLOR_EXT:  visclass = PseudoColor;  break;
554bf215546Sopenharmony_ci      case GLX_STATIC_COLOR_EXT:  visclass = StaticColor;  break;
555bf215546Sopenharmony_ci      case GLX_GRAY_SCALE_EXT:    visclass = GrayScale;    break;
556bf215546Sopenharmony_ci      case GLX_STATIC_GRAY_EXT:   visclass = StaticGray;   break;
557bf215546Sopenharmony_ci      default:   return NULL;
558bf215546Sopenharmony_ci      }
559bf215546Sopenharmony_ci      if (min_depth==0) {
560bf215546Sopenharmony_ci         /* start with shallowest */
561bf215546Sopenharmony_ci         for (depth=0;depth<=32;depth++) {
562bf215546Sopenharmony_ci            vis = get_visual( dpy, screen, depth, visclass );
563bf215546Sopenharmony_ci            if (vis) {
564bf215546Sopenharmony_ci               return vis;
565bf215546Sopenharmony_ci            }
566bf215546Sopenharmony_ci         }
567bf215546Sopenharmony_ci      }
568bf215546Sopenharmony_ci      else {
569bf215546Sopenharmony_ci         /* start with deepest */
570bf215546Sopenharmony_ci         for (depth=32;depth>=min_depth;depth--) {
571bf215546Sopenharmony_ci            vis = get_visual( dpy, screen, depth, visclass );
572bf215546Sopenharmony_ci            if (vis) {
573bf215546Sopenharmony_ci               return vis;
574bf215546Sopenharmony_ci            }
575bf215546Sopenharmony_ci         }
576bf215546Sopenharmony_ci      }
577bf215546Sopenharmony_ci   }
578bf215546Sopenharmony_ci
579bf215546Sopenharmony_ci   /* didn't find a visual */
580bf215546Sopenharmony_ci   return NULL;
581bf215546Sopenharmony_ci}
582bf215546Sopenharmony_ci
583bf215546Sopenharmony_ci
584bf215546Sopenharmony_ci
585bf215546Sopenharmony_ci
586bf215546Sopenharmony_ci/**********************************************************************/
587bf215546Sopenharmony_ci/***             Display-related functions                          ***/
588bf215546Sopenharmony_ci/**********************************************************************/
589bf215546Sopenharmony_ci
590bf215546Sopenharmony_ci
591bf215546Sopenharmony_ci/**
592bf215546Sopenharmony_ci * Free all XMesaVisuals which are associated with the given display.
593bf215546Sopenharmony_ci */
594bf215546Sopenharmony_cistatic void
595bf215546Sopenharmony_cidestroy_visuals_on_display(Display *dpy)
596bf215546Sopenharmony_ci{
597bf215546Sopenharmony_ci   int i;
598bf215546Sopenharmony_ci   for (i = 0; i < NumVisuals; i++) {
599bf215546Sopenharmony_ci      if (VisualTable[i]->display == dpy) {
600bf215546Sopenharmony_ci         /* remove this visual */
601bf215546Sopenharmony_ci         int j;
602bf215546Sopenharmony_ci         free(VisualTable[i]);
603bf215546Sopenharmony_ci         for (j = i; j < NumVisuals - 1; j++)
604bf215546Sopenharmony_ci            VisualTable[j] = VisualTable[j + 1];
605bf215546Sopenharmony_ci         NumVisuals--;
606bf215546Sopenharmony_ci      }
607bf215546Sopenharmony_ci   }
608bf215546Sopenharmony_ci}
609bf215546Sopenharmony_ci
610bf215546Sopenharmony_ci
611bf215546Sopenharmony_ci/**
612bf215546Sopenharmony_ci * Called from XCloseDisplay() to let us free our display-related data.
613bf215546Sopenharmony_ci */
614bf215546Sopenharmony_cistatic int
615bf215546Sopenharmony_ciclose_display_callback(Display *dpy, XExtCodes *codes)
616bf215546Sopenharmony_ci{
617bf215546Sopenharmony_ci   xmesa_destroy_buffers_on_display(dpy);
618bf215546Sopenharmony_ci   destroy_visuals_on_display(dpy);
619bf215546Sopenharmony_ci   xmesa_close_display(dpy);
620bf215546Sopenharmony_ci   return 0;
621bf215546Sopenharmony_ci}
622bf215546Sopenharmony_ci
623bf215546Sopenharmony_ci
624bf215546Sopenharmony_ci/**
625bf215546Sopenharmony_ci * Look for the named extension on given display and return a pointer
626bf215546Sopenharmony_ci * to the _XExtension data, or NULL if extension not found.
627bf215546Sopenharmony_ci */
628bf215546Sopenharmony_cistatic _XExtension *
629bf215546Sopenharmony_cilookup_extension(Display *dpy, const char *extName)
630bf215546Sopenharmony_ci{
631bf215546Sopenharmony_ci   _XExtension *ext;
632bf215546Sopenharmony_ci   for (ext = dpy->ext_procs; ext; ext = ext->next) {
633bf215546Sopenharmony_ci      if (ext->name && strcmp(ext->name, extName) == 0) {
634bf215546Sopenharmony_ci         return ext;
635bf215546Sopenharmony_ci      }
636bf215546Sopenharmony_ci   }
637bf215546Sopenharmony_ci   return NULL;
638bf215546Sopenharmony_ci}
639bf215546Sopenharmony_ci
640bf215546Sopenharmony_ci
641bf215546Sopenharmony_ci/**
642bf215546Sopenharmony_ci * Whenever we're given a new Display pointer, call this function to
643bf215546Sopenharmony_ci * register our close_display_callback function.
644bf215546Sopenharmony_ci */
645bf215546Sopenharmony_cistatic void
646bf215546Sopenharmony_ciregister_with_display(Display *dpy)
647bf215546Sopenharmony_ci{
648bf215546Sopenharmony_ci   const char *extName = "MesaGLX";
649bf215546Sopenharmony_ci   _XExtension *ext;
650bf215546Sopenharmony_ci
651bf215546Sopenharmony_ci   ext = lookup_extension(dpy, extName);
652bf215546Sopenharmony_ci   if (!ext) {
653bf215546Sopenharmony_ci      XExtCodes *c = XAddExtension(dpy);
654bf215546Sopenharmony_ci      ext = dpy->ext_procs;  /* new extension is at head of list */
655bf215546Sopenharmony_ci      assert(c->extension == ext->codes.extension);
656bf215546Sopenharmony_ci      (void) c;
657bf215546Sopenharmony_ci      ext->name = strdup(extName);
658bf215546Sopenharmony_ci      ext->close_display = close_display_callback;
659bf215546Sopenharmony_ci   }
660bf215546Sopenharmony_ci}
661bf215546Sopenharmony_ci
662bf215546Sopenharmony_ci
663bf215546Sopenharmony_ci/**
664bf215546Sopenharmony_ci * Fake an error.
665bf215546Sopenharmony_ci */
666bf215546Sopenharmony_cistatic int
667bf215546Sopenharmony_cigenerate_error(Display *dpy,
668bf215546Sopenharmony_ci               unsigned char error_code,
669bf215546Sopenharmony_ci               XID resourceid,
670bf215546Sopenharmony_ci               unsigned char minor_code,
671bf215546Sopenharmony_ci               Bool core)
672bf215546Sopenharmony_ci{
673bf215546Sopenharmony_ci   XErrorHandler handler;
674bf215546Sopenharmony_ci   int major_opcode;
675bf215546Sopenharmony_ci   int first_event;
676bf215546Sopenharmony_ci   int first_error;
677bf215546Sopenharmony_ci   XEvent event;
678bf215546Sopenharmony_ci
679bf215546Sopenharmony_ci   handler = XSetErrorHandler(NULL);
680bf215546Sopenharmony_ci   XSetErrorHandler(handler);
681bf215546Sopenharmony_ci   if (!handler) {
682bf215546Sopenharmony_ci      return 0;
683bf215546Sopenharmony_ci   }
684bf215546Sopenharmony_ci
685bf215546Sopenharmony_ci   if (!XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_opcode, &first_event, &first_error)) {
686bf215546Sopenharmony_ci      major_opcode = 0;
687bf215546Sopenharmony_ci      first_event = 0;
688bf215546Sopenharmony_ci      first_error = 0;
689bf215546Sopenharmony_ci   }
690bf215546Sopenharmony_ci
691bf215546Sopenharmony_ci   if (!core) {
692bf215546Sopenharmony_ci      error_code += first_error;
693bf215546Sopenharmony_ci   }
694bf215546Sopenharmony_ci
695bf215546Sopenharmony_ci   memset(&event, 0, sizeof event);
696bf215546Sopenharmony_ci
697bf215546Sopenharmony_ci   event.xerror.type = X_Error;
698bf215546Sopenharmony_ci   event.xerror.display = dpy;
699bf215546Sopenharmony_ci   event.xerror.resourceid = resourceid;
700bf215546Sopenharmony_ci   event.xerror.serial = NextRequest(dpy) - 1;
701bf215546Sopenharmony_ci   event.xerror.error_code = error_code;
702bf215546Sopenharmony_ci   event.xerror.request_code = major_opcode;
703bf215546Sopenharmony_ci   event.xerror.minor_code = minor_code;
704bf215546Sopenharmony_ci
705bf215546Sopenharmony_ci   return handler(dpy, &event.xerror);
706bf215546Sopenharmony_ci}
707bf215546Sopenharmony_ci
708bf215546Sopenharmony_ci
709bf215546Sopenharmony_ci/**********************************************************************/
710bf215546Sopenharmony_ci/***                  Begin Fake GLX API Functions                  ***/
711bf215546Sopenharmony_ci/**********************************************************************/
712bf215546Sopenharmony_ci
713bf215546Sopenharmony_ci
714bf215546Sopenharmony_ci/**
715bf215546Sopenharmony_ci * Helper used by glXChooseVisual and glXChooseFBConfig.
716bf215546Sopenharmony_ci * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
717bf215546Sopenharmony_ci * the later.
718bf215546Sopenharmony_ci * In either case, the attribute list is terminated with the value 'None'.
719bf215546Sopenharmony_ci */
720bf215546Sopenharmony_cistatic XMesaVisual
721bf215546Sopenharmony_cichoose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig )
722bf215546Sopenharmony_ci{
723bf215546Sopenharmony_ci   const GLboolean rgbModeDefault = fbConfig;
724bf215546Sopenharmony_ci   const int *parselist;
725bf215546Sopenharmony_ci   XVisualInfo *vis;
726bf215546Sopenharmony_ci   int min_red=0, min_green=0, min_blue=0;
727bf215546Sopenharmony_ci   GLboolean rgb_flag = rgbModeDefault;
728bf215546Sopenharmony_ci   GLboolean alpha_flag = GL_FALSE;
729bf215546Sopenharmony_ci   GLboolean double_flag = GL_FALSE;
730bf215546Sopenharmony_ci   GLboolean stereo_flag = GL_FALSE;
731bf215546Sopenharmony_ci   GLint depth_size = 0;
732bf215546Sopenharmony_ci   GLint stencil_size = 0;
733bf215546Sopenharmony_ci   GLint accumRedSize = 0;
734bf215546Sopenharmony_ci   GLint accumGreenSize = 0;
735bf215546Sopenharmony_ci   GLint accumBlueSize = 0;
736bf215546Sopenharmony_ci   GLint accumAlphaSize = 0;
737bf215546Sopenharmony_ci   int level = 0;
738bf215546Sopenharmony_ci   int visual_type = DONT_CARE;
739bf215546Sopenharmony_ci   GLint caveat = DONT_CARE;
740bf215546Sopenharmony_ci   XMesaVisual xmvis = NULL;
741bf215546Sopenharmony_ci   int desiredVisualID = -1;
742bf215546Sopenharmony_ci   int numAux = 0;
743bf215546Sopenharmony_ci   GLint num_samples = 0;
744bf215546Sopenharmony_ci
745bf215546Sopenharmony_ci   if (xmesa_init( dpy ) != 0) {
746bf215546Sopenharmony_ci      _mesa_warning(NULL, "Failed to initialize display");
747bf215546Sopenharmony_ci      return NULL;
748bf215546Sopenharmony_ci   }
749bf215546Sopenharmony_ci
750bf215546Sopenharmony_ci   parselist = list;
751bf215546Sopenharmony_ci
752bf215546Sopenharmony_ci   while (*parselist) {
753bf215546Sopenharmony_ci
754bf215546Sopenharmony_ci      if (fbConfig &&
755bf215546Sopenharmony_ci          parselist[1] == GLX_DONT_CARE &&
756bf215546Sopenharmony_ci          parselist[0] != GLX_LEVEL) {
757bf215546Sopenharmony_ci         /* For glXChooseFBConfig(), skip attributes whose value is
758bf215546Sopenharmony_ci          * GLX_DONT_CARE, unless it's GLX_LEVEL (which can legitimately be
759bf215546Sopenharmony_ci          * a negative value).
760bf215546Sopenharmony_ci          *
761bf215546Sopenharmony_ci          * From page 17 (23 of the pdf) of the GLX 1.4 spec:
762bf215546Sopenharmony_ci          * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
763bf215546Sopenharmony_ci          */
764bf215546Sopenharmony_ci         parselist += 2;
765bf215546Sopenharmony_ci         continue;
766bf215546Sopenharmony_ci      }
767bf215546Sopenharmony_ci
768bf215546Sopenharmony_ci      switch (*parselist) {
769bf215546Sopenharmony_ci	 case GLX_USE_GL:
770bf215546Sopenharmony_ci            if (fbConfig) {
771bf215546Sopenharmony_ci               /* invalid token */
772bf215546Sopenharmony_ci               return NULL;
773bf215546Sopenharmony_ci            }
774bf215546Sopenharmony_ci            else {
775bf215546Sopenharmony_ci               /* skip */
776bf215546Sopenharmony_ci               parselist++;
777bf215546Sopenharmony_ci            }
778bf215546Sopenharmony_ci	    break;
779bf215546Sopenharmony_ci	 case GLX_BUFFER_SIZE:
780bf215546Sopenharmony_ci	    parselist++;
781bf215546Sopenharmony_ci	    parselist++;
782bf215546Sopenharmony_ci	    break;
783bf215546Sopenharmony_ci	 case GLX_LEVEL:
784bf215546Sopenharmony_ci	    parselist++;
785bf215546Sopenharmony_ci            level = *parselist++;
786bf215546Sopenharmony_ci	    break;
787bf215546Sopenharmony_ci	 case GLX_RGBA:
788bf215546Sopenharmony_ci            if (fbConfig) {
789bf215546Sopenharmony_ci               /* invalid token */
790bf215546Sopenharmony_ci               return NULL;
791bf215546Sopenharmony_ci            }
792bf215546Sopenharmony_ci            else {
793bf215546Sopenharmony_ci               rgb_flag = GL_TRUE;
794bf215546Sopenharmony_ci               parselist++;
795bf215546Sopenharmony_ci            }
796bf215546Sopenharmony_ci	    break;
797bf215546Sopenharmony_ci	 case GLX_DOUBLEBUFFER:
798bf215546Sopenharmony_ci            parselist++;
799bf215546Sopenharmony_ci            if (fbConfig) {
800bf215546Sopenharmony_ci               double_flag = *parselist++;
801bf215546Sopenharmony_ci            }
802bf215546Sopenharmony_ci            else {
803bf215546Sopenharmony_ci               double_flag = GL_TRUE;
804bf215546Sopenharmony_ci            }
805bf215546Sopenharmony_ci	    break;
806bf215546Sopenharmony_ci	 case GLX_STEREO:
807bf215546Sopenharmony_ci            parselist++;
808bf215546Sopenharmony_ci            if (fbConfig) {
809bf215546Sopenharmony_ci               stereo_flag = *parselist++;
810bf215546Sopenharmony_ci            }
811bf215546Sopenharmony_ci            else {
812bf215546Sopenharmony_ci               stereo_flag = GL_TRUE;
813bf215546Sopenharmony_ci            }
814bf215546Sopenharmony_ci            break;
815bf215546Sopenharmony_ci	 case GLX_AUX_BUFFERS:
816bf215546Sopenharmony_ci	    parselist++;
817bf215546Sopenharmony_ci            numAux = *parselist++;
818bf215546Sopenharmony_ci            if (numAux > MAX_AUX_BUFFERS)
819bf215546Sopenharmony_ci               return NULL;
820bf215546Sopenharmony_ci	    break;
821bf215546Sopenharmony_ci	 case GLX_RED_SIZE:
822bf215546Sopenharmony_ci	    parselist++;
823bf215546Sopenharmony_ci	    min_red = *parselist++;
824bf215546Sopenharmony_ci	    break;
825bf215546Sopenharmony_ci	 case GLX_GREEN_SIZE:
826bf215546Sopenharmony_ci	    parselist++;
827bf215546Sopenharmony_ci	    min_green = *parselist++;
828bf215546Sopenharmony_ci	    break;
829bf215546Sopenharmony_ci	 case GLX_BLUE_SIZE:
830bf215546Sopenharmony_ci	    parselist++;
831bf215546Sopenharmony_ci	    min_blue = *parselist++;
832bf215546Sopenharmony_ci	    break;
833bf215546Sopenharmony_ci	 case GLX_ALPHA_SIZE:
834bf215546Sopenharmony_ci	    parselist++;
835bf215546Sopenharmony_ci            {
836bf215546Sopenharmony_ci               GLint size = *parselist++;
837bf215546Sopenharmony_ci               alpha_flag = size ? GL_TRUE : GL_FALSE;
838bf215546Sopenharmony_ci            }
839bf215546Sopenharmony_ci	    break;
840bf215546Sopenharmony_ci	 case GLX_DEPTH_SIZE:
841bf215546Sopenharmony_ci	    parselist++;
842bf215546Sopenharmony_ci	    depth_size = *parselist++;
843bf215546Sopenharmony_ci	    break;
844bf215546Sopenharmony_ci	 case GLX_STENCIL_SIZE:
845bf215546Sopenharmony_ci	    parselist++;
846bf215546Sopenharmony_ci	    stencil_size = *parselist++;
847bf215546Sopenharmony_ci	    break;
848bf215546Sopenharmony_ci	 case GLX_ACCUM_RED_SIZE:
849bf215546Sopenharmony_ci	    parselist++;
850bf215546Sopenharmony_ci            {
851bf215546Sopenharmony_ci               GLint size = *parselist++;
852bf215546Sopenharmony_ci               accumRedSize = MAX2( accumRedSize, size );
853bf215546Sopenharmony_ci            }
854bf215546Sopenharmony_ci            break;
855bf215546Sopenharmony_ci	 case GLX_ACCUM_GREEN_SIZE:
856bf215546Sopenharmony_ci	    parselist++;
857bf215546Sopenharmony_ci            {
858bf215546Sopenharmony_ci               GLint size = *parselist++;
859bf215546Sopenharmony_ci               accumGreenSize = MAX2( accumGreenSize, size );
860bf215546Sopenharmony_ci            }
861bf215546Sopenharmony_ci            break;
862bf215546Sopenharmony_ci	 case GLX_ACCUM_BLUE_SIZE:
863bf215546Sopenharmony_ci	    parselist++;
864bf215546Sopenharmony_ci            {
865bf215546Sopenharmony_ci               GLint size = *parselist++;
866bf215546Sopenharmony_ci               accumBlueSize = MAX2( accumBlueSize, size );
867bf215546Sopenharmony_ci            }
868bf215546Sopenharmony_ci            break;
869bf215546Sopenharmony_ci	 case GLX_ACCUM_ALPHA_SIZE:
870bf215546Sopenharmony_ci	    parselist++;
871bf215546Sopenharmony_ci            {
872bf215546Sopenharmony_ci               GLint size = *parselist++;
873bf215546Sopenharmony_ci               accumAlphaSize = MAX2( accumAlphaSize, size );
874bf215546Sopenharmony_ci            }
875bf215546Sopenharmony_ci	    break;
876bf215546Sopenharmony_ci
877bf215546Sopenharmony_ci         /*
878bf215546Sopenharmony_ci          * GLX_EXT_visual_info extension
879bf215546Sopenharmony_ci          */
880bf215546Sopenharmony_ci         case GLX_X_VISUAL_TYPE_EXT:
881bf215546Sopenharmony_ci            parselist++;
882bf215546Sopenharmony_ci            visual_type = *parselist++;
883bf215546Sopenharmony_ci            break;
884bf215546Sopenharmony_ci         case GLX_TRANSPARENT_TYPE_EXT:
885bf215546Sopenharmony_ci            parselist++;
886bf215546Sopenharmony_ci            parselist++;
887bf215546Sopenharmony_ci            break;
888bf215546Sopenharmony_ci         case GLX_TRANSPARENT_INDEX_VALUE_EXT:
889bf215546Sopenharmony_ci            parselist++;
890bf215546Sopenharmony_ci            parselist++;
891bf215546Sopenharmony_ci            break;
892bf215546Sopenharmony_ci         case GLX_TRANSPARENT_RED_VALUE_EXT:
893bf215546Sopenharmony_ci         case GLX_TRANSPARENT_GREEN_VALUE_EXT:
894bf215546Sopenharmony_ci         case GLX_TRANSPARENT_BLUE_VALUE_EXT:
895bf215546Sopenharmony_ci         case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
896bf215546Sopenharmony_ci	    /* ignore */
897bf215546Sopenharmony_ci	    parselist++;
898bf215546Sopenharmony_ci	    parselist++;
899bf215546Sopenharmony_ci	    break;
900bf215546Sopenharmony_ci
901bf215546Sopenharmony_ci         /*
902bf215546Sopenharmony_ci          * GLX_EXT_visual_info extension
903bf215546Sopenharmony_ci          */
904bf215546Sopenharmony_ci         case GLX_VISUAL_CAVEAT_EXT:
905bf215546Sopenharmony_ci            parselist++;
906bf215546Sopenharmony_ci            caveat = *parselist++; /* ignored for now */
907bf215546Sopenharmony_ci            break;
908bf215546Sopenharmony_ci
909bf215546Sopenharmony_ci         /*
910bf215546Sopenharmony_ci          * GLX_ARB_multisample
911bf215546Sopenharmony_ci          */
912bf215546Sopenharmony_ci         case GLX_SAMPLE_BUFFERS_ARB:
913bf215546Sopenharmony_ci            /* ignore */
914bf215546Sopenharmony_ci            parselist++;
915bf215546Sopenharmony_ci            parselist++;
916bf215546Sopenharmony_ci            break;
917bf215546Sopenharmony_ci         case GLX_SAMPLES_ARB:
918bf215546Sopenharmony_ci            parselist++;
919bf215546Sopenharmony_ci            num_samples = *parselist++;
920bf215546Sopenharmony_ci            break;
921bf215546Sopenharmony_ci
922bf215546Sopenharmony_ci         /*
923bf215546Sopenharmony_ci          * FBConfig attribs.
924bf215546Sopenharmony_ci          */
925bf215546Sopenharmony_ci         case GLX_RENDER_TYPE:
926bf215546Sopenharmony_ci            if (!fbConfig)
927bf215546Sopenharmony_ci               return NULL;
928bf215546Sopenharmony_ci            parselist++;
929bf215546Sopenharmony_ci            if (*parselist & GLX_RGBA_BIT) {
930bf215546Sopenharmony_ci               rgb_flag = GL_TRUE;
931bf215546Sopenharmony_ci            }
932bf215546Sopenharmony_ci            else if (*parselist & GLX_COLOR_INDEX_BIT) {
933bf215546Sopenharmony_ci               rgb_flag = GL_FALSE;
934bf215546Sopenharmony_ci            }
935bf215546Sopenharmony_ci            else if (*parselist == 0) {
936bf215546Sopenharmony_ci               rgb_flag = GL_TRUE;
937bf215546Sopenharmony_ci            }
938bf215546Sopenharmony_ci            parselist++;
939bf215546Sopenharmony_ci            break;
940bf215546Sopenharmony_ci         case GLX_DRAWABLE_TYPE:
941bf215546Sopenharmony_ci            if (!fbConfig)
942bf215546Sopenharmony_ci               return NULL;
943bf215546Sopenharmony_ci            parselist++;
944bf215546Sopenharmony_ci            if (*parselist & ~(GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT)) {
945bf215546Sopenharmony_ci               return NULL; /* bad bit */
946bf215546Sopenharmony_ci            }
947bf215546Sopenharmony_ci            parselist++;
948bf215546Sopenharmony_ci            break;
949bf215546Sopenharmony_ci         case GLX_FBCONFIG_ID:
950bf215546Sopenharmony_ci         case GLX_VISUAL_ID:
951bf215546Sopenharmony_ci            if (!fbConfig)
952bf215546Sopenharmony_ci               return NULL;
953bf215546Sopenharmony_ci            parselist++;
954bf215546Sopenharmony_ci            desiredVisualID = *parselist++;
955bf215546Sopenharmony_ci            break;
956bf215546Sopenharmony_ci         case GLX_X_RENDERABLE:
957bf215546Sopenharmony_ci         case GLX_MAX_PBUFFER_WIDTH:
958bf215546Sopenharmony_ci         case GLX_MAX_PBUFFER_HEIGHT:
959bf215546Sopenharmony_ci         case GLX_MAX_PBUFFER_PIXELS:
960bf215546Sopenharmony_ci            if (!fbConfig)
961bf215546Sopenharmony_ci               return NULL; /* invalid config option */
962bf215546Sopenharmony_ci            parselist += 2; /* ignore the parameter */
963bf215546Sopenharmony_ci            break;
964bf215546Sopenharmony_ci
965bf215546Sopenharmony_ci         case GLX_BIND_TO_TEXTURE_RGB_EXT:
966bf215546Sopenharmony_ci            parselist++; /*skip*/
967bf215546Sopenharmony_ci            break;
968bf215546Sopenharmony_ci         case GLX_BIND_TO_TEXTURE_RGBA_EXT:
969bf215546Sopenharmony_ci            parselist++; /*skip*/
970bf215546Sopenharmony_ci            break;
971bf215546Sopenharmony_ci         case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
972bf215546Sopenharmony_ci            parselist++; /*skip*/
973bf215546Sopenharmony_ci            break;
974bf215546Sopenharmony_ci         case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
975bf215546Sopenharmony_ci            parselist++;
976bf215546Sopenharmony_ci            if (*parselist & ~(GLX_TEXTURE_1D_BIT_EXT |
977bf215546Sopenharmony_ci                               GLX_TEXTURE_2D_BIT_EXT |
978bf215546Sopenharmony_ci                               GLX_TEXTURE_RECTANGLE_BIT_EXT)) {
979bf215546Sopenharmony_ci               /* invalid bit */
980bf215546Sopenharmony_ci               return NULL;
981bf215546Sopenharmony_ci            }
982bf215546Sopenharmony_ci            break;
983bf215546Sopenharmony_ci         case GLX_Y_INVERTED_EXT:
984bf215546Sopenharmony_ci            parselist++; /*skip*/
985bf215546Sopenharmony_ci            break;
986bf215546Sopenharmony_ci
987bf215546Sopenharmony_ci	 case None:
988bf215546Sopenharmony_ci            /* end of list */
989bf215546Sopenharmony_ci	    break;
990bf215546Sopenharmony_ci
991bf215546Sopenharmony_ci	 default:
992bf215546Sopenharmony_ci	    /* undefined attribute */
993bf215546Sopenharmony_ci            _mesa_warning(NULL, "unexpected attrib 0x%x in choose_visual()",
994bf215546Sopenharmony_ci                          *parselist);
995bf215546Sopenharmony_ci	    return NULL;
996bf215546Sopenharmony_ci      }
997bf215546Sopenharmony_ci   }
998bf215546Sopenharmony_ci
999bf215546Sopenharmony_ci   (void) caveat;
1000bf215546Sopenharmony_ci
1001bf215546Sopenharmony_ci   if (num_samples < 0) {
1002bf215546Sopenharmony_ci      _mesa_warning(NULL, "GLX_SAMPLES_ARB: number of samples must not be negative");
1003bf215546Sopenharmony_ci      return NULL;
1004bf215546Sopenharmony_ci   }
1005bf215546Sopenharmony_ci
1006bf215546Sopenharmony_ci   /*
1007bf215546Sopenharmony_ci    * Since we're only simulating the GLX extension this function will never
1008bf215546Sopenharmony_ci    * find any real GL visuals.  Instead, all we can do is try to find an RGB
1009bf215546Sopenharmony_ci    * or CI visual of appropriate depth.  Other requested attributes such as
1010bf215546Sopenharmony_ci    * double buffering, depth buffer, etc. will be associated with the X
1011bf215546Sopenharmony_ci    * visual and stored in the VisualTable[].
1012bf215546Sopenharmony_ci    */
1013bf215546Sopenharmony_ci   if (desiredVisualID != -1) {
1014bf215546Sopenharmony_ci      /* try to get a specific visual, by visualID */
1015bf215546Sopenharmony_ci      XVisualInfo temp;
1016bf215546Sopenharmony_ci      int n;
1017bf215546Sopenharmony_ci      temp.visualid = desiredVisualID;
1018bf215546Sopenharmony_ci      temp.screen = screen;
1019bf215546Sopenharmony_ci      vis = XGetVisualInfo(dpy, VisualIDMask | VisualScreenMask, &temp, &n);
1020bf215546Sopenharmony_ci      if (vis) {
1021bf215546Sopenharmony_ci         /* give the visual some useful GLX attributes */
1022bf215546Sopenharmony_ci         double_flag = GL_TRUE;
1023bf215546Sopenharmony_ci         rgb_flag = GL_TRUE;
1024bf215546Sopenharmony_ci      }
1025bf215546Sopenharmony_ci   }
1026bf215546Sopenharmony_ci   else if (level==0) {
1027bf215546Sopenharmony_ci      /* normal color planes */
1028bf215546Sopenharmony_ci      /* Get an RGB visual */
1029bf215546Sopenharmony_ci      int min_rgb = min_red + min_green + min_blue;
1030bf215546Sopenharmony_ci      if (min_rgb>1 && min_rgb<8) {
1031bf215546Sopenharmony_ci         /* a special case to be sure we can get a monochrome visual */
1032bf215546Sopenharmony_ci         min_rgb = 1;
1033bf215546Sopenharmony_ci      }
1034bf215546Sopenharmony_ci      vis = choose_x_visual( dpy, screen, min_rgb, visual_type );
1035bf215546Sopenharmony_ci   }
1036bf215546Sopenharmony_ci   else {
1037bf215546Sopenharmony_ci      _mesa_warning(NULL, "overlay not supported");
1038bf215546Sopenharmony_ci      return NULL;
1039bf215546Sopenharmony_ci   }
1040bf215546Sopenharmony_ci
1041bf215546Sopenharmony_ci   if (vis) {
1042bf215546Sopenharmony_ci      /* Note: we're not exactly obeying the glXChooseVisual rules here.
1043bf215546Sopenharmony_ci       * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1044bf215546Sopenharmony_ci       * largest depth buffer size, which is 32bits/value.  Instead, we
1045bf215546Sopenharmony_ci       * return 16 to maintain performance with earlier versions of Mesa.
1046bf215546Sopenharmony_ci       */
1047bf215546Sopenharmony_ci      if (stencil_size > 0)
1048bf215546Sopenharmony_ci         depth_size = 24;  /* if Z and stencil, always use 24+8 format */
1049bf215546Sopenharmony_ci      else if (depth_size > 24)
1050bf215546Sopenharmony_ci         depth_size = 32;
1051bf215546Sopenharmony_ci      else if (depth_size > 16)
1052bf215546Sopenharmony_ci         depth_size = 24;
1053bf215546Sopenharmony_ci      else if (depth_size > 0) {
1054bf215546Sopenharmony_ci         depth_size = default_depth_bits();
1055bf215546Sopenharmony_ci      }
1056bf215546Sopenharmony_ci
1057bf215546Sopenharmony_ci      if (!alpha_flag) {
1058bf215546Sopenharmony_ci         alpha_flag = default_alpha_bits() > 0;
1059bf215546Sopenharmony_ci      }
1060bf215546Sopenharmony_ci
1061bf215546Sopenharmony_ci      /* we only support one size of stencil and accum buffers. */
1062bf215546Sopenharmony_ci      if (stencil_size > 0)
1063bf215546Sopenharmony_ci         stencil_size = 8;
1064bf215546Sopenharmony_ci
1065bf215546Sopenharmony_ci      if (accumRedSize > 0 ||
1066bf215546Sopenharmony_ci          accumGreenSize > 0 ||
1067bf215546Sopenharmony_ci          accumBlueSize > 0 ||
1068bf215546Sopenharmony_ci          accumAlphaSize > 0) {
1069bf215546Sopenharmony_ci
1070bf215546Sopenharmony_ci         accumRedSize =
1071bf215546Sopenharmony_ci            accumGreenSize =
1072bf215546Sopenharmony_ci            accumBlueSize = default_accum_bits();
1073bf215546Sopenharmony_ci
1074bf215546Sopenharmony_ci         accumAlphaSize = alpha_flag ? accumRedSize : 0;
1075bf215546Sopenharmony_ci      }
1076bf215546Sopenharmony_ci
1077bf215546Sopenharmony_ci      xmvis = save_glx_visual( dpy, vis, rgb_flag, alpha_flag, double_flag,
1078bf215546Sopenharmony_ci                               stereo_flag, depth_size, stencil_size,
1079bf215546Sopenharmony_ci                               accumRedSize, accumGreenSize,
1080bf215546Sopenharmony_ci                               accumBlueSize, accumAlphaSize, level, numAux,
1081bf215546Sopenharmony_ci                               num_samples );
1082bf215546Sopenharmony_ci   }
1083bf215546Sopenharmony_ci
1084bf215546Sopenharmony_ci   return xmvis;
1085bf215546Sopenharmony_ci}
1086bf215546Sopenharmony_ci
1087bf215546Sopenharmony_ci
1088bf215546Sopenharmony_ciPUBLIC XVisualInfo *
1089bf215546Sopenharmony_ciglXChooseVisual( Display *dpy, int screen, int *list )
1090bf215546Sopenharmony_ci{
1091bf215546Sopenharmony_ci   XMesaVisual xmvis;
1092bf215546Sopenharmony_ci
1093bf215546Sopenharmony_ci   /* register ourselves as an extension on this display */
1094bf215546Sopenharmony_ci   register_with_display(dpy);
1095bf215546Sopenharmony_ci
1096bf215546Sopenharmony_ci   xmvis = choose_visual(dpy, screen, list, GL_FALSE);
1097bf215546Sopenharmony_ci   if (xmvis) {
1098bf215546Sopenharmony_ci      /* create a new vishandle - the cached one may be stale */
1099bf215546Sopenharmony_ci      xmvis->vishandle = malloc(sizeof(XVisualInfo));
1100bf215546Sopenharmony_ci      if (xmvis->vishandle) {
1101bf215546Sopenharmony_ci         memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
1102bf215546Sopenharmony_ci      }
1103bf215546Sopenharmony_ci      return xmvis->vishandle;
1104bf215546Sopenharmony_ci   }
1105bf215546Sopenharmony_ci   else
1106bf215546Sopenharmony_ci      return NULL;
1107bf215546Sopenharmony_ci}
1108bf215546Sopenharmony_ci
1109bf215546Sopenharmony_ci
1110bf215546Sopenharmony_ci/**
1111bf215546Sopenharmony_ci * Helper function used by other glXCreateContext functions.
1112bf215546Sopenharmony_ci */
1113bf215546Sopenharmony_cistatic GLXContext
1114bf215546Sopenharmony_cicreate_context(Display *dpy, XMesaVisual xmvis,
1115bf215546Sopenharmony_ci               XMesaContext shareCtx, Bool direct,
1116bf215546Sopenharmony_ci               unsigned major, unsigned minor,
1117bf215546Sopenharmony_ci               unsigned profileMask, unsigned contextFlags)
1118bf215546Sopenharmony_ci{
1119bf215546Sopenharmony_ci   GLXContext glxCtx;
1120bf215546Sopenharmony_ci
1121bf215546Sopenharmony_ci   if (!dpy || !xmvis)
1122bf215546Sopenharmony_ci      return 0;
1123bf215546Sopenharmony_ci
1124bf215546Sopenharmony_ci   glxCtx = CALLOC_STRUCT(__GLXcontextRec);
1125bf215546Sopenharmony_ci   if (!glxCtx)
1126bf215546Sopenharmony_ci      return 0;
1127bf215546Sopenharmony_ci
1128bf215546Sopenharmony_ci   /* deallocate unused windows/buffers */
1129bf215546Sopenharmony_ci#if 0
1130bf215546Sopenharmony_ci   XMesaGarbageCollect();
1131bf215546Sopenharmony_ci#endif
1132bf215546Sopenharmony_ci
1133bf215546Sopenharmony_ci   glxCtx->xmesaContext = XMesaCreateContext(xmvis, shareCtx, major, minor,
1134bf215546Sopenharmony_ci                                             profileMask, contextFlags);
1135bf215546Sopenharmony_ci   if (!glxCtx->xmesaContext) {
1136bf215546Sopenharmony_ci      free(glxCtx);
1137bf215546Sopenharmony_ci      return NULL;
1138bf215546Sopenharmony_ci   }
1139bf215546Sopenharmony_ci
1140bf215546Sopenharmony_ci   glxCtx->isDirect = DEFAULT_DIRECT;
1141bf215546Sopenharmony_ci   glxCtx->currentDpy = dpy;
1142bf215546Sopenharmony_ci   glxCtx->xid = (XID) glxCtx;  /* self pointer */
1143bf215546Sopenharmony_ci
1144bf215546Sopenharmony_ci   return glxCtx;
1145bf215546Sopenharmony_ci}
1146bf215546Sopenharmony_ci
1147bf215546Sopenharmony_ci
1148bf215546Sopenharmony_ciPUBLIC GLXContext
1149bf215546Sopenharmony_ciglXCreateContext( Display *dpy, XVisualInfo *visinfo,
1150bf215546Sopenharmony_ci                  GLXContext shareCtx, Bool direct )
1151bf215546Sopenharmony_ci{
1152bf215546Sopenharmony_ci   XMesaVisual xmvis;
1153bf215546Sopenharmony_ci
1154bf215546Sopenharmony_ci   xmvis = find_glx_visual( dpy, visinfo );
1155bf215546Sopenharmony_ci   if (!xmvis) {
1156bf215546Sopenharmony_ci      /* This visual wasn't found with glXChooseVisual() */
1157bf215546Sopenharmony_ci      xmvis = create_glx_visual( dpy, visinfo );
1158bf215546Sopenharmony_ci      if (!xmvis) {
1159bf215546Sopenharmony_ci         /* unusable visual */
1160bf215546Sopenharmony_ci         return NULL;
1161bf215546Sopenharmony_ci      }
1162bf215546Sopenharmony_ci   }
1163bf215546Sopenharmony_ci
1164bf215546Sopenharmony_ci   return create_context(dpy, xmvis,
1165bf215546Sopenharmony_ci                         shareCtx ? shareCtx->xmesaContext : NULL,
1166bf215546Sopenharmony_ci                         direct,
1167bf215546Sopenharmony_ci                         1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, 0x0);
1168bf215546Sopenharmony_ci}
1169bf215546Sopenharmony_ci
1170bf215546Sopenharmony_ci
1171bf215546Sopenharmony_ci/* GLX 1.3 and later */
1172bf215546Sopenharmony_ciPUBLIC Bool
1173bf215546Sopenharmony_ciglXMakeContextCurrent( Display *dpy, GLXDrawable draw,
1174bf215546Sopenharmony_ci                       GLXDrawable read, GLXContext ctx )
1175bf215546Sopenharmony_ci{
1176bf215546Sopenharmony_ci   GLXContext glxCtx = ctx;
1177bf215546Sopenharmony_ci   GLXContext current = GetCurrentContext();
1178bf215546Sopenharmony_ci   static boolean firsttime = 1, no_rast = 0;
1179bf215546Sopenharmony_ci
1180bf215546Sopenharmony_ci   if (firsttime) {
1181bf215546Sopenharmony_ci      no_rast = getenv("SP_NO_RAST") != NULL;
1182bf215546Sopenharmony_ci      firsttime = 0;
1183bf215546Sopenharmony_ci   }
1184bf215546Sopenharmony_ci
1185bf215546Sopenharmony_ci   if (ctx) {
1186bf215546Sopenharmony_ci      XMesaBuffer drawBuffer = NULL, readBuffer = NULL;
1187bf215546Sopenharmony_ci      XMesaContext xmctx = glxCtx->xmesaContext;
1188bf215546Sopenharmony_ci
1189bf215546Sopenharmony_ci      /* either both must be null, or both must be non-null */
1190bf215546Sopenharmony_ci      if (!draw != !read)
1191bf215546Sopenharmony_ci         return False;
1192bf215546Sopenharmony_ci
1193bf215546Sopenharmony_ci      if (draw) {
1194bf215546Sopenharmony_ci         /* Find the XMesaBuffer which corresponds to 'draw' */
1195bf215546Sopenharmony_ci         drawBuffer = XMesaFindBuffer( dpy, draw );
1196bf215546Sopenharmony_ci         if (!drawBuffer) {
1197bf215546Sopenharmony_ci            /* drawable must be a new window! */
1198bf215546Sopenharmony_ci            drawBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, draw );
1199bf215546Sopenharmony_ci            if (!drawBuffer) {
1200bf215546Sopenharmony_ci               /* Out of memory, or context/drawable depth mismatch */
1201bf215546Sopenharmony_ci               return False;
1202bf215546Sopenharmony_ci            }
1203bf215546Sopenharmony_ci         }
1204bf215546Sopenharmony_ci      }
1205bf215546Sopenharmony_ci
1206bf215546Sopenharmony_ci      if (read) {
1207bf215546Sopenharmony_ci         /* Find the XMesaBuffer which corresponds to 'read' */
1208bf215546Sopenharmony_ci         readBuffer = XMesaFindBuffer( dpy, read );
1209bf215546Sopenharmony_ci         if (!readBuffer) {
1210bf215546Sopenharmony_ci            /* drawable must be a new window! */
1211bf215546Sopenharmony_ci            readBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, read );
1212bf215546Sopenharmony_ci            if (!readBuffer) {
1213bf215546Sopenharmony_ci               /* Out of memory, or context/drawable depth mismatch */
1214bf215546Sopenharmony_ci               return False;
1215bf215546Sopenharmony_ci            }
1216bf215546Sopenharmony_ci         }
1217bf215546Sopenharmony_ci      }
1218bf215546Sopenharmony_ci
1219bf215546Sopenharmony_ci      if (no_rast && current == ctx)
1220bf215546Sopenharmony_ci         return True;
1221bf215546Sopenharmony_ci
1222bf215546Sopenharmony_ci      /* Now make current! */
1223bf215546Sopenharmony_ci      if (XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer)) {
1224bf215546Sopenharmony_ci         ctx->currentDpy = dpy;
1225bf215546Sopenharmony_ci         ctx->currentDrawable = draw;
1226bf215546Sopenharmony_ci         ctx->currentReadable = read;
1227bf215546Sopenharmony_ci         SetCurrentContext(ctx);
1228bf215546Sopenharmony_ci         return True;
1229bf215546Sopenharmony_ci      }
1230bf215546Sopenharmony_ci      else {
1231bf215546Sopenharmony_ci         return False;
1232bf215546Sopenharmony_ci      }
1233bf215546Sopenharmony_ci   }
1234bf215546Sopenharmony_ci   else if (!ctx && !draw && !read) {
1235bf215546Sopenharmony_ci      /* release current context w/out assigning new one. */
1236bf215546Sopenharmony_ci      XMesaMakeCurrent2( NULL, NULL, NULL );
1237bf215546Sopenharmony_ci      SetCurrentContext(NULL);
1238bf215546Sopenharmony_ci      return True;
1239bf215546Sopenharmony_ci   }
1240bf215546Sopenharmony_ci   else {
1241bf215546Sopenharmony_ci      /* We were given an invalid set of arguments */
1242bf215546Sopenharmony_ci      return False;
1243bf215546Sopenharmony_ci   }
1244bf215546Sopenharmony_ci}
1245bf215546Sopenharmony_ci
1246bf215546Sopenharmony_ci
1247bf215546Sopenharmony_ciPUBLIC Bool
1248bf215546Sopenharmony_ciglXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
1249bf215546Sopenharmony_ci{
1250bf215546Sopenharmony_ci   return glXMakeContextCurrent( dpy, drawable, drawable, ctx );
1251bf215546Sopenharmony_ci}
1252bf215546Sopenharmony_ci
1253bf215546Sopenharmony_ci
1254bf215546Sopenharmony_ciPUBLIC GLXContext
1255bf215546Sopenharmony_ciglXGetCurrentContext(void)
1256bf215546Sopenharmony_ci{
1257bf215546Sopenharmony_ci   return GetCurrentContext();
1258bf215546Sopenharmony_ci}
1259bf215546Sopenharmony_ci
1260bf215546Sopenharmony_ci
1261bf215546Sopenharmony_ciPUBLIC Display *
1262bf215546Sopenharmony_ciglXGetCurrentDisplay(void)
1263bf215546Sopenharmony_ci{
1264bf215546Sopenharmony_ci   GLXContext glxCtx = glXGetCurrentContext();
1265bf215546Sopenharmony_ci
1266bf215546Sopenharmony_ci   return glxCtx ? glxCtx->currentDpy : NULL;
1267bf215546Sopenharmony_ci}
1268bf215546Sopenharmony_ci
1269bf215546Sopenharmony_ci
1270bf215546Sopenharmony_ciPUBLIC Display *
1271bf215546Sopenharmony_ciglXGetCurrentDisplayEXT(void)
1272bf215546Sopenharmony_ci{
1273bf215546Sopenharmony_ci   return glXGetCurrentDisplay();
1274bf215546Sopenharmony_ci}
1275bf215546Sopenharmony_ci
1276bf215546Sopenharmony_ci
1277bf215546Sopenharmony_ciPUBLIC GLXDrawable
1278bf215546Sopenharmony_ciglXGetCurrentDrawable(void)
1279bf215546Sopenharmony_ci{
1280bf215546Sopenharmony_ci   GLXContext gc = glXGetCurrentContext();
1281bf215546Sopenharmony_ci   return gc ? gc->currentDrawable : 0;
1282bf215546Sopenharmony_ci}
1283bf215546Sopenharmony_ci
1284bf215546Sopenharmony_ci
1285bf215546Sopenharmony_ciPUBLIC GLXDrawable
1286bf215546Sopenharmony_ciglXGetCurrentReadDrawable(void)
1287bf215546Sopenharmony_ci{
1288bf215546Sopenharmony_ci   GLXContext gc = glXGetCurrentContext();
1289bf215546Sopenharmony_ci   return gc ? gc->currentReadable : 0;
1290bf215546Sopenharmony_ci}
1291bf215546Sopenharmony_ci
1292bf215546Sopenharmony_ci
1293bf215546Sopenharmony_ciPUBLIC GLXDrawable
1294bf215546Sopenharmony_ciglXGetCurrentReadDrawableSGI(void)
1295bf215546Sopenharmony_ci{
1296bf215546Sopenharmony_ci   return glXGetCurrentReadDrawable();
1297bf215546Sopenharmony_ci}
1298bf215546Sopenharmony_ci
1299bf215546Sopenharmony_ci
1300bf215546Sopenharmony_ciPUBLIC GLXPixmap
1301bf215546Sopenharmony_ciglXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap )
1302bf215546Sopenharmony_ci{
1303bf215546Sopenharmony_ci   XMesaVisual v;
1304bf215546Sopenharmony_ci   XMesaBuffer b;
1305bf215546Sopenharmony_ci
1306bf215546Sopenharmony_ci   v = find_glx_visual( dpy, visinfo );
1307bf215546Sopenharmony_ci   if (!v) {
1308bf215546Sopenharmony_ci      v = create_glx_visual( dpy, visinfo );
1309bf215546Sopenharmony_ci      if (!v) {
1310bf215546Sopenharmony_ci         /* unusable visual */
1311bf215546Sopenharmony_ci         return 0;
1312bf215546Sopenharmony_ci      }
1313bf215546Sopenharmony_ci   }
1314bf215546Sopenharmony_ci
1315bf215546Sopenharmony_ci   b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1316bf215546Sopenharmony_ci   if (!b) {
1317bf215546Sopenharmony_ci      return 0;
1318bf215546Sopenharmony_ci   }
1319bf215546Sopenharmony_ci   return b->ws.drawable;
1320bf215546Sopenharmony_ci}
1321bf215546Sopenharmony_ci
1322bf215546Sopenharmony_ci
1323bf215546Sopenharmony_ci/*** GLX_MESA_pixmap_colormap ***/
1324bf215546Sopenharmony_ci
1325bf215546Sopenharmony_ciPUBLIC GLXPixmap
1326bf215546Sopenharmony_ciglXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
1327bf215546Sopenharmony_ci                        Pixmap pixmap, Colormap cmap )
1328bf215546Sopenharmony_ci{
1329bf215546Sopenharmony_ci   XMesaVisual v;
1330bf215546Sopenharmony_ci   XMesaBuffer b;
1331bf215546Sopenharmony_ci
1332bf215546Sopenharmony_ci   v = find_glx_visual( dpy, visinfo );
1333bf215546Sopenharmony_ci   if (!v) {
1334bf215546Sopenharmony_ci      v = create_glx_visual( dpy, visinfo );
1335bf215546Sopenharmony_ci      if (!v) {
1336bf215546Sopenharmony_ci         /* unusable visual */
1337bf215546Sopenharmony_ci         return 0;
1338bf215546Sopenharmony_ci      }
1339bf215546Sopenharmony_ci   }
1340bf215546Sopenharmony_ci
1341bf215546Sopenharmony_ci   b = XMesaCreatePixmapBuffer( v, pixmap, cmap );
1342bf215546Sopenharmony_ci   if (!b) {
1343bf215546Sopenharmony_ci      return 0;
1344bf215546Sopenharmony_ci   }
1345bf215546Sopenharmony_ci   return b->ws.drawable;
1346bf215546Sopenharmony_ci}
1347bf215546Sopenharmony_ci
1348bf215546Sopenharmony_ci
1349bf215546Sopenharmony_ciPUBLIC void
1350bf215546Sopenharmony_ciglXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
1351bf215546Sopenharmony_ci{
1352bf215546Sopenharmony_ci   XMesaBuffer b = XMesaFindBuffer(dpy, pixmap);
1353bf215546Sopenharmony_ci   if (b) {
1354bf215546Sopenharmony_ci      XMesaDestroyBuffer(b);
1355bf215546Sopenharmony_ci   }
1356bf215546Sopenharmony_ci   else if (getenv("MESA_DEBUG")) {
1357bf215546Sopenharmony_ci      _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1358bf215546Sopenharmony_ci   }
1359bf215546Sopenharmony_ci}
1360bf215546Sopenharmony_ci
1361bf215546Sopenharmony_ci
1362bf215546Sopenharmony_ciPUBLIC void
1363bf215546Sopenharmony_ciglXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
1364bf215546Sopenharmony_ci                unsigned long mask )
1365bf215546Sopenharmony_ci{
1366bf215546Sopenharmony_ci   XMesaContext xm_src = src->xmesaContext;
1367bf215546Sopenharmony_ci   XMesaContext xm_dst = dst->xmesaContext;
1368bf215546Sopenharmony_ci   (void) dpy;
1369bf215546Sopenharmony_ci   if (GetCurrentContext() == src) {
1370bf215546Sopenharmony_ci      glFlush();
1371bf215546Sopenharmony_ci   }
1372bf215546Sopenharmony_ci   XMesaCopyContext(xm_src, xm_dst, mask);
1373bf215546Sopenharmony_ci}
1374bf215546Sopenharmony_ci
1375bf215546Sopenharmony_ci
1376bf215546Sopenharmony_ciPUBLIC Bool
1377bf215546Sopenharmony_ciglXQueryExtension( Display *dpy, int *errorBase, int *eventBase )
1378bf215546Sopenharmony_ci{
1379bf215546Sopenharmony_ci   int op, ev, err;
1380bf215546Sopenharmony_ci   /* Mesa's GLX isn't really an X extension but we try to act like one. */
1381bf215546Sopenharmony_ci   if (!XQueryExtension(dpy, GLX_EXTENSION_NAME, &op, &ev, &err))
1382bf215546Sopenharmony_ci      ev = err = 0;
1383bf215546Sopenharmony_ci   if (errorBase)
1384bf215546Sopenharmony_ci      *errorBase = err;
1385bf215546Sopenharmony_ci   if (eventBase)
1386bf215546Sopenharmony_ci      *eventBase = ev;
1387bf215546Sopenharmony_ci   return True; /* we're faking GLX so always return success */
1388bf215546Sopenharmony_ci}
1389bf215546Sopenharmony_ci
1390bf215546Sopenharmony_ci
1391bf215546Sopenharmony_ciPUBLIC void
1392bf215546Sopenharmony_ciglXDestroyContext( Display *dpy, GLXContext ctx )
1393bf215546Sopenharmony_ci{
1394bf215546Sopenharmony_ci   if (ctx) {
1395bf215546Sopenharmony_ci      GLXContext glxCtx = ctx;
1396bf215546Sopenharmony_ci      (void) dpy;
1397bf215546Sopenharmony_ci      XMesaDestroyContext( glxCtx->xmesaContext );
1398bf215546Sopenharmony_ci      XMesaGarbageCollect();
1399bf215546Sopenharmony_ci      free(glxCtx);
1400bf215546Sopenharmony_ci   }
1401bf215546Sopenharmony_ci}
1402bf215546Sopenharmony_ci
1403bf215546Sopenharmony_ci
1404bf215546Sopenharmony_ciPUBLIC Bool
1405bf215546Sopenharmony_ciglXIsDirect( Display *dpy, GLXContext ctx )
1406bf215546Sopenharmony_ci{
1407bf215546Sopenharmony_ci   return ctx ? ctx->isDirect : False;
1408bf215546Sopenharmony_ci}
1409bf215546Sopenharmony_ci
1410bf215546Sopenharmony_ci
1411bf215546Sopenharmony_ci
1412bf215546Sopenharmony_ciPUBLIC void
1413bf215546Sopenharmony_ciglXSwapBuffers( Display *dpy, GLXDrawable drawable )
1414bf215546Sopenharmony_ci{
1415bf215546Sopenharmony_ci   XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1416bf215546Sopenharmony_ci   static boolean firsttime = 1, no_rast = 0;
1417bf215546Sopenharmony_ci
1418bf215546Sopenharmony_ci   if (firsttime) {
1419bf215546Sopenharmony_ci      no_rast = getenv("SP_NO_RAST") != NULL;
1420bf215546Sopenharmony_ci      firsttime = 0;
1421bf215546Sopenharmony_ci   }
1422bf215546Sopenharmony_ci
1423bf215546Sopenharmony_ci   if (no_rast)
1424bf215546Sopenharmony_ci      return;
1425bf215546Sopenharmony_ci
1426bf215546Sopenharmony_ci   if (buffer) {
1427bf215546Sopenharmony_ci      XMesaSwapBuffers(buffer);
1428bf215546Sopenharmony_ci   }
1429bf215546Sopenharmony_ci   else if (getenv("MESA_DEBUG")) {
1430bf215546Sopenharmony_ci      _mesa_warning(NULL, "glXSwapBuffers: invalid drawable 0x%x\n",
1431bf215546Sopenharmony_ci                    (int) drawable);
1432bf215546Sopenharmony_ci   }
1433bf215546Sopenharmony_ci}
1434bf215546Sopenharmony_ci
1435bf215546Sopenharmony_ci
1436bf215546Sopenharmony_ci
1437bf215546Sopenharmony_ci/*** GLX_MESA_copy_sub_buffer ***/
1438bf215546Sopenharmony_ci
1439bf215546Sopenharmony_ciPUBLIC void
1440bf215546Sopenharmony_ciglXCopySubBufferMESA(Display *dpy, GLXDrawable drawable,
1441bf215546Sopenharmony_ci                     int x, int y, int width, int height)
1442bf215546Sopenharmony_ci{
1443bf215546Sopenharmony_ci   XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1444bf215546Sopenharmony_ci   if (buffer) {
1445bf215546Sopenharmony_ci      XMesaCopySubBuffer(buffer, x, y, width, height);
1446bf215546Sopenharmony_ci   }
1447bf215546Sopenharmony_ci   else if (getenv("MESA_DEBUG")) {
1448bf215546Sopenharmony_ci      _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1449bf215546Sopenharmony_ci   }
1450bf215546Sopenharmony_ci}
1451bf215546Sopenharmony_ci
1452bf215546Sopenharmony_ci
1453bf215546Sopenharmony_ciPUBLIC Bool
1454bf215546Sopenharmony_ciglXQueryVersion( Display *dpy, int *maj, int *min )
1455bf215546Sopenharmony_ci{
1456bf215546Sopenharmony_ci   (void) dpy;
1457bf215546Sopenharmony_ci   /* Return GLX version, not Mesa version */
1458bf215546Sopenharmony_ci   assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION);
1459bf215546Sopenharmony_ci   *maj = CLIENT_MAJOR_VERSION;
1460bf215546Sopenharmony_ci   *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION );
1461bf215546Sopenharmony_ci   return True;
1462bf215546Sopenharmony_ci}
1463bf215546Sopenharmony_ci
1464bf215546Sopenharmony_ci
1465bf215546Sopenharmony_ci/*
1466bf215546Sopenharmony_ci * Query the GLX attributes of the given XVisualInfo.
1467bf215546Sopenharmony_ci */
1468bf215546Sopenharmony_cistatic int
1469bf215546Sopenharmony_ciget_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig )
1470bf215546Sopenharmony_ci{
1471bf215546Sopenharmony_ci   assert(xmvis);
1472bf215546Sopenharmony_ci   switch(attrib) {
1473bf215546Sopenharmony_ci      case GLX_USE_GL:
1474bf215546Sopenharmony_ci         if (fbconfig)
1475bf215546Sopenharmony_ci            return GLX_BAD_ATTRIBUTE;
1476bf215546Sopenharmony_ci         *value = (int) True;
1477bf215546Sopenharmony_ci	 return 0;
1478bf215546Sopenharmony_ci      case GLX_BUFFER_SIZE:
1479bf215546Sopenharmony_ci	 *value = xmvis->visinfo->depth;
1480bf215546Sopenharmony_ci	 return 0;
1481bf215546Sopenharmony_ci      case GLX_LEVEL:
1482bf215546Sopenharmony_ci	 *value = 0;
1483bf215546Sopenharmony_ci	 return 0;
1484bf215546Sopenharmony_ci      case GLX_RGBA:
1485bf215546Sopenharmony_ci         if (fbconfig)
1486bf215546Sopenharmony_ci            return GLX_BAD_ATTRIBUTE;
1487bf215546Sopenharmony_ci         *value = True;
1488bf215546Sopenharmony_ci	 return 0;
1489bf215546Sopenharmony_ci      case GLX_DOUBLEBUFFER:
1490bf215546Sopenharmony_ci	 *value = (int) xmvis->mesa_visual.doubleBufferMode;
1491bf215546Sopenharmony_ci	 return 0;
1492bf215546Sopenharmony_ci      case GLX_STEREO:
1493bf215546Sopenharmony_ci	 *value = (int) xmvis->mesa_visual.stereoMode;
1494bf215546Sopenharmony_ci	 return 0;
1495bf215546Sopenharmony_ci      case GLX_AUX_BUFFERS:
1496bf215546Sopenharmony_ci	 *value = 0;
1497bf215546Sopenharmony_ci	 return 0;
1498bf215546Sopenharmony_ci      case GLX_RED_SIZE:
1499bf215546Sopenharmony_ci         *value = xmvis->mesa_visual.redBits;
1500bf215546Sopenharmony_ci	 return 0;
1501bf215546Sopenharmony_ci      case GLX_GREEN_SIZE:
1502bf215546Sopenharmony_ci         *value = xmvis->mesa_visual.greenBits;
1503bf215546Sopenharmony_ci	 return 0;
1504bf215546Sopenharmony_ci      case GLX_BLUE_SIZE:
1505bf215546Sopenharmony_ci         *value = xmvis->mesa_visual.blueBits;
1506bf215546Sopenharmony_ci	 return 0;
1507bf215546Sopenharmony_ci      case GLX_ALPHA_SIZE:
1508bf215546Sopenharmony_ci         *value = xmvis->mesa_visual.alphaBits;
1509bf215546Sopenharmony_ci	 return 0;
1510bf215546Sopenharmony_ci      case GLX_DEPTH_SIZE:
1511bf215546Sopenharmony_ci         *value = xmvis->mesa_visual.depthBits;
1512bf215546Sopenharmony_ci	 return 0;
1513bf215546Sopenharmony_ci      case GLX_STENCIL_SIZE:
1514bf215546Sopenharmony_ci	 *value = xmvis->mesa_visual.stencilBits;
1515bf215546Sopenharmony_ci	 return 0;
1516bf215546Sopenharmony_ci      case GLX_ACCUM_RED_SIZE:
1517bf215546Sopenharmony_ci	 *value = xmvis->mesa_visual.accumRedBits;
1518bf215546Sopenharmony_ci	 return 0;
1519bf215546Sopenharmony_ci      case GLX_ACCUM_GREEN_SIZE:
1520bf215546Sopenharmony_ci	 *value = xmvis->mesa_visual.accumGreenBits;
1521bf215546Sopenharmony_ci	 return 0;
1522bf215546Sopenharmony_ci      case GLX_ACCUM_BLUE_SIZE:
1523bf215546Sopenharmony_ci	 *value = xmvis->mesa_visual.accumBlueBits;
1524bf215546Sopenharmony_ci	 return 0;
1525bf215546Sopenharmony_ci      case GLX_ACCUM_ALPHA_SIZE:
1526bf215546Sopenharmony_ci         *value = xmvis->mesa_visual.accumAlphaBits;
1527bf215546Sopenharmony_ci	 return 0;
1528bf215546Sopenharmony_ci
1529bf215546Sopenharmony_ci      /*
1530bf215546Sopenharmony_ci       * GLX_EXT_visual_info extension
1531bf215546Sopenharmony_ci       */
1532bf215546Sopenharmony_ci      case GLX_X_VISUAL_TYPE_EXT:
1533bf215546Sopenharmony_ci         switch (xmvis->visinfo->CLASS) {
1534bf215546Sopenharmony_ci            case StaticGray:   *value = GLX_STATIC_GRAY_EXT;   return 0;
1535bf215546Sopenharmony_ci            case GrayScale:    *value = GLX_GRAY_SCALE_EXT;    return 0;
1536bf215546Sopenharmony_ci            case StaticColor:  *value = GLX_STATIC_GRAY_EXT;   return 0;
1537bf215546Sopenharmony_ci            case PseudoColor:  *value = GLX_PSEUDO_COLOR_EXT;  return 0;
1538bf215546Sopenharmony_ci            case TrueColor:    *value = GLX_TRUE_COLOR_EXT;    return 0;
1539bf215546Sopenharmony_ci            case DirectColor:  *value = GLX_DIRECT_COLOR_EXT;  return 0;
1540bf215546Sopenharmony_ci         }
1541bf215546Sopenharmony_ci         return 0;
1542bf215546Sopenharmony_ci      case GLX_TRANSPARENT_TYPE_EXT:
1543bf215546Sopenharmony_ci         /* normal planes */
1544bf215546Sopenharmony_ci         *value = GLX_NONE_EXT;
1545bf215546Sopenharmony_ci         return 0;
1546bf215546Sopenharmony_ci      case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1547bf215546Sopenharmony_ci         /* undefined */
1548bf215546Sopenharmony_ci         return 0;
1549bf215546Sopenharmony_ci      case GLX_TRANSPARENT_RED_VALUE_EXT:
1550bf215546Sopenharmony_ci         /* undefined */
1551bf215546Sopenharmony_ci         return 0;
1552bf215546Sopenharmony_ci      case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1553bf215546Sopenharmony_ci         /* undefined */
1554bf215546Sopenharmony_ci         return 0;
1555bf215546Sopenharmony_ci      case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1556bf215546Sopenharmony_ci         /* undefined */
1557bf215546Sopenharmony_ci         return 0;
1558bf215546Sopenharmony_ci      case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1559bf215546Sopenharmony_ci         /* undefined */
1560bf215546Sopenharmony_ci         return 0;
1561bf215546Sopenharmony_ci
1562bf215546Sopenharmony_ci      /*
1563bf215546Sopenharmony_ci       * GLX_EXT_visual_info extension
1564bf215546Sopenharmony_ci       */
1565bf215546Sopenharmony_ci      case GLX_VISUAL_CAVEAT_EXT:
1566bf215546Sopenharmony_ci         *value = GLX_NONE_EXT;
1567bf215546Sopenharmony_ci         return 0;
1568bf215546Sopenharmony_ci
1569bf215546Sopenharmony_ci      /*
1570bf215546Sopenharmony_ci       * GLX_ARB_multisample
1571bf215546Sopenharmony_ci       */
1572bf215546Sopenharmony_ci      case GLX_SAMPLE_BUFFERS_ARB:
1573bf215546Sopenharmony_ci         *value = xmvis->mesa_visual.samples > 0;
1574bf215546Sopenharmony_ci         return 0;
1575bf215546Sopenharmony_ci      case GLX_SAMPLES_ARB:
1576bf215546Sopenharmony_ci         *value = xmvis->mesa_visual.samples;
1577bf215546Sopenharmony_ci         return 0;
1578bf215546Sopenharmony_ci
1579bf215546Sopenharmony_ci      /*
1580bf215546Sopenharmony_ci       * For FBConfigs:
1581bf215546Sopenharmony_ci       */
1582bf215546Sopenharmony_ci      case GLX_SCREEN_EXT:
1583bf215546Sopenharmony_ci         if (!fbconfig)
1584bf215546Sopenharmony_ci            return GLX_BAD_ATTRIBUTE;
1585bf215546Sopenharmony_ci         *value = xmvis->visinfo->screen;
1586bf215546Sopenharmony_ci         break;
1587bf215546Sopenharmony_ci      case GLX_DRAWABLE_TYPE: /*SGIX too */
1588bf215546Sopenharmony_ci         if (!fbconfig)
1589bf215546Sopenharmony_ci            return GLX_BAD_ATTRIBUTE;
1590bf215546Sopenharmony_ci         *value = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
1591bf215546Sopenharmony_ci         break;
1592bf215546Sopenharmony_ci      case GLX_RENDER_TYPE_SGIX:
1593bf215546Sopenharmony_ci         if (!fbconfig)
1594bf215546Sopenharmony_ci            return GLX_BAD_ATTRIBUTE;
1595bf215546Sopenharmony_ci         *value = GLX_RGBA_BIT;
1596bf215546Sopenharmony_ci         break;
1597bf215546Sopenharmony_ci      case GLX_X_RENDERABLE_SGIX:
1598bf215546Sopenharmony_ci         if (!fbconfig)
1599bf215546Sopenharmony_ci            return GLX_BAD_ATTRIBUTE;
1600bf215546Sopenharmony_ci         *value = True; /* XXX really? */
1601bf215546Sopenharmony_ci         break;
1602bf215546Sopenharmony_ci      case GLX_FBCONFIG_ID_SGIX:
1603bf215546Sopenharmony_ci         if (!fbconfig)
1604bf215546Sopenharmony_ci            return GLX_BAD_ATTRIBUTE;
1605bf215546Sopenharmony_ci         *value = xmvis->visinfo->visualid;
1606bf215546Sopenharmony_ci         break;
1607bf215546Sopenharmony_ci      case GLX_MAX_PBUFFER_WIDTH:
1608bf215546Sopenharmony_ci         if (!fbconfig)
1609bf215546Sopenharmony_ci            return GLX_BAD_ATTRIBUTE;
1610bf215546Sopenharmony_ci         /* XXX should be same as ctx->Const.MaxRenderbufferSize */
1611bf215546Sopenharmony_ci         *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen);
1612bf215546Sopenharmony_ci         break;
1613bf215546Sopenharmony_ci      case GLX_MAX_PBUFFER_HEIGHT:
1614bf215546Sopenharmony_ci         if (!fbconfig)
1615bf215546Sopenharmony_ci            return GLX_BAD_ATTRIBUTE;
1616bf215546Sopenharmony_ci         *value = DisplayHeight(xmvis->display, xmvis->visinfo->screen);
1617bf215546Sopenharmony_ci         break;
1618bf215546Sopenharmony_ci      case GLX_MAX_PBUFFER_PIXELS:
1619bf215546Sopenharmony_ci         if (!fbconfig)
1620bf215546Sopenharmony_ci            return GLX_BAD_ATTRIBUTE;
1621bf215546Sopenharmony_ci         *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen) *
1622bf215546Sopenharmony_ci                  DisplayHeight(xmvis->display, xmvis->visinfo->screen);
1623bf215546Sopenharmony_ci         break;
1624bf215546Sopenharmony_ci      case GLX_VISUAL_ID:
1625bf215546Sopenharmony_ci         if (!fbconfig)
1626bf215546Sopenharmony_ci            return GLX_BAD_ATTRIBUTE;
1627bf215546Sopenharmony_ci         *value = xmvis->visinfo->visualid;
1628bf215546Sopenharmony_ci         break;
1629bf215546Sopenharmony_ci
1630bf215546Sopenharmony_ci      case GLX_BIND_TO_TEXTURE_RGB_EXT:
1631bf215546Sopenharmony_ci         *value = True; /*XXX*/
1632bf215546Sopenharmony_ci         break;
1633bf215546Sopenharmony_ci      case GLX_BIND_TO_TEXTURE_RGBA_EXT:
1634bf215546Sopenharmony_ci         /* XXX review */
1635bf215546Sopenharmony_ci         *value = xmvis->mesa_visual.alphaBits > 0 ? True : False;
1636bf215546Sopenharmony_ci         break;
1637bf215546Sopenharmony_ci      case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
1638bf215546Sopenharmony_ci         *value = True; /*XXX*/
1639bf215546Sopenharmony_ci         break;
1640bf215546Sopenharmony_ci      case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
1641bf215546Sopenharmony_ci         *value = (GLX_TEXTURE_1D_BIT_EXT |
1642bf215546Sopenharmony_ci                   GLX_TEXTURE_2D_BIT_EXT |
1643bf215546Sopenharmony_ci                   GLX_TEXTURE_RECTANGLE_BIT_EXT); /*XXX*/
1644bf215546Sopenharmony_ci         break;
1645bf215546Sopenharmony_ci      case GLX_Y_INVERTED_EXT:
1646bf215546Sopenharmony_ci         *value = True; /*XXX*/
1647bf215546Sopenharmony_ci         break;
1648bf215546Sopenharmony_ci
1649bf215546Sopenharmony_ci      default:
1650bf215546Sopenharmony_ci	 return GLX_BAD_ATTRIBUTE;
1651bf215546Sopenharmony_ci   }
1652bf215546Sopenharmony_ci   return Success;
1653bf215546Sopenharmony_ci}
1654bf215546Sopenharmony_ci
1655bf215546Sopenharmony_ci
1656bf215546Sopenharmony_ciPUBLIC int
1657bf215546Sopenharmony_ciglXGetConfig( Display *dpy, XVisualInfo *visinfo,
1658bf215546Sopenharmony_ci                   int attrib, int *value )
1659bf215546Sopenharmony_ci{
1660bf215546Sopenharmony_ci   XMesaVisual xmvis;
1661bf215546Sopenharmony_ci   int k;
1662bf215546Sopenharmony_ci   if (!dpy || !visinfo)
1663bf215546Sopenharmony_ci      return GLX_BAD_ATTRIBUTE;
1664bf215546Sopenharmony_ci
1665bf215546Sopenharmony_ci   xmvis = find_glx_visual( dpy, visinfo );
1666bf215546Sopenharmony_ci   if (!xmvis) {
1667bf215546Sopenharmony_ci      /* this visual wasn't obtained with glXChooseVisual */
1668bf215546Sopenharmony_ci      xmvis = create_glx_visual( dpy, visinfo );
1669bf215546Sopenharmony_ci      if (!xmvis) {
1670bf215546Sopenharmony_ci	 /* this visual can't be used for GL rendering */
1671bf215546Sopenharmony_ci	 if (attrib==GLX_USE_GL) {
1672bf215546Sopenharmony_ci	    *value = (int) False;
1673bf215546Sopenharmony_ci	    return 0;
1674bf215546Sopenharmony_ci	 }
1675bf215546Sopenharmony_ci	 else {
1676bf215546Sopenharmony_ci	    return GLX_BAD_VISUAL;
1677bf215546Sopenharmony_ci	 }
1678bf215546Sopenharmony_ci      }
1679bf215546Sopenharmony_ci   }
1680bf215546Sopenharmony_ci
1681bf215546Sopenharmony_ci   k = get_config(xmvis, attrib, value, GL_FALSE);
1682bf215546Sopenharmony_ci   return k;
1683bf215546Sopenharmony_ci}
1684bf215546Sopenharmony_ci
1685bf215546Sopenharmony_ci
1686bf215546Sopenharmony_ciPUBLIC void
1687bf215546Sopenharmony_ciglXWaitGL( void )
1688bf215546Sopenharmony_ci{
1689bf215546Sopenharmony_ci   XMesaContext xmesa = XMesaGetCurrentContext();
1690bf215546Sopenharmony_ci   XMesaFlush( xmesa );
1691bf215546Sopenharmony_ci}
1692bf215546Sopenharmony_ci
1693bf215546Sopenharmony_ci
1694bf215546Sopenharmony_ci
1695bf215546Sopenharmony_ciPUBLIC void
1696bf215546Sopenharmony_ciglXWaitX( void )
1697bf215546Sopenharmony_ci{
1698bf215546Sopenharmony_ci   XMesaContext xmesa = XMesaGetCurrentContext();
1699bf215546Sopenharmony_ci   XMesaFlush( xmesa );
1700bf215546Sopenharmony_ci}
1701bf215546Sopenharmony_ci
1702bf215546Sopenharmony_ci
1703bf215546Sopenharmony_cistatic const char *
1704bf215546Sopenharmony_ciget_extensions( void )
1705bf215546Sopenharmony_ci{
1706bf215546Sopenharmony_ci   return EXTENSIONS;
1707bf215546Sopenharmony_ci}
1708bf215546Sopenharmony_ci
1709bf215546Sopenharmony_ci
1710bf215546Sopenharmony_ci
1711bf215546Sopenharmony_ci/* GLX 1.1 and later */
1712bf215546Sopenharmony_ciPUBLIC const char *
1713bf215546Sopenharmony_ciglXQueryExtensionsString( Display *dpy, int screen )
1714bf215546Sopenharmony_ci{
1715bf215546Sopenharmony_ci   (void) dpy;
1716bf215546Sopenharmony_ci   (void) screen;
1717bf215546Sopenharmony_ci   return get_extensions();
1718bf215546Sopenharmony_ci}
1719bf215546Sopenharmony_ci
1720bf215546Sopenharmony_ci
1721bf215546Sopenharmony_ci
1722bf215546Sopenharmony_ci/* GLX 1.1 and later */
1723bf215546Sopenharmony_ciPUBLIC const char *
1724bf215546Sopenharmony_ciglXQueryServerString( Display *dpy, int screen, int name )
1725bf215546Sopenharmony_ci{
1726bf215546Sopenharmony_ci   static char version[1000];
1727bf215546Sopenharmony_ci   sprintf(version, "%d.%d %s",
1728bf215546Sopenharmony_ci	   SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, xmesa_get_name());
1729bf215546Sopenharmony_ci
1730bf215546Sopenharmony_ci   (void) dpy;
1731bf215546Sopenharmony_ci   (void) screen;
1732bf215546Sopenharmony_ci
1733bf215546Sopenharmony_ci   switch (name) {
1734bf215546Sopenharmony_ci      case GLX_EXTENSIONS:
1735bf215546Sopenharmony_ci         return get_extensions();
1736bf215546Sopenharmony_ci      case GLX_VENDOR:
1737bf215546Sopenharmony_ci	 return VENDOR;
1738bf215546Sopenharmony_ci      case GLX_VERSION:
1739bf215546Sopenharmony_ci	 return version;
1740bf215546Sopenharmony_ci      default:
1741bf215546Sopenharmony_ci         return NULL;
1742bf215546Sopenharmony_ci   }
1743bf215546Sopenharmony_ci}
1744bf215546Sopenharmony_ci
1745bf215546Sopenharmony_ci
1746bf215546Sopenharmony_ci
1747bf215546Sopenharmony_ci/* GLX 1.1 and later */
1748bf215546Sopenharmony_ciPUBLIC const char *
1749bf215546Sopenharmony_ciglXGetClientString( Display *dpy, int name )
1750bf215546Sopenharmony_ci{
1751bf215546Sopenharmony_ci   static char version[1000];
1752bf215546Sopenharmony_ci   sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION,
1753bf215546Sopenharmony_ci	   CLIENT_MINOR_VERSION, xmesa_get_name());
1754bf215546Sopenharmony_ci
1755bf215546Sopenharmony_ci   (void) dpy;
1756bf215546Sopenharmony_ci
1757bf215546Sopenharmony_ci   switch (name) {
1758bf215546Sopenharmony_ci      case GLX_EXTENSIONS:
1759bf215546Sopenharmony_ci         return get_extensions();
1760bf215546Sopenharmony_ci      case GLX_VENDOR:
1761bf215546Sopenharmony_ci	 return VENDOR;
1762bf215546Sopenharmony_ci      case GLX_VERSION:
1763bf215546Sopenharmony_ci	 return version;
1764bf215546Sopenharmony_ci      default:
1765bf215546Sopenharmony_ci         return NULL;
1766bf215546Sopenharmony_ci   }
1767bf215546Sopenharmony_ci}
1768bf215546Sopenharmony_ci
1769bf215546Sopenharmony_ci
1770bf215546Sopenharmony_ci
1771bf215546Sopenharmony_ci/*
1772bf215546Sopenharmony_ci * GLX 1.3 and later
1773bf215546Sopenharmony_ci */
1774bf215546Sopenharmony_ci
1775bf215546Sopenharmony_ci
1776bf215546Sopenharmony_ciPUBLIC int
1777bf215546Sopenharmony_ciglXGetFBConfigAttrib(Display *dpy, GLXFBConfig config,
1778bf215546Sopenharmony_ci                     int attribute, int *value)
1779bf215546Sopenharmony_ci{
1780bf215546Sopenharmony_ci   XMesaVisual v = (XMesaVisual) config;
1781bf215546Sopenharmony_ci   (void) dpy;
1782bf215546Sopenharmony_ci   (void) config;
1783bf215546Sopenharmony_ci
1784bf215546Sopenharmony_ci   if (!dpy || !config || !value)
1785bf215546Sopenharmony_ci      return -1;
1786bf215546Sopenharmony_ci
1787bf215546Sopenharmony_ci   return get_config(v, attribute, value, GL_TRUE);
1788bf215546Sopenharmony_ci}
1789bf215546Sopenharmony_ci
1790bf215546Sopenharmony_ci
1791bf215546Sopenharmony_ciPUBLIC GLXFBConfig *
1792bf215546Sopenharmony_ciglXGetFBConfigs( Display *dpy, int screen, int *nelements )
1793bf215546Sopenharmony_ci{
1794bf215546Sopenharmony_ci   XVisualInfo *visuals, visTemplate;
1795bf215546Sopenharmony_ci   const long visMask = VisualScreenMask;
1796bf215546Sopenharmony_ci   int i;
1797bf215546Sopenharmony_ci
1798bf215546Sopenharmony_ci   /* Get list of all X visuals */
1799bf215546Sopenharmony_ci   visTemplate.screen = screen;
1800bf215546Sopenharmony_ci   visuals = XGetVisualInfo(dpy, visMask, &visTemplate, nelements);
1801bf215546Sopenharmony_ci   if (*nelements > 0) {
1802bf215546Sopenharmony_ci      XMesaVisual *results = malloc(*nelements * sizeof(XMesaVisual));
1803bf215546Sopenharmony_ci      if (!results) {
1804bf215546Sopenharmony_ci         *nelements = 0;
1805bf215546Sopenharmony_ci         return NULL;
1806bf215546Sopenharmony_ci      }
1807bf215546Sopenharmony_ci      for (i = 0; i < *nelements; i++) {
1808bf215546Sopenharmony_ci         results[i] = create_glx_visual(dpy, visuals + i);
1809bf215546Sopenharmony_ci         if (!results[i]) {
1810bf215546Sopenharmony_ci            *nelements = i;
1811bf215546Sopenharmony_ci            break;
1812bf215546Sopenharmony_ci         }
1813bf215546Sopenharmony_ci      }
1814bf215546Sopenharmony_ci      return (GLXFBConfig *) results;
1815bf215546Sopenharmony_ci   }
1816bf215546Sopenharmony_ci   return NULL;
1817bf215546Sopenharmony_ci}
1818bf215546Sopenharmony_ci
1819bf215546Sopenharmony_ci
1820bf215546Sopenharmony_ciPUBLIC GLXFBConfig *
1821bf215546Sopenharmony_ciglXChooseFBConfig(Display *dpy, int screen,
1822bf215546Sopenharmony_ci                  const int *attribList, int *nitems)
1823bf215546Sopenharmony_ci{
1824bf215546Sopenharmony_ci   XMesaVisual xmvis;
1825bf215546Sopenharmony_ci
1826bf215546Sopenharmony_ci   /* register ourselves as an extension on this display */
1827bf215546Sopenharmony_ci   register_with_display(dpy);
1828bf215546Sopenharmony_ci
1829bf215546Sopenharmony_ci   if (!attribList || !attribList[0]) {
1830bf215546Sopenharmony_ci      /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1831bf215546Sopenharmony_ci      return glXGetFBConfigs(dpy, screen, nitems);
1832bf215546Sopenharmony_ci   }
1833bf215546Sopenharmony_ci
1834bf215546Sopenharmony_ci   xmvis = choose_visual(dpy, screen, attribList, GL_TRUE);
1835bf215546Sopenharmony_ci   if (xmvis) {
1836bf215546Sopenharmony_ci      GLXFBConfig *config = malloc(sizeof(XMesaVisual));
1837bf215546Sopenharmony_ci      if (!config) {
1838bf215546Sopenharmony_ci         *nitems = 0;
1839bf215546Sopenharmony_ci         return NULL;
1840bf215546Sopenharmony_ci      }
1841bf215546Sopenharmony_ci      *nitems = 1;
1842bf215546Sopenharmony_ci      config[0] = (GLXFBConfig) xmvis;
1843bf215546Sopenharmony_ci      return (GLXFBConfig *) config;
1844bf215546Sopenharmony_ci   }
1845bf215546Sopenharmony_ci   else {
1846bf215546Sopenharmony_ci      *nitems = 0;
1847bf215546Sopenharmony_ci      return NULL;
1848bf215546Sopenharmony_ci   }
1849bf215546Sopenharmony_ci}
1850bf215546Sopenharmony_ci
1851bf215546Sopenharmony_ci
1852bf215546Sopenharmony_ciPUBLIC XVisualInfo *
1853bf215546Sopenharmony_ciglXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
1854bf215546Sopenharmony_ci{
1855bf215546Sopenharmony_ci   if (dpy && config) {
1856bf215546Sopenharmony_ci      XMesaVisual xmvis = (XMesaVisual) config;
1857bf215546Sopenharmony_ci#if 0
1858bf215546Sopenharmony_ci      return xmvis->vishandle;
1859bf215546Sopenharmony_ci#else
1860bf215546Sopenharmony_ci      /* create a new vishandle - the cached one may be stale */
1861bf215546Sopenharmony_ci      xmvis->vishandle = malloc(sizeof(XVisualInfo));
1862bf215546Sopenharmony_ci      if (xmvis->vishandle) {
1863bf215546Sopenharmony_ci         memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
1864bf215546Sopenharmony_ci      }
1865bf215546Sopenharmony_ci      return xmvis->vishandle;
1866bf215546Sopenharmony_ci#endif
1867bf215546Sopenharmony_ci   }
1868bf215546Sopenharmony_ci   else {
1869bf215546Sopenharmony_ci      return NULL;
1870bf215546Sopenharmony_ci   }
1871bf215546Sopenharmony_ci}
1872bf215546Sopenharmony_ci
1873bf215546Sopenharmony_ci
1874bf215546Sopenharmony_ciPUBLIC GLXWindow
1875bf215546Sopenharmony_ciglXCreateWindow(Display *dpy, GLXFBConfig config, Window win,
1876bf215546Sopenharmony_ci                const int *attribList)
1877bf215546Sopenharmony_ci{
1878bf215546Sopenharmony_ci   XMesaVisual xmvis = (XMesaVisual) config;
1879bf215546Sopenharmony_ci   XMesaBuffer xmbuf;
1880bf215546Sopenharmony_ci   if (!xmvis)
1881bf215546Sopenharmony_ci      return 0;
1882bf215546Sopenharmony_ci
1883bf215546Sopenharmony_ci   xmbuf = XMesaCreateWindowBuffer(xmvis, win);
1884bf215546Sopenharmony_ci   if (!xmbuf)
1885bf215546Sopenharmony_ci      return 0;
1886bf215546Sopenharmony_ci
1887bf215546Sopenharmony_ci   (void) dpy;
1888bf215546Sopenharmony_ci   (void) attribList;  /* Ignored in GLX 1.3 */
1889bf215546Sopenharmony_ci
1890bf215546Sopenharmony_ci   return win;  /* A hack for now */
1891bf215546Sopenharmony_ci}
1892bf215546Sopenharmony_ci
1893bf215546Sopenharmony_ci
1894bf215546Sopenharmony_ciPUBLIC void
1895bf215546Sopenharmony_ciglXDestroyWindow( Display *dpy, GLXWindow window )
1896bf215546Sopenharmony_ci{
1897bf215546Sopenharmony_ci   XMesaBuffer b = XMesaFindBuffer(dpy, (Drawable) window);
1898bf215546Sopenharmony_ci   if (b)
1899bf215546Sopenharmony_ci      XMesaDestroyBuffer(b);
1900bf215546Sopenharmony_ci   /* don't destroy X window */
1901bf215546Sopenharmony_ci}
1902bf215546Sopenharmony_ci
1903bf215546Sopenharmony_ci
1904bf215546Sopenharmony_ci/* XXX untested */
1905bf215546Sopenharmony_ciPUBLIC GLXPixmap
1906bf215546Sopenharmony_ciglXCreatePixmap(Display *dpy, GLXFBConfig config, Pixmap pixmap,
1907bf215546Sopenharmony_ci                const int *attribList)
1908bf215546Sopenharmony_ci{
1909bf215546Sopenharmony_ci   XMesaVisual v = (XMesaVisual) config;
1910bf215546Sopenharmony_ci   XMesaBuffer b;
1911bf215546Sopenharmony_ci   const int *attr;
1912bf215546Sopenharmony_ci   int target = 0, format = 0, mipmap = 0;
1913bf215546Sopenharmony_ci   int value;
1914bf215546Sopenharmony_ci
1915bf215546Sopenharmony_ci   if (!dpy || !config || !pixmap)
1916bf215546Sopenharmony_ci      return 0;
1917bf215546Sopenharmony_ci
1918bf215546Sopenharmony_ci   for (attr = attribList; attr && *attr; attr++) {
1919bf215546Sopenharmony_ci      switch (*attr) {
1920bf215546Sopenharmony_ci      case GLX_TEXTURE_FORMAT_EXT:
1921bf215546Sopenharmony_ci         attr++;
1922bf215546Sopenharmony_ci         switch (*attr) {
1923bf215546Sopenharmony_ci         case GLX_TEXTURE_FORMAT_NONE_EXT:
1924bf215546Sopenharmony_ci         case GLX_TEXTURE_FORMAT_RGB_EXT:
1925bf215546Sopenharmony_ci         case GLX_TEXTURE_FORMAT_RGBA_EXT:
1926bf215546Sopenharmony_ci            format = *attr;
1927bf215546Sopenharmony_ci            break;
1928bf215546Sopenharmony_ci         default:
1929bf215546Sopenharmony_ci            /* error */
1930bf215546Sopenharmony_ci            return 0;
1931bf215546Sopenharmony_ci         }
1932bf215546Sopenharmony_ci         break;
1933bf215546Sopenharmony_ci      case GLX_TEXTURE_TARGET_EXT:
1934bf215546Sopenharmony_ci         attr++;
1935bf215546Sopenharmony_ci         switch (*attr) {
1936bf215546Sopenharmony_ci         case GLX_TEXTURE_1D_EXT:
1937bf215546Sopenharmony_ci         case GLX_TEXTURE_2D_EXT:
1938bf215546Sopenharmony_ci         case GLX_TEXTURE_RECTANGLE_EXT:
1939bf215546Sopenharmony_ci            target = *attr;
1940bf215546Sopenharmony_ci            break;
1941bf215546Sopenharmony_ci         default:
1942bf215546Sopenharmony_ci            /* error */
1943bf215546Sopenharmony_ci            return 0;
1944bf215546Sopenharmony_ci         }
1945bf215546Sopenharmony_ci         break;
1946bf215546Sopenharmony_ci      case GLX_MIPMAP_TEXTURE_EXT:
1947bf215546Sopenharmony_ci         attr++;
1948bf215546Sopenharmony_ci         if (*attr)
1949bf215546Sopenharmony_ci            mipmap = 1;
1950bf215546Sopenharmony_ci         break;
1951bf215546Sopenharmony_ci      default:
1952bf215546Sopenharmony_ci         /* error */
1953bf215546Sopenharmony_ci         return 0;
1954bf215546Sopenharmony_ci      }
1955bf215546Sopenharmony_ci   }
1956bf215546Sopenharmony_ci
1957bf215546Sopenharmony_ci   if (format == GLX_TEXTURE_FORMAT_RGB_EXT) {
1958bf215546Sopenharmony_ci      if (get_config(v, GLX_BIND_TO_TEXTURE_RGB_EXT,
1959bf215546Sopenharmony_ci                     &value, GL_TRUE) != Success
1960bf215546Sopenharmony_ci          || !value) {
1961bf215546Sopenharmony_ci         return 0; /* error! */
1962bf215546Sopenharmony_ci      }
1963bf215546Sopenharmony_ci   }
1964bf215546Sopenharmony_ci   else if (format == GLX_TEXTURE_FORMAT_RGBA_EXT) {
1965bf215546Sopenharmony_ci      if (get_config(v, GLX_BIND_TO_TEXTURE_RGBA_EXT,
1966bf215546Sopenharmony_ci                     &value, GL_TRUE) != Success
1967bf215546Sopenharmony_ci          || !value) {
1968bf215546Sopenharmony_ci         return 0; /* error! */
1969bf215546Sopenharmony_ci      }
1970bf215546Sopenharmony_ci   }
1971bf215546Sopenharmony_ci   if (mipmap) {
1972bf215546Sopenharmony_ci      if (get_config(v, GLX_BIND_TO_MIPMAP_TEXTURE_EXT,
1973bf215546Sopenharmony_ci                     &value, GL_TRUE) != Success
1974bf215546Sopenharmony_ci          || !value) {
1975bf215546Sopenharmony_ci         return 0; /* error! */
1976bf215546Sopenharmony_ci      }
1977bf215546Sopenharmony_ci   }
1978bf215546Sopenharmony_ci   if (target == GLX_TEXTURE_1D_EXT) {
1979bf215546Sopenharmony_ci      if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
1980bf215546Sopenharmony_ci                     &value, GL_TRUE) != Success
1981bf215546Sopenharmony_ci          || (value & GLX_TEXTURE_1D_BIT_EXT) == 0) {
1982bf215546Sopenharmony_ci         return 0; /* error! */
1983bf215546Sopenharmony_ci      }
1984bf215546Sopenharmony_ci   }
1985bf215546Sopenharmony_ci   else if (target == GLX_TEXTURE_2D_EXT) {
1986bf215546Sopenharmony_ci      if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
1987bf215546Sopenharmony_ci                     &value, GL_TRUE) != Success
1988bf215546Sopenharmony_ci          || (value & GLX_TEXTURE_2D_BIT_EXT) == 0) {
1989bf215546Sopenharmony_ci         return 0; /* error! */
1990bf215546Sopenharmony_ci      }
1991bf215546Sopenharmony_ci   }
1992bf215546Sopenharmony_ci   if (target == GLX_TEXTURE_RECTANGLE_EXT) {
1993bf215546Sopenharmony_ci      if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
1994bf215546Sopenharmony_ci                     &value, GL_TRUE) != Success
1995bf215546Sopenharmony_ci          || (value & GLX_TEXTURE_RECTANGLE_BIT_EXT) == 0) {
1996bf215546Sopenharmony_ci         return 0; /* error! */
1997bf215546Sopenharmony_ci      }
1998bf215546Sopenharmony_ci   }
1999bf215546Sopenharmony_ci
2000bf215546Sopenharmony_ci   if (format || target || mipmap) {
2001bf215546Sopenharmony_ci      /* texture from pixmap */
2002bf215546Sopenharmony_ci      b = XMesaCreatePixmapTextureBuffer(v, pixmap, 0, format, target, mipmap);
2003bf215546Sopenharmony_ci   }
2004bf215546Sopenharmony_ci   else {
2005bf215546Sopenharmony_ci      b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
2006bf215546Sopenharmony_ci   }
2007bf215546Sopenharmony_ci   if (!b) {
2008bf215546Sopenharmony_ci      return 0;
2009bf215546Sopenharmony_ci   }
2010bf215546Sopenharmony_ci
2011bf215546Sopenharmony_ci   return pixmap;
2012bf215546Sopenharmony_ci}
2013bf215546Sopenharmony_ci
2014bf215546Sopenharmony_ci
2015bf215546Sopenharmony_ciPUBLIC void
2016bf215546Sopenharmony_ciglXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
2017bf215546Sopenharmony_ci{
2018bf215546Sopenharmony_ci   XMesaBuffer b = XMesaFindBuffer(dpy, (Drawable)pixmap);
2019bf215546Sopenharmony_ci   if (b)
2020bf215546Sopenharmony_ci      XMesaDestroyBuffer(b);
2021bf215546Sopenharmony_ci   /* don't destroy X pixmap */
2022bf215546Sopenharmony_ci}
2023bf215546Sopenharmony_ci
2024bf215546Sopenharmony_ci
2025bf215546Sopenharmony_ciPUBLIC GLXPbuffer
2026bf215546Sopenharmony_ciglXCreatePbuffer(Display *dpy, GLXFBConfig config, const int *attribList)
2027bf215546Sopenharmony_ci{
2028bf215546Sopenharmony_ci   XMesaVisual xmvis = (XMesaVisual) config;
2029bf215546Sopenharmony_ci   XMesaBuffer xmbuf;
2030bf215546Sopenharmony_ci   const int *attrib;
2031bf215546Sopenharmony_ci   int width = 0, height = 0;
2032bf215546Sopenharmony_ci   GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2033bf215546Sopenharmony_ci
2034bf215546Sopenharmony_ci   (void) dpy;
2035bf215546Sopenharmony_ci
2036bf215546Sopenharmony_ci   for (attrib = attribList; *attrib; attrib++) {
2037bf215546Sopenharmony_ci      switch (*attrib) {
2038bf215546Sopenharmony_ci         case GLX_PBUFFER_WIDTH:
2039bf215546Sopenharmony_ci            attrib++;
2040bf215546Sopenharmony_ci            width = *attrib;
2041bf215546Sopenharmony_ci            break;
2042bf215546Sopenharmony_ci         case GLX_PBUFFER_HEIGHT:
2043bf215546Sopenharmony_ci            attrib++;
2044bf215546Sopenharmony_ci            height = *attrib;
2045bf215546Sopenharmony_ci            break;
2046bf215546Sopenharmony_ci         case GLX_PRESERVED_CONTENTS:
2047bf215546Sopenharmony_ci            attrib++;
2048bf215546Sopenharmony_ci            preserveContents = *attrib;
2049bf215546Sopenharmony_ci            break;
2050bf215546Sopenharmony_ci         case GLX_LARGEST_PBUFFER:
2051bf215546Sopenharmony_ci            attrib++;
2052bf215546Sopenharmony_ci            useLargest = *attrib;
2053bf215546Sopenharmony_ci            break;
2054bf215546Sopenharmony_ci         default:
2055bf215546Sopenharmony_ci            return 0;
2056bf215546Sopenharmony_ci      }
2057bf215546Sopenharmony_ci   }
2058bf215546Sopenharmony_ci
2059bf215546Sopenharmony_ci   if (width == 0 || height == 0)
2060bf215546Sopenharmony_ci      return 0;
2061bf215546Sopenharmony_ci
2062bf215546Sopenharmony_ci   if (width > PBUFFER_MAX_SIZE || height > PBUFFER_MAX_SIZE) {
2063bf215546Sopenharmony_ci      /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2064bf215546Sopenharmony_ci       * allocate the largest possible buffer.
2065bf215546Sopenharmony_ci       */
2066bf215546Sopenharmony_ci      if (useLargest) {
2067bf215546Sopenharmony_ci         width = PBUFFER_MAX_SIZE;
2068bf215546Sopenharmony_ci         height = PBUFFER_MAX_SIZE;
2069bf215546Sopenharmony_ci      }
2070bf215546Sopenharmony_ci   }
2071bf215546Sopenharmony_ci
2072bf215546Sopenharmony_ci   xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2073bf215546Sopenharmony_ci   /* A GLXPbuffer handle must be an X Drawable because that's what
2074bf215546Sopenharmony_ci    * glXMakeCurrent takes.
2075bf215546Sopenharmony_ci    */
2076bf215546Sopenharmony_ci   if (xmbuf) {
2077bf215546Sopenharmony_ci      xmbuf->largestPbuffer = useLargest;
2078bf215546Sopenharmony_ci      xmbuf->preservedContents = preserveContents;
2079bf215546Sopenharmony_ci      return (GLXPbuffer) xmbuf->ws.drawable;
2080bf215546Sopenharmony_ci   }
2081bf215546Sopenharmony_ci   else {
2082bf215546Sopenharmony_ci      return 0;
2083bf215546Sopenharmony_ci   }
2084bf215546Sopenharmony_ci}
2085bf215546Sopenharmony_ci
2086bf215546Sopenharmony_ci
2087bf215546Sopenharmony_ciPUBLIC void
2088bf215546Sopenharmony_ciglXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
2089bf215546Sopenharmony_ci{
2090bf215546Sopenharmony_ci   XMesaBuffer b = XMesaFindBuffer(dpy, pbuf);
2091bf215546Sopenharmony_ci   if (b) {
2092bf215546Sopenharmony_ci      XMesaDestroyBuffer(b);
2093bf215546Sopenharmony_ci   }
2094bf215546Sopenharmony_ci}
2095bf215546Sopenharmony_ci
2096bf215546Sopenharmony_ci
2097bf215546Sopenharmony_ciPUBLIC void
2098bf215546Sopenharmony_ciglXQueryDrawable(Display *dpy, GLXDrawable draw, int attribute,
2099bf215546Sopenharmony_ci                 unsigned int *value)
2100bf215546Sopenharmony_ci{
2101bf215546Sopenharmony_ci   GLuint width, height;
2102bf215546Sopenharmony_ci   XMesaBuffer xmbuf = XMesaFindBuffer(dpy, draw);
2103bf215546Sopenharmony_ci   if (!xmbuf) {
2104bf215546Sopenharmony_ci      generate_error(dpy, GLXBadDrawable, draw, X_GLXGetDrawableAttributes, False);
2105bf215546Sopenharmony_ci      return;
2106bf215546Sopenharmony_ci   }
2107bf215546Sopenharmony_ci
2108bf215546Sopenharmony_ci   /* make sure buffer's dimensions are up to date */
2109bf215546Sopenharmony_ci   xmesa_get_window_size(dpy, xmbuf, &width, &height);
2110bf215546Sopenharmony_ci
2111bf215546Sopenharmony_ci   switch (attribute) {
2112bf215546Sopenharmony_ci      case GLX_WIDTH:
2113bf215546Sopenharmony_ci         *value = width;
2114bf215546Sopenharmony_ci         break;
2115bf215546Sopenharmony_ci      case GLX_HEIGHT:
2116bf215546Sopenharmony_ci         *value = height;
2117bf215546Sopenharmony_ci         break;
2118bf215546Sopenharmony_ci      case GLX_PRESERVED_CONTENTS:
2119bf215546Sopenharmony_ci         *value = xmbuf->preservedContents;
2120bf215546Sopenharmony_ci         break;
2121bf215546Sopenharmony_ci      case GLX_LARGEST_PBUFFER:
2122bf215546Sopenharmony_ci         *value = xmbuf->largestPbuffer;
2123bf215546Sopenharmony_ci         break;
2124bf215546Sopenharmony_ci      case GLX_FBCONFIG_ID:
2125bf215546Sopenharmony_ci         *value = xmbuf->xm_visual->visinfo->visualid;
2126bf215546Sopenharmony_ci         return;
2127bf215546Sopenharmony_ci      case GLX_TEXTURE_FORMAT_EXT:
2128bf215546Sopenharmony_ci         *value = xmbuf->TextureFormat;
2129bf215546Sopenharmony_ci         break;
2130bf215546Sopenharmony_ci      case GLX_TEXTURE_TARGET_EXT:
2131bf215546Sopenharmony_ci         *value = xmbuf->TextureTarget;
2132bf215546Sopenharmony_ci         break;
2133bf215546Sopenharmony_ci      case GLX_MIPMAP_TEXTURE_EXT:
2134bf215546Sopenharmony_ci         *value = xmbuf->TextureMipmap;
2135bf215546Sopenharmony_ci         break;
2136bf215546Sopenharmony_ci
2137bf215546Sopenharmony_ci      default:
2138bf215546Sopenharmony_ci         generate_error(dpy, BadValue, 0, X_GLXCreateContextAttribsARB, true);
2139bf215546Sopenharmony_ci         return;
2140bf215546Sopenharmony_ci   }
2141bf215546Sopenharmony_ci}
2142bf215546Sopenharmony_ci
2143bf215546Sopenharmony_ci
2144bf215546Sopenharmony_ciPUBLIC GLXContext
2145bf215546Sopenharmony_ciglXCreateNewContext( Display *dpy, GLXFBConfig config,
2146bf215546Sopenharmony_ci                     int renderType, GLXContext shareCtx, Bool direct )
2147bf215546Sopenharmony_ci{
2148bf215546Sopenharmony_ci   XMesaVisual xmvis = (XMesaVisual) config;
2149bf215546Sopenharmony_ci
2150bf215546Sopenharmony_ci   if (!dpy || !config ||
2151bf215546Sopenharmony_ci       (renderType != GLX_RGBA_TYPE && renderType != GLX_COLOR_INDEX_TYPE))
2152bf215546Sopenharmony_ci      return 0;
2153bf215546Sopenharmony_ci
2154bf215546Sopenharmony_ci   return create_context(dpy, xmvis,
2155bf215546Sopenharmony_ci                         shareCtx ? shareCtx->xmesaContext : NULL,
2156bf215546Sopenharmony_ci                         direct,
2157bf215546Sopenharmony_ci                         1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, 0x0);
2158bf215546Sopenharmony_ci}
2159bf215546Sopenharmony_ci
2160bf215546Sopenharmony_ci
2161bf215546Sopenharmony_ciPUBLIC int
2162bf215546Sopenharmony_ciglXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
2163bf215546Sopenharmony_ci{
2164bf215546Sopenharmony_ci   GLXContext glxCtx = ctx;
2165bf215546Sopenharmony_ci   XMesaContext xmctx = glxCtx->xmesaContext;
2166bf215546Sopenharmony_ci
2167bf215546Sopenharmony_ci   (void) dpy;
2168bf215546Sopenharmony_ci   (void) ctx;
2169bf215546Sopenharmony_ci
2170bf215546Sopenharmony_ci   switch (attribute) {
2171bf215546Sopenharmony_ci   case GLX_FBCONFIG_ID:
2172bf215546Sopenharmony_ci      *value = xmctx->xm_visual->visinfo->visualid;
2173bf215546Sopenharmony_ci      break;
2174bf215546Sopenharmony_ci   case GLX_RENDER_TYPE:
2175bf215546Sopenharmony_ci      *value = GLX_RGBA_TYPE;
2176bf215546Sopenharmony_ci      break;
2177bf215546Sopenharmony_ci   case GLX_SCREEN:
2178bf215546Sopenharmony_ci      *value = 0;
2179bf215546Sopenharmony_ci      return Success;
2180bf215546Sopenharmony_ci   default:
2181bf215546Sopenharmony_ci      return GLX_BAD_ATTRIBUTE;
2182bf215546Sopenharmony_ci   }
2183bf215546Sopenharmony_ci   return 0;
2184bf215546Sopenharmony_ci}
2185bf215546Sopenharmony_ci
2186bf215546Sopenharmony_ci
2187bf215546Sopenharmony_ciPUBLIC void
2188bf215546Sopenharmony_ciglXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask )
2189bf215546Sopenharmony_ci{
2190bf215546Sopenharmony_ci   XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2191bf215546Sopenharmony_ci   if (xmbuf)
2192bf215546Sopenharmony_ci      xmbuf->selectedEvents = mask;
2193bf215546Sopenharmony_ci}
2194bf215546Sopenharmony_ci
2195bf215546Sopenharmony_ci
2196bf215546Sopenharmony_ciPUBLIC void
2197bf215546Sopenharmony_ciglXGetSelectedEvent(Display *dpy, GLXDrawable drawable, unsigned long *mask)
2198bf215546Sopenharmony_ci{
2199bf215546Sopenharmony_ci   XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2200bf215546Sopenharmony_ci   if (xmbuf)
2201bf215546Sopenharmony_ci      *mask = xmbuf->selectedEvents;
2202bf215546Sopenharmony_ci   else
2203bf215546Sopenharmony_ci      *mask = 0;
2204bf215546Sopenharmony_ci}
2205bf215546Sopenharmony_ci
2206bf215546Sopenharmony_ci
2207bf215546Sopenharmony_ci
2208bf215546Sopenharmony_ci/*** GLX_SGI_swap_control ***/
2209bf215546Sopenharmony_ci
2210bf215546Sopenharmony_ciPUBLIC int
2211bf215546Sopenharmony_ciglXSwapIntervalSGI(int interval)
2212bf215546Sopenharmony_ci{
2213bf215546Sopenharmony_ci   (void) interval;
2214bf215546Sopenharmony_ci   return 0;
2215bf215546Sopenharmony_ci}
2216bf215546Sopenharmony_ci
2217bf215546Sopenharmony_ci
2218bf215546Sopenharmony_ci
2219bf215546Sopenharmony_ci/*** GLX_SGI_video_sync ***/
2220bf215546Sopenharmony_ci
2221bf215546Sopenharmony_cistatic unsigned int FrameCounter = 0;
2222bf215546Sopenharmony_ci
2223bf215546Sopenharmony_ciPUBLIC int
2224bf215546Sopenharmony_ciglXGetVideoSyncSGI(unsigned int *count)
2225bf215546Sopenharmony_ci{
2226bf215546Sopenharmony_ci   /* this is a bogus implementation */
2227bf215546Sopenharmony_ci   *count = FrameCounter++;
2228bf215546Sopenharmony_ci   return 0;
2229bf215546Sopenharmony_ci}
2230bf215546Sopenharmony_ci
2231bf215546Sopenharmony_ciPUBLIC int
2232bf215546Sopenharmony_ciglXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
2233bf215546Sopenharmony_ci{
2234bf215546Sopenharmony_ci   if (divisor <= 0 || remainder < 0)
2235bf215546Sopenharmony_ci      return GLX_BAD_VALUE;
2236bf215546Sopenharmony_ci   /* this is a bogus implementation */
2237bf215546Sopenharmony_ci   FrameCounter++;
2238bf215546Sopenharmony_ci   while (FrameCounter % divisor != remainder)
2239bf215546Sopenharmony_ci      FrameCounter++;
2240bf215546Sopenharmony_ci   *count = FrameCounter;
2241bf215546Sopenharmony_ci   return 0;
2242bf215546Sopenharmony_ci}
2243bf215546Sopenharmony_ci
2244bf215546Sopenharmony_ci
2245bf215546Sopenharmony_ci
2246bf215546Sopenharmony_ci/*** GLX_SGI_make_current_read ***/
2247bf215546Sopenharmony_ci
2248bf215546Sopenharmony_ciPUBLIC Bool
2249bf215546Sopenharmony_ciglXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read,
2250bf215546Sopenharmony_ci                      GLXContext ctx)
2251bf215546Sopenharmony_ci{
2252bf215546Sopenharmony_ci   return glXMakeContextCurrent( dpy, draw, read, ctx );
2253bf215546Sopenharmony_ci}
2254bf215546Sopenharmony_ci
2255bf215546Sopenharmony_ci/* not used
2256bf215546Sopenharmony_cistatic GLXDrawable
2257bf215546Sopenharmony_ciglXGetCurrentReadDrawableSGI(void)
2258bf215546Sopenharmony_ci{
2259bf215546Sopenharmony_ci   return 0;
2260bf215546Sopenharmony_ci}
2261bf215546Sopenharmony_ci*/
2262bf215546Sopenharmony_ci
2263bf215546Sopenharmony_ci
2264bf215546Sopenharmony_ci/*** GLX_SGIX_video_source ***/
2265bf215546Sopenharmony_ci#if defined(_VL_H)
2266bf215546Sopenharmony_ci
2267bf215546Sopenharmony_ciPUBLIC GLXVideoSourceSGIX
2268bf215546Sopenharmony_ciglXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server,
2269bf215546Sopenharmony_ci                            VLPath path, int nodeClass, VLNode drainNode)
2270bf215546Sopenharmony_ci{
2271bf215546Sopenharmony_ci   (void) dpy;
2272bf215546Sopenharmony_ci   (void) screen;
2273bf215546Sopenharmony_ci   (void) server;
2274bf215546Sopenharmony_ci   (void) path;
2275bf215546Sopenharmony_ci   (void) nodeClass;
2276bf215546Sopenharmony_ci   (void) drainNode;
2277bf215546Sopenharmony_ci   return 0;
2278bf215546Sopenharmony_ci}
2279bf215546Sopenharmony_ci
2280bf215546Sopenharmony_ciPUBLIC void
2281bf215546Sopenharmony_ciglXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src)
2282bf215546Sopenharmony_ci{
2283bf215546Sopenharmony_ci   (void) dpy;
2284bf215546Sopenharmony_ci   (void) src;
2285bf215546Sopenharmony_ci}
2286bf215546Sopenharmony_ci
2287bf215546Sopenharmony_ci#endif
2288bf215546Sopenharmony_ci
2289bf215546Sopenharmony_ci
2290bf215546Sopenharmony_ci/*** GLX_EXT_import_context ***/
2291bf215546Sopenharmony_ci
2292bf215546Sopenharmony_ciPUBLIC void
2293bf215546Sopenharmony_ciglXFreeContextEXT(Display *dpy, GLXContext context)
2294bf215546Sopenharmony_ci{
2295bf215546Sopenharmony_ci   (void) dpy;
2296bf215546Sopenharmony_ci   (void) context;
2297bf215546Sopenharmony_ci}
2298bf215546Sopenharmony_ci
2299bf215546Sopenharmony_ciPUBLIC GLXContextID
2300bf215546Sopenharmony_ciglXGetContextIDEXT(const GLXContext context)
2301bf215546Sopenharmony_ci{
2302bf215546Sopenharmony_ci   (void) context;
2303bf215546Sopenharmony_ci   return 0;
2304bf215546Sopenharmony_ci}
2305bf215546Sopenharmony_ci
2306bf215546Sopenharmony_ciPUBLIC GLXContext
2307bf215546Sopenharmony_ciglXImportContextEXT(Display *dpy, GLXContextID contextID)
2308bf215546Sopenharmony_ci{
2309bf215546Sopenharmony_ci   (void) dpy;
2310bf215546Sopenharmony_ci   (void) contextID;
2311bf215546Sopenharmony_ci   return 0;
2312bf215546Sopenharmony_ci}
2313bf215546Sopenharmony_ci
2314bf215546Sopenharmony_ciPUBLIC int
2315bf215546Sopenharmony_ciglXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute,
2316bf215546Sopenharmony_ci                       int *value)
2317bf215546Sopenharmony_ci{
2318bf215546Sopenharmony_ci   (void) dpy;
2319bf215546Sopenharmony_ci   (void) context;
2320bf215546Sopenharmony_ci   (void) attribute;
2321bf215546Sopenharmony_ci   (void) value;
2322bf215546Sopenharmony_ci   return 0;
2323bf215546Sopenharmony_ci}
2324bf215546Sopenharmony_ci
2325bf215546Sopenharmony_ci
2326bf215546Sopenharmony_ci
2327bf215546Sopenharmony_ci/*** GLX_SGIX_fbconfig ***/
2328bf215546Sopenharmony_ci
2329bf215546Sopenharmony_ciPUBLIC int
2330bf215546Sopenharmony_ciglXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config,
2331bf215546Sopenharmony_ci                         int attribute, int *value)
2332bf215546Sopenharmony_ci{
2333bf215546Sopenharmony_ci   return glXGetFBConfigAttrib(dpy, config, attribute, value);
2334bf215546Sopenharmony_ci}
2335bf215546Sopenharmony_ci
2336bf215546Sopenharmony_ciPUBLIC GLXFBConfigSGIX *
2337bf215546Sopenharmony_ciglXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list,
2338bf215546Sopenharmony_ci                      int *nelements)
2339bf215546Sopenharmony_ci{
2340bf215546Sopenharmony_ci   return (GLXFBConfig *) glXChooseFBConfig(dpy, screen,
2341bf215546Sopenharmony_ci                                            attrib_list, nelements);
2342bf215546Sopenharmony_ci}
2343bf215546Sopenharmony_ci
2344bf215546Sopenharmony_ci
2345bf215546Sopenharmony_ciPUBLIC GLXPixmap
2346bf215546Sopenharmony_ciglXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config,
2347bf215546Sopenharmony_ci                                 Pixmap pixmap)
2348bf215546Sopenharmony_ci{
2349bf215546Sopenharmony_ci   XMesaVisual xmvis = (XMesaVisual) config;
2350bf215546Sopenharmony_ci   XMesaBuffer xmbuf = XMesaCreatePixmapBuffer(xmvis, pixmap, 0);
2351bf215546Sopenharmony_ci   return xmbuf->ws.drawable; /* need to return an X ID */
2352bf215546Sopenharmony_ci}
2353bf215546Sopenharmony_ci
2354bf215546Sopenharmony_ci
2355bf215546Sopenharmony_ciPUBLIC GLXContext
2356bf215546Sopenharmony_ciglXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config,
2357bf215546Sopenharmony_ci                               int renderType, GLXContext shareCtx,
2358bf215546Sopenharmony_ci                               Bool direct)
2359bf215546Sopenharmony_ci{
2360bf215546Sopenharmony_ci   XMesaVisual xmvis = (XMesaVisual) config;
2361bf215546Sopenharmony_ci
2362bf215546Sopenharmony_ci   if (!dpy || !config ||
2363bf215546Sopenharmony_ci       (renderType != GLX_RGBA_TYPE && renderType != GLX_COLOR_INDEX_TYPE))
2364bf215546Sopenharmony_ci      return 0;
2365bf215546Sopenharmony_ci
2366bf215546Sopenharmony_ci   return create_context(dpy, xmvis,
2367bf215546Sopenharmony_ci                         shareCtx ? shareCtx->xmesaContext : NULL,
2368bf215546Sopenharmony_ci                         direct,
2369bf215546Sopenharmony_ci                         1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, 0x0);
2370bf215546Sopenharmony_ci}
2371bf215546Sopenharmony_ci
2372bf215546Sopenharmony_ci
2373bf215546Sopenharmony_ciPUBLIC XVisualInfo *
2374bf215546Sopenharmony_ciglXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config)
2375bf215546Sopenharmony_ci{
2376bf215546Sopenharmony_ci   return glXGetVisualFromFBConfig(dpy, config);
2377bf215546Sopenharmony_ci}
2378bf215546Sopenharmony_ci
2379bf215546Sopenharmony_ci
2380bf215546Sopenharmony_ciPUBLIC GLXFBConfigSGIX
2381bf215546Sopenharmony_ciglXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis)
2382bf215546Sopenharmony_ci{
2383bf215546Sopenharmony_ci   XMesaVisual xmvis = find_glx_visual(dpy, vis);
2384bf215546Sopenharmony_ci   if (!xmvis) {
2385bf215546Sopenharmony_ci      /* This visual wasn't found with glXChooseVisual() */
2386bf215546Sopenharmony_ci      xmvis = create_glx_visual(dpy, vis);
2387bf215546Sopenharmony_ci   }
2388bf215546Sopenharmony_ci
2389bf215546Sopenharmony_ci   return (GLXFBConfigSGIX) xmvis;
2390bf215546Sopenharmony_ci}
2391bf215546Sopenharmony_ci
2392bf215546Sopenharmony_ci
2393bf215546Sopenharmony_ci
2394bf215546Sopenharmony_ci/*** GLX_SGIX_pbuffer ***/
2395bf215546Sopenharmony_ci
2396bf215546Sopenharmony_ciPUBLIC GLXPbufferSGIX
2397bf215546Sopenharmony_ciglXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config,
2398bf215546Sopenharmony_ci                        unsigned int width, unsigned int height,
2399bf215546Sopenharmony_ci                        int *attribList)
2400bf215546Sopenharmony_ci{
2401bf215546Sopenharmony_ci   XMesaVisual xmvis = (XMesaVisual) config;
2402bf215546Sopenharmony_ci   XMesaBuffer xmbuf;
2403bf215546Sopenharmony_ci   const int *attrib;
2404bf215546Sopenharmony_ci   GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2405bf215546Sopenharmony_ci
2406bf215546Sopenharmony_ci   (void) dpy;
2407bf215546Sopenharmony_ci
2408bf215546Sopenharmony_ci   for (attrib = attribList; attrib && *attrib; attrib++) {
2409bf215546Sopenharmony_ci      switch (*attrib) {
2410bf215546Sopenharmony_ci         case GLX_PRESERVED_CONTENTS_SGIX:
2411bf215546Sopenharmony_ci            attrib++;
2412bf215546Sopenharmony_ci            preserveContents = *attrib; /* ignored */
2413bf215546Sopenharmony_ci            break;
2414bf215546Sopenharmony_ci         case GLX_LARGEST_PBUFFER_SGIX:
2415bf215546Sopenharmony_ci            attrib++;
2416bf215546Sopenharmony_ci            useLargest = *attrib; /* ignored */
2417bf215546Sopenharmony_ci            break;
2418bf215546Sopenharmony_ci         default:
2419bf215546Sopenharmony_ci            return 0;
2420bf215546Sopenharmony_ci      }
2421bf215546Sopenharmony_ci   }
2422bf215546Sopenharmony_ci
2423bf215546Sopenharmony_ci   /* not used at this time */
2424bf215546Sopenharmony_ci   (void) useLargest;
2425bf215546Sopenharmony_ci   (void) preserveContents;
2426bf215546Sopenharmony_ci
2427bf215546Sopenharmony_ci   xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2428bf215546Sopenharmony_ci   /* A GLXPbuffer handle must be an X Drawable because that's what
2429bf215546Sopenharmony_ci    * glXMakeCurrent takes.
2430bf215546Sopenharmony_ci    */
2431bf215546Sopenharmony_ci   return (GLXPbuffer) xmbuf->ws.drawable;
2432bf215546Sopenharmony_ci}
2433bf215546Sopenharmony_ci
2434bf215546Sopenharmony_ci
2435bf215546Sopenharmony_ciPUBLIC void
2436bf215546Sopenharmony_ciglXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf)
2437bf215546Sopenharmony_ci{
2438bf215546Sopenharmony_ci   XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2439bf215546Sopenharmony_ci   if (xmbuf) {
2440bf215546Sopenharmony_ci      XMesaDestroyBuffer(xmbuf);
2441bf215546Sopenharmony_ci   }
2442bf215546Sopenharmony_ci}
2443bf215546Sopenharmony_ci
2444bf215546Sopenharmony_ci
2445bf215546Sopenharmony_ciPUBLIC void
2446bf215546Sopenharmony_ciglXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute,
2447bf215546Sopenharmony_ci                       unsigned int *value)
2448bf215546Sopenharmony_ci{
2449bf215546Sopenharmony_ci   const XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2450bf215546Sopenharmony_ci
2451bf215546Sopenharmony_ci   if (!xmbuf) {
2452bf215546Sopenharmony_ci      /* Generate GLXBadPbufferSGIX for bad pbuffer */
2453bf215546Sopenharmony_ci      return;
2454bf215546Sopenharmony_ci   }
2455bf215546Sopenharmony_ci
2456bf215546Sopenharmony_ci   switch (attribute) {
2457bf215546Sopenharmony_ci      case GLX_PRESERVED_CONTENTS_SGIX:
2458bf215546Sopenharmony_ci         *value = True;
2459bf215546Sopenharmony_ci         break;
2460bf215546Sopenharmony_ci      case GLX_LARGEST_PBUFFER_SGIX:
2461bf215546Sopenharmony_ci         *value = xmesa_buffer_width(xmbuf) * xmesa_buffer_height(xmbuf);
2462bf215546Sopenharmony_ci         break;
2463bf215546Sopenharmony_ci      case GLX_WIDTH_SGIX:
2464bf215546Sopenharmony_ci         *value = xmesa_buffer_width(xmbuf);
2465bf215546Sopenharmony_ci         break;
2466bf215546Sopenharmony_ci      case GLX_HEIGHT_SGIX:
2467bf215546Sopenharmony_ci         *value = xmesa_buffer_height(xmbuf);
2468bf215546Sopenharmony_ci         break;
2469bf215546Sopenharmony_ci      case GLX_EVENT_MASK_SGIX:
2470bf215546Sopenharmony_ci         *value = 0;  /* XXX might be wrong */
2471bf215546Sopenharmony_ci         break;
2472bf215546Sopenharmony_ci      default:
2473bf215546Sopenharmony_ci         *value = 0;
2474bf215546Sopenharmony_ci   }
2475bf215546Sopenharmony_ci}
2476bf215546Sopenharmony_ci
2477bf215546Sopenharmony_ci
2478bf215546Sopenharmony_ciPUBLIC void
2479bf215546Sopenharmony_ciglXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask)
2480bf215546Sopenharmony_ci{
2481bf215546Sopenharmony_ci   XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2482bf215546Sopenharmony_ci   if (xmbuf) {
2483bf215546Sopenharmony_ci      /* Note: we'll never generate clobber events */
2484bf215546Sopenharmony_ci      xmbuf->selectedEvents = mask;
2485bf215546Sopenharmony_ci   }
2486bf215546Sopenharmony_ci}
2487bf215546Sopenharmony_ci
2488bf215546Sopenharmony_ci
2489bf215546Sopenharmony_ciPUBLIC void
2490bf215546Sopenharmony_ciglXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable,
2491bf215546Sopenharmony_ci                        unsigned long *mask)
2492bf215546Sopenharmony_ci{
2493bf215546Sopenharmony_ci   XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2494bf215546Sopenharmony_ci   if (xmbuf) {
2495bf215546Sopenharmony_ci      *mask = xmbuf->selectedEvents;
2496bf215546Sopenharmony_ci   }
2497bf215546Sopenharmony_ci   else {
2498bf215546Sopenharmony_ci      *mask = 0;
2499bf215546Sopenharmony_ci   }
2500bf215546Sopenharmony_ci}
2501bf215546Sopenharmony_ci
2502bf215546Sopenharmony_ci
2503bf215546Sopenharmony_ci
2504bf215546Sopenharmony_ci/*** GLX_SGI_cushion ***/
2505bf215546Sopenharmony_ci
2506bf215546Sopenharmony_ciPUBLIC void
2507bf215546Sopenharmony_ciglXCushionSGI(Display *dpy, Window win, float cushion)
2508bf215546Sopenharmony_ci{
2509bf215546Sopenharmony_ci   (void) dpy;
2510bf215546Sopenharmony_ci   (void) win;
2511bf215546Sopenharmony_ci   (void) cushion;
2512bf215546Sopenharmony_ci}
2513bf215546Sopenharmony_ci
2514bf215546Sopenharmony_ci
2515bf215546Sopenharmony_ci
2516bf215546Sopenharmony_ci/*** GLX_SGIX_video_resize ***/
2517bf215546Sopenharmony_ci
2518bf215546Sopenharmony_ciPUBLIC int
2519bf215546Sopenharmony_ciglXBindChannelToWindowSGIX(Display *dpy, int screen, int channel,
2520bf215546Sopenharmony_ci                           Window window)
2521bf215546Sopenharmony_ci{
2522bf215546Sopenharmony_ci   (void) dpy;
2523bf215546Sopenharmony_ci   (void) screen;
2524bf215546Sopenharmony_ci   (void) channel;
2525bf215546Sopenharmony_ci   (void) window;
2526bf215546Sopenharmony_ci   return 0;
2527bf215546Sopenharmony_ci}
2528bf215546Sopenharmony_ci
2529bf215546Sopenharmony_ciPUBLIC int
2530bf215546Sopenharmony_ciglXChannelRectSGIX(Display *dpy, int screen, int channel,
2531bf215546Sopenharmony_ci                   int x, int y, int w, int h)
2532bf215546Sopenharmony_ci{
2533bf215546Sopenharmony_ci   (void) dpy;
2534bf215546Sopenharmony_ci   (void) screen;
2535bf215546Sopenharmony_ci   (void) channel;
2536bf215546Sopenharmony_ci   (void) x;
2537bf215546Sopenharmony_ci   (void) y;
2538bf215546Sopenharmony_ci   (void) w;
2539bf215546Sopenharmony_ci   (void) h;
2540bf215546Sopenharmony_ci   return 0;
2541bf215546Sopenharmony_ci}
2542bf215546Sopenharmony_ci
2543bf215546Sopenharmony_ciPUBLIC int
2544bf215546Sopenharmony_ciglXQueryChannelRectSGIX(Display *dpy, int screen, int channel,
2545bf215546Sopenharmony_ci                        int *x, int *y, int *w, int *h)
2546bf215546Sopenharmony_ci{
2547bf215546Sopenharmony_ci   (void) dpy;
2548bf215546Sopenharmony_ci   (void) screen;
2549bf215546Sopenharmony_ci   (void) channel;
2550bf215546Sopenharmony_ci   (void) x;
2551bf215546Sopenharmony_ci   (void) y;
2552bf215546Sopenharmony_ci   (void) w;
2553bf215546Sopenharmony_ci   (void) h;
2554bf215546Sopenharmony_ci   return 0;
2555bf215546Sopenharmony_ci}
2556bf215546Sopenharmony_ci
2557bf215546Sopenharmony_ciPUBLIC int
2558bf215546Sopenharmony_ciglXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel,
2559bf215546Sopenharmony_ci                          int *dx, int *dy, int *dw, int *dh)
2560bf215546Sopenharmony_ci{
2561bf215546Sopenharmony_ci   (void) dpy;
2562bf215546Sopenharmony_ci   (void) screen;
2563bf215546Sopenharmony_ci   (void) channel;
2564bf215546Sopenharmony_ci   (void) dx;
2565bf215546Sopenharmony_ci   (void) dy;
2566bf215546Sopenharmony_ci   (void) dw;
2567bf215546Sopenharmony_ci   (void) dh;
2568bf215546Sopenharmony_ci   return 0;
2569bf215546Sopenharmony_ci}
2570bf215546Sopenharmony_ci
2571bf215546Sopenharmony_ciPUBLIC int
2572bf215546Sopenharmony_ciglXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype)
2573bf215546Sopenharmony_ci{
2574bf215546Sopenharmony_ci   (void) dpy;
2575bf215546Sopenharmony_ci   (void) screen;
2576bf215546Sopenharmony_ci   (void) channel;
2577bf215546Sopenharmony_ci   (void) synctype;
2578bf215546Sopenharmony_ci   return 0;
2579bf215546Sopenharmony_ci}
2580bf215546Sopenharmony_ci
2581bf215546Sopenharmony_ci
2582bf215546Sopenharmony_ci
2583bf215546Sopenharmony_ci/*** GLX_SGIX_dmbuffer **/
2584bf215546Sopenharmony_ci
2585bf215546Sopenharmony_ci#if defined(_DM_BUFFER_H_)
2586bf215546Sopenharmony_ciPUBLIC Bool
2587bf215546Sopenharmony_ciglXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer,
2588bf215546Sopenharmony_ci                          DMparams *params, DMbuffer dmbuffer)
2589bf215546Sopenharmony_ci{
2590bf215546Sopenharmony_ci   (void) dpy;
2591bf215546Sopenharmony_ci   (void) pbuffer;
2592bf215546Sopenharmony_ci   (void) params;
2593bf215546Sopenharmony_ci   (void) dmbuffer;
2594bf215546Sopenharmony_ci   return False;
2595bf215546Sopenharmony_ci}
2596bf215546Sopenharmony_ci#endif
2597bf215546Sopenharmony_ci
2598bf215546Sopenharmony_ci
2599bf215546Sopenharmony_ci/*** GLX_SUN_get_transparent_index ***/
2600bf215546Sopenharmony_ci
2601bf215546Sopenharmony_ciPUBLIC Status
2602bf215546Sopenharmony_ciglXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay,
2603bf215546Sopenharmony_ci                          unsigned long *pTransparent)
2604bf215546Sopenharmony_ci{
2605bf215546Sopenharmony_ci   (void) dpy;
2606bf215546Sopenharmony_ci   (void) overlay;
2607bf215546Sopenharmony_ci   (void) underlay;
2608bf215546Sopenharmony_ci   (void) pTransparent;
2609bf215546Sopenharmony_ci   return 0;
2610bf215546Sopenharmony_ci}
2611bf215546Sopenharmony_ci
2612bf215546Sopenharmony_ci
2613bf215546Sopenharmony_ci
2614bf215546Sopenharmony_ci/*** GLX_MESA_release_buffers ***/
2615bf215546Sopenharmony_ci
2616bf215546Sopenharmony_ci/*
2617bf215546Sopenharmony_ci * Release the depth, stencil, accum buffers attached to a GLXDrawable
2618bf215546Sopenharmony_ci * (a window or pixmap) prior to destroying the GLXDrawable.
2619bf215546Sopenharmony_ci */
2620bf215546Sopenharmony_ciPUBLIC Bool
2621bf215546Sopenharmony_ciglXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
2622bf215546Sopenharmony_ci{
2623bf215546Sopenharmony_ci   XMesaBuffer b = XMesaFindBuffer(dpy, d);
2624bf215546Sopenharmony_ci   if (b) {
2625bf215546Sopenharmony_ci      XMesaDestroyBuffer(b);
2626bf215546Sopenharmony_ci      return True;
2627bf215546Sopenharmony_ci   }
2628bf215546Sopenharmony_ci   return False;
2629bf215546Sopenharmony_ci}
2630bf215546Sopenharmony_ci
2631bf215546Sopenharmony_ci/*** GLX_EXT_texture_from_pixmap ***/
2632bf215546Sopenharmony_ci
2633bf215546Sopenharmony_ciPUBLIC void
2634bf215546Sopenharmony_ciglXBindTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer,
2635bf215546Sopenharmony_ci                        const int *attrib_list)
2636bf215546Sopenharmony_ci{
2637bf215546Sopenharmony_ci   XMesaBuffer b = XMesaFindBuffer(dpy, drawable);
2638bf215546Sopenharmony_ci   if (b)
2639bf215546Sopenharmony_ci      XMesaBindTexImage(dpy, b, buffer, attrib_list);
2640bf215546Sopenharmony_ci}
2641bf215546Sopenharmony_ci
2642bf215546Sopenharmony_ciPUBLIC void
2643bf215546Sopenharmony_ciglXReleaseTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer)
2644bf215546Sopenharmony_ci{
2645bf215546Sopenharmony_ci   XMesaBuffer b = XMesaFindBuffer(dpy, drawable);
2646bf215546Sopenharmony_ci   if (b)
2647bf215546Sopenharmony_ci      XMesaReleaseTexImage(dpy, b, buffer);
2648bf215546Sopenharmony_ci}
2649bf215546Sopenharmony_ci
2650bf215546Sopenharmony_ci
2651bf215546Sopenharmony_ci
2652bf215546Sopenharmony_ci/*** GLX_ARB_create_context ***/
2653bf215546Sopenharmony_ci
2654bf215546Sopenharmony_ci
2655bf215546Sopenharmony_ciGLXContext
2656bf215546Sopenharmony_ciglXCreateContextAttribsARB(Display *dpy, GLXFBConfig config,
2657bf215546Sopenharmony_ci                           GLXContext shareCtx, Bool direct,
2658bf215546Sopenharmony_ci                           const int *attrib_list)
2659bf215546Sopenharmony_ci{
2660bf215546Sopenharmony_ci   XMesaVisual xmvis = (XMesaVisual) config;
2661bf215546Sopenharmony_ci   int majorVersion = 1, minorVersion = 0;
2662bf215546Sopenharmony_ci   int contextFlags = 0x0;
2663bf215546Sopenharmony_ci   int profileMask = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
2664bf215546Sopenharmony_ci   int renderType = GLX_RGBA_TYPE;
2665bf215546Sopenharmony_ci   unsigned i;
2666bf215546Sopenharmony_ci   Bool done = False;
2667bf215546Sopenharmony_ci   const int contextFlagsAll = (GLX_CONTEXT_DEBUG_BIT_ARB |
2668bf215546Sopenharmony_ci                                GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB);
2669bf215546Sopenharmony_ci   GLXContext ctx;
2670bf215546Sopenharmony_ci
2671bf215546Sopenharmony_ci   /* parse attrib_list */
2672bf215546Sopenharmony_ci   for (i = 0; !done && attrib_list && attrib_list[i]; i++) {
2673bf215546Sopenharmony_ci      switch (attrib_list[i]) {
2674bf215546Sopenharmony_ci      case GLX_CONTEXT_MAJOR_VERSION_ARB:
2675bf215546Sopenharmony_ci         majorVersion = attrib_list[++i];
2676bf215546Sopenharmony_ci         break;
2677bf215546Sopenharmony_ci      case GLX_CONTEXT_MINOR_VERSION_ARB:
2678bf215546Sopenharmony_ci         minorVersion = attrib_list[++i];
2679bf215546Sopenharmony_ci         break;
2680bf215546Sopenharmony_ci      case GLX_CONTEXT_FLAGS_ARB:
2681bf215546Sopenharmony_ci         contextFlags = attrib_list[++i];
2682bf215546Sopenharmony_ci         break;
2683bf215546Sopenharmony_ci      case GLX_CONTEXT_PROFILE_MASK_ARB:
2684bf215546Sopenharmony_ci         profileMask = attrib_list[++i];
2685bf215546Sopenharmony_ci         break;
2686bf215546Sopenharmony_ci      case GLX_RENDER_TYPE:
2687bf215546Sopenharmony_ci         renderType = attrib_list[++i];
2688bf215546Sopenharmony_ci         break;
2689bf215546Sopenharmony_ci      case 0:
2690bf215546Sopenharmony_ci         /* end of list */
2691bf215546Sopenharmony_ci         done = True;
2692bf215546Sopenharmony_ci         break;
2693bf215546Sopenharmony_ci      default:
2694bf215546Sopenharmony_ci         /* bad attribute */
2695bf215546Sopenharmony_ci         generate_error(dpy, BadValue, 0, X_GLXCreateContextAttribsARB, True);
2696bf215546Sopenharmony_ci         return NULL;
2697bf215546Sopenharmony_ci      }
2698bf215546Sopenharmony_ci   }
2699bf215546Sopenharmony_ci
2700bf215546Sopenharmony_ci   /* check contextFlags */
2701bf215546Sopenharmony_ci   if (contextFlags & ~contextFlagsAll) {
2702bf215546Sopenharmony_ci      generate_error(dpy, BadValue, 0, X_GLXCreateContextAttribsARB, True);
2703bf215546Sopenharmony_ci      return NULL;
2704bf215546Sopenharmony_ci   }
2705bf215546Sopenharmony_ci
2706bf215546Sopenharmony_ci   /* check profileMask */
2707bf215546Sopenharmony_ci   if (profileMask != GLX_CONTEXT_CORE_PROFILE_BIT_ARB &&
2708bf215546Sopenharmony_ci       profileMask != GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB &&
2709bf215546Sopenharmony_ci       profileMask != GLX_CONTEXT_ES_PROFILE_BIT_EXT) {
2710bf215546Sopenharmony_ci      generate_error(dpy, GLXBadProfileARB, 0, X_GLXCreateContextAttribsARB, False);
2711bf215546Sopenharmony_ci      return NULL;
2712bf215546Sopenharmony_ci   }
2713bf215546Sopenharmony_ci
2714bf215546Sopenharmony_ci   /* check renderType */
2715bf215546Sopenharmony_ci   if (renderType != GLX_RGBA_TYPE &&
2716bf215546Sopenharmony_ci       renderType != GLX_COLOR_INDEX_TYPE) {
2717bf215546Sopenharmony_ci      generate_error(dpy, BadValue, 0, X_GLXCreateContextAttribsARB, True);
2718bf215546Sopenharmony_ci      return NULL;
2719bf215546Sopenharmony_ci   }
2720bf215546Sopenharmony_ci
2721bf215546Sopenharmony_ci   /* check version */
2722bf215546Sopenharmony_ci   if (majorVersion <= 0 ||
2723bf215546Sopenharmony_ci       minorVersion < 0 ||
2724bf215546Sopenharmony_ci       (profileMask != GLX_CONTEXT_ES_PROFILE_BIT_EXT &&
2725bf215546Sopenharmony_ci        ((majorVersion == 1 && minorVersion > 5) ||
2726bf215546Sopenharmony_ci         (majorVersion == 2 && minorVersion > 1) ||
2727bf215546Sopenharmony_ci         (majorVersion == 3 && minorVersion > 3) ||
2728bf215546Sopenharmony_ci         (majorVersion == 4 && minorVersion > 5) ||
2729bf215546Sopenharmony_ci         majorVersion > 4))) {
2730bf215546Sopenharmony_ci      generate_error(dpy, BadMatch, 0, X_GLXCreateContextAttribsARB, True);
2731bf215546Sopenharmony_ci      return NULL;
2732bf215546Sopenharmony_ci   }
2733bf215546Sopenharmony_ci   if (profileMask == GLX_CONTEXT_ES_PROFILE_BIT_EXT &&
2734bf215546Sopenharmony_ci       ((majorVersion == 1 && minorVersion > 1) ||
2735bf215546Sopenharmony_ci        (majorVersion == 2 && minorVersion > 0) ||
2736bf215546Sopenharmony_ci        (majorVersion == 3 && minorVersion > 1) ||
2737bf215546Sopenharmony_ci        majorVersion > 3)) {
2738bf215546Sopenharmony_ci      /* GLX_EXT_create_context_es2_profile says nothing to justifying a
2739bf215546Sopenharmony_ci       * different error code for invalid ES versions, but this is what NVIDIA
2740bf215546Sopenharmony_ci       * does and piglit expects.
2741bf215546Sopenharmony_ci       */
2742bf215546Sopenharmony_ci      generate_error(dpy, GLXBadProfileARB, 0, X_GLXCreateContextAttribsARB, False);
2743bf215546Sopenharmony_ci      return NULL;
2744bf215546Sopenharmony_ci   }
2745bf215546Sopenharmony_ci
2746bf215546Sopenharmony_ci   if ((contextFlags & GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB) &&
2747bf215546Sopenharmony_ci       majorVersion < 3) {
2748bf215546Sopenharmony_ci      generate_error(dpy, BadMatch, 0, X_GLXCreateContextAttribsARB, True);
2749bf215546Sopenharmony_ci      return NULL;
2750bf215546Sopenharmony_ci   }
2751bf215546Sopenharmony_ci
2752bf215546Sopenharmony_ci   if (renderType == GLX_COLOR_INDEX_TYPE && majorVersion >= 3) {
2753bf215546Sopenharmony_ci      generate_error(dpy, BadMatch, 0, X_GLXCreateContextAttribsARB, True);
2754bf215546Sopenharmony_ci      return NULL;
2755bf215546Sopenharmony_ci   }
2756bf215546Sopenharmony_ci
2757bf215546Sopenharmony_ci   ctx = create_context(dpy, xmvis,
2758bf215546Sopenharmony_ci                        shareCtx ? shareCtx->xmesaContext : NULL,
2759bf215546Sopenharmony_ci                        direct,
2760bf215546Sopenharmony_ci                        majorVersion, minorVersion,
2761bf215546Sopenharmony_ci                        profileMask, contextFlags);
2762bf215546Sopenharmony_ci   if (!ctx) {
2763bf215546Sopenharmony_ci      generate_error(dpy, GLXBadFBConfig, 0, X_GLXCreateContextAttribsARB, False);
2764bf215546Sopenharmony_ci   }
2765bf215546Sopenharmony_ci
2766bf215546Sopenharmony_ci   return ctx;
2767bf215546Sopenharmony_ci}
2768