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
);
618 xmesa_close_display(dpy
);
624 * Look for the named extension on given display and return a pointer
625 * to the _XExtension data, or NULL if extension not found.
628 lookup_extension(Display
*dpy
, const char *extName
)
631 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
632 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
641 * Whenever we're given a new Display pointer, call this function to
642 * register our close_display_callback function.
645 register_with_display(Display
*dpy
)
647 const char *extName
= "MesaGLX";
650 ext
= lookup_extension(dpy
, extName
);
652 XExtCodes
*c
= XAddExtension(dpy
);
653 ext
= dpy
->ext_procs
; /* new extension is at head of list */
654 assert(c
->extension
== ext
->codes
.extension
);
656 ext
->name
= strdup(extName
);
657 ext
->close_display
= close_display_callback
;
666 generate_error(Display
*dpy
,
667 unsigned char error_code
,
669 unsigned char minor_code
,
672 XErrorHandler handler
;
678 handler
= XSetErrorHandler(NULL
);
679 XSetErrorHandler(handler
);
684 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_opcode
, &first_event
, &first_error
)) {
691 error_code
+= first_error
;
694 memset(&event
, 0, sizeof event
);
696 event
.xerror
.type
= X_Error
;
697 event
.xerror
.display
= dpy
;
698 event
.xerror
.resourceid
= resourceid
;
699 event
.xerror
.serial
= NextRequest(dpy
) - 1;
700 event
.xerror
.error_code
= error_code
;
701 event
.xerror
.request_code
= major_opcode
;
702 event
.xerror
.minor_code
= minor_code
;
704 return handler(dpy
, &event
.xerror
);
708 /**********************************************************************/
709 /*** Begin Fake GLX API Functions ***/
710 /**********************************************************************/
714 * Helper used by glXChooseVisual and glXChooseFBConfig.
715 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
717 * In either case, the attribute list is terminated with the value 'None'.
720 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
722 const GLboolean rgbModeDefault
= fbConfig
;
723 const int *parselist
;
725 int min_red
=0, min_green
=0, min_blue
=0;
726 GLboolean rgb_flag
= rgbModeDefault
;
727 GLboolean alpha_flag
= GL_FALSE
;
728 GLboolean double_flag
= GL_FALSE
;
729 GLboolean stereo_flag
= GL_FALSE
;
730 GLint depth_size
= 0;
731 GLint stencil_size
= 0;
732 GLint accumRedSize
= 0;
733 GLint accumGreenSize
= 0;
734 GLint accumBlueSize
= 0;
735 GLint accumAlphaSize
= 0;
737 int visual_type
= DONT_CARE
;
738 GLint caveat
= DONT_CARE
;
739 XMesaVisual xmvis
= NULL
;
740 int desiredVisualID
= -1;
750 parselist
[1] == GLX_DONT_CARE
&&
751 parselist
[0] != GLX_LEVEL
) {
752 /* For glXChooseFBConfig(), skip attributes whose value is
753 * GLX_DONT_CARE, unless it's GLX_LEVEL (which can legitimately be
756 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
757 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
763 switch (*parselist
) {
774 case GLX_BUFFER_SIZE
:
780 level
= *parselist
++;
792 case GLX_DOUBLEBUFFER
:
795 double_flag
= *parselist
++;
798 double_flag
= GL_TRUE
;
804 stereo_flag
= *parselist
++;
807 stereo_flag
= GL_TRUE
;
810 case GLX_AUX_BUFFERS
:
812 numAux
= *parselist
++;
813 if (numAux
> MAX_AUX_BUFFERS
)
818 min_red
= *parselist
++;
822 min_green
= *parselist
++;
826 min_blue
= *parselist
++;
831 GLint size
= *parselist
++;
832 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
837 depth_size
= *parselist
++;
839 case GLX_STENCIL_SIZE
:
841 stencil_size
= *parselist
++;
843 case GLX_ACCUM_RED_SIZE
:
846 GLint size
= *parselist
++;
847 accumRedSize
= MAX2( accumRedSize
, size
);
850 case GLX_ACCUM_GREEN_SIZE
:
853 GLint size
= *parselist
++;
854 accumGreenSize
= MAX2( accumGreenSize
, size
);
857 case GLX_ACCUM_BLUE_SIZE
:
860 GLint size
= *parselist
++;
861 accumBlueSize
= MAX2( accumBlueSize
, size
);
864 case GLX_ACCUM_ALPHA_SIZE
:
867 GLint size
= *parselist
++;
868 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
873 * GLX_EXT_visual_info extension
875 case GLX_X_VISUAL_TYPE_EXT
:
877 visual_type
= *parselist
++;
879 case GLX_TRANSPARENT_TYPE_EXT
:
883 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
887 case GLX_TRANSPARENT_RED_VALUE_EXT
:
888 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
889 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
890 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
897 * GLX_EXT_visual_info extension
899 case GLX_VISUAL_CAVEAT_EXT
:
901 caveat
= *parselist
++; /* ignored for now */
905 * GLX_ARB_multisample
907 case GLX_SAMPLE_BUFFERS_ARB
:
908 case GLX_SAMPLES_ARB
:
910 if (*parselist
++ != 0) {
911 /* ms not supported */
919 case GLX_RENDER_TYPE
:
923 if (*parselist
& GLX_RGBA_BIT
) {
926 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
929 else if (*parselist
== 0) {
934 case GLX_DRAWABLE_TYPE
:
938 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
939 return NULL
; /* bad bit */
943 case GLX_FBCONFIG_ID
:
948 desiredVisualID
= *parselist
++;
950 case GLX_X_RENDERABLE
:
951 case GLX_MAX_PBUFFER_WIDTH
:
952 case GLX_MAX_PBUFFER_HEIGHT
:
953 case GLX_MAX_PBUFFER_PIXELS
:
955 return NULL
; /* invalid config option */
956 parselist
+= 2; /* ignore the parameter */
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*/
986 /* undefined attribute */
987 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
997 * Since we're only simulating the GLX extension this function will never
998 * find any real GL visuals. Instead, all we can do is try to find an RGB
999 * or CI visual of appropriate depth. Other requested attributes such as
1000 * double buffering, depth buffer, etc. will be associated with the X
1001 * visual and stored in the VisualTable[].
1003 if (desiredVisualID
!= -1) {
1004 /* try to get a specific visual, by visualID */
1007 temp
.visualid
= desiredVisualID
;
1008 temp
.screen
= screen
;
1009 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1011 /* give the visual some useful GLX attributes */
1012 double_flag
= GL_TRUE
;
1016 else if (level
==0) {
1017 /* normal color planes */
1018 /* Get an RGB visual */
1019 int min_rgb
= min_red
+ min_green
+ min_blue
;
1020 if (min_rgb
>1 && min_rgb
<8) {
1021 /* a special case to be sure we can get a monochrome visual */
1024 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
1027 _mesa_warning(NULL
, "overlay not supported");
1032 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1033 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1034 * largest depth buffer size, which is 32bits/value. Instead, we
1035 * return 16 to maintain performance with earlier versions of Mesa.
1037 if (stencil_size
> 0)
1038 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
1039 else if (depth_size
> 24)
1041 else if (depth_size
> 16)
1043 else if (depth_size
> 0) {
1044 depth_size
= default_depth_bits();
1048 alpha_flag
= default_alpha_bits() > 0;
1051 /* we only support one size of stencil and accum buffers. */
1052 if (stencil_size
> 0)
1055 if (accumRedSize
> 0 ||
1056 accumGreenSize
> 0 ||
1057 accumBlueSize
> 0 ||
1058 accumAlphaSize
> 0) {
1062 accumBlueSize
= default_accum_bits();
1064 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1067 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1068 stereo_flag
, depth_size
, stencil_size
,
1069 accumRedSize
, accumGreenSize
,
1070 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1077 PUBLIC XVisualInfo
*
1078 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1082 /* register ourselves as an extension on this display */
1083 register_with_display(dpy
);
1085 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1087 /* create a new vishandle - the cached one may be stale */
1088 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1089 if (xmvis
->vishandle
) {
1090 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1092 return xmvis
->vishandle
;
1100 * Helper function used by other glXCreateContext functions.
1103 create_context(Display
*dpy
, XMesaVisual xmvis
,
1104 XMesaContext shareCtx
, Bool direct
,
1105 unsigned major
, unsigned minor
,
1106 unsigned profileMask
, unsigned contextFlags
)
1113 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1117 /* deallocate unused windows/buffers */
1119 XMesaGarbageCollect();
1122 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
, shareCtx
, major
, minor
,
1123 profileMask
, contextFlags
);
1124 if (!glxCtx
->xmesaContext
) {
1129 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1130 glxCtx
->currentDpy
= dpy
;
1131 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1138 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1139 GLXContext shareCtx
, Bool direct
)
1143 xmvis
= find_glx_visual( dpy
, visinfo
);
1145 /* This visual wasn't found with glXChooseVisual() */
1146 xmvis
= create_glx_visual( dpy
, visinfo
);
1148 /* unusable visual */
1153 return create_context(dpy
, xmvis
,
1154 shareCtx
? shareCtx
->xmesaContext
: NULL
,
1156 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
1160 /* XXX these may have to be removed due to thread-safety issues. */
1161 static GLXContext MakeCurrent_PrevContext
= 0;
1162 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1163 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1164 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1165 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1168 /* GLX 1.3 and later */
1170 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1171 GLXDrawable read
, GLXContext ctx
)
1173 GLXContext glxCtx
= ctx
;
1174 static boolean firsttime
= 1, no_rast
= 0;
1177 no_rast
= getenv("SP_NO_RAST") != NULL
;
1181 if (ctx
&& draw
&& read
) {
1182 XMesaBuffer drawBuffer
, readBuffer
;
1183 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1185 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1186 if (ctx
== MakeCurrent_PrevContext
1187 && draw
== MakeCurrent_PrevDrawable
) {
1188 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1191 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1194 /* drawable must be a new window! */
1195 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1197 /* Out of memory, or context/drawable depth mismatch */
1202 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1203 if (ctx
== MakeCurrent_PrevContext
1204 && read
== MakeCurrent_PrevReadable
) {
1205 readBuffer
= MakeCurrent_PrevReadBuffer
;
1208 readBuffer
= XMesaFindBuffer( dpy
, read
);
1211 /* drawable must be a new window! */
1212 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1214 /* Out of memory, or context/drawable depth mismatch */
1220 MakeCurrent_PrevContext
== ctx
&&
1221 MakeCurrent_PrevDrawable
== draw
&&
1222 MakeCurrent_PrevReadable
== read
&&
1223 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1224 MakeCurrent_PrevReadBuffer
== readBuffer
)
1227 MakeCurrent_PrevContext
= ctx
;
1228 MakeCurrent_PrevDrawable
= draw
;
1229 MakeCurrent_PrevReadable
= read
;
1230 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1231 MakeCurrent_PrevReadBuffer
= readBuffer
;
1233 /* Now make current! */
1234 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1235 ctx
->currentDpy
= dpy
;
1236 ctx
->currentDrawable
= draw
;
1237 ctx
->currentReadable
= read
;
1238 SetCurrentContext(ctx
);
1245 else if (!ctx
&& !draw
&& !read
) {
1246 /* release current context w/out assigning new one. */
1247 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1248 MakeCurrent_PrevContext
= 0;
1249 MakeCurrent_PrevDrawable
= 0;
1250 MakeCurrent_PrevReadable
= 0;
1251 MakeCurrent_PrevDrawBuffer
= 0;
1252 MakeCurrent_PrevReadBuffer
= 0;
1253 SetCurrentContext(NULL
);
1257 /* The args must either all be non-zero or all zero.
1266 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1268 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1273 glXGetCurrentContext(void)
1275 return GetCurrentContext();
1280 glXGetCurrentDisplay(void)
1282 GLXContext glxCtx
= glXGetCurrentContext();
1284 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1289 glXGetCurrentDisplayEXT(void)
1291 return glXGetCurrentDisplay();
1296 glXGetCurrentDrawable(void)
1298 GLXContext gc
= glXGetCurrentContext();
1299 return gc
? gc
->currentDrawable
: 0;
1304 glXGetCurrentReadDrawable(void)
1306 GLXContext gc
= glXGetCurrentContext();
1307 return gc
? gc
->currentReadable
: 0;
1312 glXGetCurrentReadDrawableSGI(void)
1314 return glXGetCurrentReadDrawable();
1319 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1324 v
= find_glx_visual( dpy
, visinfo
);
1326 v
= create_glx_visual( dpy
, visinfo
);
1328 /* unusable visual */
1333 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1337 return b
->ws
.drawable
;
1341 /*** GLX_MESA_pixmap_colormap ***/
1344 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1345 Pixmap pixmap
, Colormap cmap
)
1350 v
= find_glx_visual( dpy
, visinfo
);
1352 v
= create_glx_visual( dpy
, visinfo
);
1354 /* unusable visual */
1359 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1363 return b
->ws
.drawable
;
1368 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1370 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1372 XMesaDestroyBuffer(b
);
1374 else if (getenv("MESA_DEBUG")) {
1375 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1381 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1382 unsigned long mask
)
1384 XMesaContext xm_src
= src
->xmesaContext
;
1385 XMesaContext xm_dst
= dst
->xmesaContext
;
1387 if (MakeCurrent_PrevContext
== src
) {
1390 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1395 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1398 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1399 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1405 return True
; /* we're faking GLX so always return success */
1410 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1413 GLXContext glxCtx
= ctx
;
1415 MakeCurrent_PrevContext
= 0;
1416 MakeCurrent_PrevDrawable
= 0;
1417 MakeCurrent_PrevReadable
= 0;
1418 MakeCurrent_PrevDrawBuffer
= 0;
1419 MakeCurrent_PrevReadBuffer
= 0;
1420 XMesaDestroyContext( glxCtx
->xmesaContext
);
1421 XMesaGarbageCollect();
1428 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1430 return ctx
? ctx
->isDirect
: False
;
1436 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1438 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1439 static boolean firsttime
= 1, no_rast
= 0;
1442 no_rast
= getenv("SP_NO_RAST") != NULL
;
1450 XMesaSwapBuffers(buffer
);
1452 else if (getenv("MESA_DEBUG")) {
1453 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1460 /*** GLX_MESA_copy_sub_buffer ***/
1463 glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
1464 int x
, int y
, int width
, int height
)
1466 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1468 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1470 else if (getenv("MESA_DEBUG")) {
1471 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1477 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1480 /* Return GLX version, not Mesa version */
1481 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1482 *maj
= CLIENT_MAJOR_VERSION
;
1483 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1489 * Query the GLX attributes of the given XVisualInfo.
1492 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1498 return GLX_BAD_ATTRIBUTE
;
1499 *value
= (int) True
;
1501 case GLX_BUFFER_SIZE
:
1502 *value
= xmvis
->visinfo
->depth
;
1505 *value
= xmvis
->mesa_visual
.level
;
1509 return GLX_BAD_ATTRIBUTE
;
1510 if (xmvis
->mesa_visual
.rgbMode
) {
1517 case GLX_DOUBLEBUFFER
:
1518 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1521 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1523 case GLX_AUX_BUFFERS
:
1524 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1527 *value
= xmvis
->mesa_visual
.redBits
;
1529 case GLX_GREEN_SIZE
:
1530 *value
= xmvis
->mesa_visual
.greenBits
;
1533 *value
= xmvis
->mesa_visual
.blueBits
;
1535 case GLX_ALPHA_SIZE
:
1536 *value
= xmvis
->mesa_visual
.alphaBits
;
1538 case GLX_DEPTH_SIZE
:
1539 *value
= xmvis
->mesa_visual
.depthBits
;
1541 case GLX_STENCIL_SIZE
:
1542 *value
= xmvis
->mesa_visual
.stencilBits
;
1544 case GLX_ACCUM_RED_SIZE
:
1545 *value
= xmvis
->mesa_visual
.accumRedBits
;
1547 case GLX_ACCUM_GREEN_SIZE
:
1548 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1550 case GLX_ACCUM_BLUE_SIZE
:
1551 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1553 case GLX_ACCUM_ALPHA_SIZE
:
1554 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1558 * GLX_EXT_visual_info extension
1560 case GLX_X_VISUAL_TYPE_EXT
:
1561 switch (xmvis
->visinfo
->CLASS
) {
1562 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1563 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1564 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1565 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1566 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1567 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1570 case GLX_TRANSPARENT_TYPE_EXT
:
1572 *value
= GLX_NONE_EXT
;
1574 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1577 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1580 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1583 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1586 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1591 * GLX_EXT_visual_info extension
1593 case GLX_VISUAL_CAVEAT_EXT
:
1594 /* test for zero, just in case */
1595 if (xmvis
->mesa_visual
.visualRating
> 0)
1596 *value
= xmvis
->mesa_visual
.visualRating
;
1598 *value
= GLX_NONE_EXT
;
1602 * GLX_ARB_multisample
1604 case GLX_SAMPLE_BUFFERS_ARB
:
1607 case GLX_SAMPLES_ARB
:
1614 case GLX_SCREEN_EXT
:
1616 return GLX_BAD_ATTRIBUTE
;
1617 *value
= xmvis
->visinfo
->screen
;
1619 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1621 return GLX_BAD_ATTRIBUTE
;
1622 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1624 case GLX_RENDER_TYPE_SGIX
:
1626 return GLX_BAD_ATTRIBUTE
;
1627 if (xmvis
->mesa_visual
.rgbMode
)
1628 *value
= GLX_RGBA_BIT
;
1630 *value
= GLX_COLOR_INDEX_BIT
;
1632 case GLX_X_RENDERABLE_SGIX
:
1634 return GLX_BAD_ATTRIBUTE
;
1635 *value
= True
; /* XXX really? */
1637 case GLX_FBCONFIG_ID_SGIX
:
1639 return GLX_BAD_ATTRIBUTE
;
1640 *value
= xmvis
->visinfo
->visualid
;
1642 case GLX_MAX_PBUFFER_WIDTH
:
1644 return GLX_BAD_ATTRIBUTE
;
1645 /* XXX should be same as ctx->Const.MaxRenderbufferSize */
1646 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1648 case GLX_MAX_PBUFFER_HEIGHT
:
1650 return GLX_BAD_ATTRIBUTE
;
1651 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1653 case GLX_MAX_PBUFFER_PIXELS
:
1655 return GLX_BAD_ATTRIBUTE
;
1656 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1657 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1661 return GLX_BAD_ATTRIBUTE
;
1662 *value
= xmvis
->visinfo
->visualid
;
1665 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1666 *value
= True
; /*XXX*/
1668 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1670 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1672 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1673 *value
= True
; /*XXX*/
1675 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1676 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1677 GLX_TEXTURE_2D_BIT_EXT
|
1678 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1680 case GLX_Y_INVERTED_EXT
:
1681 *value
= True
; /*XXX*/
1685 return GLX_BAD_ATTRIBUTE
;
1692 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1693 int attrib
, int *value
)
1697 if (!dpy
|| !visinfo
)
1698 return GLX_BAD_ATTRIBUTE
;
1700 xmvis
= find_glx_visual( dpy
, visinfo
);
1702 /* this visual wasn't obtained with glXChooseVisual */
1703 xmvis
= create_glx_visual( dpy
, visinfo
);
1705 /* this visual can't be used for GL rendering */
1706 if (attrib
==GLX_USE_GL
) {
1707 *value
= (int) False
;
1711 return GLX_BAD_VISUAL
;
1716 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1724 XMesaContext xmesa
= XMesaGetCurrentContext();
1725 XMesaFlush( xmesa
);
1733 XMesaContext xmesa
= XMesaGetCurrentContext();
1734 XMesaFlush( xmesa
);
1739 get_extensions( void )
1746 /* GLX 1.1 and later */
1748 glXQueryExtensionsString( Display
*dpy
, int screen
)
1752 return get_extensions();
1757 /* GLX 1.1 and later */
1759 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1761 static char version
[1000];
1762 sprintf(version
, "%d.%d %s",
1763 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, xmesa_get_name());
1769 case GLX_EXTENSIONS
:
1770 return get_extensions();
1782 /* GLX 1.1 and later */
1784 glXGetClientString( Display
*dpy
, int name
)
1786 static char version
[1000];
1787 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1788 CLIENT_MINOR_VERSION
, xmesa_get_name());
1793 case GLX_EXTENSIONS
:
1794 return get_extensions();
1812 glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1813 int attribute
, int *value
)
1815 XMesaVisual v
= (XMesaVisual
) config
;
1819 if (!dpy
|| !config
|| !value
)
1822 return get_config(v
, attribute
, value
, GL_TRUE
);
1826 PUBLIC GLXFBConfig
*
1827 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1829 XVisualInfo
*visuals
, visTemplate
;
1830 const long visMask
= VisualScreenMask
;
1833 /* Get list of all X visuals */
1834 visTemplate
.screen
= screen
;
1835 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1836 if (*nelements
> 0) {
1837 XMesaVisual
*results
= malloc(*nelements
* sizeof(XMesaVisual
));
1842 for (i
= 0; i
< *nelements
; i
++) {
1843 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1849 return (GLXFBConfig
*) results
;
1855 PUBLIC GLXFBConfig
*
1856 glXChooseFBConfig(Display
*dpy
, int screen
,
1857 const int *attribList
, int *nitems
)
1861 /* register ourselves as an extension on this display */
1862 register_with_display(dpy
);
1864 if (!attribList
|| !attribList
[0]) {
1865 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1866 return glXGetFBConfigs(dpy
, screen
, nitems
);
1869 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1871 GLXFBConfig
*config
= malloc(sizeof(XMesaVisual
));
1877 config
[0] = (GLXFBConfig
) xmvis
;
1878 return (GLXFBConfig
*) config
;
1887 PUBLIC XVisualInfo
*
1888 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1890 if (dpy
&& config
) {
1891 XMesaVisual xmvis
= (XMesaVisual
) config
;
1893 return xmvis
->vishandle
;
1895 /* create a new vishandle - the cached one may be stale */
1896 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1897 if (xmvis
->vishandle
) {
1898 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1900 return xmvis
->vishandle
;
1910 glXCreateWindow(Display
*dpy
, GLXFBConfig config
, Window win
,
1911 const int *attribList
)
1913 XMesaVisual xmvis
= (XMesaVisual
) config
;
1918 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1923 (void) attribList
; /* Ignored in GLX 1.3 */
1925 return win
; /* A hack for now */
1930 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1932 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1934 XMesaDestroyBuffer(b
);
1935 /* don't destroy X window */
1941 glXCreatePixmap(Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1942 const int *attribList
)
1944 XMesaVisual v
= (XMesaVisual
) config
;
1947 int target
= 0, format
= 0, mipmap
= 0;
1950 if (!dpy
|| !config
|| !pixmap
)
1953 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1955 case GLX_TEXTURE_FORMAT_EXT
:
1958 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1959 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1960 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1968 case GLX_TEXTURE_TARGET_EXT
:
1971 case GLX_TEXTURE_1D_EXT
:
1972 case GLX_TEXTURE_2D_EXT
:
1973 case GLX_TEXTURE_RECTANGLE_EXT
:
1981 case GLX_MIPMAP_TEXTURE_EXT
:
1992 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1993 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1994 &value
, GL_TRUE
) != Success
1996 return 0; /* error! */
1999 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2000 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2001 &value
, GL_TRUE
) != Success
2003 return 0; /* error! */
2007 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2008 &value
, GL_TRUE
) != Success
2010 return 0; /* error! */
2013 if (target
== GLX_TEXTURE_1D_EXT
) {
2014 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2015 &value
, GL_TRUE
) != Success
2016 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2017 return 0; /* error! */
2020 else if (target
== GLX_TEXTURE_2D_EXT
) {
2021 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2022 &value
, GL_TRUE
) != Success
2023 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2024 return 0; /* error! */
2027 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2028 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2029 &value
, GL_TRUE
) != Success
2030 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2031 return 0; /* error! */
2035 if (format
|| target
|| mipmap
) {
2036 /* texture from pixmap */
2037 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2040 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2051 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2053 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
2055 XMesaDestroyBuffer(b
);
2056 /* don't destroy X pixmap */
2061 glXCreatePbuffer(Display
*dpy
, GLXFBConfig config
, const int *attribList
)
2063 XMesaVisual xmvis
= (XMesaVisual
) config
;
2066 int width
= 0, height
= 0;
2067 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2071 for (attrib
= attribList
; *attrib
; attrib
++) {
2073 case GLX_PBUFFER_WIDTH
:
2077 case GLX_PBUFFER_HEIGHT
:
2081 case GLX_PRESERVED_CONTENTS
:
2083 preserveContents
= *attrib
;
2085 case GLX_LARGEST_PBUFFER
:
2087 useLargest
= *attrib
;
2094 if (width
== 0 || height
== 0)
2097 if (width
> PBUFFER_MAX_SIZE
|| height
> PBUFFER_MAX_SIZE
) {
2098 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2099 * allocate the largest possible buffer.
2102 width
= PBUFFER_MAX_SIZE
;
2103 height
= PBUFFER_MAX_SIZE
;
2107 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2108 /* A GLXPbuffer handle must be an X Drawable because that's what
2109 * glXMakeCurrent takes.
2112 xmbuf
->largestPbuffer
= useLargest
;
2113 xmbuf
->preservedContents
= preserveContents
;
2114 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2123 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2125 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2127 XMesaDestroyBuffer(b
);
2133 glXQueryDrawable(Display
*dpy
, GLXDrawable draw
, int attribute
,
2134 unsigned int *value
)
2136 GLuint width
, height
;
2137 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2139 generate_error(dpy
, GLXBadDrawable
, draw
, X_GLXGetDrawableAttributes
, False
);
2143 /* make sure buffer's dimensions are up to date */
2144 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2146 switch (attribute
) {
2153 case GLX_PRESERVED_CONTENTS
:
2154 *value
= xmbuf
->preservedContents
;
2156 case GLX_LARGEST_PBUFFER
:
2157 *value
= xmbuf
->largestPbuffer
;
2159 case GLX_FBCONFIG_ID
:
2160 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2162 case GLX_TEXTURE_FORMAT_EXT
:
2163 *value
= xmbuf
->TextureFormat
;
2165 case GLX_TEXTURE_TARGET_EXT
:
2166 *value
= xmbuf
->TextureTarget
;
2168 case GLX_MIPMAP_TEXTURE_EXT
:
2169 *value
= xmbuf
->TextureMipmap
;
2173 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, true);
2180 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2181 int renderType
, GLXContext shareCtx
, Bool direct
)
2183 XMesaVisual xmvis
= (XMesaVisual
) config
;
2185 if (!dpy
|| !config
||
2186 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2189 return create_context(dpy
, xmvis
,
2190 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2192 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2197 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2199 GLXContext glxCtx
= ctx
;
2200 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2205 switch (attribute
) {
2206 case GLX_FBCONFIG_ID
:
2207 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2209 case GLX_RENDER_TYPE
:
2210 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2211 *value
= GLX_RGBA_TYPE
;
2213 *value
= GLX_COLOR_INDEX_TYPE
;
2219 return GLX_BAD_ATTRIBUTE
;
2226 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2228 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2230 xmbuf
->selectedEvents
= mask
;
2235 glXGetSelectedEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2237 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2239 *mask
= xmbuf
->selectedEvents
;
2246 /*** GLX_SGI_swap_control ***/
2249 glXSwapIntervalSGI(int interval
)
2257 /*** GLX_SGI_video_sync ***/
2259 static unsigned int FrameCounter
= 0;
2262 glXGetVideoSyncSGI(unsigned int *count
)
2264 /* this is a bogus implementation */
2265 *count
= FrameCounter
++;
2270 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2272 if (divisor
<= 0 || remainder
< 0)
2273 return GLX_BAD_VALUE
;
2274 /* this is a bogus implementation */
2276 while (FrameCounter
% divisor
!= remainder
)
2278 *count
= FrameCounter
;
2284 /*** GLX_SGI_make_current_read ***/
2287 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
,
2290 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2295 glXGetCurrentReadDrawableSGI(void)
2302 /*** GLX_SGIX_video_source ***/
2305 PUBLIC GLXVideoSourceSGIX
2306 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
,
2307 VLPath path
, int nodeClass
, VLNode drainNode
)
2319 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2328 /*** GLX_EXT_import_context ***/
2331 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2338 glXGetContextIDEXT(const GLXContext context
)
2345 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2353 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
,
2365 /*** GLX_SGIX_fbconfig ***/
2368 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2369 int attribute
, int *value
)
2371 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2374 PUBLIC GLXFBConfigSGIX
*
2375 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
,
2378 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
,
2379 attrib_list
, nelements
);
2384 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2387 XMesaVisual xmvis
= (XMesaVisual
) config
;
2388 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2389 return xmbuf
->ws
.drawable
; /* need to return an X ID */
2394 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2395 int renderType
, GLXContext shareCtx
,
2398 XMesaVisual xmvis
= (XMesaVisual
) config
;
2400 if (!dpy
|| !config
||
2401 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2404 return create_context(dpy
, xmvis
,
2405 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2407 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2411 PUBLIC XVisualInfo
*
2412 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2414 return glXGetVisualFromFBConfig(dpy
, config
);
2418 PUBLIC GLXFBConfigSGIX
2419 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2421 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2423 /* This visual wasn't found with glXChooseVisual() */
2424 xmvis
= create_glx_visual(dpy
, vis
);
2427 return (GLXFBConfigSGIX
) xmvis
;
2432 /*** GLX_SGIX_pbuffer ***/
2434 PUBLIC GLXPbufferSGIX
2435 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2436 unsigned int width
, unsigned int height
,
2439 XMesaVisual xmvis
= (XMesaVisual
) config
;
2442 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2446 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2448 case GLX_PRESERVED_CONTENTS_SGIX
:
2450 preserveContents
= *attrib
; /* ignored */
2452 case GLX_LARGEST_PBUFFER_SGIX
:
2454 useLargest
= *attrib
; /* ignored */
2461 /* not used at this time */
2463 (void) preserveContents
;
2465 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2466 /* A GLXPbuffer handle must be an X Drawable because that's what
2467 * glXMakeCurrent takes.
2469 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2474 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2476 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2478 XMesaDestroyBuffer(xmbuf
);
2484 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
,
2485 unsigned int *value
)
2487 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2490 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2494 switch (attribute
) {
2495 case GLX_PRESERVED_CONTENTS_SGIX
:
2498 case GLX_LARGEST_PBUFFER_SGIX
:
2499 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2501 case GLX_WIDTH_SGIX
:
2502 *value
= xmesa_buffer_width(xmbuf
);
2504 case GLX_HEIGHT_SGIX
:
2505 *value
= xmesa_buffer_height(xmbuf
);
2507 case GLX_EVENT_MASK_SGIX
:
2508 *value
= 0; /* XXX might be wrong */
2518 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2520 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2522 /* Note: we'll never generate clobber events */
2523 xmbuf
->selectedEvents
= mask
;
2529 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
,
2530 unsigned long *mask
)
2532 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2534 *mask
= xmbuf
->selectedEvents
;
2543 /*** GLX_SGI_cushion ***/
2546 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2555 /*** GLX_SGIX_video_resize ***/
2558 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
,
2569 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2570 int x
, int y
, int w
, int h
)
2583 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2584 int *x
, int *y
, int *w
, int *h
)
2597 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
,
2598 int *dx
, int *dy
, int *dw
, int *dh
)
2611 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2622 /*** GLX_SGIX_dmbuffer **/
2624 #if defined(_DM_BUFFER_H_)
2626 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
,
2627 DMparams
*params
, DMbuffer dmbuffer
)
2638 /*** GLX_SGIX_swap_group ***/
2641 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2650 /*** GLX_SGIX_swap_barrier ***/
2653 glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2661 glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2671 /*** GLX_SUN_get_transparent_index ***/
2674 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
,
2680 (void) pTransparent
;
2686 /*** GLX_MESA_release_buffers ***/
2689 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2690 * (a window or pixmap) prior to destroying the GLXDrawable.
2693 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2695 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2697 XMesaDestroyBuffer(b
);
2703 /*** GLX_EXT_texture_from_pixmap ***/
2706 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2707 const int *attrib_list
)
2709 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2711 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2715 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2717 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2719 XMesaReleaseTexImage(dpy
, b
, buffer
);
2724 /*** GLX_ARB_create_context ***/
2728 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
2729 GLXContext shareCtx
, Bool direct
,
2730 const int *attrib_list
)
2732 XMesaVisual xmvis
= (XMesaVisual
) config
;
2733 int majorVersion
= 1, minorVersion
= 0;
2734 int contextFlags
= 0x0;
2735 int profileMask
= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
;
2736 int renderType
= GLX_RGBA_TYPE
;
2739 const int contextFlagsAll
= (GLX_CONTEXT_DEBUG_BIT_ARB
|
2740 GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
);
2743 /* parse attrib_list */
2744 for (i
= 0; !done
&& attrib_list
&& attrib_list
[i
]; i
++) {
2745 switch (attrib_list
[i
]) {
2746 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2747 majorVersion
= attrib_list
[++i
];
2749 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2750 minorVersion
= attrib_list
[++i
];
2752 case GLX_CONTEXT_FLAGS_ARB
:
2753 contextFlags
= attrib_list
[++i
];
2755 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2756 profileMask
= attrib_list
[++i
];
2758 case GLX_RENDER_TYPE
:
2759 renderType
= attrib_list
[++i
];
2767 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2772 /* check contextFlags */
2773 if (contextFlags
& ~contextFlagsAll
) {
2774 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2778 /* check profileMask */
2779 if (profileMask
!= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
&&
2780 profileMask
!= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
&&
2781 profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
) {
2782 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAttribsARB
, False
);
2786 /* check renderType */
2787 if (renderType
!= GLX_RGBA_TYPE
&&
2788 renderType
!= GLX_COLOR_INDEX_TYPE
) {
2789 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2794 if (majorVersion
<= 0 ||
2796 (profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2797 ((majorVersion
== 1 && minorVersion
> 5) ||
2798 (majorVersion
== 2 && minorVersion
> 1) ||
2799 (majorVersion
== 3 && minorVersion
> 3) ||
2800 (majorVersion
== 4 && minorVersion
> 5) ||
2801 majorVersion
> 4))) {
2802 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2805 if (profileMask
== GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2806 ((majorVersion
== 1 && minorVersion
> 1) ||
2807 (majorVersion
== 2 && minorVersion
> 0) ||
2808 (majorVersion
== 3 && minorVersion
> 1) ||
2809 majorVersion
> 3)) {
2810 /* GLX_EXT_create_context_es2_profile says nothing to justifying a
2811 * different error code for invalid ES versions, but this is what NVIDIA
2812 * does and piglit expects.
2814 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAttribsARB
, False
);
2818 if ((contextFlags
& GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
) &&
2820 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2824 if (renderType
== GLX_COLOR_INDEX_TYPE
&& majorVersion
>= 3) {
2825 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2829 ctx
= create_context(dpy
, xmvis
,
2830 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2832 majorVersion
, minorVersion
,
2833 profileMask
, contextFlags
);
2835 generate_error(dpy
, GLXBadFBConfig
, 0, X_GLXCreateContextAttribsARB
, False
);