blob: 4fd6d758da912e62f0f1dbb47b540a5d85449b44 [file] [log] [blame]
jtgafb833d1999-08-19 00:55:39 +00001/*
2 * Mesa 3-D graphics library
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00003 *
Brian Paul49e80bf2009-02-03 10:12:51 -07004 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00006 *
jtgafb833d1999-08-19 00:55:39 +00007 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000013 *
jtgafb833d1999-08-19 00:55:39 +000014 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000016 *
jtgafb833d1999-08-19 00:55:39 +000017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
Kenneth Graunke3d8d5b22013-04-21 13:46:48 -070020 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
jtgafb833d1999-08-19 00:55:39 +000024 */
25
26
jtgafb833d1999-08-19 00:55:39 +000027/*
Brian Paul36cfa381999-11-28 20:15:04 +000028 * This is an emulation of the GLX API which allows Mesa/GLX-based programs
29 * to run on X servers which do not have the real GLX extension.
jtgafb833d1999-08-19 00:55:39 +000030 *
31 * Thanks to the contributors:
32 *
Brian Paulddf69f22000-08-02 20:35:09 +000033 * Initial version: Philip Brown (phil@bolthole.com)
jtgafb833d1999-08-19 00:55:39 +000034 * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu)
35 * Further visual-handling refinements: Wolfram Gloger
36 * (wmglo@Dent.MED.Uni-Muenchen.DE).
37 *
38 * Notes:
39 * Don't be fooled, stereo isn't supported yet.
40 */
41
42
Brian Paul279c5962015-03-07 13:15:22 -070043#include <string.h>
Brian Paul80524542015-03-04 19:17:57 -070044#include <stdio.h>
Brian Paulfbd8f211999-11-11 01:22:25 +000045#include "glxheader.h"
Brian Paul426cb9f1999-11-28 20:08:02 +000046#include "glxapi.h"
Brian Paul374e7fd2008-09-18 13:46:47 -060047#include "main/context.h"
48#include "main/config.h"
49#include "main/macros.h"
50#include "main/imports.h"
51#include "main/mtypes.h"
52#include "main/version.h"
Brian Paul71dea342000-04-19 01:44:01 +000053#include "xfonts.h"
jtgafb833d1999-08-19 00:55:39 +000054#include "xmesaP.h"
55
Brian Paul78fc78e1999-11-22 22:17:06 +000056/* This indicates the client-side GLX API and GLX encoder version. */
57#define CLIENT_MAJOR_VERSION 1
Brian Paula5738032001-09-23 16:10:02 +000058#define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
Brian Paul78fc78e1999-11-22 22:17:06 +000059
60/* This indicates the server-side GLX decoder version.
Brian Paulba57e522001-09-14 02:43:03 +000061 * GLX 1.4 indicates OpenGL 1.3 support
Brian Paul78fc78e1999-11-22 22:17:06 +000062 */
63#define SERVER_MAJOR_VERSION 1
Brian Paulba57e522001-09-14 02:43:03 +000064#define SERVER_MINOR_VERSION 4
Brian Paul78fc78e1999-11-22 22:17:06 +000065
66/* This is appended onto the glXGetClient/ServerString version strings. */
Matt Turner439c3d42013-03-09 00:25:45 -080067#define MESA_GLX_VERSION "Mesa " PACKAGE_VERSION
Brian Paul78fc78e1999-11-22 22:17:06 +000068
69/* Who implemented this GLX? */
70#define VENDOR "Brian Paul"
71
Brian Paule4656002002-10-05 18:27:41 +000072#define EXTENSIONS \
73 "GLX_MESA_set_3dfx_mode " \
74 "GLX_MESA_copy_sub_buffer " \
75 "GLX_MESA_pixmap_colormap " \
76 "GLX_MESA_release_buffers " \
77 "GLX_ARB_get_proc_address " \
Brianfd545642007-05-19 08:27:35 -060078 "GLX_EXT_texture_from_pixmap " \
Brian Paule4656002002-10-05 18:27:41 +000079 "GLX_EXT_visual_info " \
80 "GLX_EXT_visual_rating " \
Brian Paulee061062006-06-13 23:06:25 +000081 /*"GLX_SGI_video_sync "*/ \
Brian Paule4656002002-10-05 18:27:41 +000082 "GLX_SGIX_fbconfig " \
Brian Paul6d6efd62003-03-24 23:41:10 +000083 "GLX_SGIX_pbuffer "
Brian Paul43c9c2c1999-09-16 15:52:51 +000084
Brian Paul7cf50e12001-05-24 19:06:21 +000085
86
87/**********************************************************************/
88/*** GLX Visual Code ***/
89/**********************************************************************/
Brian Paul43c9c2c1999-09-16 15:52:51 +000090
jtgafb833d1999-08-19 00:55:39 +000091#define DONT_CARE -1
92
93
Alan Hourihane64034c42005-05-13 11:56:13 +000094static XMesaVisual *VisualTable = NULL;
jtgafb833d1999-08-19 00:55:39 +000095static int NumVisuals = 0;
96
97
jtgafb833d1999-08-19 00:55:39 +000098/*
99 * This struct and some code fragments borrowed
100 * from Mark Kilgard's GLUT library.
101 */
102typedef struct _OverlayInfo {
103 /* Avoid 64-bit portability problems by being careful to use
104 longs due to the way XGetWindowProperty is specified. Note
105 that these parameters are passed as CARD32s over X
106 protocol. */
107 unsigned long overlay_visual;
108 long transparent_type;
109 long value;
110 long layer;
111} OverlayInfo;
112
113
114
115/* Macro to handle c_class vs class field name in XVisualInfo struct */
116#if defined(__cplusplus) || defined(c_plusplus)
117#define CLASS c_class
118#else
119#define CLASS class
120#endif
121
122
123
jtgafb833d1999-08-19 00:55:39 +0000124/*
125 * Test if the given XVisualInfo is usable for Mesa rendering.
126 */
Brian Paul7287bbf2004-09-23 17:30:54 +0000127static GLboolean
128is_usable_visual( XVisualInfo *vinfo )
jtgafb833d1999-08-19 00:55:39 +0000129{
130 switch (vinfo->CLASS) {
131 case StaticGray:
132 case GrayScale:
133 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
134 return GL_TRUE;
135 case StaticColor:
136 case PseudoColor:
Ian Romanick81fe9942010-02-24 17:44:28 -0800137 /* Color-index rendering is not supported. */
138 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000139 case TrueColor:
140 case DirectColor:
141 /* Any depth of TrueColor or DirectColor works in RGB mode */
142 return GL_TRUE;
143 default:
144 /* This should never happen */
145 return GL_FALSE;
146 }
147}
148
149
150
Brian Paul1d97c272004-11-27 16:49:52 +0000151/**
152 * Get an array OverlayInfo records for specified screen.
153 * \param dpy the display
154 * \param screen screen number
155 * \param numOverlays returns numver of OverlayInfo records
156 * \return pointer to OverlayInfo array, free with XFree()
157 */
158static OverlayInfo *
159GetOverlayInfo(Display *dpy, int screen, int *numOverlays)
160{
161 Atom overlayVisualsAtom;
162 Atom actualType;
163 Status status;
164 unsigned char *ovInfo;
165 unsigned long sizeData, bytesLeft;
166 int actualFormat;
167
168 /*
169 * The SERVER_OVERLAY_VISUALS property on the root window contains
170 * a list of overlay visuals. Get that list now.
171 */
172 overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True);
173 if (overlayVisualsAtom == None) {
174 return 0;
175 }
176
177 status = XGetWindowProperty(dpy, RootWindow(dpy, screen),
178 overlayVisualsAtom, 0L, (long) 10000, False,
179 overlayVisualsAtom, &actualType, &actualFormat,
180 &sizeData, &bytesLeft,
181 &ovInfo);
182
183 if (status != Success || actualType != overlayVisualsAtom ||
184 actualFormat != 32 || sizeData < 4) {
185 /* something went wrong */
Matt Turner7c7b7b02012-09-04 22:52:36 -0700186 free((void *) ovInfo);
Brian Paul1d97c272004-11-27 16:49:52 +0000187 *numOverlays = 0;
188 return NULL;
189 }
190
191 *numOverlays = sizeData / 4;
192 return (OverlayInfo *) ovInfo;
193}
194
195
196
197/**
jtgafb833d1999-08-19 00:55:39 +0000198 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
199 * Input: dpy - the X display
200 * vinfo - the XVisualInfo to test
201 * Return: level of the visual:
202 * 0 = normal planes
203 * >0 = overlay planes
204 * <0 = underlay planes
205 */
Brian Paul7287bbf2004-09-23 17:30:54 +0000206static int
207level_of_visual( Display *dpy, XVisualInfo *vinfo )
jtgafb833d1999-08-19 00:55:39 +0000208{
Brian Paul1d97c272004-11-27 16:49:52 +0000209 OverlayInfo *overlay_info;
210 int numOverlaysPerScreen, i;
jtgafb833d1999-08-19 00:55:39 +0000211
Brian Paul1d97c272004-11-27 16:49:52 +0000212 overlay_info = GetOverlayInfo(dpy, vinfo->screen, &numOverlaysPerScreen);
213 if (!overlay_info) {
jtgafb833d1999-08-19 00:55:39 +0000214 return 0;
215 }
216
217 /* search the overlay visual list for the visual ID of interest */
Brian Paul1d97c272004-11-27 16:49:52 +0000218 for (i = 0; i < numOverlaysPerScreen; i++) {
219 const OverlayInfo *ov = overlay_info + i;
220 if (ov->overlay_visual == vinfo->visualid) {
jtgafb833d1999-08-19 00:55:39 +0000221 /* found the visual */
222 if (/*ov->transparent_type==1 &&*/ ov->layer!=0) {
223 int level = ov->layer;
Matt Turner7c7b7b02012-09-04 22:52:36 -0700224 free((void *) overlay_info);
jtgafb833d1999-08-19 00:55:39 +0000225 return level;
226 }
227 else {
Matt Turner7c7b7b02012-09-04 22:52:36 -0700228 free((void *) overlay_info);
jtgafb833d1999-08-19 00:55:39 +0000229 return 0;
230 }
231 }
232 }
233
234 /* The visual ID was not found in the overlay list. */
Matt Turner7c7b7b02012-09-04 22:52:36 -0700235 free((void *) overlay_info);
jtgafb833d1999-08-19 00:55:39 +0000236 return 0;
237}
238
239
240
241
242/*
243 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
244 * configuration in our list of GLX visuals.
245 */
246static XMesaVisual
247save_glx_visual( Display *dpy, XVisualInfo *vinfo,
Ian Romanick81fe9942010-02-24 17:44:28 -0800248 GLboolean alphaFlag, GLboolean dbFlag,
jtgafb833d1999-08-19 00:55:39 +0000249 GLboolean stereoFlag,
250 GLint depth_size, GLint stencil_size,
Brian Paulb2e46002000-03-31 01:07:13 +0000251 GLint accumRedSize, GLint accumGreenSize,
252 GLint accumBlueSize, GLint accumAlphaSize,
Brian Paul894844a2004-03-21 17:05:03 +0000253 GLint level, GLint numAuxBuffers )
jtgafb833d1999-08-19 00:55:39 +0000254{
255 GLboolean ximageFlag = GL_TRUE;
256 XMesaVisual xmvis;
257 GLint i;
258 GLboolean comparePointers;
259
260 if (dbFlag) {
261 /* Check if the MESA_BACK_BUFFER env var is set */
Matt Turner5980fc32014-09-21 22:53:04 -0700262 char *backbuffer = getenv("MESA_BACK_BUFFER");
jtgafb833d1999-08-19 00:55:39 +0000263 if (backbuffer) {
264 if (backbuffer[0]=='p' || backbuffer[0]=='P') {
265 ximageFlag = GL_FALSE;
266 }
267 else if (backbuffer[0]=='x' || backbuffer[0]=='X') {
268 ximageFlag = GL_TRUE;
269 }
270 else {
Brian Pauld09a1d82002-06-13 04:49:17 +0000271 _mesa_warning(NULL, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
jtgafb833d1999-08-19 00:55:39 +0000272 }
273 }
274 }
275
Brianda2f1e82007-07-23 16:51:57 -0600276 if (stereoFlag) {
277 /* stereo not supported */
278 return NULL;
279 }
280
jtgafb833d1999-08-19 00:55:39 +0000281 /* Comparing IDs uses less memory but sometimes fails. */
282 /* XXX revisit this after 3.0 is finished. */
Matt Turner5980fc32014-09-21 22:53:04 -0700283 if (getenv("MESA_GLX_VISUAL_HACK"))
jtgafb833d1999-08-19 00:55:39 +0000284 comparePointers = GL_TRUE;
285 else
286 comparePointers = GL_FALSE;
287
Brian Paula13331d2004-07-23 15:47:04 +0000288 /* Force the visual to have an alpha channel */
Matt Turner5980fc32014-09-21 22:53:04 -0700289 if (getenv("MESA_GLX_FORCE_ALPHA"))
Brian Paula13331d2004-07-23 15:47:04 +0000290 alphaFlag = GL_TRUE;
291
jtgafb833d1999-08-19 00:55:39 +0000292 /* First check if a matching visual is already in the list */
293 for (i=0; i<NumVisuals; i++) {
294 XMesaVisual v = VisualTable[i];
295 if (v->display == dpy
Ian Romanick304d3aa2004-02-19 00:57:04 +0000296 && v->mesa_visual.level == level
Brian Paul894844a2004-03-21 17:05:03 +0000297 && v->mesa_visual.numAuxBuffers == numAuxBuffers
jtgafb833d1999-08-19 00:55:39 +0000298 && v->ximage_flag == ximageFlag
Brian Paul1832f1c2001-04-27 21:18:25 +0000299 && v->mesa_visual.doubleBufferMode == dbFlag
300 && v->mesa_visual.stereoMode == stereoFlag
301 && (v->mesa_visual.alphaBits > 0) == alphaFlag
302 && (v->mesa_visual.depthBits >= depth_size || depth_size == 0)
303 && (v->mesa_visual.stencilBits >= stencil_size || stencil_size == 0)
304 && (v->mesa_visual.accumRedBits >= accumRedSize || accumRedSize == 0)
305 && (v->mesa_visual.accumGreenBits >= accumGreenSize || accumGreenSize == 0)
306 && (v->mesa_visual.accumBlueBits >= accumBlueSize || accumBlueSize == 0)
307 && (v->mesa_visual.accumAlphaBits >= accumAlphaSize || accumAlphaSize == 0)) {
jtgafb833d1999-08-19 00:55:39 +0000308 /* now either compare XVisualInfo pointers or visual IDs */
Brian Pauld0247f51999-11-18 15:17:01 +0000309 if ((!comparePointers && v->visinfo->visualid == vinfo->visualid)
jtgafb833d1999-08-19 00:55:39 +0000310 || (comparePointers && v->vishandle == vinfo)) {
311 return v;
312 }
313 }
314 }
315
316 /* Create a new visual and add it to the list. */
317
Ian Romanick81fe9942010-02-24 17:44:28 -0800318 xmvis = XMesaCreateVisual( dpy, vinfo, GL_TRUE, alphaFlag, dbFlag,
Brian Paulc8735e82000-04-05 22:09:58 +0000319 stereoFlag, ximageFlag,
320 depth_size, stencil_size,
321 accumRedSize, accumBlueSize,
322 accumBlueSize, accumAlphaSize, 0, level,
323 GLX_NONE_EXT );
jtgafb833d1999-08-19 00:55:39 +0000324 if (xmvis) {
Brian Paulf1046192002-11-10 17:07:06 +0000325 /* Save a copy of the pointer now so we can find this visual again
326 * if we need to search for it in find_glx_visual().
327 */
328 xmvis->vishandle = vinfo;
Alan Hourihane64034c42005-05-13 11:56:13 +0000329 /* Allocate more space for additional visual */
Matt Turner8af4aaf2014-09-21 21:24:01 -0700330 VisualTable = realloc(VisualTable, sizeof(XMesaVisual) * (NumVisuals + 1));
Brian Paulf1046192002-11-10 17:07:06 +0000331 /* add xmvis to the list */
jtgafb833d1999-08-19 00:55:39 +0000332 VisualTable[NumVisuals] = xmvis;
333 NumVisuals++;
Brian Paul7287bbf2004-09-23 17:30:54 +0000334 /* XXX minor hack, because XMesaCreateVisual doesn't support an
335 * aux buffers parameter.
336 */
Brian Paul894844a2004-03-21 17:05:03 +0000337 xmvis->mesa_visual.numAuxBuffers = numAuxBuffers;
jtgafb833d1999-08-19 00:55:39 +0000338 }
339 return xmvis;
340}
341
342
Brian Pauldfa5c2b2004-07-23 23:32:15 +0000343/**
344 * Return the default number of bits for the Z buffer.
345 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
346 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
347 * XXX probably do the same thing for stencil, accum, etc.
348 */
349static GLint
350default_depth_bits(void)
351{
352 int zBits;
Matt Turner5980fc32014-09-21 22:53:04 -0700353 const char *zEnv = getenv("MESA_GLX_DEPTH_BITS");
Brian Pauldfa5c2b2004-07-23 23:32:15 +0000354 if (zEnv)
Kenneth Graunke60b0cae2010-02-18 23:50:58 -0800355 zBits = atoi(zEnv);
Brian Pauldfa5c2b2004-07-23 23:32:15 +0000356 else
357 zBits = DEFAULT_SOFTWARE_DEPTH_BITS;
358 return zBits;
359}
360
Brian Paul978ef2b2005-09-21 03:35:08 +0000361static GLint
Brian Paulc12ee992005-11-04 16:41:06 +0000362default_alpha_bits(void)
363{
364 int aBits;
Matt Turner5980fc32014-09-21 22:53:04 -0700365 const char *aEnv = getenv("MESA_GLX_ALPHA_BITS");
Brian Paulc12ee992005-11-04 16:41:06 +0000366 if (aEnv)
Kenneth Graunke60b0cae2010-02-18 23:50:58 -0800367 aBits = atoi(aEnv);
Brian Paulc12ee992005-11-04 16:41:06 +0000368 else
369 aBits = 0;
370 return aBits;
371}
372
373static GLint
Brian Paul978ef2b2005-09-21 03:35:08 +0000374default_accum_bits(void)
375{
376 return 16;
377}
378
Brian Pauldfa5c2b2004-07-23 23:32:15 +0000379
jtgafb833d1999-08-19 00:55:39 +0000380
381/*
382 * Create a GLX visual from a regular XVisualInfo.
Brian Pauled30dfa2000-03-03 17:47:39 +0000383 * This is called when Fake GLX is given an XVisualInfo which wasn't
384 * returned by glXChooseVisual. Since this is the first time we're
385 * considering this visual we'll take a guess at reasonable values
386 * for depth buffer size, stencil size, accum size, etc.
387 * This is the best we can do with a client-side emulation of GLX.
jtgafb833d1999-08-19 00:55:39 +0000388 */
389static XMesaVisual
390create_glx_visual( Display *dpy, XVisualInfo *visinfo )
391{
392 int vislevel;
Brian Pauldfa5c2b2004-07-23 23:32:15 +0000393 GLint zBits = default_depth_bits();
Brian Paul978ef2b2005-09-21 03:35:08 +0000394 GLint accBits = default_accum_bits();
Brian Paulc12ee992005-11-04 16:41:06 +0000395 GLboolean alphaFlag = default_alpha_bits() > 0;
jtgafb833d1999-08-19 00:55:39 +0000396
397 vislevel = level_of_visual( dpy, visinfo );
398 if (vislevel) {
Ian Romanick81fe9942010-02-24 17:44:28 -0800399 /* Color-index rendering to overlays is not supported. */
400 return NULL;
jtgafb833d1999-08-19 00:55:39 +0000401 }
402 else if (is_usable_visual( visinfo )) {
Ian Romanick81fe9942010-02-24 17:44:28 -0800403 /* Configure this visual as RGB, double-buffered, depth-buffered. */
404 /* This is surely wrong for some people's needs but what else */
405 /* can be done? They should use glXChooseVisual(). */
406 return save_glx_visual( dpy, visinfo,
407 alphaFlag, /* alpha */
408 GL_TRUE, /* double */
409 GL_FALSE, /* stereo */
410 zBits,
Brian Paul074637b2012-02-21 08:01:05 -0700411 8, /* stencil bits */
Ian Romanick81fe9942010-02-24 17:44:28 -0800412 accBits, /* r */
413 accBits, /* g */
414 accBits, /* b */
415 accBits, /* a */
416 0, /* level */
417 0 /* numAux */
418 );
jtgafb833d1999-08-19 00:55:39 +0000419 }
420 else {
Brian Pauld09a1d82002-06-13 04:49:17 +0000421 _mesa_warning(NULL, "Mesa: error in glXCreateContext: bad visual\n");
jtgafb833d1999-08-19 00:55:39 +0000422 return NULL;
423 }
424}
425
426
427
428/*
429 * Find the GLX visual associated with an XVisualInfo.
430 */
431static XMesaVisual
432find_glx_visual( Display *dpy, XVisualInfo *vinfo )
433{
434 int i;
435
jtgafb833d1999-08-19 00:55:39 +0000436 /* try to match visual id */
437 for (i=0;i<NumVisuals;i++) {
438 if (VisualTable[i]->display==dpy
439 && VisualTable[i]->visinfo->visualid == vinfo->visualid) {
440 return VisualTable[i];
441 }
442 }
Brian Paulf1046192002-11-10 17:07:06 +0000443
444 /* if that fails, try to match pointers */
445 for (i=0;i<NumVisuals;i++) {
446 if (VisualTable[i]->display==dpy && VisualTable[i]->vishandle==vinfo) {
447 return VisualTable[i];
448 }
449 }
450
jtgafb833d1999-08-19 00:55:39 +0000451 return NULL;
452}
453
454
455
Brian Paul1d97c272004-11-27 16:49:52 +0000456/**
jtgafb833d1999-08-19 00:55:39 +0000457 * Return the transparent pixel value for a GLX visual.
458 * Input: glxvis - the glx_visual
459 * Return: a pixel value or -1 if no transparent pixel
460 */
Brian Paul7287bbf2004-09-23 17:30:54 +0000461static int
462transparent_pixel( XMesaVisual glxvis )
jtgafb833d1999-08-19 00:55:39 +0000463{
464 Display *dpy = glxvis->display;
465 XVisualInfo *vinfo = glxvis->visinfo;
Brian Paul1d97c272004-11-27 16:49:52 +0000466 OverlayInfo *overlay_info;
467 int numOverlaysPerScreen, i;
jtgafb833d1999-08-19 00:55:39 +0000468
Brian Paul1d97c272004-11-27 16:49:52 +0000469 overlay_info = GetOverlayInfo(dpy, vinfo->screen, &numOverlaysPerScreen);
470 if (!overlay_info) {
jtgafb833d1999-08-19 00:55:39 +0000471 return -1;
472 }
473
Brian Paul1d97c272004-11-27 16:49:52 +0000474 for (i = 0; i < numOverlaysPerScreen; i++) {
475 const OverlayInfo *ov = overlay_info + i;
476 if (ov->overlay_visual == vinfo->visualid) {
jtgafb833d1999-08-19 00:55:39 +0000477 /* found it! */
Brian Paul1d97c272004-11-27 16:49:52 +0000478 if (ov->transparent_type == 0) {
jtgafb833d1999-08-19 00:55:39 +0000479 /* type 0 indicates no transparency */
Matt Turner7c7b7b02012-09-04 22:52:36 -0700480 free((void *) overlay_info);
jtgafb833d1999-08-19 00:55:39 +0000481 return -1;
482 }
483 else {
484 /* ov->value is the transparent pixel */
Matt Turner7c7b7b02012-09-04 22:52:36 -0700485 free((void *) overlay_info);
jtgafb833d1999-08-19 00:55:39 +0000486 return ov->value;
487 }
488 }
489 }
490
491 /* The visual ID was not found in the overlay list. */
Matt Turner7c7b7b02012-09-04 22:52:36 -0700492 free((void *) overlay_info);
jtgafb833d1999-08-19 00:55:39 +0000493 return -1;
494}
495
496
497
Brian Paul1d97c272004-11-27 16:49:52 +0000498/**
jtgafb833d1999-08-19 00:55:39 +0000499 * Try to get an X visual which matches the given arguments.
500 */
Brian Paul7287bbf2004-09-23 17:30:54 +0000501static XVisualInfo *
502get_visual( Display *dpy, int scr, unsigned int depth, int xclass )
jtgafb833d1999-08-19 00:55:39 +0000503{
504 XVisualInfo temp, *vis;
505 long mask;
506 int n;
507 unsigned int default_depth;
508 int default_class;
509
510 mask = VisualScreenMask | VisualDepthMask | VisualClassMask;
511 temp.screen = scr;
512 temp.depth = depth;
513 temp.CLASS = xclass;
514
515 default_depth = DefaultDepth(dpy,scr);
516 default_class = DefaultVisual(dpy,scr)->CLASS;
517
518 if (depth==default_depth && xclass==default_class) {
519 /* try to get root window's visual */
520 temp.visualid = DefaultVisual(dpy,scr)->visualid;
521 mask |= VisualIDMask;
522 }
523
524 vis = XGetVisualInfo( dpy, mask, &temp, &n );
525
526 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
527 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
528 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
529 */
530 if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) {
Brian Paul71dea342000-04-19 01:44:01 +0000531 if (_mesa_bitcount((GLuint) vis->red_mask ) <= 8 &&
532 _mesa_bitcount((GLuint) vis->green_mask) <= 8 &&
533 _mesa_bitcount((GLuint) vis->blue_mask ) <= 8) {
jtgafb833d1999-08-19 00:55:39 +0000534 return vis;
535 }
536 else {
Matt Turner7c7b7b02012-09-04 22:52:36 -0700537 free((void *) vis);
jtgafb833d1999-08-19 00:55:39 +0000538 return NULL;
539 }
540 }
541
542 return vis;
543}
544
545
546
547/*
548 * Retrieve the value of the given environment variable and find
549 * the X visual which matches it.
550 * Input: dpy - the display
551 * screen - the screen number
552 * varname - the name of the environment variable
553 * Return: an XVisualInfo pointer to NULL if error.
554 */
Brian Paul7287bbf2004-09-23 17:30:54 +0000555static XVisualInfo *
556get_env_visual(Display *dpy, int scr, const char *varname)
jtgafb833d1999-08-19 00:55:39 +0000557{
558 char value[100], type[100];
559 int depth, xclass = -1;
560 XVisualInfo *vis;
561
Matt Turner5980fc32014-09-21 22:53:04 -0700562 if (!getenv( varname )) {
jtgafb833d1999-08-19 00:55:39 +0000563 return NULL;
564 }
565
Matt Turner5980fc32014-09-21 22:53:04 -0700566 strncpy( value, getenv(varname), 100 );
jtgafb833d1999-08-19 00:55:39 +0000567 value[99] = 0;
568
569 sscanf( value, "%s %d", type, &depth );
570
Kenneth Graunke8d73aa62010-02-18 23:50:56 -0800571 if (strcmp(type,"TrueColor")==0) xclass = TrueColor;
572 else if (strcmp(type,"DirectColor")==0) xclass = DirectColor;
Kenneth Graunke8d73aa62010-02-18 23:50:56 -0800573 else if (strcmp(type,"GrayScale")==0) xclass = GrayScale;
574 else if (strcmp(type,"StaticGray")==0) xclass = StaticGray;
jtgafb833d1999-08-19 00:55:39 +0000575
576 if (xclass>-1 && depth>0) {
577 vis = get_visual( dpy, scr, depth, xclass );
578 if (vis) {
579 return vis;
580 }
581 }
582
Brian Paul2ad59212002-10-30 20:24:45 +0000583 _mesa_warning(NULL, "GLX unable to find visual class=%s, depth=%d.",
584 type, depth);
Brian Pauld09a1d82002-06-13 04:49:17 +0000585
jtgafb833d1999-08-19 00:55:39 +0000586 return NULL;
587}
588
589
590
591/*
592 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
593 * Input: dpy, screen - X display and screen number
jtgafb833d1999-08-19 00:55:39 +0000594 * min_depth - minimum visual depth
595 * preferred_class - preferred GLX visual class or DONT_CARE
596 * Return: pointer to an XVisualInfo or NULL.
597 */
Brian Paul7287bbf2004-09-23 17:30:54 +0000598static XVisualInfo *
Ian Romanick81fe9942010-02-24 17:44:28 -0800599choose_x_visual(Display *dpy, int screen, int min_depth, int preferred_class)
jtgafb833d1999-08-19 00:55:39 +0000600{
601 XVisualInfo *vis;
Brian Pauldb6aa582000-11-10 17:23:02 +0000602 int xclass, visclass = 0;
jtgafb833d1999-08-19 00:55:39 +0000603 int depth;
604
Ian Romanick81fe9942010-02-24 17:44:28 -0800605 /* First see if the MESA_RGB_VISUAL env var is defined */
606 vis = get_env_visual( dpy, screen, "MESA_RGB_VISUAL" );
607 if (vis) {
608 return vis;
609 }
610 /* Otherwise, search for a suitable visual */
611 if (preferred_class==DONT_CARE) {
612 for (xclass=0;xclass<4;xclass++) {
613 switch (xclass) {
614 case 0: visclass = TrueColor; break;
615 case 1: visclass = DirectColor; break;
616 case 2: visclass = GrayScale; break;
617 case 3: visclass = StaticGray; break;
618 }
619 if (min_depth==0) {
620 /* start with shallowest */
621 for (depth=0;depth<=32;depth++) {
622 vis = get_visual( dpy, screen, depth, visclass );
623 if (vis) {
624 return vis;
625 }
626 }
627 }
628 else {
629 /* start with deepest */
630 for (depth=32;depth>=min_depth;depth--) {
631 vis = get_visual( dpy, screen, depth, visclass );
632 if (vis) {
633 return vis;
634 }
635 }
636 }
jtgafb833d1999-08-19 00:55:39 +0000637 }
638 }
639 else {
Ian Romanick81fe9942010-02-24 17:44:28 -0800640 /* search for a specific visual class */
641 switch (preferred_class) {
642 case GLX_TRUE_COLOR_EXT: visclass = TrueColor; break;
643 case GLX_DIRECT_COLOR_EXT: visclass = DirectColor; break;
644 case GLX_GRAY_SCALE_EXT: visclass = GrayScale; break;
645 case GLX_STATIC_GRAY_EXT: visclass = StaticGray; break;
646 case GLX_PSEUDO_COLOR_EXT:
647 case GLX_STATIC_COLOR_EXT:
648 default: return NULL;
jtgafb833d1999-08-19 00:55:39 +0000649 }
Ian Romanick81fe9942010-02-24 17:44:28 -0800650 if (min_depth==0) {
651 /* start with shallowest */
652 for (depth=0;depth<=32;depth++) {
653 vis = get_visual( dpy, screen, depth, visclass );
654 if (vis) {
655 return vis;
656 }
657 }
jtgafb833d1999-08-19 00:55:39 +0000658 }
659 else {
Ian Romanick81fe9942010-02-24 17:44:28 -0800660 /* start with deepest */
661 for (depth=32;depth>=min_depth;depth--) {
662 vis = get_visual( dpy, screen, depth, visclass );
663 if (vis) {
664 return vis;
665 }
666 }
jtgafb833d1999-08-19 00:55:39 +0000667 }
668 }
669
670 /* didn't find a visual */
671 return NULL;
672}
673
674
675
676/*
677 * Find the deepest X over/underlay visual of at least min_depth.
678 * Input: dpy, screen - X display and screen number
679 * level - the over/underlay level
680 * trans_type - transparent pixel type: GLX_NONE_EXT,
681 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
682 * or DONT_CARE
683 * trans_value - transparent pixel value or DONT_CARE
684 * min_depth - minimum visual depth
685 * preferred_class - preferred GLX visual class or DONT_CARE
686 * Return: pointer to an XVisualInfo or NULL.
687 */
Brian Paul7287bbf2004-09-23 17:30:54 +0000688static XVisualInfo *
Ian Romanick81fe9942010-02-24 17:44:28 -0800689choose_x_overlay_visual( Display *dpy, int scr,
Brian Paul7287bbf2004-09-23 17:30:54 +0000690 int level, int trans_type, int trans_value,
691 int min_depth, int preferred_class )
jtgafb833d1999-08-19 00:55:39 +0000692{
jtgafb833d1999-08-19 00:55:39 +0000693 OverlayInfo *overlay_info;
694 int numOverlaysPerScreen;
jtgafb833d1999-08-19 00:55:39 +0000695 int i;
696 XVisualInfo *deepvis;
697 int deepest;
698
699 /*DEBUG int tt, tv; */
700
701 switch (preferred_class) {
702 case GLX_TRUE_COLOR_EXT: preferred_class = TrueColor; break;
703 case GLX_DIRECT_COLOR_EXT: preferred_class = DirectColor; break;
704 case GLX_PSEUDO_COLOR_EXT: preferred_class = PseudoColor; break;
705 case GLX_STATIC_COLOR_EXT: preferred_class = StaticColor; break;
706 case GLX_GRAY_SCALE_EXT: preferred_class = GrayScale; break;
707 case GLX_STATIC_GRAY_EXT: preferred_class = StaticGray; break;
708 default: preferred_class = DONT_CARE;
709 }
710
Brian Paul1d97c272004-11-27 16:49:52 +0000711 overlay_info = GetOverlayInfo(dpy, scr, &numOverlaysPerScreen);
712 if (!overlay_info) {
jtgafb833d1999-08-19 00:55:39 +0000713 return NULL;
714 }
715
716 /* Search for the deepest overlay which satisifies all criteria. */
717 deepest = min_depth;
718 deepvis = NULL;
719
Brian Paul1d97c272004-11-27 16:49:52 +0000720 for (i = 0; i < numOverlaysPerScreen; i++) {
721 const OverlayInfo *ov = overlay_info + i;
jtgafb833d1999-08-19 00:55:39 +0000722 XVisualInfo *vislist, vistemplate;
723 int count;
jtgafb833d1999-08-19 00:55:39 +0000724
725 if (ov->layer!=level) {
726 /* failed overlay level criteria */
727 continue;
728 }
729 if (!(trans_type==DONT_CARE
730 || (trans_type==GLX_TRANSPARENT_INDEX_EXT
731 && ov->transparent_type>0)
732 || (trans_type==GLX_NONE_EXT && ov->transparent_type==0))) {
733 /* failed transparent pixel type criteria */
734 continue;
735 }
736 if (trans_value!=DONT_CARE && trans_value!=ov->value) {
737 /* failed transparent pixel value criteria */
738 continue;
739 }
740
741 /* get XVisualInfo and check the depth */
742 vistemplate.visualid = ov->overlay_visual;
743 vistemplate.screen = scr;
744 vislist = XGetVisualInfo( dpy, VisualIDMask | VisualScreenMask,
745 &vistemplate, &count );
746
747 if (count!=1) {
748 /* something went wrong */
749 continue;
750 }
751 if (preferred_class!=DONT_CARE && preferred_class!=vislist->CLASS) {
752 /* wrong visual class */
753 continue;
754 }
755
Ian Romanick81fe9942010-02-24 17:44:28 -0800756 /* Color-index rendering is not supported. Make sure we have True/DirectColor */
757 if (vislist->CLASS != TrueColor && vislist->CLASS != DirectColor)
Brian Paul42f252f1999-10-14 18:47:37 +0000758 continue;
759
jtgafb833d1999-08-19 00:55:39 +0000760 if (deepvis==NULL || vislist->depth > deepest) {
761 /* YES! found a satisfactory visual */
Matt Turner50675062012-09-03 20:24:35 -0700762 free(deepvis);
jtgafb833d1999-08-19 00:55:39 +0000763 deepest = vislist->depth;
764 deepvis = vislist;
765 /* DEBUG tt = ov->transparent_type;*/
766 /* DEBUG tv = ov->value; */
767 }
768 }
769
770/*DEBUG
771 if (deepvis) {
772 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
773 deepvis->visualid, level, deepvis->depth, tt, tv );
774 }
775*/
776 return deepvis;
777}
778
779
Brian Paul7cf50e12001-05-24 19:06:21 +0000780/**********************************************************************/
Brian Paul6c06ce22006-08-30 21:17:51 +0000781/*** Display-related functions ***/
782/**********************************************************************/
783
784
785/**
786 * Free all XMesaVisuals which are associated with the given display.
787 */
788static void
789destroy_visuals_on_display(Display *dpy)
790{
791 int i;
792 for (i = 0; i < NumVisuals; i++) {
793 if (VisualTable[i]->display == dpy) {
794 /* remove this visual */
795 int j;
796 free(VisualTable[i]);
797 for (j = i; j < NumVisuals - 1; j++)
798 VisualTable[j] = VisualTable[j + 1];
799 NumVisuals--;
800 }
801 }
802}
803
804
805/**
806 * Called from XCloseDisplay() to let us free our display-related data.
807 */
808static int
809close_display_callback(Display *dpy, XExtCodes *codes)
810{
811 destroy_visuals_on_display(dpy);
812 xmesa_destroy_buffers_on_display(dpy);
813 return 0;
814}
815
816
817/**
818 * Look for the named extension on given display and return a pointer
819 * to the _XExtension data, or NULL if extension not found.
820 */
821static _XExtension *
822lookup_extension(Display *dpy, const char *extName)
823{
824 _XExtension *ext;
825 for (ext = dpy->ext_procs; ext; ext = ext->next) {
Brian Paul52e36cd2006-08-31 13:58:08 +0000826 if (ext->name && strcmp(ext->name, extName) == 0) {
Brian Paul6c06ce22006-08-30 21:17:51 +0000827 return ext;
828 }
829 }
830 return NULL;
831}
832
833
834/**
835 * Whenever we're given a new Display pointer, call this function to
836 * register our close_display_callback function.
837 */
838static void
839register_with_display(Display *dpy)
840{
841 const char *extName = "MesaGLX";
842 _XExtension *ext;
843
844 ext = lookup_extension(dpy, extName);
845 if (!ext) {
846 XExtCodes *c = XAddExtension(dpy);
847 ext = dpy->ext_procs; /* new extension is at head of list */
848 assert(c->extension == ext->codes.extension);
Brian Paulda580db2010-10-25 09:17:09 -0600849 (void) c; /* silence warning */
Brian Paul279c5962015-03-07 13:15:22 -0700850 ext->name = strdup(extName);
Brian Paul6c06ce22006-08-30 21:17:51 +0000851 ext->close_display = close_display_callback;
852 }
853}
854
855
856/**********************************************************************/
Brian Paul7cf50e12001-05-24 19:06:21 +0000857/*** Begin Fake GLX API Functions ***/
858/**********************************************************************/
859
jtgafb833d1999-08-19 00:55:39 +0000860
Brian Paulba0fe182005-02-23 16:54:18 +0000861/**
862 * Helper used by glXChooseVisual and glXChooseFBConfig.
863 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
864 * the later.
865 * In either case, the attribute list is terminated with the value 'None'.
866 */
Brian Paul7287bbf2004-09-23 17:30:54 +0000867static XMesaVisual
Brian Paul1f98ee92005-01-06 21:56:16 +0000868choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig )
jtgafb833d1999-08-19 00:55:39 +0000869{
Brian Paul1f98ee92005-01-06 21:56:16 +0000870 const GLboolean rgbModeDefault = fbConfig;
Brian Paul3265fe52002-10-05 03:02:34 +0000871 const int *parselist;
jtgafb833d1999-08-19 00:55:39 +0000872 XVisualInfo *vis;
873 int min_ci = 0;
874 int min_red=0, min_green=0, min_blue=0;
Brian Paulb3063ac2004-02-04 23:39:19 +0000875 GLboolean rgb_flag = rgbModeDefault;
jtgafb833d1999-08-19 00:55:39 +0000876 GLboolean alpha_flag = GL_FALSE;
877 GLboolean double_flag = GL_FALSE;
878 GLboolean stereo_flag = GL_FALSE;
879 GLint depth_size = 0;
880 GLint stencil_size = 0;
Brian Paulb2e46002000-03-31 01:07:13 +0000881 GLint accumRedSize = 0;
882 GLint accumGreenSize = 0;
883 GLint accumBlueSize = 0;
884 GLint accumAlphaSize = 0;
jtgafb833d1999-08-19 00:55:39 +0000885 int level = 0;
886 int visual_type = DONT_CARE;
887 int trans_type = DONT_CARE;
888 int trans_value = DONT_CARE;
Brian Paule1210b12000-03-31 01:17:52 +0000889 GLint caveat = DONT_CARE;
Brian Paul3265fe52002-10-05 03:02:34 +0000890 XMesaVisual xmvis = NULL;
Brian Paul3a996742004-02-02 15:40:21 +0000891 int desiredVisualID = -1;
Brian Paul894844a2004-03-21 17:05:03 +0000892 int numAux = 0;
jtgafb833d1999-08-19 00:55:39 +0000893
894 parselist = list;
895
896 while (*parselist) {
897
Brian Paul46bad052013-01-03 17:31:22 -0700898 if (fbConfig &&
899 parselist[1] == GLX_DONT_CARE &&
900 parselist[0] != GLX_LEVEL) {
901 /* For glXChooseFBConfig(), skip attributes whose value is
902 * GLX_DONT_CARE (-1), unless it's GLX_LEVEL (which can legitimately be
903 * a negative value).
904 *
905 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
906 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
907 */
908 parselist += 2;
909 continue;
910 }
911
jtgafb833d1999-08-19 00:55:39 +0000912 switch (*parselist) {
913 case GLX_USE_GL:
Brian Paul1f98ee92005-01-06 21:56:16 +0000914 if (fbConfig) {
915 /* invalid token */
916 return NULL;
917 }
918 else {
919 /* skip */
920 parselist++;
921 }
jtgafb833d1999-08-19 00:55:39 +0000922 break;
923 case GLX_BUFFER_SIZE:
924 parselist++;
925 min_ci = *parselist++;
926 break;
927 case GLX_LEVEL:
928 parselist++;
929 level = *parselist++;
930 break;
931 case GLX_RGBA:
Brian Paul1f98ee92005-01-06 21:56:16 +0000932 if (fbConfig) {
933 /* invalid token */
934 return NULL;
935 }
936 else {
937 rgb_flag = GL_TRUE;
938 parselist++;
939 }
jtgafb833d1999-08-19 00:55:39 +0000940 break;
941 case GLX_DOUBLEBUFFER:
Brian Paul1f98ee92005-01-06 21:56:16 +0000942 parselist++;
943 if (fbConfig) {
944 double_flag = *parselist++;
945 }
946 else {
947 double_flag = GL_TRUE;
948 }
jtgafb833d1999-08-19 00:55:39 +0000949 break;
950 case GLX_STEREO:
Brian Paul1f98ee92005-01-06 21:56:16 +0000951 parselist++;
952 if (fbConfig) {
953 stereo_flag = *parselist++;
954 }
955 else {
956 stereo_flag = GL_TRUE;
957 }
Brianda2f1e82007-07-23 16:51:57 -0600958 break;
jtgafb833d1999-08-19 00:55:39 +0000959 case GLX_AUX_BUFFERS:
jtgafb833d1999-08-19 00:55:39 +0000960 parselist++;
Brian Paul894844a2004-03-21 17:05:03 +0000961 numAux = *parselist++;
962 if (numAux > MAX_AUX_BUFFERS)
963 return NULL;
jtgafb833d1999-08-19 00:55:39 +0000964 break;
965 case GLX_RED_SIZE:
966 parselist++;
967 min_red = *parselist++;
968 break;
969 case GLX_GREEN_SIZE:
970 parselist++;
971 min_green = *parselist++;
972 break;
973 case GLX_BLUE_SIZE:
974 parselist++;
975 min_blue = *parselist++;
976 break;
977 case GLX_ALPHA_SIZE:
978 parselist++;
979 {
980 GLint size = *parselist++;
Brian Paulc12ee992005-11-04 16:41:06 +0000981 alpha_flag = size ? GL_TRUE : GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000982 }
983 break;
984 case GLX_DEPTH_SIZE:
985 parselist++;
986 depth_size = *parselist++;
987 break;
988 case GLX_STENCIL_SIZE:
989 parselist++;
990 stencil_size = *parselist++;
991 break;
992 case GLX_ACCUM_RED_SIZE:
Brian Paulb2e46002000-03-31 01:07:13 +0000993 parselist++;
994 {
995 GLint size = *parselist++;
996 accumRedSize = MAX2( accumRedSize, size );
997 }
998 break;
jtgafb833d1999-08-19 00:55:39 +0000999 case GLX_ACCUM_GREEN_SIZE:
Brian Paulb2e46002000-03-31 01:07:13 +00001000 parselist++;
1001 {
1002 GLint size = *parselist++;
1003 accumGreenSize = MAX2( accumGreenSize, size );
1004 }
1005 break;
jtgafb833d1999-08-19 00:55:39 +00001006 case GLX_ACCUM_BLUE_SIZE:
Brian Paulb2e46002000-03-31 01:07:13 +00001007 parselist++;
1008 {
1009 GLint size = *parselist++;
1010 accumBlueSize = MAX2( accumBlueSize, size );
1011 }
1012 break;
jtgafb833d1999-08-19 00:55:39 +00001013 case GLX_ACCUM_ALPHA_SIZE:
1014 parselist++;
1015 {
1016 GLint size = *parselist++;
Brian Paulb2e46002000-03-31 01:07:13 +00001017 accumAlphaSize = MAX2( accumAlphaSize, size );
jtgafb833d1999-08-19 00:55:39 +00001018 }
1019 break;
1020
1021 /*
1022 * GLX_EXT_visual_info extension
1023 */
1024 case GLX_X_VISUAL_TYPE_EXT:
1025 parselist++;
1026 visual_type = *parselist++;
1027 break;
1028 case GLX_TRANSPARENT_TYPE_EXT:
1029 parselist++;
1030 trans_type = *parselist++;
1031 break;
1032 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1033 parselist++;
1034 trans_value = *parselist++;
1035 break;
1036 case GLX_TRANSPARENT_RED_VALUE_EXT:
1037 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1038 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1039 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1040 /* ignore */
1041 parselist++;
1042 parselist++;
1043 break;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001044
Brian Paule1210b12000-03-31 01:17:52 +00001045 /*
1046 * GLX_EXT_visual_info extension
1047 */
1048 case GLX_VISUAL_CAVEAT_EXT:
1049 parselist++;
1050 caveat = *parselist++; /* ignored for now */
1051 break;
1052
Brian Paul3265fe52002-10-05 03:02:34 +00001053 /*
Brian Paul66ab7272002-11-05 21:11:18 +00001054 * GLX_ARB_multisample
1055 */
1056 case GLX_SAMPLE_BUFFERS_ARB:
Brian Paul66ab7272002-11-05 21:11:18 +00001057 case GLX_SAMPLES_ARB:
Brian Paule903f512008-05-27 09:49:18 -06001058 parselist++;
1059 if (*parselist++ != 0)
1060 /* ms not supported */
1061 return NULL;
1062 break;
Brian Paul66ab7272002-11-05 21:11:18 +00001063
1064 /*
Brian Paul3265fe52002-10-05 03:02:34 +00001065 * FBConfig attribs.
1066 */
1067 case GLX_RENDER_TYPE:
Brian Pauldfb6c562005-08-22 14:28:19 +00001068 if (!fbConfig)
1069 return NULL;
Brian Paul3265fe52002-10-05 03:02:34 +00001070 parselist++;
Brian Paul584b0872009-10-02 07:51:15 -06001071 if (*parselist & GLX_RGBA_BIT) {
Brian Paul3265fe52002-10-05 03:02:34 +00001072 rgb_flag = GL_TRUE;
1073 }
Brian Paul584b0872009-10-02 07:51:15 -06001074 else if (*parselist & GLX_COLOR_INDEX_BIT) {
Brian Paul3265fe52002-10-05 03:02:34 +00001075 rgb_flag = GL_FALSE;
1076 }
Tomasz Lisb8126c72013-07-17 13:49:16 +02001077 else if (*parselist & (GLX_RGBA_FLOAT_BIT_ARB|GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT)) {
1078 rgb_flag = GL_TRUE;
1079 }
Brian Paul3265fe52002-10-05 03:02:34 +00001080 else if (*parselist == 0) {
1081 rgb_flag = GL_TRUE;
1082 }
1083 parselist++;
1084 break;
1085 case GLX_DRAWABLE_TYPE:
Brian Pauldfb6c562005-08-22 14:28:19 +00001086 if (!fbConfig)
1087 return NULL;
Brian Paul3265fe52002-10-05 03:02:34 +00001088 parselist++;
1089 if (*parselist & ~(GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT)) {
1090 return NULL; /* bad bit */
1091 }
1092 parselist++;
1093 break;
Brian Paul3a996742004-02-02 15:40:21 +00001094 case GLX_FBCONFIG_ID:
Brian Pauld60880d2011-07-11 08:00:59 -06001095 case GLX_VISUAL_ID:
Brian Pauldfb6c562005-08-22 14:28:19 +00001096 if (!fbConfig)
1097 return NULL;
Brian Paul3a996742004-02-02 15:40:21 +00001098 parselist++;
Brian Pauldfb6c562005-08-22 14:28:19 +00001099 desiredVisualID = *parselist++;
1100 break;
1101 case GLX_X_RENDERABLE:
Brian Pauld60880d2011-07-11 08:00:59 -06001102 case GLX_MAX_PBUFFER_WIDTH:
1103 case GLX_MAX_PBUFFER_HEIGHT:
1104 case GLX_MAX_PBUFFER_PIXELS:
Brian Pauldfb6c562005-08-22 14:28:19 +00001105 if (!fbConfig)
1106 return NULL;
1107 parselist += 2;
1108 /* ignore */
Brian Paul3a996742004-02-02 15:40:21 +00001109 break;
Brian Paul3265fe52002-10-05 03:02:34 +00001110
Brianfd545642007-05-19 08:27:35 -06001111#ifdef GLX_EXT_texture_from_pixmap
1112 case GLX_BIND_TO_TEXTURE_RGB_EXT:
1113 parselist++; /*skip*/
1114 break;
1115 case GLX_BIND_TO_TEXTURE_RGBA_EXT:
1116 parselist++; /*skip*/
1117 break;
1118 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
1119 parselist++; /*skip*/
1120 break;
1121 case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
1122 parselist++;
1123 if (*parselist & ~(GLX_TEXTURE_1D_BIT_EXT |
1124 GLX_TEXTURE_2D_BIT_EXT |
1125 GLX_TEXTURE_RECTANGLE_BIT_EXT)) {
1126 /* invalid bit */
1127 return NULL;
1128 }
1129 break;
1130 case GLX_Y_INVERTED_EXT:
1131 parselist++; /*skip*/
1132 break;
1133#endif
1134
jtgafb833d1999-08-19 00:55:39 +00001135 case None:
Brian Paul3a996742004-02-02 15:40:21 +00001136 /* end of list */
jtgafb833d1999-08-19 00:55:39 +00001137 break;
Brian Paul3265fe52002-10-05 03:02:34 +00001138
jtgafb833d1999-08-19 00:55:39 +00001139 default:
1140 /* undefined attribute */
Brian Paul2ad59212002-10-30 20:24:45 +00001141 _mesa_warning(NULL, "unexpected attrib 0x%x in choose_visual()",
1142 *parselist);
jtgafb833d1999-08-19 00:55:39 +00001143 return NULL;
1144 }
1145 }
1146
Ian Romanick81fe9942010-02-24 17:44:28 -08001147 if (!rgb_flag)
1148 return NULL;
1149
Brian Paulb3050282003-12-04 03:19:46 +00001150 (void) caveat;
Brian Paul2aeadab2012-02-27 20:28:09 -07001151 (void) min_ci;
Brian Paulb3050282003-12-04 03:19:46 +00001152
jtgafb833d1999-08-19 00:55:39 +00001153 /*
1154 * Since we're only simulating the GLX extension this function will never
1155 * find any real GL visuals. Instead, all we can do is try to find an RGB
1156 * or CI visual of appropriate depth. Other requested attributes such as
1157 * double buffering, depth buffer, etc. will be associated with the X
1158 * visual and stored in the VisualTable[].
1159 */
Brian Paul3a996742004-02-02 15:40:21 +00001160 if (desiredVisualID != -1) {
1161 /* try to get a specific visual, by visualID */
1162 XVisualInfo temp;
1163 int n;
1164 temp.visualid = desiredVisualID;
1165 temp.screen = screen;
1166 vis = XGetVisualInfo(dpy, VisualIDMask | VisualScreenMask, &temp, &n);
1167 if (vis) {
1168 /* give the visual some useful GLX attributes */
1169 double_flag = GL_TRUE;
Ian Romanick81fe9942010-02-24 17:44:28 -08001170 if (vis->depth <= 8)
1171 return NULL;
Brian Pauldfa5c2b2004-07-23 23:32:15 +00001172 depth_size = default_depth_bits();
Brian Paul074637b2012-02-21 08:01:05 -07001173 stencil_size = 8;
Brian Paul3a996742004-02-02 15:40:21 +00001174 /* XXX accum??? */
1175 }
1176 }
jtgafb833d1999-08-19 00:55:39 +00001177 else {
Ian Romanick81fe9942010-02-24 17:44:28 -08001178 /* RGB visual */
1179 int min_rgb = min_red + min_green + min_blue;
1180 if (min_rgb>1 && min_rgb<8) {
1181 /* a special case to be sure we can get a monochrome visual */
1182 min_rgb = 1;
1183 }
1184
1185 if (level==0) {
1186 vis = choose_x_visual(dpy, screen, min_rgb, visual_type);
Brian Paul42f252f1999-10-14 18:47:37 +00001187 }
1188 else {
Ian Romanick81fe9942010-02-24 17:44:28 -08001189 vis = choose_x_overlay_visual(dpy, screen, level,
1190 trans_type, trans_value, min_rgb, visual_type);
Brian Paul42f252f1999-10-14 18:47:37 +00001191 }
jtgafb833d1999-08-19 00:55:39 +00001192 }
1193
1194 if (vis) {
Brian Pauled30dfa2000-03-03 17:47:39 +00001195 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1196 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
Brian Paul2c7e6332000-10-05 17:38:21 +00001197 * largest depth buffer size, which is 32bits/value. Instead, we
Brian Pauled30dfa2000-03-03 17:47:39 +00001198 * return 16 to maintain performance with earlier versions of Mesa.
1199 */
Brian Paul2c7e6332000-10-05 17:38:21 +00001200 if (depth_size > 24)
Brian Paul9e4e3ad2005-09-20 04:47:34 +00001201 depth_size = 32;
Brian Pauled30dfa2000-03-03 17:47:39 +00001202 else if (depth_size > 16)
1203 depth_size = 24;
Brian Pauldfa5c2b2004-07-23 23:32:15 +00001204 else if (depth_size > 0) {
1205 depth_size = default_depth_bits();
1206 }
Brian Paul2c7e6332000-10-05 17:38:21 +00001207
Brian Paulc12ee992005-11-04 16:41:06 +00001208 if (!alpha_flag) {
1209 alpha_flag = default_alpha_bits() > 0;
1210 }
1211
Brian Pauled30dfa2000-03-03 17:47:39 +00001212 /* we only support one size of stencil and accum buffers. */
1213 if (stencil_size > 0)
Brian Paul074637b2012-02-21 08:01:05 -07001214 stencil_size = 8;
Brian Paul6d62d7f2001-03-23 21:37:05 +00001215 if (accumRedSize > 0 || accumGreenSize > 0 || accumBlueSize > 0 ||
1216 accumAlphaSize > 0) {
Brian Paul978ef2b2005-09-21 03:35:08 +00001217 accumRedSize =
1218 accumGreenSize =
1219 accumBlueSize = default_accum_bits();
1220 accumAlphaSize = alpha_flag ? accumRedSize : 0;
Brian Paul6d62d7f2001-03-23 21:37:05 +00001221 }
1222
Ian Romanick81fe9942010-02-24 17:44:28 -08001223 xmvis = save_glx_visual( dpy, vis, alpha_flag, double_flag,
Brian Paul3265fe52002-10-05 03:02:34 +00001224 stereo_flag, depth_size, stencil_size,
1225 accumRedSize, accumGreenSize,
Brian Paul894844a2004-03-21 17:05:03 +00001226 accumBlueSize, accumAlphaSize, level, numAux );
jtgafb833d1999-08-19 00:55:39 +00001227 }
1228
Brian Paul3265fe52002-10-05 03:02:34 +00001229 return xmvis;
jtgafb833d1999-08-19 00:55:39 +00001230}
1231
1232
Brian Paul3265fe52002-10-05 03:02:34 +00001233static XVisualInfo *
1234Fake_glXChooseVisual( Display *dpy, int screen, int *list )
1235{
Brian Paul6c06ce22006-08-30 21:17:51 +00001236 XMesaVisual xmvis;
1237
1238 /* register ourselves as an extension on this display */
1239 register_with_display(dpy);
1240
1241 xmvis = choose_visual(dpy, screen, list, GL_FALSE);
Brian Paulf1046192002-11-10 17:07:06 +00001242 if (xmvis) {
1243#if 0
Brian Paul3265fe52002-10-05 03:02:34 +00001244 return xmvis->vishandle;
Brian Paulf1046192002-11-10 17:07:06 +00001245#else
1246 /* create a new vishandle - the cached one may be stale */
Matt Turner2b7a9722012-09-03 19:44:00 -07001247 xmvis->vishandle = malloc(sizeof(XVisualInfo));
Brian Paulf1046192002-11-10 17:07:06 +00001248 if (xmvis->vishandle) {
Kenneth Graunkec7ac48622010-02-18 23:50:59 -08001249 memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
Brian Paulf1046192002-11-10 17:07:06 +00001250 }
1251 return xmvis->vishandle;
1252#endif
1253 }
Brian Paul3265fe52002-10-05 03:02:34 +00001254 else
1255 return NULL;
1256}
jtgafb833d1999-08-19 00:55:39 +00001257
1258
Brian Paul426cb9f1999-11-28 20:08:02 +00001259static GLXContext
1260Fake_glXCreateContext( Display *dpy, XVisualInfo *visinfo,
1261 GLXContext share_list, Bool direct )
jtgafb833d1999-08-19 00:55:39 +00001262{
Brian Paule4656002002-10-05 18:27:41 +00001263 XMesaVisual xmvis;
Brian Paulc00b2502014-03-01 10:21:08 -07001264 XMesaContext xmesaCtx;
Brian Paul99aab342002-04-02 23:52:53 +00001265
1266 if (!dpy || !visinfo)
1267 return 0;
1268
jtgafb833d1999-08-19 00:55:39 +00001269 /* deallocate unused windows/buffers */
Brian Paul6c06ce22006-08-30 21:17:51 +00001270#if 0
Andy Skinner90e227f2011-02-11 07:31:25 -08001271 XMesaGarbageCollect(dpy);
Brian Paul6c06ce22006-08-30 21:17:51 +00001272#endif
jtgafb833d1999-08-19 00:55:39 +00001273
Brian Paule4656002002-10-05 18:27:41 +00001274 xmvis = find_glx_visual( dpy, visinfo );
1275 if (!xmvis) {
jtgafb833d1999-08-19 00:55:39 +00001276 /* This visual wasn't found with glXChooseVisual() */
Brian Paule4656002002-10-05 18:27:41 +00001277 xmvis = create_glx_visual( dpy, visinfo );
1278 if (!xmvis) {
jtgafb833d1999-08-19 00:55:39 +00001279 return NULL;
1280 }
1281 }
1282
Brian Paulc00b2502014-03-01 10:21:08 -07001283 xmesaCtx = XMesaCreateContext(xmvis, (XMesaContext) share_list);
Brian Paul7cf50e12001-05-24 19:06:21 +00001284
Brian Paulc00b2502014-03-01 10:21:08 -07001285 return (GLXContext) xmesaCtx;
jtgafb833d1999-08-19 00:55:39 +00001286}
1287
1288
Brian Paul7cf50e12001-05-24 19:06:21 +00001289/* XXX these may have to be removed due to thread-safety issues. */
jtgafb833d1999-08-19 00:55:39 +00001290static GLXContext MakeCurrent_PrevContext = 0;
Brian Paul086a1511999-11-25 17:37:49 +00001291static GLXDrawable MakeCurrent_PrevDrawable = 0;
1292static GLXDrawable MakeCurrent_PrevReadable = 0;
1293static XMesaBuffer MakeCurrent_PrevDrawBuffer = 0;
1294static XMesaBuffer MakeCurrent_PrevReadBuffer = 0;
jtgafb833d1999-08-19 00:55:39 +00001295
Brian Paul7cf50e12001-05-24 19:06:21 +00001296
Brian Paul086a1511999-11-25 17:37:49 +00001297/* GLX 1.3 and later */
Brian Paul426cb9f1999-11-28 20:08:02 +00001298static Bool
1299Fake_glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
Keith Whitwell7a1f3a32001-01-08 04:55:22 +00001300 GLXDrawable read, GLXContext ctx )
Brian Paul086a1511999-11-25 17:37:49 +00001301{
Keith Whitwell7a1f3a32001-01-08 04:55:22 +00001302 if (ctx && draw && read) {
Brian Paul086a1511999-11-25 17:37:49 +00001303 XMesaBuffer drawBuffer, readBuffer;
Brian Paulc00b2502014-03-01 10:21:08 -07001304 XMesaContext xmctx = (XMesaContext) ctx;
Brian Paul086a1511999-11-25 17:37:49 +00001305
1306 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
Keith Whitwell7a1f3a32001-01-08 04:55:22 +00001307 if (ctx == MakeCurrent_PrevContext
1308 && draw == MakeCurrent_PrevDrawable) {
Brian Paul086a1511999-11-25 17:37:49 +00001309 drawBuffer = MakeCurrent_PrevDrawBuffer;
1310 }
1311 else {
1312 drawBuffer = XMesaFindBuffer( dpy, draw );
1313 }
1314 if (!drawBuffer) {
1315 /* drawable must be a new window! */
George Sapountzis6aa56682007-04-20 17:51:55 +03001316 drawBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, draw );
Brian Paul086a1511999-11-25 17:37:49 +00001317 if (!drawBuffer) {
1318 /* Out of memory, or context/drawable depth mismatch */
1319 return False;
1320 }
1321 }
1322
1323 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
Keith Whitwell7a1f3a32001-01-08 04:55:22 +00001324 if (ctx == MakeCurrent_PrevContext
Brian Paul086a1511999-11-25 17:37:49 +00001325 && read == MakeCurrent_PrevReadable) {
1326 readBuffer = MakeCurrent_PrevReadBuffer;
1327 }
1328 else {
1329 readBuffer = XMesaFindBuffer( dpy, read );
1330 }
1331 if (!readBuffer) {
1332 /* drawable must be a new window! */
George Sapountzis6aa56682007-04-20 17:51:55 +03001333 readBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, read );
Brian Paul086a1511999-11-25 17:37:49 +00001334 if (!readBuffer) {
1335 /* Out of memory, or context/drawable depth mismatch */
1336 return False;
1337 }
1338 }
1339
Keith Whitwell7a1f3a32001-01-08 04:55:22 +00001340 MakeCurrent_PrevContext = ctx;
Brian Paul086a1511999-11-25 17:37:49 +00001341 MakeCurrent_PrevDrawable = draw;
1342 MakeCurrent_PrevReadable = read;
1343 MakeCurrent_PrevDrawBuffer = drawBuffer;
1344 MakeCurrent_PrevReadBuffer = readBuffer;
1345
1346 /* Now make current! */
Brian Paulc00b2502014-03-01 10:21:08 -07001347 return XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer);
Brian Paul086a1511999-11-25 17:37:49 +00001348 }
Keith Whitwell7a1f3a32001-01-08 04:55:22 +00001349 else if (!ctx && !draw && !read) {
Brian Paul086a1511999-11-25 17:37:49 +00001350 /* release current context w/out assigning new one. */
1351 XMesaMakeCurrent( NULL, NULL );
1352 MakeCurrent_PrevContext = 0;
1353 MakeCurrent_PrevDrawable = 0;
1354 MakeCurrent_PrevReadable = 0;
1355 MakeCurrent_PrevDrawBuffer = 0;
1356 MakeCurrent_PrevReadBuffer = 0;
1357 return True;
1358 }
1359 else {
1360 /* The args must either all be non-zero or all zero.
1361 * This is an error.
1362 */
1363 return False;
1364 }
1365}
1366
1367
Brian Paul426cb9f1999-11-28 20:08:02 +00001368static Bool
1369Fake_glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
1370{
1371 return Fake_glXMakeContextCurrent( dpy, drawable, drawable, ctx );
1372}
1373
1374
Brian Paul426cb9f1999-11-28 20:08:02 +00001375static GLXPixmap
1376Fake_glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap )
jtgafb833d1999-08-19 00:55:39 +00001377{
1378 XMesaVisual v;
1379 XMesaBuffer b;
1380
1381 v = find_glx_visual( dpy, visinfo );
1382 if (!v) {
1383 v = create_glx_visual( dpy, visinfo );
1384 if (!v) {
1385 /* unusable visual */
1386 return 0;
1387 }
1388 }
1389
1390 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1391 if (!b) {
1392 return 0;
1393 }
Brian Paule4b23562005-05-04 20:11:35 +00001394 return b->frontxrb->pixmap;
jtgafb833d1999-08-19 00:55:39 +00001395}
1396
1397
Brian Paulb0bb4f62001-05-25 21:51:02 +00001398/*** GLX_MESA_pixmap_colormap ***/
1399
Brian Paul426cb9f1999-11-28 20:08:02 +00001400static GLXPixmap
1401Fake_glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
1402 Pixmap pixmap, Colormap cmap )
jtgafb833d1999-08-19 00:55:39 +00001403{
1404 XMesaVisual v;
1405 XMesaBuffer b;
1406
1407 v = find_glx_visual( dpy, visinfo );
1408 if (!v) {
1409 v = create_glx_visual( dpy, visinfo );
1410 if (!v) {
1411 /* unusable visual */
1412 return 0;
1413 }
1414 }
1415
1416 b = XMesaCreatePixmapBuffer( v, pixmap, cmap );
1417 if (!b) {
1418 return 0;
1419 }
Brian Paule4b23562005-05-04 20:11:35 +00001420 return b->frontxrb->pixmap;
jtgafb833d1999-08-19 00:55:39 +00001421}
jtgafb833d1999-08-19 00:55:39 +00001422
1423
Brian Paul426cb9f1999-11-28 20:08:02 +00001424static void
1425Fake_glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
jtgafb833d1999-08-19 00:55:39 +00001426{
1427 XMesaBuffer b = XMesaFindBuffer(dpy, pixmap);
1428 if (b) {
1429 XMesaDestroyBuffer(b);
1430 }
Matt Turner5980fc32014-09-21 22:53:04 -07001431 else if (getenv("MESA_DEBUG")) {
Brian Pauld09a1d82002-06-13 04:49:17 +00001432 _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
jtgafb833d1999-08-19 00:55:39 +00001433 }
1434}
1435
1436
Brian Paul426cb9f1999-11-28 20:08:02 +00001437static void
1438Fake_glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
Brian Paul3994b772000-02-27 18:26:54 +00001439 unsigned long mask )
jtgafb833d1999-08-19 00:55:39 +00001440{
Brian Paulc00b2502014-03-01 10:21:08 -07001441 XMesaContext xmSrc = (XMesaContext) src;
1442 XMesaContext xmDst = (XMesaContext) dst;
jtgafb833d1999-08-19 00:55:39 +00001443 (void) dpy;
Brian Paul68edf282006-03-01 15:32:38 +00001444 if (MakeCurrent_PrevContext == src) {
1445 _mesa_Flush();
1446 }
Brian Paulc00b2502014-03-01 10:21:08 -07001447 _mesa_copy_context( &xmSrc->mesa, &xmDst->mesa, (GLuint) mask );
jtgafb833d1999-08-19 00:55:39 +00001448}
1449
1450
Brian Paul426cb9f1999-11-28 20:08:02 +00001451static Bool
Brian Paule3fff3d2009-10-07 07:45:15 -06001452Fake_glXQueryExtension( Display *dpy, int *errorBase, int *eventBase )
jtgafb833d1999-08-19 00:55:39 +00001453{
Brian Paul9f002e42009-10-07 14:42:14 -06001454 int op, ev, err;
jtgafb833d1999-08-19 00:55:39 +00001455 /* Mesa's GLX isn't really an X extension but we try to act like one. */
Brian Paul9f002e42009-10-07 14:42:14 -06001456 if (!XQueryExtension(dpy, GLX_EXTENSION_NAME, &op, &ev, &err))
1457 ev = err = 0;
Brian Paule3fff3d2009-10-07 07:45:15 -06001458 if (errorBase)
Brian Paul9f002e42009-10-07 14:42:14 -06001459 *errorBase = err;
Brian Paule3fff3d2009-10-07 07:45:15 -06001460 if (eventBase)
Brian Paul9f002e42009-10-07 14:42:14 -06001461 *eventBase = ev;
1462 return True; /* we're faking GLX so always return success */
jtgafb833d1999-08-19 00:55:39 +00001463}
1464
1465
Brian Paule7b16b72000-03-17 15:33:09 +00001466extern void _kw_ungrab_all( Display *dpy );
jtgafb833d1999-08-19 00:55:39 +00001467void _kw_ungrab_all( Display *dpy )
1468{
1469 XUngrabPointer( dpy, CurrentTime );
1470 XUngrabKeyboard( dpy, CurrentTime );
1471}
1472
1473
Brian Paul426cb9f1999-11-28 20:08:02 +00001474static void
1475Fake_glXDestroyContext( Display *dpy, GLXContext ctx )
jtgafb833d1999-08-19 00:55:39 +00001476{
Brian Paulfd9fe442013-05-24 08:06:19 -06001477 if (ctx) {
Brian Paulfd9fe442013-05-24 08:06:19 -06001478 (void) dpy;
1479 MakeCurrent_PrevContext = 0;
1480 MakeCurrent_PrevDrawable = 0;
1481 MakeCurrent_PrevReadable = 0;
1482 MakeCurrent_PrevDrawBuffer = 0;
1483 MakeCurrent_PrevReadBuffer = 0;
Brian Paulc00b2502014-03-01 10:21:08 -07001484 XMesaDestroyContext((XMesaContext) ctx);
Brian Paulfd9fe442013-05-24 08:06:19 -06001485 XMesaGarbageCollect(dpy);
Brian Paulfd9fe442013-05-24 08:06:19 -06001486 }
jtgafb833d1999-08-19 00:55:39 +00001487}
1488
1489
Brian Paul426cb9f1999-11-28 20:08:02 +00001490static Bool
1491Fake_glXIsDirect( Display *dpy, GLXContext ctx )
jtgafb833d1999-08-19 00:55:39 +00001492{
Brian Paulc00b2502014-03-01 10:21:08 -07001493 XMesaContext xmCtx = (XMesaContext) ctx;
1494 return xmCtx ? xmCtx->direct : False;
jtgafb833d1999-08-19 00:55:39 +00001495}
1496
1497
1498
Brian Paul426cb9f1999-11-28 20:08:02 +00001499static void
1500Fake_glXSwapBuffers( Display *dpy, GLXDrawable drawable )
jtgafb833d1999-08-19 00:55:39 +00001501{
1502 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
jtgafb833d1999-08-19 00:55:39 +00001503
jtgafb833d1999-08-19 00:55:39 +00001504 if (buffer) {
1505 XMesaSwapBuffers(buffer);
1506 }
Matt Turner5980fc32014-09-21 22:53:04 -07001507 else if (getenv("MESA_DEBUG")) {
Brian Paulba0fe182005-02-23 16:54:18 +00001508 _mesa_warning(NULL, "glXSwapBuffers: invalid drawable 0x%x\n",
1509 (int) drawable);
jtgafb833d1999-08-19 00:55:39 +00001510 }
1511}
1512
1513
Brian Paul4c07bd52000-06-08 22:50:28 +00001514
Brian Paulb0bb4f62001-05-25 21:51:02 +00001515/*** GLX_MESA_copy_sub_buffer ***/
1516
Brian Paul426cb9f1999-11-28 20:08:02 +00001517static void
1518Fake_glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable,
1519 int x, int y, int width, int height )
jtgafb833d1999-08-19 00:55:39 +00001520{
1521 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1522 if (buffer) {
1523 XMesaCopySubBuffer(buffer, x, y, width, height);
1524 }
Matt Turner5980fc32014-09-21 22:53:04 -07001525 else if (getenv("MESA_DEBUG")) {
Brian Pauld09a1d82002-06-13 04:49:17 +00001526 _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
jtgafb833d1999-08-19 00:55:39 +00001527 }
1528}
1529
1530
Brian Paul426cb9f1999-11-28 20:08:02 +00001531static Bool
1532Fake_glXQueryVersion( Display *dpy, int *maj, int *min )
jtgafb833d1999-08-19 00:55:39 +00001533{
1534 (void) dpy;
1535 /* Return GLX version, not Mesa version */
Brian Paul78fc78e1999-11-22 22:17:06 +00001536 assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION);
1537 *maj = CLIENT_MAJOR_VERSION;
1538 *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION );
jtgafb833d1999-08-19 00:55:39 +00001539 return True;
1540}
1541
1542
jtgafb833d1999-08-19 00:55:39 +00001543/*
1544 * Query the GLX attributes of the given XVisualInfo.
1545 */
Brian Paul426cb9f1999-11-28 20:08:02 +00001546static int
Brian Paule4656002002-10-05 18:27:41 +00001547get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig )
jtgafb833d1999-08-19 00:55:39 +00001548{
Matt Turnerbfcdb842015-02-20 20:18:47 -08001549 assert(xmvis);
jtgafb833d1999-08-19 00:55:39 +00001550 switch(attrib) {
1551 case GLX_USE_GL:
Brian Paul1f98ee92005-01-06 21:56:16 +00001552 if (fbconfig)
1553 return GLX_BAD_ATTRIBUTE;
jtgafb833d1999-08-19 00:55:39 +00001554 *value = (int) True;
1555 return 0;
1556 case GLX_BUFFER_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001557 *value = xmvis->visinfo->depth;
jtgafb833d1999-08-19 00:55:39 +00001558 return 0;
1559 case GLX_LEVEL:
Ian Romanick304d3aa2004-02-19 00:57:04 +00001560 *value = xmvis->mesa_visual.level;
jtgafb833d1999-08-19 00:55:39 +00001561 return 0;
1562 case GLX_RGBA:
Brian Paul1f98ee92005-01-06 21:56:16 +00001563 if (fbconfig)
1564 return GLX_BAD_ATTRIBUTE;
Brian Paule4656002002-10-05 18:27:41 +00001565 if (xmvis->mesa_visual.rgbMode) {
jtgafb833d1999-08-19 00:55:39 +00001566 *value = True;
1567 }
1568 else {
1569 *value = False;
1570 }
1571 return 0;
1572 case GLX_DOUBLEBUFFER:
Brian Paule4656002002-10-05 18:27:41 +00001573 *value = (int) xmvis->mesa_visual.doubleBufferMode;
jtgafb833d1999-08-19 00:55:39 +00001574 return 0;
1575 case GLX_STEREO:
Brian Paule4656002002-10-05 18:27:41 +00001576 *value = (int) xmvis->mesa_visual.stereoMode;
jtgafb833d1999-08-19 00:55:39 +00001577 return 0;
1578 case GLX_AUX_BUFFERS:
Brian Paul894844a2004-03-21 17:05:03 +00001579 *value = xmvis->mesa_visual.numAuxBuffers;
jtgafb833d1999-08-19 00:55:39 +00001580 return 0;
1581 case GLX_RED_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001582 *value = xmvis->mesa_visual.redBits;
jtgafb833d1999-08-19 00:55:39 +00001583 return 0;
1584 case GLX_GREEN_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001585 *value = xmvis->mesa_visual.greenBits;
jtgafb833d1999-08-19 00:55:39 +00001586 return 0;
1587 case GLX_BLUE_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001588 *value = xmvis->mesa_visual.blueBits;
jtgafb833d1999-08-19 00:55:39 +00001589 return 0;
1590 case GLX_ALPHA_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001591 *value = xmvis->mesa_visual.alphaBits;
jtgafb833d1999-08-19 00:55:39 +00001592 return 0;
1593 case GLX_DEPTH_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001594 *value = xmvis->mesa_visual.depthBits;
jtgafb833d1999-08-19 00:55:39 +00001595 return 0;
1596 case GLX_STENCIL_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001597 *value = xmvis->mesa_visual.stencilBits;
jtgafb833d1999-08-19 00:55:39 +00001598 return 0;
1599 case GLX_ACCUM_RED_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001600 *value = xmvis->mesa_visual.accumRedBits;
Brian Paulb2e46002000-03-31 01:07:13 +00001601 return 0;
jtgafb833d1999-08-19 00:55:39 +00001602 case GLX_ACCUM_GREEN_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001603 *value = xmvis->mesa_visual.accumGreenBits;
Brian Paulb2e46002000-03-31 01:07:13 +00001604 return 0;
jtgafb833d1999-08-19 00:55:39 +00001605 case GLX_ACCUM_BLUE_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001606 *value = xmvis->mesa_visual.accumBlueBits;
jtgafb833d1999-08-19 00:55:39 +00001607 return 0;
1608 case GLX_ACCUM_ALPHA_SIZE:
Brian Paule4656002002-10-05 18:27:41 +00001609 *value = xmvis->mesa_visual.accumAlphaBits;
jtgafb833d1999-08-19 00:55:39 +00001610 return 0;
1611
1612 /*
1613 * GLX_EXT_visual_info extension
1614 */
1615 case GLX_X_VISUAL_TYPE_EXT:
Brian Paule4656002002-10-05 18:27:41 +00001616 switch (xmvis->visinfo->CLASS) {
jtgafb833d1999-08-19 00:55:39 +00001617 case StaticGray: *value = GLX_STATIC_GRAY_EXT; return 0;
1618 case GrayScale: *value = GLX_GRAY_SCALE_EXT; return 0;
1619 case StaticColor: *value = GLX_STATIC_GRAY_EXT; return 0;
1620 case PseudoColor: *value = GLX_PSEUDO_COLOR_EXT; return 0;
1621 case TrueColor: *value = GLX_TRUE_COLOR_EXT; return 0;
1622 case DirectColor: *value = GLX_DIRECT_COLOR_EXT; return 0;
1623 }
1624 return 0;
1625 case GLX_TRANSPARENT_TYPE_EXT:
Ian Romanick304d3aa2004-02-19 00:57:04 +00001626 if (xmvis->mesa_visual.level==0) {
jtgafb833d1999-08-19 00:55:39 +00001627 /* normal planes */
1628 *value = GLX_NONE_EXT;
1629 }
Ian Romanick304d3aa2004-02-19 00:57:04 +00001630 else if (xmvis->mesa_visual.level>0) {
jtgafb833d1999-08-19 00:55:39 +00001631 /* overlay */
Brian Paule4656002002-10-05 18:27:41 +00001632 if (xmvis->mesa_visual.rgbMode) {
jtgafb833d1999-08-19 00:55:39 +00001633 *value = GLX_TRANSPARENT_RGB_EXT;
1634 }
1635 else {
1636 *value = GLX_TRANSPARENT_INDEX_EXT;
1637 }
1638 }
Ian Romanick304d3aa2004-02-19 00:57:04 +00001639 else if (xmvis->mesa_visual.level<0) {
jtgafb833d1999-08-19 00:55:39 +00001640 /* underlay */
1641 *value = GLX_NONE_EXT;
1642 }
1643 return 0;
1644 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1645 {
Brian Paule4656002002-10-05 18:27:41 +00001646 int pixel = transparent_pixel( xmvis );
jtgafb833d1999-08-19 00:55:39 +00001647 if (pixel>=0) {
1648 *value = pixel;
1649 }
1650 /* else undefined */
1651 }
1652 return 0;
1653 case GLX_TRANSPARENT_RED_VALUE_EXT:
1654 /* undefined */
1655 return 0;
1656 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1657 /* undefined */
1658 return 0;
1659 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1660 /* undefined */
1661 return 0;
1662 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1663 /* undefined */
1664 return 0;
1665
1666 /*
Brian Paulb2e46002000-03-31 01:07:13 +00001667 * GLX_EXT_visual_info extension
1668 */
1669 case GLX_VISUAL_CAVEAT_EXT:
Brian Paulfc68be62000-03-31 01:12:40 +00001670 /* test for zero, just in case */
Ian Romanick304d3aa2004-02-19 00:57:04 +00001671 if (xmvis->mesa_visual.visualRating > 0)
1672 *value = xmvis->mesa_visual.visualRating;
Brian Paul962f4262000-03-31 18:17:01 +00001673 else
1674 *value = GLX_NONE_EXT;
1675 return 0;
Brian Paulb2e46002000-03-31 01:07:13 +00001676
1677 /*
Brian Paul66ab7272002-11-05 21:11:18 +00001678 * GLX_ARB_multisample
jtgafb833d1999-08-19 00:55:39 +00001679 */
Brian Paul66ab7272002-11-05 21:11:18 +00001680 case GLX_SAMPLE_BUFFERS_ARB:
Brian Paul3265fe52002-10-05 03:02:34 +00001681 *value = 0;
1682 return 0;
Brian Paul66ab7272002-11-05 21:11:18 +00001683 case GLX_SAMPLES_ARB:
Brian Paul3265fe52002-10-05 03:02:34 +00001684 *value = 0;
1685 return 0;
1686
1687 /*
1688 * For FBConfigs:
1689 */
1690 case GLX_SCREEN_EXT:
1691 if (!fbconfig)
1692 return GLX_BAD_ATTRIBUTE;
Brian Paule4656002002-10-05 18:27:41 +00001693 *value = xmvis->visinfo->screen;
Brian Paul3265fe52002-10-05 03:02:34 +00001694 break;
1695 case GLX_DRAWABLE_TYPE: /*SGIX too */
1696 if (!fbconfig)
1697 return GLX_BAD_ATTRIBUTE;
1698 *value = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
1699 break;
1700 case GLX_RENDER_TYPE_SGIX:
1701 if (!fbconfig)
1702 return GLX_BAD_ATTRIBUTE;
Tomasz Lisb8126c72013-07-17 13:49:16 +02001703 if (xmvis->mesa_visual.floatMode)
1704 *value = GLX_RGBA_FLOAT_BIT_ARB;
1705 else if (xmvis->mesa_visual.rgbMode)
Brian Paul3265fe52002-10-05 03:02:34 +00001706 *value = GLX_RGBA_BIT;
1707 else
1708 *value = GLX_COLOR_INDEX_BIT;
1709 break;
1710 case GLX_X_RENDERABLE_SGIX:
1711 if (!fbconfig)
1712 return GLX_BAD_ATTRIBUTE;
1713 *value = True; /* XXX really? */
1714 break;
1715 case GLX_FBCONFIG_ID_SGIX:
1716 if (!fbconfig)
1717 return GLX_BAD_ATTRIBUTE;
Brian Paulf1046192002-11-10 17:07:06 +00001718 *value = xmvis->visinfo->visualid;
Brian Paul3265fe52002-10-05 03:02:34 +00001719 break;
1720 case GLX_MAX_PBUFFER_WIDTH:
1721 if (!fbconfig)
1722 return GLX_BAD_ATTRIBUTE;
1723 /* XXX or MAX_WIDTH? */
Brian Paulf1046192002-11-10 17:07:06 +00001724 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen);
Brian Paul3265fe52002-10-05 03:02:34 +00001725 break;
1726 case GLX_MAX_PBUFFER_HEIGHT:
1727 if (!fbconfig)
1728 return GLX_BAD_ATTRIBUTE;
Brian Paulf1046192002-11-10 17:07:06 +00001729 *value = DisplayHeight(xmvis->display, xmvis->visinfo->screen);
Brian Paul3265fe52002-10-05 03:02:34 +00001730 break;
1731 case GLX_MAX_PBUFFER_PIXELS:
1732 if (!fbconfig)
1733 return GLX_BAD_ATTRIBUTE;
Brian Paulf1046192002-11-10 17:07:06 +00001734 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen) *
1735 DisplayHeight(xmvis->display, xmvis->visinfo->screen);
Brian Paul3265fe52002-10-05 03:02:34 +00001736 break;
1737 case GLX_VISUAL_ID:
1738 if (!fbconfig)
1739 return GLX_BAD_ATTRIBUTE;
Brian Paulf1046192002-11-10 17:07:06 +00001740 *value = xmvis->visinfo->visualid;
Brian Paul3265fe52002-10-05 03:02:34 +00001741 break;
1742
Brianfd545642007-05-19 08:27:35 -06001743#ifdef GLX_EXT_texture_from_pixmap
1744 case GLX_BIND_TO_TEXTURE_RGB_EXT:
1745 *value = True; /*XXX*/
1746 break;
1747 case GLX_BIND_TO_TEXTURE_RGBA_EXT:
1748 /* XXX review */
1749 *value = xmvis->mesa_visual.alphaBits > 0 ? True : False;
1750 break;
1751 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
1752 *value = True; /*XXX*/
1753 break;
1754 case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
1755 *value = (GLX_TEXTURE_1D_BIT_EXT |
1756 GLX_TEXTURE_2D_BIT_EXT |
1757 GLX_TEXTURE_RECTANGLE_BIT_EXT); /*XXX*/
1758 break;
1759 case GLX_Y_INVERTED_EXT:
Briana10ba382007-05-21 20:56:35 -06001760 *value = True; /*XXX*/
Brianfd545642007-05-19 08:27:35 -06001761 break;
1762#endif
1763
jtgafb833d1999-08-19 00:55:39 +00001764 default:
1765 return GLX_BAD_ATTRIBUTE;
1766 }
Brian Paul3265fe52002-10-05 03:02:34 +00001767 return Success;
jtgafb833d1999-08-19 00:55:39 +00001768}
1769
1770
Brian Paul3265fe52002-10-05 03:02:34 +00001771static int
1772Fake_glXGetConfig( Display *dpy, XVisualInfo *visinfo,
1773 int attrib, int *value )
1774{
Brian Paule4656002002-10-05 18:27:41 +00001775 XMesaVisual xmvis;
Brian Paulba0fe182005-02-23 16:54:18 +00001776 int k;
Brian Paul37964192003-12-12 00:08:01 +00001777 if (!dpy || !visinfo)
Brian Paula9a1c3f2003-12-12 00:01:17 +00001778 return GLX_BAD_ATTRIBUTE;
1779
Brian Paule4656002002-10-05 18:27:41 +00001780 xmvis = find_glx_visual( dpy, visinfo );
1781 if (!xmvis) {
Brian Paul3265fe52002-10-05 03:02:34 +00001782 /* this visual wasn't obtained with glXChooseVisual */
Brian Paule4656002002-10-05 18:27:41 +00001783 xmvis = create_glx_visual( dpy, visinfo );
1784 if (!xmvis) {
Brian Paul3265fe52002-10-05 03:02:34 +00001785 /* this visual can't be used for GL rendering */
1786 if (attrib==GLX_USE_GL) {
1787 *value = (int) False;
1788 return 0;
1789 }
1790 else {
1791 return GLX_BAD_VISUAL;
1792 }
1793 }
1794 }
1795
Brian Paulba0fe182005-02-23 16:54:18 +00001796 k = get_config(xmvis, attrib, value, GL_FALSE);
1797 return k;
Brian Paul3265fe52002-10-05 03:02:34 +00001798}
1799
jtgafb833d1999-08-19 00:55:39 +00001800
Brian Paulc00b2502014-03-01 10:21:08 -07001801static GLXContext
1802Fake_glXGetCurrentContext(void)
1803{
1804 XMesaContext xmesa = XMesaGetCurrentContext();
1805 return (GLXContext) xmesa;
1806}
1807
Brian Paul426cb9f1999-11-28 20:08:02 +00001808static void
1809Fake_glXWaitGL( void )
jtgafb833d1999-08-19 00:55:39 +00001810{
1811 XMesaContext xmesa = XMesaGetCurrentContext();
1812 XMesaFlush( xmesa );
1813}
1814
1815
1816
Brian Paul426cb9f1999-11-28 20:08:02 +00001817static void
1818Fake_glXWaitX( void )
jtgafb833d1999-08-19 00:55:39 +00001819{
1820 XMesaContext xmesa = XMesaGetCurrentContext();
1821 XMesaFlush( xmesa );
1822}
1823
1824
Brian Paule4656002002-10-05 18:27:41 +00001825static const char *
1826get_extensions( void )
Brian Paul43c9c2c1999-09-16 15:52:51 +00001827{
Brian Paule4656002002-10-05 18:27:41 +00001828 return EXTENSIONS + 23; /* skip "GLX_MESA_set_3dfx_mode" */
Brian Paul43c9c2c1999-09-16 15:52:51 +00001829}
jtgafb833d1999-08-19 00:55:39 +00001830
jtgafb833d1999-08-19 00:55:39 +00001831
1832
1833/* GLX 1.1 and later */
Brian Paul426cb9f1999-11-28 20:08:02 +00001834static const char *
1835Fake_glXQueryExtensionsString( Display *dpy, int screen )
jtgafb833d1999-08-19 00:55:39 +00001836{
jtgafb833d1999-08-19 00:55:39 +00001837 (void) dpy;
1838 (void) screen;
Brian Paul43c9c2c1999-09-16 15:52:51 +00001839 return get_extensions();
jtgafb833d1999-08-19 00:55:39 +00001840}
1841
1842
1843
1844/* GLX 1.1 and later */
Brian Paul426cb9f1999-11-28 20:08:02 +00001845static const char *
1846Fake_glXQueryServerString( Display *dpy, int screen, int name )
jtgafb833d1999-08-19 00:55:39 +00001847{
Brian Paul78fc78e1999-11-22 22:17:06 +00001848 static char version[1000];
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001849 sprintf(version, "%d.%d %s",
1850 SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, MESA_GLX_VERSION);
jtgafb833d1999-08-19 00:55:39 +00001851
1852 (void) dpy;
1853 (void) screen;
1854
1855 switch (name) {
1856 case GLX_EXTENSIONS:
Brian Paul43c9c2c1999-09-16 15:52:51 +00001857 return get_extensions();
jtgafb833d1999-08-19 00:55:39 +00001858 case GLX_VENDOR:
Brian Paul78fc78e1999-11-22 22:17:06 +00001859 return VENDOR;
jtgafb833d1999-08-19 00:55:39 +00001860 case GLX_VERSION:
1861 return version;
1862 default:
1863 return NULL;
1864 }
1865}
1866
1867
1868
1869/* GLX 1.1 and later */
Brian Paul426cb9f1999-11-28 20:08:02 +00001870static const char *
1871Fake_glXGetClientString( Display *dpy, int name )
jtgafb833d1999-08-19 00:55:39 +00001872{
Brian Paul78fc78e1999-11-22 22:17:06 +00001873 static char version[1000];
Kristian Høgsberg298be2b2010-02-19 12:32:24 -05001874 sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION,
1875 CLIENT_MINOR_VERSION, MESA_GLX_VERSION);
jtgafb833d1999-08-19 00:55:39 +00001876
1877 (void) dpy;
1878
1879 switch (name) {
1880 case GLX_EXTENSIONS:
Brian Paul43c9c2c1999-09-16 15:52:51 +00001881 return get_extensions();
jtgafb833d1999-08-19 00:55:39 +00001882 case GLX_VENDOR:
Brian Paul78fc78e1999-11-22 22:17:06 +00001883 return VENDOR;
jtgafb833d1999-08-19 00:55:39 +00001884 case GLX_VERSION:
1885 return version;
1886 default:
1887 return NULL;
1888 }
1889}
1890
1891
1892
Brian Paul426cb9f1999-11-28 20:08:02 +00001893/*
1894 * GLX 1.3 and later
1895 */
1896
Brian Paul7d5656b2001-09-01 20:23:25 +00001897
Brian Paul426cb9f1999-11-28 20:08:02 +00001898static int
1899Fake_glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
1900 int attribute, int *value )
1901{
Brian Paul3265fe52002-10-05 03:02:34 +00001902 XMesaVisual v = (XMesaVisual) config;
Brian Paul426cb9f1999-11-28 20:08:02 +00001903 (void) dpy;
1904 (void) config;
Brian Paul7d5656b2001-09-01 20:23:25 +00001905
1906 if (!dpy || !config || !value)
1907 return -1;
1908
Brian Paul3265fe52002-10-05 03:02:34 +00001909 return get_config(v, attribute, value, GL_TRUE);
Brian Paul426cb9f1999-11-28 20:08:02 +00001910}
1911
1912
Brian Paul56057982000-04-10 21:13:19 +00001913static GLXFBConfig *
1914Fake_glXGetFBConfigs( Display *dpy, int screen, int *nelements )
1915{
Brian Paul3265fe52002-10-05 03:02:34 +00001916 XVisualInfo *visuals, visTemplate;
1917 const long visMask = VisualScreenMask;
1918 int i;
1919
1920 /* Get list of all X visuals */
1921 visTemplate.screen = screen;
1922 visuals = XGetVisualInfo(dpy, visMask, &visTemplate, nelements);
1923 if (*nelements > 0) {
1924 XMesaVisual *results;
Matt Turner2b7a9722012-09-03 19:44:00 -07001925 results = malloc(*nelements * sizeof(XMesaVisual));
Brian Paul3265fe52002-10-05 03:02:34 +00001926 if (!results) {
1927 *nelements = 0;
1928 return NULL;
1929 }
1930 for (i = 0; i < *nelements; i++) {
1931 results[i] = create_glx_visual(dpy, visuals + i);
1932 }
1933 return (GLXFBConfig *) results;
1934 }
1935 return NULL;
Brian Paul56057982000-04-10 21:13:19 +00001936}
1937
1938
Brian Paul481bdd32005-04-06 22:33:15 +00001939static GLXFBConfig *
1940Fake_glXChooseFBConfig( Display *dpy, int screen,
1941 const int *attribList, int *nitems )
1942{
1943 XMesaVisual xmvis;
1944
Brian Paulecbdb172012-01-10 19:24:41 -07001945 /* register ourselves as an extension on this display */
1946 register_with_display(dpy);
1947
Brian Paul481bdd32005-04-06 22:33:15 +00001948 if (!attribList || !attribList[0]) {
1949 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1950 return Fake_glXGetFBConfigs(dpy, screen, nitems);
1951 }
1952
1953 xmvis = choose_visual(dpy, screen, attribList, GL_TRUE);
1954 if (xmvis) {
Matt Turner2b7a9722012-09-03 19:44:00 -07001955 GLXFBConfig *config = malloc(sizeof(XMesaVisual));
Brian Paul481bdd32005-04-06 22:33:15 +00001956 if (!config) {
1957 *nitems = 0;
1958 return NULL;
1959 }
1960 *nitems = 1;
1961 config[0] = (GLXFBConfig) xmvis;
1962 return (GLXFBConfig *) config;
1963 }
1964 else {
1965 *nitems = 0;
1966 return NULL;
1967 }
1968}
1969
1970
Brian Paul426cb9f1999-11-28 20:08:02 +00001971static XVisualInfo *
1972Fake_glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
1973{
Brian Paul7d5656b2001-09-01 20:23:25 +00001974 if (dpy && config) {
Brian Paulf1046192002-11-10 17:07:06 +00001975 XMesaVisual xmvis = (XMesaVisual) config;
1976#if 0
1977 return xmvis->vishandle;
1978#else
1979 /* create a new vishandle - the cached one may be stale */
Matt Turner2b7a9722012-09-03 19:44:00 -07001980 xmvis->vishandle = malloc(sizeof(XVisualInfo));
Brian Paulf1046192002-11-10 17:07:06 +00001981 if (xmvis->vishandle) {
Kenneth Graunkec7ac48622010-02-18 23:50:59 -08001982 memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
Brian Paulf1046192002-11-10 17:07:06 +00001983 }
1984 return xmvis->vishandle;
1985#endif
Brian Paul7d5656b2001-09-01 20:23:25 +00001986 }
1987 else {
1988 return NULL;
1989 }
Brian Paul426cb9f1999-11-28 20:08:02 +00001990}
1991
1992
1993static GLXWindow
1994Fake_glXCreateWindow( Display *dpy, GLXFBConfig config, Window win,
1995 const int *attribList )
1996{
Brian Paul529614c2004-02-08 00:11:14 +00001997 XMesaVisual xmvis = (XMesaVisual) config;
1998 XMesaBuffer xmbuf;
1999 if (!xmvis)
2000 return 0;
2001
George Sapountzis6aa56682007-04-20 17:51:55 +03002002 xmbuf = XMesaCreateWindowBuffer(xmvis, win);
Brian Paul529614c2004-02-08 00:11:14 +00002003 if (!xmbuf)
2004 return 0;
2005
Brian Paul426cb9f1999-11-28 20:08:02 +00002006 (void) dpy;
Brian Paul7d5656b2001-09-01 20:23:25 +00002007 (void) attribList; /* Ignored in GLX 1.3 */
2008
2009 return win; /* A hack for now */
Brian Paul426cb9f1999-11-28 20:08:02 +00002010}
2011
2012
2013static void
2014Fake_glXDestroyWindow( Display *dpy, GLXWindow window )
2015{
Brian Paul7d5656b2001-09-01 20:23:25 +00002016 XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable) window);
2017 if (b)
2018 XMesaDestroyBuffer(b);
2019 /* don't destroy X window */
Brian Paul426cb9f1999-11-28 20:08:02 +00002020}
2021
2022
Brian Paul7d5656b2001-09-01 20:23:25 +00002023/* XXX untested */
Brian Paul426cb9f1999-11-28 20:08:02 +00002024static GLXPixmap
2025Fake_glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap,
2026 const int *attribList )
2027{
Brian Paul7d5656b2001-09-01 20:23:25 +00002028 XMesaVisual v = (XMesaVisual) config;
Brian Paul7d5656b2001-09-01 20:23:25 +00002029 XMesaBuffer b;
Brianfd545642007-05-19 08:27:35 -06002030 const int *attr;
2031 int target = 0, format = 0, mipmap = 0;
2032 int value;
Brian Paul7d5656b2001-09-01 20:23:25 +00002033
2034 if (!dpy || !config || !pixmap)
2035 return 0;
2036
Brian Pauld18c57a2009-06-17 08:34:24 -06002037 for (attr = attribList; attr && *attr; attr++) {
Brianfd545642007-05-19 08:27:35 -06002038 switch (*attr) {
2039 case GLX_TEXTURE_FORMAT_EXT:
2040 attr++;
2041 switch (*attr) {
2042 case GLX_TEXTURE_FORMAT_NONE_EXT:
2043 case GLX_TEXTURE_FORMAT_RGB_EXT:
2044 case GLX_TEXTURE_FORMAT_RGBA_EXT:
2045 format = *attr;
2046 break;
2047 default:
2048 /* error */
2049 return 0;
2050 }
2051 break;
2052 case GLX_TEXTURE_TARGET_EXT:
2053 attr++;
2054 switch (*attr) {
2055 case GLX_TEXTURE_1D_EXT:
2056 case GLX_TEXTURE_2D_EXT:
2057 case GLX_TEXTURE_RECTANGLE_EXT:
2058 target = *attr;
2059 break;
2060 default:
2061 /* error */
2062 return 0;
2063 }
2064 break;
2065 case GLX_MIPMAP_TEXTURE_EXT:
2066 attr++;
2067 if (*attr)
2068 mipmap = 1;
2069 break;
2070 default:
2071 /* error */
2072 return 0;
2073 }
2074 }
2075
2076 if (format == GLX_TEXTURE_FORMAT_RGB_EXT) {
2077 if (get_config(v, GLX_BIND_TO_TEXTURE_RGB_EXT,
2078 &value, GL_TRUE) != Success
2079 || !value) {
2080 return 0; /* error! */
2081 }
2082 }
2083 else if (format == GLX_TEXTURE_FORMAT_RGBA_EXT) {
2084 if (get_config(v, GLX_BIND_TO_TEXTURE_RGBA_EXT,
2085 &value, GL_TRUE) != Success
2086 || !value) {
2087 return 0; /* error! */
2088 }
2089 }
2090 if (mipmap) {
2091 if (get_config(v, GLX_BIND_TO_MIPMAP_TEXTURE_EXT,
2092 &value, GL_TRUE) != Success
2093 || !value) {
2094 return 0; /* error! */
2095 }
2096 }
2097 if (target == GLX_TEXTURE_1D_EXT) {
2098 if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
2099 &value, GL_TRUE) != Success
2100 || (value & GLX_TEXTURE_1D_BIT_EXT) == 0) {
2101 return 0; /* error! */
2102 }
2103 }
2104 else if (target == GLX_TEXTURE_2D_EXT) {
2105 if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
2106 &value, GL_TRUE) != Success
2107 || (value & GLX_TEXTURE_2D_BIT_EXT) == 0) {
2108 return 0; /* error! */
2109 }
2110 }
2111 if (target == GLX_TEXTURE_RECTANGLE_EXT) {
2112 if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
2113 &value, GL_TRUE) != Success
2114 || (value & GLX_TEXTURE_RECTANGLE_BIT_EXT) == 0) {
2115 return 0; /* error! */
2116 }
2117 }
2118
2119 if (format || target || mipmap) {
2120 /* texture from pixmap */
2121 b = XMesaCreatePixmapTextureBuffer(v, pixmap, 0, format, target, mipmap);
2122 }
2123 else {
2124 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
2125 }
Brian Paul7d5656b2001-09-01 20:23:25 +00002126 if (!b) {
2127 return 0;
2128 }
2129
2130 return pixmap;
Brian Paul426cb9f1999-11-28 20:08:02 +00002131}
2132
2133
2134static void
2135Fake_glXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
2136{
Brian Paul7d5656b2001-09-01 20:23:25 +00002137 XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable)pixmap);
2138 if (b)
2139 XMesaDestroyBuffer(b);
2140 /* don't destroy X pixmap */
Brian Paul426cb9f1999-11-28 20:08:02 +00002141}
2142
2143
2144static GLXPbuffer
2145Fake_glXCreatePbuffer( Display *dpy, GLXFBConfig config,
2146 const int *attribList )
2147{
Brian Paul3265fe52002-10-05 03:02:34 +00002148 XMesaVisual xmvis = (XMesaVisual) config;
2149 XMesaBuffer xmbuf;
Brian Paul7d5656b2001-09-01 20:23:25 +00002150 const int *attrib;
2151 int width = 0, height = 0;
2152 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2153
Brian Paul426cb9f1999-11-28 20:08:02 +00002154 (void) dpy;
Brian Paul7d5656b2001-09-01 20:23:25 +00002155
Brian Paul3265fe52002-10-05 03:02:34 +00002156 for (attrib = attribList; *attrib; attrib++) {
Brian Paul7d5656b2001-09-01 20:23:25 +00002157 switch (*attrib) {
2158 case GLX_PBUFFER_WIDTH:
Brian Paul3265fe52002-10-05 03:02:34 +00002159 attrib++;
2160 width = *attrib;
Brian Paul7d5656b2001-09-01 20:23:25 +00002161 break;
2162 case GLX_PBUFFER_HEIGHT:
Brian Paul3265fe52002-10-05 03:02:34 +00002163 attrib++;
2164 height = *attrib;
Brian Paul7d5656b2001-09-01 20:23:25 +00002165 break;
2166 case GLX_PRESERVED_CONTENTS:
Brian Paul3265fe52002-10-05 03:02:34 +00002167 attrib++;
Brian Paulc3eef602009-10-07 09:40:22 -06002168 preserveContents = *attrib;
Brian Paul7d5656b2001-09-01 20:23:25 +00002169 break;
2170 case GLX_LARGEST_PBUFFER:
Brian Paul3265fe52002-10-05 03:02:34 +00002171 attrib++;
Brian Paulc3eef602009-10-07 09:40:22 -06002172 useLargest = *attrib;
Brian Paul7d5656b2001-09-01 20:23:25 +00002173 break;
2174 default:
2175 return 0;
2176 }
2177 }
2178
2179 if (width == 0 || height == 0)
2180 return 0;
2181
Brian Paul3f8a61f2012-02-20 11:07:00 -07002182 if (width > SWRAST_MAX_WIDTH || height > SWRAST_MAX_HEIGHT) {
Brian Paulc3eef602009-10-07 09:40:22 -06002183 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2184 * allocate the largest possible buffer.
2185 */
2186 if (useLargest) {
Brian Paul3f8a61f2012-02-20 11:07:00 -07002187 width = SWRAST_MAX_WIDTH;
2188 height = SWRAST_MAX_HEIGHT;
Brian Paulc3eef602009-10-07 09:40:22 -06002189 }
2190 }
2191
Brian Paul3265fe52002-10-05 03:02:34 +00002192 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
Brian Paule4656002002-10-05 18:27:41 +00002193 /* A GLXPbuffer handle must be an X Drawable because that's what
2194 * glXMakeCurrent takes.
2195 */
Brian Paulc3eef602009-10-07 09:40:22 -06002196 if (xmbuf) {
2197 xmbuf->largestPbuffer = useLargest;
2198 xmbuf->preservedContents = preserveContents;
Brian Pauldd1a9f72005-08-25 14:07:06 +00002199 return (GLXPbuffer) xmbuf->frontxrb->pixmap;
Brian Paulc3eef602009-10-07 09:40:22 -06002200 }
2201 else {
Brian Pauldd1a9f72005-08-25 14:07:06 +00002202 return 0;
Brian Paulc3eef602009-10-07 09:40:22 -06002203 }
Brian Paul426cb9f1999-11-28 20:08:02 +00002204}
2205
2206
2207static void
2208Fake_glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
2209{
Brian Paule4656002002-10-05 18:27:41 +00002210 XMesaBuffer b = XMesaFindBuffer(dpy, pbuf);
2211 if (b) {
2212 XMesaDestroyBuffer(b);
2213 }
Brian Paul426cb9f1999-11-28 20:08:02 +00002214}
2215
2216
2217static void
2218Fake_glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
2219 unsigned int *value )
2220{
Brian Paule4656002002-10-05 18:27:41 +00002221 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, draw);
2222 if (!xmbuf)
2223 return;
Brian Paul7d5656b2001-09-01 20:23:25 +00002224
Brian Paulc3eef602009-10-07 09:40:22 -06002225 /* make sure buffer's dimensions are up to date */
2226 xmesa_check_and_update_buffer_size(NULL, xmbuf);
2227
Brian Paul7d5656b2001-09-01 20:23:25 +00002228 switch (attribute) {
2229 case GLX_WIDTH:
Brian Paul29926a12004-11-27 21:20:37 +00002230 *value = xmbuf->mesa_buffer.Width;
Brian Paule4656002002-10-05 18:27:41 +00002231 break;
Brian Paul7d5656b2001-09-01 20:23:25 +00002232 case GLX_HEIGHT:
Brian Paul29926a12004-11-27 21:20:37 +00002233 *value = xmbuf->mesa_buffer.Height;
Brian Paule4656002002-10-05 18:27:41 +00002234 break;
Brian Paul7d5656b2001-09-01 20:23:25 +00002235 case GLX_PRESERVED_CONTENTS:
Brian Paulc3eef602009-10-07 09:40:22 -06002236 *value = xmbuf->preservedContents;
Brian Paule4656002002-10-05 18:27:41 +00002237 break;
Brian Paul7d5656b2001-09-01 20:23:25 +00002238 case GLX_LARGEST_PBUFFER:
Brian Paulc3eef602009-10-07 09:40:22 -06002239 *value = xmbuf->largestPbuffer;
Brian Paule4656002002-10-05 18:27:41 +00002240 break;
Brian Paul7d5656b2001-09-01 20:23:25 +00002241 case GLX_FBCONFIG_ID:
Brian Paulf1046192002-11-10 17:07:06 +00002242 *value = xmbuf->xm_visual->visinfo->visualid;
Brian Paul7d5656b2001-09-01 20:23:25 +00002243 return;
Brianfd545642007-05-19 08:27:35 -06002244#ifdef GLX_EXT_texture_from_pixmap
2245 case GLX_TEXTURE_FORMAT_EXT:
2246 *value = xmbuf->TextureFormat;
2247 break;
2248 case GLX_TEXTURE_TARGET_EXT:
2249 *value = xmbuf->TextureTarget;
2250 break;
2251 case GLX_MIPMAP_TEXTURE_EXT:
2252 *value = xmbuf->TextureMipmap;
2253 break;
2254#endif
2255
Brian Paul7d5656b2001-09-01 20:23:25 +00002256 default:
Brianfd545642007-05-19 08:27:35 -06002257 return; /* raise BadValue error */
Brian Paul7d5656b2001-09-01 20:23:25 +00002258 }
Brian Paul426cb9f1999-11-28 20:08:02 +00002259}
2260
2261
2262static GLXContext
2263Fake_glXCreateNewContext( Display *dpy, GLXFBConfig config,
2264 int renderType, GLXContext shareList, Bool direct )
2265{
Brian Paulc00b2502014-03-01 10:21:08 -07002266 XMesaContext xmCtx;
Brian Paulf1046192002-11-10 17:07:06 +00002267 XMesaVisual xmvis = (XMesaVisual) config;
Brian Paul7d5656b2001-09-01 20:23:25 +00002268
2269 if (!dpy || !config ||
Tomasz Lis2eed9ff2013-07-18 14:19:38 -07002270 (renderType != GLX_RGBA_TYPE &&
2271 renderType != GLX_COLOR_INDEX_TYPE &&
2272 renderType != GLX_RGBA_FLOAT_TYPE_ARB &&
2273 renderType != GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT))
Brian Paul7d5656b2001-09-01 20:23:25 +00002274 return 0;
2275
Brian Paulf1046192002-11-10 17:07:06 +00002276 /* deallocate unused windows/buffers */
Andy Skinner90e227f2011-02-11 07:31:25 -08002277 XMesaGarbageCollect(dpy);
Brian Paulf1046192002-11-10 17:07:06 +00002278
Brian Paulc00b2502014-03-01 10:21:08 -07002279 xmCtx = XMesaCreateContext(xmvis, (XMesaContext) shareList);
Brian Paulf1046192002-11-10 17:07:06 +00002280
Brian Paulc00b2502014-03-01 10:21:08 -07002281 return (GLXContext) xmCtx;
Brian Paul426cb9f1999-11-28 20:08:02 +00002282}
2283
2284
2285static int
2286Fake_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
2287{
Brian Paulc00b2502014-03-01 10:21:08 -07002288 XMesaContext xmctx = (XMesaContext) ctx;
Brian Paul426cb9f1999-11-28 20:08:02 +00002289 (void) dpy;
2290 (void) ctx;
Brian Paul7d5656b2001-09-01 20:23:25 +00002291
2292 switch (attribute) {
2293 case GLX_FBCONFIG_ID:
Brian Paulf1046192002-11-10 17:07:06 +00002294 *value = xmctx->xm_visual->visinfo->visualid;
Brian Paule4656002002-10-05 18:27:41 +00002295 break;
Brian Paul7d5656b2001-09-01 20:23:25 +00002296 case GLX_RENDER_TYPE:
Ian Romanick81fe9942010-02-24 17:44:28 -08002297 *value = GLX_RGBA_TYPE;
Brian Paule4656002002-10-05 18:27:41 +00002298 break;
Brian Paul7d5656b2001-09-01 20:23:25 +00002299 case GLX_SCREEN:
2300 *value = 0;
2301 return Success;
2302 default:
2303 return GLX_BAD_ATTRIBUTE;
2304 }
Brian Paule4656002002-10-05 18:27:41 +00002305 return 0;
Brian Paul426cb9f1999-11-28 20:08:02 +00002306}
2307
2308
2309static void
2310Fake_glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask )
2311{
Brian Paule4656002002-10-05 18:27:41 +00002312 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2313 if (xmbuf)
2314 xmbuf->selectedEvents = mask;
Brian Paul426cb9f1999-11-28 20:08:02 +00002315}
2316
2317
2318static void
2319Fake_glXGetSelectedEvent( Display *dpy, GLXDrawable drawable,
2320 unsigned long *mask )
2321{
Brian Paule4656002002-10-05 18:27:41 +00002322 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2323 if (xmbuf)
2324 *mask = xmbuf->selectedEvents;
2325 else
2326 *mask = 0;
Brian Paul426cb9f1999-11-28 20:08:02 +00002327}
Brian Paulb82d9931999-11-22 21:52:23 +00002328
2329
2330
Brian Paulb0bb4f62001-05-25 21:51:02 +00002331/*** GLX_SGI_swap_control ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002332
2333static int
2334Fake_glXSwapIntervalSGI(int interval)
2335{
2336 (void) interval;
2337 return 0;
2338}
2339
Brian Paul783d7df2000-12-15 04:02:50 +00002340
2341
Brian Paulb0bb4f62001-05-25 21:51:02 +00002342/*** GLX_SGI_video_sync ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002343
Brian Paulee061062006-06-13 23:06:25 +00002344static unsigned int FrameCounter = 0;
2345
Brian Paul783d7df2000-12-15 04:02:50 +00002346static int
2347Fake_glXGetVideoSyncSGI(unsigned int *count)
2348{
Brian Paulee061062006-06-13 23:06:25 +00002349 /* this is a bogus implementation */
2350 *count = FrameCounter++;
Brian Paul783d7df2000-12-15 04:02:50 +00002351 return 0;
2352}
2353
2354static int
2355Fake_glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
2356{
Brian Paulee061062006-06-13 23:06:25 +00002357 if (divisor <= 0 || remainder < 0)
2358 return GLX_BAD_VALUE;
2359 /* this is a bogus implementation */
2360 FrameCounter++;
2361 while (FrameCounter % divisor != remainder)
2362 FrameCounter++;
2363 *count = FrameCounter;
Brian Paul783d7df2000-12-15 04:02:50 +00002364 return 0;
2365}
2366
Brian Paul783d7df2000-12-15 04:02:50 +00002367
2368
Brian Paulb0bb4f62001-05-25 21:51:02 +00002369/*** GLX_SGI_make_current_read ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002370
2371static Bool
2372Fake_glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
2373{
Brian Paula078d752002-05-27 17:06:59 +00002374 return Fake_glXMakeContextCurrent( dpy, draw, read, ctx );
Brian Paul783d7df2000-12-15 04:02:50 +00002375}
2376
Brian Paul7cf50e12001-05-24 19:06:21 +00002377/* not used
Brian Paul783d7df2000-12-15 04:02:50 +00002378static GLXDrawable
Brian Paulb0bb4f62001-05-25 21:51:02 +00002379Fake_glXGetCurrentReadDrawableSGI(void)
Brian Paul783d7df2000-12-15 04:02:50 +00002380{
2381 return 0;
2382}
Brian Paul7cf50e12001-05-24 19:06:21 +00002383*/
Brian Paul783d7df2000-12-15 04:02:50 +00002384
2385
Brian Paulb0bb4f62001-05-25 21:51:02 +00002386/*** GLX_SGIX_video_source ***/
2387#if defined(_VL_H)
Brian Paul783d7df2000-12-15 04:02:50 +00002388
2389static GLXVideoSourceSGIX
2390Fake_glXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode)
2391{
2392 (void) dpy;
2393 (void) screen;
2394 (void) server;
2395 (void) path;
2396 (void) nodeClass;
2397 (void) drainNode;
2398 return 0;
2399}
2400
2401static void
2402Fake_glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src)
2403{
2404 (void) dpy;
2405 (void) src;
2406}
2407
2408#endif
2409
2410
Brian Paulb0bb4f62001-05-25 21:51:02 +00002411/*** GLX_EXT_import_context ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002412
2413static void
2414Fake_glXFreeContextEXT(Display *dpy, GLXContext context)
2415{
2416 (void) dpy;
2417 (void) context;
2418}
2419
2420static GLXContextID
2421Fake_glXGetContextIDEXT(const GLXContext context)
2422{
2423 (void) context;
2424 return 0;
2425}
2426
Brian Paul783d7df2000-12-15 04:02:50 +00002427static GLXContext
2428Fake_glXImportContextEXT(Display *dpy, GLXContextID contextID)
2429{
2430 (void) dpy;
2431 (void) contextID;
2432 return 0;
2433}
2434
2435static int
2436Fake_glXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute, int *value)
2437{
2438 (void) dpy;
2439 (void) context;
2440 (void) attribute;
2441 (void) value;
2442 return 0;
2443}
2444
Brian Paul783d7df2000-12-15 04:02:50 +00002445
2446
Brian Paulb0bb4f62001-05-25 21:51:02 +00002447/*** GLX_SGIX_fbconfig ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002448
2449static int
2450Fake_glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value)
2451{
Brian Paul3265fe52002-10-05 03:02:34 +00002452 return Fake_glXGetFBConfigAttrib(dpy, config, attribute, value);
Brian Paul783d7df2000-12-15 04:02:50 +00002453}
2454
2455static GLXFBConfigSGIX *
2456Fake_glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list, int *nelements)
2457{
Brian Paul3265fe52002-10-05 03:02:34 +00002458 return (GLXFBConfig *) Fake_glXChooseFBConfig(dpy, screen, attrib_list, nelements);
Brian Paul783d7df2000-12-15 04:02:50 +00002459}
2460
Brian Paule4656002002-10-05 18:27:41 +00002461
Brian Paul783d7df2000-12-15 04:02:50 +00002462static GLXPixmap
2463Fake_glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap)
2464{
Brian Paule4656002002-10-05 18:27:41 +00002465 XMesaVisual xmvis = (XMesaVisual) config;
2466 XMesaBuffer xmbuf = XMesaCreatePixmapBuffer(xmvis, pixmap, 0);
Brian Paule4b23562005-05-04 20:11:35 +00002467 return xmbuf->frontxrb->pixmap; /* need to return an X ID */
Brian Paul783d7df2000-12-15 04:02:50 +00002468}
2469
Brian Paule4656002002-10-05 18:27:41 +00002470
Brian Paul783d7df2000-12-15 04:02:50 +00002471static GLXContext
2472Fake_glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct)
2473{
Brian Paulc00b2502014-03-01 10:21:08 -07002474 XMesaContext xmCtx;
Brian Paule4656002002-10-05 18:27:41 +00002475 XMesaVisual xmvis = (XMesaVisual) config;
Brian Paule4656002002-10-05 18:27:41 +00002476
2477 /* deallocate unused windows/buffers */
Andy Skinner90e227f2011-02-11 07:31:25 -08002478 XMesaGarbageCollect(dpy);
Brian Paule4656002002-10-05 18:27:41 +00002479
Brian Paulc00b2502014-03-01 10:21:08 -07002480 xmCtx = XMesaCreateContext(xmvis, (XMesaContext) share_list);
Brian Paule4656002002-10-05 18:27:41 +00002481
Brian Paulc00b2502014-03-01 10:21:08 -07002482 return (GLXContext) xmCtx;
Brian Paul783d7df2000-12-15 04:02:50 +00002483}
2484
Brian Paule4656002002-10-05 18:27:41 +00002485
Brian Paul783d7df2000-12-15 04:02:50 +00002486static XVisualInfo *
2487Fake_glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config)
2488{
Brian Paul3265fe52002-10-05 03:02:34 +00002489 return Fake_glXGetVisualFromFBConfig(dpy, config);
Brian Paul783d7df2000-12-15 04:02:50 +00002490}
2491
Brian Paule4656002002-10-05 18:27:41 +00002492
Brian Paul783d7df2000-12-15 04:02:50 +00002493static GLXFBConfigSGIX
2494Fake_glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis)
2495{
Brian Paule4656002002-10-05 18:27:41 +00002496 XMesaVisual xmvis = find_glx_visual(dpy, vis);
2497 if (!xmvis) {
2498 /* This visual wasn't found with glXChooseVisual() */
2499 xmvis = create_glx_visual(dpy, vis);
2500 }
2501
2502 return (GLXFBConfigSGIX) xmvis;
Brian Paul783d7df2000-12-15 04:02:50 +00002503}
2504
Brian Paul783d7df2000-12-15 04:02:50 +00002505
2506
Brian Paulb0bb4f62001-05-25 21:51:02 +00002507/*** GLX_SGIX_pbuffer ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002508
2509static GLXPbufferSGIX
Brian Paul3265fe52002-10-05 03:02:34 +00002510Fake_glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config,
2511 unsigned int width, unsigned int height,
2512 int *attribList)
Brian Paul783d7df2000-12-15 04:02:50 +00002513{
Brian Paul3265fe52002-10-05 03:02:34 +00002514 XMesaVisual xmvis = (XMesaVisual) config;
2515 XMesaBuffer xmbuf;
2516 const int *attrib;
2517 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2518
Brian Paul783d7df2000-12-15 04:02:50 +00002519 (void) dpy;
Brian Paul3265fe52002-10-05 03:02:34 +00002520
Brian Paul11b30282004-05-29 14:41:52 +00002521 for (attrib = attribList; attrib && *attrib; attrib++) {
Brian Paul3265fe52002-10-05 03:02:34 +00002522 switch (*attrib) {
2523 case GLX_PRESERVED_CONTENTS_SGIX:
2524 attrib++;
2525 preserveContents = *attrib; /* ignored */
2526 break;
2527 case GLX_LARGEST_PBUFFER_SGIX:
2528 attrib++;
2529 useLargest = *attrib; /* ignored */
2530 break;
2531 default:
2532 return 0;
2533 }
2534 }
2535
Brian Paulb3050282003-12-04 03:19:46 +00002536 /* not used at this time */
2537 (void) useLargest;
2538 (void) preserveContents;
2539
Brian Paul3265fe52002-10-05 03:02:34 +00002540 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
Brian Paule4656002002-10-05 18:27:41 +00002541 /* A GLXPbuffer handle must be an X Drawable because that's what
2542 * glXMakeCurrent takes.
2543 */
Brian Paule4b23562005-05-04 20:11:35 +00002544 return (GLXPbuffer) xmbuf->frontxrb->pixmap;
Brian Paul783d7df2000-12-15 04:02:50 +00002545}
2546
Brian Paule4656002002-10-05 18:27:41 +00002547
Brian Paul783d7df2000-12-15 04:02:50 +00002548static void
2549Fake_glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf)
2550{
Brian Paule4656002002-10-05 18:27:41 +00002551 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2552 if (xmbuf) {
2553 XMesaDestroyBuffer(xmbuf);
2554 }
Brian Paul783d7df2000-12-15 04:02:50 +00002555}
2556
Brian Paule4656002002-10-05 18:27:41 +00002557
Brian Paul783d7df2000-12-15 04:02:50 +00002558static int
2559Fake_glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value)
2560{
Brian Paule4656002002-10-05 18:27:41 +00002561 const XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2562
2563 if (!xmbuf) {
2564 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2565 return 0;
2566 }
2567
2568 switch (attribute) {
2569 case GLX_PRESERVED_CONTENTS_SGIX:
Brian Paulc3eef602009-10-07 09:40:22 -06002570 *value = xmbuf->preservedContents;
Brian Paule4656002002-10-05 18:27:41 +00002571 break;
2572 case GLX_LARGEST_PBUFFER_SGIX:
Brian Paulc3eef602009-10-07 09:40:22 -06002573 *value = xmbuf->largestPbuffer;
Brian Paule4656002002-10-05 18:27:41 +00002574 break;
2575 case GLX_WIDTH_SGIX:
Brian Paul29926a12004-11-27 21:20:37 +00002576 *value = xmbuf->mesa_buffer.Width;
Brian Paule4656002002-10-05 18:27:41 +00002577 break;
2578 case GLX_HEIGHT_SGIX:
Brian Paul29926a12004-11-27 21:20:37 +00002579 *value = xmbuf->mesa_buffer.Height;
Brian Paule4656002002-10-05 18:27:41 +00002580 break;
2581 case GLX_EVENT_MASK_SGIX:
2582 *value = 0; /* XXX might be wrong */
2583 break;
2584 default:
2585 *value = 0;
2586 }
Brian Paul783d7df2000-12-15 04:02:50 +00002587 return 0;
2588}
2589
Brian Paule4656002002-10-05 18:27:41 +00002590
Brian Paul783d7df2000-12-15 04:02:50 +00002591static void
2592Fake_glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask)
2593{
Brian Paule4656002002-10-05 18:27:41 +00002594 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2595 if (xmbuf) {
2596 /* Note: we'll never generate clobber events */
2597 xmbuf->selectedEvents = mask;
2598 }
Brian Paul783d7df2000-12-15 04:02:50 +00002599}
2600
Brian Paule4656002002-10-05 18:27:41 +00002601
Brian Paul783d7df2000-12-15 04:02:50 +00002602static void
2603Fake_glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long *mask)
2604{
Brian Paule4656002002-10-05 18:27:41 +00002605 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2606 if (xmbuf) {
2607 *mask = xmbuf->selectedEvents;
2608 }
2609 else {
2610 *mask = 0;
2611 }
Brian Paul783d7df2000-12-15 04:02:50 +00002612}
2613
Brian Paul783d7df2000-12-15 04:02:50 +00002614
2615
Brian Paulb0bb4f62001-05-25 21:51:02 +00002616/*** GLX_SGI_cushion ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002617
2618static void
2619Fake_glXCushionSGI(Display *dpy, Window win, float cushion)
2620{
2621 (void) dpy;
2622 (void) win;
2623 (void) cushion;
2624}
2625
Brian Paul783d7df2000-12-15 04:02:50 +00002626
2627
Brian Paulb0bb4f62001-05-25 21:51:02 +00002628/*** GLX_SGIX_video_resize ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002629
2630static int
2631Fake_glXBindChannelToWindowSGIX(Display *dpy, int screen, int channel , Window window)
2632{
2633 (void) dpy;
2634 (void) screen;
2635 (void) channel;
2636 (void) window;
2637 return 0;
2638}
2639
2640static int
2641Fake_glXChannelRectSGIX(Display *dpy, int screen, int channel, int x, int y, int w, int h)
2642{
2643 (void) dpy;
2644 (void) screen;
2645 (void) channel;
2646 (void) x;
2647 (void) y;
2648 (void) w;
2649 (void) h;
2650 return 0;
2651}
2652
2653static int
2654Fake_glXQueryChannelRectSGIX(Display *dpy, int screen, int channel, int *x, int *y, int *w, int *h)
2655{
2656 (void) dpy;
2657 (void) screen;
2658 (void) channel;
2659 (void) x;
2660 (void) y;
2661 (void) w;
2662 (void) h;
2663 return 0;
2664}
2665
2666static int
2667Fake_glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel, int *dx, int *dy, int *dw, int *dh)
2668{
2669 (void) dpy;
2670 (void) screen;
2671 (void) channel;
2672 (void) dx;
2673 (void) dy;
2674 (void) dw;
2675 (void) dh;
2676 return 0;
2677}
2678
2679static int
2680Fake_glXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype)
2681{
2682 (void) dpy;
2683 (void) screen;
2684 (void) channel;
2685 (void) synctype;
2686 return 0;
2687}
2688
Brian Paul783d7df2000-12-15 04:02:50 +00002689
2690
Brian Paulb0bb4f62001-05-25 21:51:02 +00002691/*** GLX_SGIX_dmbuffer **/
Brian Paul783d7df2000-12-15 04:02:50 +00002692
Brian Paulb0bb4f62001-05-25 21:51:02 +00002693#if defined(_DM_BUFFER_H_)
Brian Paul783d7df2000-12-15 04:02:50 +00002694static Bool
2695Fake_glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer)
2696{
2697 (void) dpy;
2698 (void) pbuffer;
2699 (void) params;
2700 (void) dmbuffer;
2701 return False;
2702}
Brian Paul783d7df2000-12-15 04:02:50 +00002703#endif
2704
2705
Brian Paulb0bb4f62001-05-25 21:51:02 +00002706/*** GLX_SGIX_swap_group ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002707
2708static void
2709Fake_glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, GLXDrawable member)
2710{
2711 (void) dpy;
2712 (void) drawable;
2713 (void) member;
2714}
2715
Brian Paul783d7df2000-12-15 04:02:50 +00002716
2717
Brian Paulb0bb4f62001-05-25 21:51:02 +00002718/*** GLX_SGIX_swap_barrier ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002719
2720static void
2721Fake_glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, int barrier)
2722{
2723 (void) dpy;
2724 (void) drawable;
2725 (void) barrier;
2726}
2727
2728static Bool
2729Fake_glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
2730{
2731 (void) dpy;
2732 (void) screen;
2733 (void) max;
2734 return False;
2735}
2736
Brian Paul783d7df2000-12-15 04:02:50 +00002737
2738
Brian Paulb0bb4f62001-05-25 21:51:02 +00002739/*** GLX_SUN_get_transparent_index ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002740
2741static Status
2742Fake_glXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay, long *pTransparent)
2743{
2744 (void) dpy;
2745 (void) overlay;
2746 (void) underlay;
2747 (void) pTransparent;
2748 return 0;
2749}
2750
Brian Paul783d7df2000-12-15 04:02:50 +00002751
2752
Brian Paulb0bb4f62001-05-25 21:51:02 +00002753/*** GLX_MESA_release_buffers ***/
2754
jtgafb833d1999-08-19 00:55:39 +00002755/*
2756 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2757 * (a window or pixmap) prior to destroying the GLXDrawable.
2758 */
Brian Paul426cb9f1999-11-28 20:08:02 +00002759static Bool
2760Fake_glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
jtgafb833d1999-08-19 00:55:39 +00002761{
2762 XMesaBuffer b = XMesaFindBuffer(dpy, d);
2763 if (b) {
2764 XMesaDestroyBuffer(b);
2765 return True;
2766 }
2767 return False;
2768}
2769
2770
Brian Paul4c07bd52000-06-08 22:50:28 +00002771
Brian Paulb0bb4f62001-05-25 21:51:02 +00002772/*** GLX_MESA_set_3dfx_mode ***/
2773
Brian Paul45360212000-12-14 17:44:08 +00002774static Bool
2775Fake_glXSet3DfxModeMESA( int mode )
jtgafb833d1999-08-19 00:55:39 +00002776{
Brian Paul43c9c2c1999-09-16 15:52:51 +00002777 return XMesaSetFXmode( mode );
jtgafb833d1999-08-19 00:55:39 +00002778}
Brian Paul4c07bd52000-06-08 22:50:28 +00002779
Brian Paul89a42b71999-09-11 11:33:45 +00002780
2781
Brian Paul3c5bfac2003-01-14 04:49:07 +00002782/*** GLX_NV_vertex_array range ***/
Brian Paul8fefafa2002-08-22 21:10:01 +00002783static void *
2784Fake_glXAllocateMemoryNV( GLsizei size,
2785 GLfloat readFrequency,
2786 GLfloat writeFrequency,
2787 GLfloat priority )
2788{
2789 (void) size;
2790 (void) readFrequency;
2791 (void) writeFrequency;
2792 (void) priority;
2793 return NULL;
2794}
2795
2796
2797static void
2798Fake_glXFreeMemoryNV( GLvoid *pointer )
2799{
2800 (void) pointer;
2801}
2802
2803
Brian Paul3c5bfac2003-01-14 04:49:07 +00002804/*** GLX_MESA_agp_offset ***/
Brian Pauld6113fc2002-11-18 15:11:49 +00002805
2806static GLuint
2807Fake_glXGetAGPOffsetMESA( const GLvoid *pointer )
2808{
2809 (void) pointer;
2810 return ~0;
2811}
2812
2813
Brianfd545642007-05-19 08:27:35 -06002814/*** GLX_EXT_texture_from_pixmap ***/
2815
2816static void
2817Fake_glXBindTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer,
2818 const int *attrib_list)
2819{
2820 XMesaBuffer b = XMesaFindBuffer(dpy, drawable);
2821 if (b)
2822 XMesaBindTexImage(dpy, b, buffer, attrib_list);
2823}
2824
2825static void
2826Fake_glXReleaseTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer)
2827{
2828 XMesaBuffer b = XMesaFindBuffer(dpy, drawable);
2829 if (b)
2830 XMesaReleaseTexImage(dpy, b, buffer);
2831}
2832
2833
Brian Paul7287bbf2004-09-23 17:30:54 +00002834/* silence warning */
Brian Paule7b16b72000-03-17 15:33:09 +00002835extern struct _glxapi_table *_mesa_GetGLXDispatchTable(void);
Brian Paul7287bbf2004-09-23 17:30:54 +00002836
2837
2838/**
2839 * Create a new GLX API dispatch table with its function pointers
2840 * initialized to point to Mesa's "fake" GLX API functions.
2841 * Note: there's a similar function (_real_GetGLXDispatchTable) that
2842 * returns a new dispatch table with all pointers initalized to point
2843 * to "real" GLX functions (which understand GLX wire protocol, etc).
2844 */
2845struct _glxapi_table *
2846_mesa_GetGLXDispatchTable(void)
Brian Paul426cb9f1999-11-28 20:08:02 +00002847{
2848 static struct _glxapi_table glx;
2849
2850 /* be sure our dispatch table size <= libGL's table */
2851 {
Brian Paul01915e92001-03-08 15:23:46 +00002852 GLuint size = sizeof(struct _glxapi_table) / sizeof(void *);
Brian Paul426cb9f1999-11-28 20:08:02 +00002853 (void) size;
2854 assert(_glxapi_get_dispatch_table_size() >= size);
2855 }
2856
2857 /* initialize the whole table to no-ops */
2858 _glxapi_set_no_op_table(&glx);
2859
2860 /* now initialize the table with the functions I implement */
2861 glx.ChooseVisual = Fake_glXChooseVisual;
2862 glx.CopyContext = Fake_glXCopyContext;
2863 glx.CreateContext = Fake_glXCreateContext;
2864 glx.CreateGLXPixmap = Fake_glXCreateGLXPixmap;
2865 glx.DestroyContext = Fake_glXDestroyContext;
2866 glx.DestroyGLXPixmap = Fake_glXDestroyGLXPixmap;
2867 glx.GetConfig = Fake_glXGetConfig;
Brian Paulc00b2502014-03-01 10:21:08 -07002868 glx.GetCurrentContext = Fake_glXGetCurrentContext;
Brian Paul426cb9f1999-11-28 20:08:02 +00002869 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2870 glx.IsDirect = Fake_glXIsDirect;
2871 glx.MakeCurrent = Fake_glXMakeCurrent;
2872 glx.QueryExtension = Fake_glXQueryExtension;
2873 glx.QueryVersion = Fake_glXQueryVersion;
2874 glx.SwapBuffers = Fake_glXSwapBuffers;
2875 glx.UseXFont = Fake_glXUseXFont;
2876 glx.WaitGL = Fake_glXWaitGL;
2877 glx.WaitX = Fake_glXWaitX;
2878
Brian Paulb0bb4f62001-05-25 21:51:02 +00002879 /*** GLX_VERSION_1_1 ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002880 glx.GetClientString = Fake_glXGetClientString;
2881 glx.QueryExtensionsString = Fake_glXQueryExtensionsString;
2882 glx.QueryServerString = Fake_glXQueryServerString;
Brian Paul426cb9f1999-11-28 20:08:02 +00002883
Brian Paulb0bb4f62001-05-25 21:51:02 +00002884 /*** GLX_VERSION_1_2 ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002885 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
Brian Paul426cb9f1999-11-28 20:08:02 +00002886
Brian Paulb0bb4f62001-05-25 21:51:02 +00002887 /*** GLX_VERSION_1_3 ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002888 glx.ChooseFBConfig = Fake_glXChooseFBConfig;
2889 glx.CreateNewContext = Fake_glXCreateNewContext;
2890 glx.CreatePbuffer = Fake_glXCreatePbuffer;
2891 glx.CreatePixmap = Fake_glXCreatePixmap;
2892 glx.CreateWindow = Fake_glXCreateWindow;
2893 glx.DestroyPbuffer = Fake_glXDestroyPbuffer;
2894 glx.DestroyPixmap = Fake_glXDestroyPixmap;
2895 glx.DestroyWindow = Fake_glXDestroyWindow;
2896 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2897 glx.GetFBConfigAttrib = Fake_glXGetFBConfigAttrib;
Brian Paul71dea342000-04-19 01:44:01 +00002898 glx.GetFBConfigs = Fake_glXGetFBConfigs;
Brian Paul426cb9f1999-11-28 20:08:02 +00002899 glx.GetSelectedEvent = Fake_glXGetSelectedEvent;
2900 glx.GetVisualFromFBConfig = Fake_glXGetVisualFromFBConfig;
2901 glx.MakeContextCurrent = Fake_glXMakeContextCurrent;
2902 glx.QueryContext = Fake_glXQueryContext;
2903 glx.QueryDrawable = Fake_glXQueryDrawable;
2904 glx.SelectEvent = Fake_glXSelectEvent;
Brian Paul426cb9f1999-11-28 20:08:02 +00002905
Brian Paulb0bb4f62001-05-25 21:51:02 +00002906 /*** GLX_SGI_swap_control ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002907 glx.SwapIntervalSGI = Fake_glXSwapIntervalSGI;
Brian Paul783d7df2000-12-15 04:02:50 +00002908
Brian Paulb0bb4f62001-05-25 21:51:02 +00002909 /*** GLX_SGI_video_sync ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002910 glx.GetVideoSyncSGI = Fake_glXGetVideoSyncSGI;
2911 glx.WaitVideoSyncSGI = Fake_glXWaitVideoSyncSGI;
Brian Paul426cb9f1999-11-28 20:08:02 +00002912
Brian Paulb0bb4f62001-05-25 21:51:02 +00002913 /*** GLX_SGI_make_current_read ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002914 glx.MakeCurrentReadSGI = Fake_glXMakeCurrentReadSGI;
Brian Paul7cf50e12001-05-24 19:06:21 +00002915 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
Brian Paul783d7df2000-12-15 04:02:50 +00002916
Brian Paulb0bb4f62001-05-25 21:51:02 +00002917/*** GLX_SGIX_video_source ***/
2918#if defined(_VL_H)
Brian Paul783d7df2000-12-15 04:02:50 +00002919 glx.CreateGLXVideoSourceSGIX = Fake_glXCreateGLXVideoSourceSGIX;
2920 glx.DestroyGLXVideoSourceSGIX = Fake_glXDestroyGLXVideoSourceSGIX;
2921#endif
2922
Brian Paulb0bb4f62001-05-25 21:51:02 +00002923 /*** GLX_EXT_import_context ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002924 glx.FreeContextEXT = Fake_glXFreeContextEXT;
2925 glx.GetContextIDEXT = Fake_glXGetContextIDEXT;
Brian Paul7cf50e12001-05-24 19:06:21 +00002926 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
Brian Paul783d7df2000-12-15 04:02:50 +00002927 glx.ImportContextEXT = Fake_glXImportContextEXT;
2928 glx.QueryContextInfoEXT = Fake_glXQueryContextInfoEXT;
Brian Paul45360212000-12-14 17:44:08 +00002929
Brian Paulb0bb4f62001-05-25 21:51:02 +00002930 /*** GLX_SGIX_fbconfig ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002931 glx.GetFBConfigAttribSGIX = Fake_glXGetFBConfigAttribSGIX;
2932 glx.ChooseFBConfigSGIX = Fake_glXChooseFBConfigSGIX;
2933 glx.CreateGLXPixmapWithConfigSGIX = Fake_glXCreateGLXPixmapWithConfigSGIX;
2934 glx.CreateContextWithConfigSGIX = Fake_glXCreateContextWithConfigSGIX;
2935 glx.GetVisualFromFBConfigSGIX = Fake_glXGetVisualFromFBConfigSGIX;
2936 glx.GetFBConfigFromVisualSGIX = Fake_glXGetFBConfigFromVisualSGIX;
Brian Paul783d7df2000-12-15 04:02:50 +00002937
Brian Paulb0bb4f62001-05-25 21:51:02 +00002938 /*** GLX_SGIX_pbuffer ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002939 glx.CreateGLXPbufferSGIX = Fake_glXCreateGLXPbufferSGIX;
2940 glx.DestroyGLXPbufferSGIX = Fake_glXDestroyGLXPbufferSGIX;
2941 glx.QueryGLXPbufferSGIX = Fake_glXQueryGLXPbufferSGIX;
2942 glx.SelectEventSGIX = Fake_glXSelectEventSGIX;
2943 glx.GetSelectedEventSGIX = Fake_glXGetSelectedEventSGIX;
Brian Paul783d7df2000-12-15 04:02:50 +00002944
Brian Paulb0bb4f62001-05-25 21:51:02 +00002945 /*** GLX_SGI_cushion ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002946 glx.CushionSGI = Fake_glXCushionSGI;
Brian Paul783d7df2000-12-15 04:02:50 +00002947
Brian Paulb0bb4f62001-05-25 21:51:02 +00002948 /*** GLX_SGIX_video_resize ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002949 glx.BindChannelToWindowSGIX = Fake_glXBindChannelToWindowSGIX;
2950 glx.ChannelRectSGIX = Fake_glXChannelRectSGIX;
2951 glx.QueryChannelRectSGIX = Fake_glXQueryChannelRectSGIX;
2952 glx.QueryChannelDeltasSGIX = Fake_glXQueryChannelDeltasSGIX;
2953 glx.ChannelRectSyncSGIX = Fake_glXChannelRectSyncSGIX;
Brian Paul783d7df2000-12-15 04:02:50 +00002954
Brian Paulb0bb4f62001-05-25 21:51:02 +00002955 /*** GLX_SGIX_dmbuffer **/
2956#if defined(_DM_BUFFER_H_)
Brian Paul783d7df2000-12-15 04:02:50 +00002957 glx.AssociateDMPbufferSGIX = NULL;
2958#endif
2959
Brian Paulb0bb4f62001-05-25 21:51:02 +00002960 /*** GLX_SGIX_swap_group ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002961 glx.JoinSwapGroupSGIX = Fake_glXJoinSwapGroupSGIX;
Brian Paul783d7df2000-12-15 04:02:50 +00002962
Brian Paulb0bb4f62001-05-25 21:51:02 +00002963 /*** GLX_SGIX_swap_barrier ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002964 glx.BindSwapBarrierSGIX = Fake_glXBindSwapBarrierSGIX;
2965 glx.QueryMaxSwapBarriersSGIX = Fake_glXQueryMaxSwapBarriersSGIX;
Brian Paul783d7df2000-12-15 04:02:50 +00002966
Brian Paulb0bb4f62001-05-25 21:51:02 +00002967 /*** GLX_SUN_get_transparent_index ***/
Brian Paul783d7df2000-12-15 04:02:50 +00002968 glx.GetTransparentIndexSUN = Fake_glXGetTransparentIndexSUN;
Brian Paul45360212000-12-14 17:44:08 +00002969
Brian Paulb0bb4f62001-05-25 21:51:02 +00002970 /*** GLX_MESA_copy_sub_buffer ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002971 glx.CopySubBufferMESA = Fake_glXCopySubBufferMESA;
Brian Paul426cb9f1999-11-28 20:08:02 +00002972
Brian Paulb0bb4f62001-05-25 21:51:02 +00002973 /*** GLX_MESA_release_buffers ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002974 glx.ReleaseBuffersMESA = Fake_glXReleaseBuffersMESA;
Brian Paul426cb9f1999-11-28 20:08:02 +00002975
Brian Paulb0bb4f62001-05-25 21:51:02 +00002976 /*** GLX_MESA_pixmap_colormap ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002977 glx.CreateGLXPixmapMESA = Fake_glXCreateGLXPixmapMESA;
Brian Paul426cb9f1999-11-28 20:08:02 +00002978
Brian Paulb0bb4f62001-05-25 21:51:02 +00002979 /*** GLX_MESA_set_3dfx_mode ***/
Brian Paul426cb9f1999-11-28 20:08:02 +00002980 glx.Set3DfxModeMESA = Fake_glXSet3DfxModeMESA;
Brian Paul426cb9f1999-11-28 20:08:02 +00002981
Brian Pauld6113fc2002-11-18 15:11:49 +00002982 /*** GLX_NV_vertex_array_range ***/
Brian Paul8fefafa2002-08-22 21:10:01 +00002983 glx.AllocateMemoryNV = Fake_glXAllocateMemoryNV;
2984 glx.FreeMemoryNV = Fake_glXFreeMemoryNV;
2985
Brian Pauld6113fc2002-11-18 15:11:49 +00002986 /*** GLX_MESA_agp_offset ***/
2987 glx.GetAGPOffsetMESA = Fake_glXGetAGPOffsetMESA;
2988
Brianfd545642007-05-19 08:27:35 -06002989 /*** GLX_EXT_texture_from_pixmap ***/
2990 glx.BindTexImageEXT = Fake_glXBindTexImageEXT;
2991 glx.ReleaseTexImageEXT = Fake_glXReleaseTexImageEXT;
2992
Brian Paul426cb9f1999-11-28 20:08:02 +00002993 return &glx;
2994}