2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * 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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * 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
20 * 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.
28 * "Fake" GLX API implemented in terms of the XMesa*() functions.
33 #define GLX_GLXEXT_PROTOTYPES
39 #include <GL/glxproto.h>
43 /* An "Atrribs/Attribs" typo was fixed in glxproto.h in Nov 2014.
44 * This is in case we don't have the updated header.
46 #if !defined(X_GLXCreateContextAttribsARB) && \
47 defined(X_GLXCreateContextAtrribsARB)
48 #define X_GLXCreateContextAttribsARB X_GLXCreateContextAtrribsARB
51 /* This indicates the client-side GLX API and GLX encoder version. */
52 #define CLIENT_MAJOR_VERSION 1
53 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
55 /* This indicates the server-side GLX decoder version.
56 * GLX 1.4 indicates OpenGL 1.3 support
58 #define SERVER_MAJOR_VERSION 1
59 #define SERVER_MINOR_VERSION 4
61 /* Who implemented this GLX? */
62 #define VENDOR "Brian Paul"
65 "GLX_MESA_copy_sub_buffer " \
66 "GLX_MESA_pixmap_colormap " \
67 "GLX_MESA_release_buffers " \
68 "GLX_ARB_create_context " \
69 "GLX_ARB_create_context_profile " \
70 "GLX_ARB_get_proc_address " \
71 "GLX_EXT_create_context_es_profile " \
72 "GLX_EXT_create_context_es2_profile " \
73 "GLX_EXT_texture_from_pixmap " \
74 "GLX_EXT_visual_info " \
75 "GLX_EXT_visual_rating " \
76 /*"GLX_SGI_video_sync "*/ \
77 "GLX_SGIX_fbconfig " \
80 #define DEFAULT_DIRECT GL_TRUE
83 /** XXX this could be based on gallium's max texture size */
84 #define PBUFFER_MAX_SIZE 16384
88 * The GLXContext typedef is defined as a pointer to this structure.
90 struct __GLXcontextRec
94 GLXDrawable currentDrawable
;
95 GLXDrawable currentReadable
;
98 XMesaContext xmesaContext
;
103 static pipe_tsd ContextTSD
;
105 /** Set current context for calling thread */
107 SetCurrentContext(GLXContext c
)
109 pipe_tsd_set(&ContextTSD
, c
);
112 /** Get current context for calling thread */
114 GetCurrentContext(void)
116 return pipe_tsd_get(&ContextTSD
);
121 /**********************************************************************/
122 /*** GLX Visual Code ***/
123 /**********************************************************************/
128 static XMesaVisual
*VisualTable
= NULL
;
129 static int NumVisuals
= 0;
133 /* Macro to handle c_class vs class field name in XVisualInfo struct */
134 #if defined(__cplusplus) || defined(c_plusplus)
135 #define CLASS c_class
143 * Test if the given XVisualInfo is usable for Mesa rendering.
146 is_usable_visual( XVisualInfo
*vinfo
)
148 switch (vinfo
->CLASS
) {
151 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
155 /* Any StaticColor/PseudoColor visual of at least 4 bits */
156 if (vinfo
->depth
>=4) {
164 /* Any depth of TrueColor or DirectColor works in RGB mode */
167 /* This should never happen */
174 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
175 * configuration in our list of GLX visuals.
178 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
179 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
180 GLboolean stereoFlag
,
181 GLint depth_size
, GLint stencil_size
,
182 GLint accumRedSize
, GLint accumGreenSize
,
183 GLint accumBlueSize
, GLint accumAlphaSize
,
184 GLint level
, GLint numAuxBuffers
)
186 GLboolean ximageFlag
= GL_TRUE
;
189 GLboolean comparePointers
;
192 /* Check if the MESA_BACK_BUFFER env var is set */
193 char *backbuffer
= getenv("MESA_BACK_BUFFER");
195 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
196 ximageFlag
= GL_FALSE
;
198 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
199 ximageFlag
= GL_TRUE
;
202 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
208 /* stereo not supported */
212 if (stencil_size
> 0 && depth_size
> 0)
215 /* Comparing IDs uses less memory but sometimes fails. */
216 /* XXX revisit this after 3.0 is finished. */
217 if (getenv("MESA_GLX_VISUAL_HACK"))
218 comparePointers
= GL_TRUE
;
220 comparePointers
= GL_FALSE
;
222 /* Force the visual to have an alpha channel */
223 if (rgbFlag
&& getenv("MESA_GLX_FORCE_ALPHA"))
226 /* First check if a matching visual is already in the list */
227 for (i
=0; i
<NumVisuals
; i
++) {
228 XMesaVisual v
= VisualTable
[i
];
229 if (v
->display
== dpy
230 && v
->mesa_visual
.level
== level
231 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
232 && v
->ximage_flag
== ximageFlag
233 && v
->mesa_visual
.rgbMode
== rgbFlag
234 && v
->mesa_visual
.doubleBufferMode
== dbFlag
235 && v
->mesa_visual
.stereoMode
== stereoFlag
236 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
237 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
238 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
239 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
240 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
241 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
242 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
243 /* now either compare XVisualInfo pointers or visual IDs */
244 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
245 || (comparePointers
&& v
->vishandle
== vinfo
)) {
251 /* Create a new visual and add it to the list. */
253 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
254 stereoFlag
, ximageFlag
,
255 depth_size
, stencil_size
,
256 accumRedSize
, accumBlueSize
,
257 accumBlueSize
, accumAlphaSize
, 0, level
,
260 /* Save a copy of the pointer now so we can find this visual again
261 * if we need to search for it in find_glx_visual().
263 xmvis
->vishandle
= vinfo
;
264 /* Allocate more space for additional visual */
265 VisualTable
= realloc(VisualTable
, sizeof(XMesaVisual
) * (NumVisuals
+ 1));
266 /* add xmvis to the list */
267 VisualTable
[NumVisuals
] = xmvis
;
269 /* XXX minor hack, because XMesaCreateVisual doesn't support an
270 * aux buffers parameter.
272 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
279 * Return the default number of bits for the Z buffer.
280 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
281 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
282 * XXX probably do the same thing for stencil, accum, etc.
285 default_depth_bits(void)
288 const char *zEnv
= getenv("MESA_GLX_DEPTH_BITS");
297 default_alpha_bits(void)
300 const char *aEnv
= getenv("MESA_GLX_ALPHA_BITS");
309 default_accum_bits(void)
317 * Create a GLX visual from a regular XVisualInfo.
318 * This is called when Fake GLX is given an XVisualInfo which wasn't
319 * returned by glXChooseVisual. Since this is the first time we're
320 * considering this visual we'll take a guess at reasonable values
321 * for depth buffer size, stencil size, accum size, etc.
322 * This is the best we can do with a client-side emulation of GLX.
325 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
327 GLint zBits
= default_depth_bits();
328 GLint accBits
= default_accum_bits();
329 GLboolean alphaFlag
= default_alpha_bits() > 0;
331 if (is_usable_visual( visinfo
)) {
332 /* Configure this visual as RGB, double-buffered, depth-buffered. */
333 /* This is surely wrong for some people's needs but what else */
334 /* can be done? They should use glXChooseVisual(). */
335 return save_glx_visual( dpy
, visinfo
,
337 alphaFlag
, /* alpha */
338 GL_TRUE
, /* double */
339 GL_FALSE
, /* stereo */
341 8, /* stencil bits */
351 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
359 * Find the GLX visual associated with an XVisualInfo.
362 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
366 /* try to match visual id */
367 for (i
=0;i
<NumVisuals
;i
++) {
368 if (VisualTable
[i
]->display
==dpy
369 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
370 return VisualTable
[i
];
374 /* if that fails, try to match pointers */
375 for (i
=0;i
<NumVisuals
;i
++) {
376 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
377 return VisualTable
[i
];
386 * Try to get an X visual which matches the given arguments.
389 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
391 XVisualInfo temp
, *vis
;
394 unsigned int default_depth
;
397 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
402 default_depth
= DefaultDepth(dpy
,scr
);
403 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
405 if (depth
==default_depth
&& xclass
==default_class
) {
406 /* try to get root window's visual */
407 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
408 mask
|= VisualIDMask
;
411 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
413 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
414 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
415 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
417 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
418 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
419 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
420 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
434 * Retrieve the value of the given environment variable and find
435 * the X visual which matches it.
436 * Input: dpy - the display
437 * screen - the screen number
438 * varname - the name of the environment variable
439 * Return: an XVisualInfo pointer to NULL if error.
442 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
444 char value
[100], type
[100];
445 int depth
, xclass
= -1;
448 if (!getenv( varname
)) {
452 strncpy( value
, getenv(varname
), 100 );
455 sscanf( value
, "%s %d", type
, &depth
);
457 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
458 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
459 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
460 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
461 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
462 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
464 if (xclass
>-1 && depth
>0) {
465 vis
= get_visual( dpy
, scr
, depth
, xclass
);
471 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
480 * Select an X visual which satisfies the RGBA flag and minimum depth.
482 * screen - X display and screen number
483 * min_depth - minimum visual depth
484 * preferred_class - preferred GLX visual class or DONT_CARE
485 * Return: pointer to an XVisualInfo or NULL.
488 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
489 int preferred_class
)
492 int xclass
, visclass
= 0;
495 /* First see if the MESA_RGB_VISUAL env var is defined */
496 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
500 /* Otherwise, search for a suitable visual */
501 if (preferred_class
==DONT_CARE
) {
502 for (xclass
=0;xclass
<6;xclass
++) {
504 case 0: visclass
= TrueColor
; break;
505 case 1: visclass
= DirectColor
; break;
506 case 2: visclass
= PseudoColor
; break;
507 case 3: visclass
= StaticColor
; break;
508 case 4: visclass
= GrayScale
; break;
509 case 5: visclass
= StaticGray
; break;
512 /* start with shallowest */
513 for (depth
=0;depth
<=32;depth
++) {
514 if (visclass
==TrueColor
&& depth
==8) {
515 /* Special case: try to get 8-bit PseudoColor before */
516 /* 8-bit TrueColor */
517 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
522 vis
= get_visual( dpy
, screen
, depth
, visclass
);
529 /* start with deepest */
530 for (depth
=32;depth
>=min_depth
;depth
--) {
531 if (visclass
==TrueColor
&& depth
==8) {
532 /* Special case: try to get 8-bit PseudoColor before */
533 /* 8-bit TrueColor */
534 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
539 vis
= get_visual( dpy
, screen
, depth
, visclass
);
548 /* search for a specific visual class */
549 switch (preferred_class
) {
550 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
551 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
552 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
553 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
554 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
555 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
556 default: return NULL
;
559 /* start with shallowest */
560 for (depth
=0;depth
<=32;depth
++) {
561 vis
= get_visual( dpy
, screen
, depth
, visclass
);
568 /* start with deepest */
569 for (depth
=32;depth
>=min_depth
;depth
--) {
570 vis
= get_visual( dpy
, screen
, depth
, visclass
);
578 /* didn't find a visual */
585 /**********************************************************************/
586 /*** Display-related functions ***/
587 /**********************************************************************/
591 * Free all XMesaVisuals which are associated with the given display.
594 destroy_visuals_on_display(Display
*dpy
)
597 for (i
= 0; i
< NumVisuals
; i
++) {
598 if (VisualTable
[i
]->display
== dpy
) {
599 /* remove this visual */
601 free(VisualTable
[i
]);
602 for (j
= i
; j
< NumVisuals
- 1; j
++)
603 VisualTable
[j
] = VisualTable
[j
+ 1];
611 * Called from XCloseDisplay() to let us free our display-related data.
614 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
616 xmesa_destroy_buffers_on_display(dpy
);
617 destroy_visuals_on_display(dpy
);
623 * Look for the named extension on given display and return a pointer
624 * to the _XExtension data, or NULL if extension not found.
627 lookup_extension(Display
*dpy
, const char *extName
)
630 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
631 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
640 * Whenever we're given a new Display pointer, call this function to
641 * register our close_display_callback function.
644 register_with_display(Display
*dpy
)
646 const char *extName
= "MesaGLX";
649 ext
= lookup_extension(dpy
, extName
);
651 XExtCodes
*c
= XAddExtension(dpy
);
652 ext
= dpy
->ext_procs
; /* new extension is at head of list */
653 assert(c
->extension
== ext
->codes
.extension
);
655 ext
->name
= strdup(extName
);
656 ext
->close_display
= close_display_callback
;
665 generate_error(Display
*dpy
,
666 unsigned char error_code
,
668 unsigned char minor_code
,
671 XErrorHandler handler
;
677 handler
= XSetErrorHandler(NULL
);
678 XSetErrorHandler(handler
);
683 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_opcode
, &first_event
, &first_error
)) {
690 error_code
+= first_error
;
693 memset(&event
, 0, sizeof event
);
695 event
.xerror
.type
= X_Error
;
696 event
.xerror
.display
= dpy
;
697 event
.xerror
.resourceid
= resourceid
;
698 event
.xerror
.serial
= NextRequest(dpy
) - 1;
699 event
.xerror
.error_code
= error_code
;
700 event
.xerror
.request_code
= major_opcode
;
701 event
.xerror
.minor_code
= minor_code
;
703 return handler(dpy
, &event
.xerror
);
707 /**********************************************************************/
708 /*** Begin Fake GLX API Functions ***/
709 /**********************************************************************/
713 * Helper used by glXChooseVisual and glXChooseFBConfig.
714 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
716 * In either case, the attribute list is terminated with the value 'None'.
719 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
721 const GLboolean rgbModeDefault
= fbConfig
;
722 const int *parselist
;
724 int min_red
=0, min_green
=0, min_blue
=0;
725 GLboolean rgb_flag
= rgbModeDefault
;
726 GLboolean alpha_flag
= GL_FALSE
;
727 GLboolean double_flag
= GL_FALSE
;
728 GLboolean stereo_flag
= GL_FALSE
;
729 GLint depth_size
= 0;
730 GLint stencil_size
= 0;
731 GLint accumRedSize
= 0;
732 GLint accumGreenSize
= 0;
733 GLint accumBlueSize
= 0;
734 GLint accumAlphaSize
= 0;
736 int visual_type
= DONT_CARE
;
737 GLint caveat
= DONT_CARE
;
738 XMesaVisual xmvis
= NULL
;
739 int desiredVisualID
= -1;
749 parselist
[1] == GLX_DONT_CARE
&&
750 parselist
[0] != GLX_LEVEL
) {
751 /* For glXChooseFBConfig(), skip attributes whose value is
752 * GLX_DONT_CARE, unless it's GLX_LEVEL (which can legitimately be
755 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
756 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
762 switch (*parselist
) {
773 case GLX_BUFFER_SIZE
:
779 level
= *parselist
++;
791 case GLX_DOUBLEBUFFER
:
794 double_flag
= *parselist
++;
797 double_flag
= GL_TRUE
;
803 stereo_flag
= *parselist
++;
806 stereo_flag
= GL_TRUE
;
809 case GLX_AUX_BUFFERS
:
811 numAux
= *parselist
++;
812 if (numAux
> MAX_AUX_BUFFERS
)
817 min_red
= *parselist
++;
821 min_green
= *parselist
++;
825 min_blue
= *parselist
++;
830 GLint size
= *parselist
++;
831 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
836 depth_size
= *parselist
++;
838 case GLX_STENCIL_SIZE
:
840 stencil_size
= *parselist
++;
842 case GLX_ACCUM_RED_SIZE
:
845 GLint size
= *parselist
++;
846 accumRedSize
= MAX2( accumRedSize
, size
);
849 case GLX_ACCUM_GREEN_SIZE
:
852 GLint size
= *parselist
++;
853 accumGreenSize
= MAX2( accumGreenSize
, size
);
856 case GLX_ACCUM_BLUE_SIZE
:
859 GLint size
= *parselist
++;
860 accumBlueSize
= MAX2( accumBlueSize
, size
);
863 case GLX_ACCUM_ALPHA_SIZE
:
866 GLint size
= *parselist
++;
867 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
872 * GLX_EXT_visual_info extension
874 case GLX_X_VISUAL_TYPE_EXT
:
876 visual_type
= *parselist
++;
878 case GLX_TRANSPARENT_TYPE_EXT
:
882 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
886 case GLX_TRANSPARENT_RED_VALUE_EXT
:
887 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
888 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
889 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
896 * GLX_EXT_visual_info extension
898 case GLX_VISUAL_CAVEAT_EXT
:
900 caveat
= *parselist
++; /* ignored for now */
904 * GLX_ARB_multisample
906 case GLX_SAMPLE_BUFFERS_ARB
:
907 case GLX_SAMPLES_ARB
:
909 if (*parselist
++ != 0) {
910 /* ms not supported */
918 case GLX_RENDER_TYPE
:
922 if (*parselist
& GLX_RGBA_BIT
) {
925 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
928 else if (*parselist
== 0) {
933 case GLX_DRAWABLE_TYPE
:
937 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
938 return NULL
; /* bad bit */
942 case GLX_FBCONFIG_ID
:
947 desiredVisualID
= *parselist
++;
949 case GLX_X_RENDERABLE
:
950 case GLX_MAX_PBUFFER_WIDTH
:
951 case GLX_MAX_PBUFFER_HEIGHT
:
952 case GLX_MAX_PBUFFER_PIXELS
:
954 return NULL
; /* invalid config option */
955 parselist
+= 2; /* ignore the parameter */
958 #ifdef GLX_EXT_texture_from_pixmap
959 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
960 parselist
++; /*skip*/
962 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
963 parselist
++; /*skip*/
965 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
966 parselist
++; /*skip*/
968 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
970 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
971 GLX_TEXTURE_2D_BIT_EXT
|
972 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
977 case GLX_Y_INVERTED_EXT
:
978 parselist
++; /*skip*/
987 /* undefined attribute */
988 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
998 * Since we're only simulating the GLX extension this function will never
999 * find any real GL visuals. Instead, all we can do is try to find an RGB
1000 * or CI visual of appropriate depth. Other requested attributes such as
1001 * double buffering, depth buffer, etc. will be associated with the X
1002 * visual and stored in the VisualTable[].
1004 if (desiredVisualID
!= -1) {
1005 /* try to get a specific visual, by visualID */
1008 temp
.visualid
= desiredVisualID
;
1009 temp
.screen
= screen
;
1010 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1012 /* give the visual some useful GLX attributes */
1013 double_flag
= GL_TRUE
;
1017 else if (level
==0) {
1018 /* normal color planes */
1019 /* Get an RGB visual */
1020 int min_rgb
= min_red
+ min_green
+ min_blue
;
1021 if (min_rgb
>1 && min_rgb
<8) {
1022 /* a special case to be sure we can get a monochrome visual */
1025 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
1028 _mesa_warning(NULL
, "overlay not supported");
1033 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1034 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1035 * largest depth buffer size, which is 32bits/value. Instead, we
1036 * return 16 to maintain performance with earlier versions of Mesa.
1038 if (stencil_size
> 0)
1039 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
1040 else if (depth_size
> 24)
1042 else if (depth_size
> 16)
1044 else if (depth_size
> 0) {
1045 depth_size
= default_depth_bits();
1049 alpha_flag
= default_alpha_bits() > 0;
1052 /* we only support one size of stencil and accum buffers. */
1053 if (stencil_size
> 0)
1056 if (accumRedSize
> 0 ||
1057 accumGreenSize
> 0 ||
1058 accumBlueSize
> 0 ||
1059 accumAlphaSize
> 0) {
1063 accumBlueSize
= default_accum_bits();
1065 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1068 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1069 stereo_flag
, depth_size
, stencil_size
,
1070 accumRedSize
, accumGreenSize
,
1071 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1078 PUBLIC XVisualInfo
*
1079 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1083 /* register ourselves as an extension on this display */
1084 register_with_display(dpy
);
1086 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1088 /* create a new vishandle - the cached one may be stale */
1089 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1090 if (xmvis
->vishandle
) {
1091 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1093 return xmvis
->vishandle
;
1101 * Helper function used by other glXCreateContext functions.
1104 create_context(Display
*dpy
, XMesaVisual xmvis
,
1105 XMesaContext shareCtx
, Bool direct
,
1106 unsigned major
, unsigned minor
,
1107 unsigned profileMask
, unsigned contextFlags
)
1114 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1118 /* deallocate unused windows/buffers */
1120 XMesaGarbageCollect();
1123 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
, shareCtx
, major
, minor
,
1124 profileMask
, contextFlags
);
1125 if (!glxCtx
->xmesaContext
) {
1130 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1131 glxCtx
->currentDpy
= dpy
;
1132 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1139 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1140 GLXContext shareCtx
, Bool direct
)
1144 xmvis
= find_glx_visual( dpy
, visinfo
);
1146 /* This visual wasn't found with glXChooseVisual() */
1147 xmvis
= create_glx_visual( dpy
, visinfo
);
1149 /* unusable visual */
1154 return create_context(dpy
, xmvis
,
1155 shareCtx
? shareCtx
->xmesaContext
: NULL
,
1157 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
1161 /* XXX these may have to be removed due to thread-safety issues. */
1162 static GLXContext MakeCurrent_PrevContext
= 0;
1163 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1164 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1165 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1166 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1169 /* GLX 1.3 and later */
1171 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1172 GLXDrawable read
, GLXContext ctx
)
1174 GLXContext glxCtx
= ctx
;
1175 static boolean firsttime
= 1, no_rast
= 0;
1178 no_rast
= getenv("SP_NO_RAST") != NULL
;
1182 if (ctx
&& draw
&& read
) {
1183 XMesaBuffer drawBuffer
, readBuffer
;
1184 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1186 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1187 if (ctx
== MakeCurrent_PrevContext
1188 && draw
== MakeCurrent_PrevDrawable
) {
1189 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1192 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1195 /* drawable must be a new window! */
1196 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1198 /* Out of memory, or context/drawable depth mismatch */
1203 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1204 if (ctx
== MakeCurrent_PrevContext
1205 && read
== MakeCurrent_PrevReadable
) {
1206 readBuffer
= MakeCurrent_PrevReadBuffer
;
1209 readBuffer
= XMesaFindBuffer( dpy
, read
);
1212 /* drawable must be a new window! */
1213 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1215 /* Out of memory, or context/drawable depth mismatch */
1221 MakeCurrent_PrevContext
== ctx
&&
1222 MakeCurrent_PrevDrawable
== draw
&&
1223 MakeCurrent_PrevReadable
== read
&&
1224 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1225 MakeCurrent_PrevReadBuffer
== readBuffer
)
1228 MakeCurrent_PrevContext
= ctx
;
1229 MakeCurrent_PrevDrawable
= draw
;
1230 MakeCurrent_PrevReadable
= read
;
1231 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1232 MakeCurrent_PrevReadBuffer
= readBuffer
;
1234 /* Now make current! */
1235 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1236 ctx
->currentDpy
= dpy
;
1237 ctx
->currentDrawable
= draw
;
1238 ctx
->currentReadable
= read
;
1239 SetCurrentContext(ctx
);
1246 else if (!ctx
&& !draw
&& !read
) {
1247 /* release current context w/out assigning new one. */
1248 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1249 MakeCurrent_PrevContext
= 0;
1250 MakeCurrent_PrevDrawable
= 0;
1251 MakeCurrent_PrevReadable
= 0;
1252 MakeCurrent_PrevDrawBuffer
= 0;
1253 MakeCurrent_PrevReadBuffer
= 0;
1254 SetCurrentContext(NULL
);
1258 /* The args must either all be non-zero or all zero.
1267 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1269 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1274 glXGetCurrentContext(void)
1276 return GetCurrentContext();
1281 glXGetCurrentDisplay(void)
1283 GLXContext glxCtx
= glXGetCurrentContext();
1285 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1290 glXGetCurrentDisplayEXT(void)
1292 return glXGetCurrentDisplay();
1297 glXGetCurrentDrawable(void)
1299 GLXContext gc
= glXGetCurrentContext();
1300 return gc
? gc
->currentDrawable
: 0;
1305 glXGetCurrentReadDrawable(void)
1307 GLXContext gc
= glXGetCurrentContext();
1308 return gc
? gc
->currentReadable
: 0;
1313 glXGetCurrentReadDrawableSGI(void)
1315 return glXGetCurrentReadDrawable();
1320 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1325 v
= find_glx_visual( dpy
, visinfo
);
1327 v
= create_glx_visual( dpy
, visinfo
);
1329 /* unusable visual */
1334 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1338 return b
->ws
.drawable
;
1342 /*** GLX_MESA_pixmap_colormap ***/
1345 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1346 Pixmap pixmap
, Colormap cmap
)
1351 v
= find_glx_visual( dpy
, visinfo
);
1353 v
= create_glx_visual( dpy
, visinfo
);
1355 /* unusable visual */
1360 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1364 return b
->ws
.drawable
;
1369 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1371 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1373 XMesaDestroyBuffer(b
);
1375 else if (getenv("MESA_DEBUG")) {
1376 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1382 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1383 unsigned long mask
)
1385 XMesaContext xm_src
= src
->xmesaContext
;
1386 XMesaContext xm_dst
= dst
->xmesaContext
;
1388 if (MakeCurrent_PrevContext
== src
) {
1391 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1396 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1399 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1400 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1406 return True
; /* we're faking GLX so always return success */
1411 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1414 GLXContext glxCtx
= ctx
;
1416 MakeCurrent_PrevContext
= 0;
1417 MakeCurrent_PrevDrawable
= 0;
1418 MakeCurrent_PrevReadable
= 0;
1419 MakeCurrent_PrevDrawBuffer
= 0;
1420 MakeCurrent_PrevReadBuffer
= 0;
1421 XMesaDestroyContext( glxCtx
->xmesaContext
);
1422 XMesaGarbageCollect();
1429 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1431 return ctx
? ctx
->isDirect
: False
;
1437 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1439 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1440 static boolean firsttime
= 1, no_rast
= 0;
1443 no_rast
= getenv("SP_NO_RAST") != NULL
;
1451 XMesaSwapBuffers(buffer
);
1453 else if (getenv("MESA_DEBUG")) {
1454 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1461 /*** GLX_MESA_copy_sub_buffer ***/
1464 glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
1465 int x
, int y
, int width
, int height
)
1467 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1469 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1471 else if (getenv("MESA_DEBUG")) {
1472 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1478 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1481 /* Return GLX version, not Mesa version */
1482 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1483 *maj
= CLIENT_MAJOR_VERSION
;
1484 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1490 * Query the GLX attributes of the given XVisualInfo.
1493 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1499 return GLX_BAD_ATTRIBUTE
;
1500 *value
= (int) True
;
1502 case GLX_BUFFER_SIZE
:
1503 *value
= xmvis
->visinfo
->depth
;
1506 *value
= xmvis
->mesa_visual
.level
;
1510 return GLX_BAD_ATTRIBUTE
;
1511 if (xmvis
->mesa_visual
.rgbMode
) {
1518 case GLX_DOUBLEBUFFER
:
1519 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1522 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1524 case GLX_AUX_BUFFERS
:
1525 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1528 *value
= xmvis
->mesa_visual
.redBits
;
1530 case GLX_GREEN_SIZE
:
1531 *value
= xmvis
->mesa_visual
.greenBits
;
1534 *value
= xmvis
->mesa_visual
.blueBits
;
1536 case GLX_ALPHA_SIZE
:
1537 *value
= xmvis
->mesa_visual
.alphaBits
;
1539 case GLX_DEPTH_SIZE
:
1540 *value
= xmvis
->mesa_visual
.depthBits
;
1542 case GLX_STENCIL_SIZE
:
1543 *value
= xmvis
->mesa_visual
.stencilBits
;
1545 case GLX_ACCUM_RED_SIZE
:
1546 *value
= xmvis
->mesa_visual
.accumRedBits
;
1548 case GLX_ACCUM_GREEN_SIZE
:
1549 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1551 case GLX_ACCUM_BLUE_SIZE
:
1552 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1554 case GLX_ACCUM_ALPHA_SIZE
:
1555 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1559 * GLX_EXT_visual_info extension
1561 case GLX_X_VISUAL_TYPE_EXT
:
1562 switch (xmvis
->visinfo
->CLASS
) {
1563 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1564 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1565 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1566 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1567 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1568 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1571 case GLX_TRANSPARENT_TYPE_EXT
:
1573 *value
= GLX_NONE_EXT
;
1575 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1578 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1581 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1584 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1587 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1592 * GLX_EXT_visual_info extension
1594 case GLX_VISUAL_CAVEAT_EXT
:
1595 /* test for zero, just in case */
1596 if (xmvis
->mesa_visual
.visualRating
> 0)
1597 *value
= xmvis
->mesa_visual
.visualRating
;
1599 *value
= GLX_NONE_EXT
;
1603 * GLX_ARB_multisample
1605 case GLX_SAMPLE_BUFFERS_ARB
:
1608 case GLX_SAMPLES_ARB
:
1615 case GLX_SCREEN_EXT
:
1617 return GLX_BAD_ATTRIBUTE
;
1618 *value
= xmvis
->visinfo
->screen
;
1620 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1622 return GLX_BAD_ATTRIBUTE
;
1623 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1625 case GLX_RENDER_TYPE_SGIX
:
1627 return GLX_BAD_ATTRIBUTE
;
1628 if (xmvis
->mesa_visual
.rgbMode
)
1629 *value
= GLX_RGBA_BIT
;
1631 *value
= GLX_COLOR_INDEX_BIT
;
1633 case GLX_X_RENDERABLE_SGIX
:
1635 return GLX_BAD_ATTRIBUTE
;
1636 *value
= True
; /* XXX really? */
1638 case GLX_FBCONFIG_ID_SGIX
:
1640 return GLX_BAD_ATTRIBUTE
;
1641 *value
= xmvis
->visinfo
->visualid
;
1643 case GLX_MAX_PBUFFER_WIDTH
:
1645 return GLX_BAD_ATTRIBUTE
;
1646 /* XXX should be same as ctx->Const.MaxRenderbufferSize */
1647 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1649 case GLX_MAX_PBUFFER_HEIGHT
:
1651 return GLX_BAD_ATTRIBUTE
;
1652 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1654 case GLX_MAX_PBUFFER_PIXELS
:
1656 return GLX_BAD_ATTRIBUTE
;
1657 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1658 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1662 return GLX_BAD_ATTRIBUTE
;
1663 *value
= xmvis
->visinfo
->visualid
;
1666 #ifdef GLX_EXT_texture_from_pixmap
1667 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1668 *value
= True
; /*XXX*/
1670 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1672 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1674 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1675 *value
= True
; /*XXX*/
1677 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1678 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1679 GLX_TEXTURE_2D_BIT_EXT
|
1680 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1682 case GLX_Y_INVERTED_EXT
:
1683 *value
= True
; /*XXX*/
1688 return GLX_BAD_ATTRIBUTE
;
1695 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1696 int attrib
, int *value
)
1700 if (!dpy
|| !visinfo
)
1701 return GLX_BAD_ATTRIBUTE
;
1703 xmvis
= find_glx_visual( dpy
, visinfo
);
1705 /* this visual wasn't obtained with glXChooseVisual */
1706 xmvis
= create_glx_visual( dpy
, visinfo
);
1708 /* this visual can't be used for GL rendering */
1709 if (attrib
==GLX_USE_GL
) {
1710 *value
= (int) False
;
1714 return GLX_BAD_VISUAL
;
1719 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1727 XMesaContext xmesa
= XMesaGetCurrentContext();
1728 XMesaFlush( xmesa
);
1736 XMesaContext xmesa
= XMesaGetCurrentContext();
1737 XMesaFlush( xmesa
);
1742 get_extensions( void )
1749 /* GLX 1.1 and later */
1751 glXQueryExtensionsString( Display
*dpy
, int screen
)
1755 return get_extensions();
1760 /* GLX 1.1 and later */
1762 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1764 static char version
[1000];
1765 sprintf(version
, "%d.%d %s",
1766 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, xmesa_get_name());
1772 case GLX_EXTENSIONS
:
1773 return get_extensions();
1785 /* GLX 1.1 and later */
1787 glXGetClientString( Display
*dpy
, int name
)
1789 static char version
[1000];
1790 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1791 CLIENT_MINOR_VERSION
, xmesa_get_name());
1796 case GLX_EXTENSIONS
:
1797 return get_extensions();
1815 glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1816 int attribute
, int *value
)
1818 XMesaVisual v
= (XMesaVisual
) config
;
1822 if (!dpy
|| !config
|| !value
)
1825 return get_config(v
, attribute
, value
, GL_TRUE
);
1829 PUBLIC GLXFBConfig
*
1830 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1832 XVisualInfo
*visuals
, visTemplate
;
1833 const long visMask
= VisualScreenMask
;
1836 /* Get list of all X visuals */
1837 visTemplate
.screen
= screen
;
1838 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1839 if (*nelements
> 0) {
1840 XMesaVisual
*results
= malloc(*nelements
* sizeof(XMesaVisual
));
1845 for (i
= 0; i
< *nelements
; i
++) {
1846 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1852 return (GLXFBConfig
*) results
;
1858 PUBLIC GLXFBConfig
*
1859 glXChooseFBConfig(Display
*dpy
, int screen
,
1860 const int *attribList
, int *nitems
)
1864 /* register ourselves as an extension on this display */
1865 register_with_display(dpy
);
1867 if (!attribList
|| !attribList
[0]) {
1868 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1869 return glXGetFBConfigs(dpy
, screen
, nitems
);
1872 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1874 GLXFBConfig
*config
= malloc(sizeof(XMesaVisual
));
1880 config
[0] = (GLXFBConfig
) xmvis
;
1881 return (GLXFBConfig
*) config
;
1890 PUBLIC XVisualInfo
*
1891 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1893 if (dpy
&& config
) {
1894 XMesaVisual xmvis
= (XMesaVisual
) config
;
1896 return xmvis
->vishandle
;
1898 /* create a new vishandle - the cached one may be stale */
1899 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1900 if (xmvis
->vishandle
) {
1901 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1903 return xmvis
->vishandle
;
1913 glXCreateWindow(Display
*dpy
, GLXFBConfig config
, Window win
,
1914 const int *attribList
)
1916 XMesaVisual xmvis
= (XMesaVisual
) config
;
1921 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1926 (void) attribList
; /* Ignored in GLX 1.3 */
1928 return win
; /* A hack for now */
1933 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1935 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1937 XMesaDestroyBuffer(b
);
1938 /* don't destroy X window */
1944 glXCreatePixmap(Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1945 const int *attribList
)
1947 XMesaVisual v
= (XMesaVisual
) config
;
1950 int target
= 0, format
= 0, mipmap
= 0;
1953 if (!dpy
|| !config
|| !pixmap
)
1956 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1958 case GLX_TEXTURE_FORMAT_EXT
:
1961 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1962 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1963 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1971 case GLX_TEXTURE_TARGET_EXT
:
1974 case GLX_TEXTURE_1D_EXT
:
1975 case GLX_TEXTURE_2D_EXT
:
1976 case GLX_TEXTURE_RECTANGLE_EXT
:
1984 case GLX_MIPMAP_TEXTURE_EXT
:
1995 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1996 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1997 &value
, GL_TRUE
) != Success
1999 return 0; /* error! */
2002 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2003 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2004 &value
, GL_TRUE
) != Success
2006 return 0; /* error! */
2010 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2011 &value
, GL_TRUE
) != Success
2013 return 0; /* error! */
2016 if (target
== GLX_TEXTURE_1D_EXT
) {
2017 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2018 &value
, GL_TRUE
) != Success
2019 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2020 return 0; /* error! */
2023 else if (target
== GLX_TEXTURE_2D_EXT
) {
2024 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2025 &value
, GL_TRUE
) != Success
2026 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2027 return 0; /* error! */
2030 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2031 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2032 &value
, GL_TRUE
) != Success
2033 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2034 return 0; /* error! */
2038 if (format
|| target
|| mipmap
) {
2039 /* texture from pixmap */
2040 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2043 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2054 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2056 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
2058 XMesaDestroyBuffer(b
);
2059 /* don't destroy X pixmap */
2064 glXCreatePbuffer(Display
*dpy
, GLXFBConfig config
, const int *attribList
)
2066 XMesaVisual xmvis
= (XMesaVisual
) config
;
2069 int width
= 0, height
= 0;
2070 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2074 for (attrib
= attribList
; *attrib
; attrib
++) {
2076 case GLX_PBUFFER_WIDTH
:
2080 case GLX_PBUFFER_HEIGHT
:
2084 case GLX_PRESERVED_CONTENTS
:
2086 preserveContents
= *attrib
;
2088 case GLX_LARGEST_PBUFFER
:
2090 useLargest
= *attrib
;
2097 if (width
== 0 || height
== 0)
2100 if (width
> PBUFFER_MAX_SIZE
|| height
> PBUFFER_MAX_SIZE
) {
2101 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2102 * allocate the largest possible buffer.
2105 width
= PBUFFER_MAX_SIZE
;
2106 height
= PBUFFER_MAX_SIZE
;
2110 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2111 /* A GLXPbuffer handle must be an X Drawable because that's what
2112 * glXMakeCurrent takes.
2115 xmbuf
->largestPbuffer
= useLargest
;
2116 xmbuf
->preservedContents
= preserveContents
;
2117 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2126 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2128 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2130 XMesaDestroyBuffer(b
);
2136 glXQueryDrawable(Display
*dpy
, GLXDrawable draw
, int attribute
,
2137 unsigned int *value
)
2139 GLuint width
, height
;
2140 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2142 generate_error(dpy
, GLXBadDrawable
, draw
, X_GLXGetDrawableAttributes
, False
);
2146 /* make sure buffer's dimensions are up to date */
2147 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2149 switch (attribute
) {
2156 case GLX_PRESERVED_CONTENTS
:
2157 *value
= xmbuf
->preservedContents
;
2159 case GLX_LARGEST_PBUFFER
:
2160 *value
= xmbuf
->largestPbuffer
;
2162 case GLX_FBCONFIG_ID
:
2163 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2165 #ifdef GLX_EXT_texture_from_pixmap
2166 case GLX_TEXTURE_FORMAT_EXT
:
2167 *value
= xmbuf
->TextureFormat
;
2169 case GLX_TEXTURE_TARGET_EXT
:
2170 *value
= xmbuf
->TextureTarget
;
2172 case GLX_MIPMAP_TEXTURE_EXT
:
2173 *value
= xmbuf
->TextureMipmap
;
2178 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, true);
2185 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2186 int renderType
, GLXContext shareCtx
, Bool direct
)
2188 XMesaVisual xmvis
= (XMesaVisual
) config
;
2190 if (!dpy
|| !config
||
2191 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2194 return create_context(dpy
, xmvis
,
2195 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2197 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2202 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2204 GLXContext glxCtx
= ctx
;
2205 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2210 switch (attribute
) {
2211 case GLX_FBCONFIG_ID
:
2212 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2214 case GLX_RENDER_TYPE
:
2215 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2216 *value
= GLX_RGBA_TYPE
;
2218 *value
= GLX_COLOR_INDEX_TYPE
;
2224 return GLX_BAD_ATTRIBUTE
;
2231 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2233 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2235 xmbuf
->selectedEvents
= mask
;
2240 glXGetSelectedEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2242 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2244 *mask
= xmbuf
->selectedEvents
;
2251 /*** GLX_SGI_swap_control ***/
2254 glXSwapIntervalSGI(int interval
)
2262 /*** GLX_SGI_video_sync ***/
2264 static unsigned int FrameCounter
= 0;
2267 glXGetVideoSyncSGI(unsigned int *count
)
2269 /* this is a bogus implementation */
2270 *count
= FrameCounter
++;
2275 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2277 if (divisor
<= 0 || remainder
< 0)
2278 return GLX_BAD_VALUE
;
2279 /* this is a bogus implementation */
2281 while (FrameCounter
% divisor
!= remainder
)
2283 *count
= FrameCounter
;
2289 /*** GLX_SGI_make_current_read ***/
2292 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
,
2295 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2300 glXGetCurrentReadDrawableSGI(void)
2307 /*** GLX_SGIX_video_source ***/
2310 PUBLIC GLXVideoSourceSGIX
2311 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
,
2312 VLPath path
, int nodeClass
, VLNode drainNode
)
2324 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2333 /*** GLX_EXT_import_context ***/
2336 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2343 glXGetContextIDEXT(const GLXContext context
)
2350 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2358 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
,
2370 /*** GLX_SGIX_fbconfig ***/
2373 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2374 int attribute
, int *value
)
2376 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2379 PUBLIC GLXFBConfigSGIX
*
2380 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
,
2383 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
,
2384 attrib_list
, nelements
);
2389 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2392 XMesaVisual xmvis
= (XMesaVisual
) config
;
2393 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2394 return xmbuf
->ws
.drawable
; /* need to return an X ID */
2399 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2400 int renderType
, GLXContext shareCtx
,
2403 XMesaVisual xmvis
= (XMesaVisual
) config
;
2405 if (!dpy
|| !config
||
2406 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2409 return create_context(dpy
, xmvis
,
2410 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2412 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2416 PUBLIC XVisualInfo
*
2417 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2419 return glXGetVisualFromFBConfig(dpy
, config
);
2423 PUBLIC GLXFBConfigSGIX
2424 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2426 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2428 /* This visual wasn't found with glXChooseVisual() */
2429 xmvis
= create_glx_visual(dpy
, vis
);
2432 return (GLXFBConfigSGIX
) xmvis
;
2437 /*** GLX_SGIX_pbuffer ***/
2439 PUBLIC GLXPbufferSGIX
2440 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2441 unsigned int width
, unsigned int height
,
2444 XMesaVisual xmvis
= (XMesaVisual
) config
;
2447 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2451 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2453 case GLX_PRESERVED_CONTENTS_SGIX
:
2455 preserveContents
= *attrib
; /* ignored */
2457 case GLX_LARGEST_PBUFFER_SGIX
:
2459 useLargest
= *attrib
; /* ignored */
2466 /* not used at this time */
2468 (void) preserveContents
;
2470 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2471 /* A GLXPbuffer handle must be an X Drawable because that's what
2472 * glXMakeCurrent takes.
2474 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2479 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2481 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2483 XMesaDestroyBuffer(xmbuf
);
2489 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
,
2490 unsigned int *value
)
2492 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2495 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2499 switch (attribute
) {
2500 case GLX_PRESERVED_CONTENTS_SGIX
:
2503 case GLX_LARGEST_PBUFFER_SGIX
:
2504 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2506 case GLX_WIDTH_SGIX
:
2507 *value
= xmesa_buffer_width(xmbuf
);
2509 case GLX_HEIGHT_SGIX
:
2510 *value
= xmesa_buffer_height(xmbuf
);
2512 case GLX_EVENT_MASK_SGIX
:
2513 *value
= 0; /* XXX might be wrong */
2523 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2525 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2527 /* Note: we'll never generate clobber events */
2528 xmbuf
->selectedEvents
= mask
;
2534 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
,
2535 unsigned long *mask
)
2537 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2539 *mask
= xmbuf
->selectedEvents
;
2548 /*** GLX_SGI_cushion ***/
2551 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2560 /*** GLX_SGIX_video_resize ***/
2563 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
,
2574 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2575 int x
, int y
, int w
, int h
)
2588 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2589 int *x
, int *y
, int *w
, int *h
)
2602 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
,
2603 int *dx
, int *dy
, int *dw
, int *dh
)
2616 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2627 /*** GLX_SGIX_dmbuffer **/
2629 #if defined(_DM_BUFFER_H_)
2631 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
,
2632 DMparams
*params
, DMbuffer dmbuffer
)
2643 /*** GLX_SGIX_swap_group ***/
2646 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2655 /*** GLX_SGIX_swap_barrier ***/
2658 glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2666 glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2676 /*** GLX_SUN_get_transparent_index ***/
2679 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
,
2685 (void) pTransparent
;
2691 /*** GLX_MESA_release_buffers ***/
2694 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2695 * (a window or pixmap) prior to destroying the GLXDrawable.
2698 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2700 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2702 XMesaDestroyBuffer(b
);
2708 /*** GLX_EXT_texture_from_pixmap ***/
2711 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2712 const int *attrib_list
)
2714 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2716 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2720 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2722 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2724 XMesaReleaseTexImage(dpy
, b
, buffer
);
2729 /*** GLX_ARB_create_context ***/
2733 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
2734 GLXContext shareCtx
, Bool direct
,
2735 const int *attrib_list
)
2737 XMesaVisual xmvis
= (XMesaVisual
) config
;
2738 int majorVersion
= 1, minorVersion
= 0;
2739 int contextFlags
= 0x0;
2740 int profileMask
= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
;
2741 int renderType
= GLX_RGBA_TYPE
;
2744 const int contextFlagsAll
= (GLX_CONTEXT_DEBUG_BIT_ARB
|
2745 GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
);
2748 /* parse attrib_list */
2749 for (i
= 0; !done
&& attrib_list
&& attrib_list
[i
]; i
++) {
2750 switch (attrib_list
[i
]) {
2751 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2752 majorVersion
= attrib_list
[++i
];
2754 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2755 minorVersion
= attrib_list
[++i
];
2757 case GLX_CONTEXT_FLAGS_ARB
:
2758 contextFlags
= attrib_list
[++i
];
2760 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2761 profileMask
= attrib_list
[++i
];
2763 case GLX_RENDER_TYPE
:
2764 renderType
= attrib_list
[++i
];
2772 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2777 /* check contextFlags */
2778 if (contextFlags
& ~contextFlagsAll
) {
2779 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2783 /* check profileMask */
2784 if (profileMask
!= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
&&
2785 profileMask
!= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
&&
2786 profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
) {
2787 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAttribsARB
, False
);
2791 /* check renderType */
2792 if (renderType
!= GLX_RGBA_TYPE
&&
2793 renderType
!= GLX_COLOR_INDEX_TYPE
) {
2794 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2799 if (majorVersion
<= 0 ||
2801 (profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2802 ((majorVersion
== 1 && minorVersion
> 5) ||
2803 (majorVersion
== 2 && minorVersion
> 1) ||
2804 (majorVersion
== 3 && minorVersion
> 3) ||
2805 (majorVersion
== 4 && minorVersion
> 5) ||
2806 majorVersion
> 4))) {
2807 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2810 if (profileMask
== GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2811 ((majorVersion
== 1 && minorVersion
> 1) ||
2812 (majorVersion
== 2 && minorVersion
> 0) ||
2813 (majorVersion
== 3 && minorVersion
> 1) ||
2814 majorVersion
> 3)) {
2815 /* GLX_EXT_create_context_es2_profile says nothing to justifying a
2816 * different error code for invalid ES versions, but this is what NVIDIA
2817 * does and piglit expects.
2819 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAttribsARB
, False
);
2823 if ((contextFlags
& GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
) &&
2825 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2829 if (renderType
== GLX_COLOR_INDEX_TYPE
&& majorVersion
>= 3) {
2830 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2834 ctx
= create_context(dpy
, xmvis
,
2835 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2837 majorVersion
, minorVersion
,
2838 profileMask
, contextFlags
);
2840 generate_error(dpy
, GLXBadFBConfig
, 0, X_GLXCreateContextAttribsARB
, False
);