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 #ifdef GLX_EXT_texture_from_pixmap
960 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
961 parselist
++; /*skip*/
963 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
964 parselist
++; /*skip*/
966 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
967 parselist
++; /*skip*/
969 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
971 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
972 GLX_TEXTURE_2D_BIT_EXT
|
973 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
978 case GLX_Y_INVERTED_EXT
:
979 parselist
++; /*skip*/
988 /* undefined attribute */
989 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
999 * Since we're only simulating the GLX extension this function will never
1000 * find any real GL visuals. Instead, all we can do is try to find an RGB
1001 * or CI visual of appropriate depth. Other requested attributes such as
1002 * double buffering, depth buffer, etc. will be associated with the X
1003 * visual and stored in the VisualTable[].
1005 if (desiredVisualID
!= -1) {
1006 /* try to get a specific visual, by visualID */
1009 temp
.visualid
= desiredVisualID
;
1010 temp
.screen
= screen
;
1011 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1013 /* give the visual some useful GLX attributes */
1014 double_flag
= GL_TRUE
;
1018 else if (level
==0) {
1019 /* normal color planes */
1020 /* Get an RGB visual */
1021 int min_rgb
= min_red
+ min_green
+ min_blue
;
1022 if (min_rgb
>1 && min_rgb
<8) {
1023 /* a special case to be sure we can get a monochrome visual */
1026 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
1029 _mesa_warning(NULL
, "overlay not supported");
1034 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1035 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1036 * largest depth buffer size, which is 32bits/value. Instead, we
1037 * return 16 to maintain performance with earlier versions of Mesa.
1039 if (stencil_size
> 0)
1040 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
1041 else if (depth_size
> 24)
1043 else if (depth_size
> 16)
1045 else if (depth_size
> 0) {
1046 depth_size
= default_depth_bits();
1050 alpha_flag
= default_alpha_bits() > 0;
1053 /* we only support one size of stencil and accum buffers. */
1054 if (stencil_size
> 0)
1057 if (accumRedSize
> 0 ||
1058 accumGreenSize
> 0 ||
1059 accumBlueSize
> 0 ||
1060 accumAlphaSize
> 0) {
1064 accumBlueSize
= default_accum_bits();
1066 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1069 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1070 stereo_flag
, depth_size
, stencil_size
,
1071 accumRedSize
, accumGreenSize
,
1072 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1079 PUBLIC XVisualInfo
*
1080 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1084 /* register ourselves as an extension on this display */
1085 register_with_display(dpy
);
1087 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1089 /* create a new vishandle - the cached one may be stale */
1090 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1091 if (xmvis
->vishandle
) {
1092 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1094 return xmvis
->vishandle
;
1102 * Helper function used by other glXCreateContext functions.
1105 create_context(Display
*dpy
, XMesaVisual xmvis
,
1106 XMesaContext shareCtx
, Bool direct
,
1107 unsigned major
, unsigned minor
,
1108 unsigned profileMask
, unsigned contextFlags
)
1115 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1119 /* deallocate unused windows/buffers */
1121 XMesaGarbageCollect();
1124 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
, shareCtx
, major
, minor
,
1125 profileMask
, contextFlags
);
1126 if (!glxCtx
->xmesaContext
) {
1131 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1132 glxCtx
->currentDpy
= dpy
;
1133 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1140 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1141 GLXContext shareCtx
, Bool direct
)
1145 xmvis
= find_glx_visual( dpy
, visinfo
);
1147 /* This visual wasn't found with glXChooseVisual() */
1148 xmvis
= create_glx_visual( dpy
, visinfo
);
1150 /* unusable visual */
1155 return create_context(dpy
, xmvis
,
1156 shareCtx
? shareCtx
->xmesaContext
: NULL
,
1158 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
1162 /* XXX these may have to be removed due to thread-safety issues. */
1163 static GLXContext MakeCurrent_PrevContext
= 0;
1164 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1165 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1166 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1167 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1170 /* GLX 1.3 and later */
1172 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1173 GLXDrawable read
, GLXContext ctx
)
1175 GLXContext glxCtx
= ctx
;
1176 static boolean firsttime
= 1, no_rast
= 0;
1179 no_rast
= getenv("SP_NO_RAST") != NULL
;
1183 if (ctx
&& draw
&& read
) {
1184 XMesaBuffer drawBuffer
, readBuffer
;
1185 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1187 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1188 if (ctx
== MakeCurrent_PrevContext
1189 && draw
== MakeCurrent_PrevDrawable
) {
1190 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1193 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1196 /* drawable must be a new window! */
1197 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1199 /* Out of memory, or context/drawable depth mismatch */
1204 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1205 if (ctx
== MakeCurrent_PrevContext
1206 && read
== MakeCurrent_PrevReadable
) {
1207 readBuffer
= MakeCurrent_PrevReadBuffer
;
1210 readBuffer
= XMesaFindBuffer( dpy
, read
);
1213 /* drawable must be a new window! */
1214 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1216 /* Out of memory, or context/drawable depth mismatch */
1222 MakeCurrent_PrevContext
== ctx
&&
1223 MakeCurrent_PrevDrawable
== draw
&&
1224 MakeCurrent_PrevReadable
== read
&&
1225 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1226 MakeCurrent_PrevReadBuffer
== readBuffer
)
1229 MakeCurrent_PrevContext
= ctx
;
1230 MakeCurrent_PrevDrawable
= draw
;
1231 MakeCurrent_PrevReadable
= read
;
1232 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1233 MakeCurrent_PrevReadBuffer
= readBuffer
;
1235 /* Now make current! */
1236 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1237 ctx
->currentDpy
= dpy
;
1238 ctx
->currentDrawable
= draw
;
1239 ctx
->currentReadable
= read
;
1240 SetCurrentContext(ctx
);
1247 else if (!ctx
&& !draw
&& !read
) {
1248 /* release current context w/out assigning new one. */
1249 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1250 MakeCurrent_PrevContext
= 0;
1251 MakeCurrent_PrevDrawable
= 0;
1252 MakeCurrent_PrevReadable
= 0;
1253 MakeCurrent_PrevDrawBuffer
= 0;
1254 MakeCurrent_PrevReadBuffer
= 0;
1255 SetCurrentContext(NULL
);
1259 /* The args must either all be non-zero or all zero.
1268 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1270 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1275 glXGetCurrentContext(void)
1277 return GetCurrentContext();
1282 glXGetCurrentDisplay(void)
1284 GLXContext glxCtx
= glXGetCurrentContext();
1286 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1291 glXGetCurrentDisplayEXT(void)
1293 return glXGetCurrentDisplay();
1298 glXGetCurrentDrawable(void)
1300 GLXContext gc
= glXGetCurrentContext();
1301 return gc
? gc
->currentDrawable
: 0;
1306 glXGetCurrentReadDrawable(void)
1308 GLXContext gc
= glXGetCurrentContext();
1309 return gc
? gc
->currentReadable
: 0;
1314 glXGetCurrentReadDrawableSGI(void)
1316 return glXGetCurrentReadDrawable();
1321 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1326 v
= find_glx_visual( dpy
, visinfo
);
1328 v
= create_glx_visual( dpy
, visinfo
);
1330 /* unusable visual */
1335 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1339 return b
->ws
.drawable
;
1343 /*** GLX_MESA_pixmap_colormap ***/
1346 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1347 Pixmap pixmap
, Colormap cmap
)
1352 v
= find_glx_visual( dpy
, visinfo
);
1354 v
= create_glx_visual( dpy
, visinfo
);
1356 /* unusable visual */
1361 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1365 return b
->ws
.drawable
;
1370 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1372 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1374 XMesaDestroyBuffer(b
);
1376 else if (getenv("MESA_DEBUG")) {
1377 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1383 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1384 unsigned long mask
)
1386 XMesaContext xm_src
= src
->xmesaContext
;
1387 XMesaContext xm_dst
= dst
->xmesaContext
;
1389 if (MakeCurrent_PrevContext
== src
) {
1392 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1397 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1400 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1401 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1407 return True
; /* we're faking GLX so always return success */
1412 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1415 GLXContext glxCtx
= ctx
;
1417 MakeCurrent_PrevContext
= 0;
1418 MakeCurrent_PrevDrawable
= 0;
1419 MakeCurrent_PrevReadable
= 0;
1420 MakeCurrent_PrevDrawBuffer
= 0;
1421 MakeCurrent_PrevReadBuffer
= 0;
1422 XMesaDestroyContext( glxCtx
->xmesaContext
);
1423 XMesaGarbageCollect();
1430 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1432 return ctx
? ctx
->isDirect
: False
;
1438 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1440 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1441 static boolean firsttime
= 1, no_rast
= 0;
1444 no_rast
= getenv("SP_NO_RAST") != NULL
;
1452 XMesaSwapBuffers(buffer
);
1454 else if (getenv("MESA_DEBUG")) {
1455 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1462 /*** GLX_MESA_copy_sub_buffer ***/
1465 glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
1466 int x
, int y
, int width
, int height
)
1468 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1470 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1472 else if (getenv("MESA_DEBUG")) {
1473 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1479 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1482 /* Return GLX version, not Mesa version */
1483 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1484 *maj
= CLIENT_MAJOR_VERSION
;
1485 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1491 * Query the GLX attributes of the given XVisualInfo.
1494 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1500 return GLX_BAD_ATTRIBUTE
;
1501 *value
= (int) True
;
1503 case GLX_BUFFER_SIZE
:
1504 *value
= xmvis
->visinfo
->depth
;
1507 *value
= xmvis
->mesa_visual
.level
;
1511 return GLX_BAD_ATTRIBUTE
;
1512 if (xmvis
->mesa_visual
.rgbMode
) {
1519 case GLX_DOUBLEBUFFER
:
1520 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1523 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1525 case GLX_AUX_BUFFERS
:
1526 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1529 *value
= xmvis
->mesa_visual
.redBits
;
1531 case GLX_GREEN_SIZE
:
1532 *value
= xmvis
->mesa_visual
.greenBits
;
1535 *value
= xmvis
->mesa_visual
.blueBits
;
1537 case GLX_ALPHA_SIZE
:
1538 *value
= xmvis
->mesa_visual
.alphaBits
;
1540 case GLX_DEPTH_SIZE
:
1541 *value
= xmvis
->mesa_visual
.depthBits
;
1543 case GLX_STENCIL_SIZE
:
1544 *value
= xmvis
->mesa_visual
.stencilBits
;
1546 case GLX_ACCUM_RED_SIZE
:
1547 *value
= xmvis
->mesa_visual
.accumRedBits
;
1549 case GLX_ACCUM_GREEN_SIZE
:
1550 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1552 case GLX_ACCUM_BLUE_SIZE
:
1553 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1555 case GLX_ACCUM_ALPHA_SIZE
:
1556 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1560 * GLX_EXT_visual_info extension
1562 case GLX_X_VISUAL_TYPE_EXT
:
1563 switch (xmvis
->visinfo
->CLASS
) {
1564 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1565 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1566 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1567 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1568 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1569 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1572 case GLX_TRANSPARENT_TYPE_EXT
:
1574 *value
= GLX_NONE_EXT
;
1576 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1579 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1582 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1585 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1588 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1593 * GLX_EXT_visual_info extension
1595 case GLX_VISUAL_CAVEAT_EXT
:
1596 /* test for zero, just in case */
1597 if (xmvis
->mesa_visual
.visualRating
> 0)
1598 *value
= xmvis
->mesa_visual
.visualRating
;
1600 *value
= GLX_NONE_EXT
;
1604 * GLX_ARB_multisample
1606 case GLX_SAMPLE_BUFFERS_ARB
:
1609 case GLX_SAMPLES_ARB
:
1616 case GLX_SCREEN_EXT
:
1618 return GLX_BAD_ATTRIBUTE
;
1619 *value
= xmvis
->visinfo
->screen
;
1621 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1623 return GLX_BAD_ATTRIBUTE
;
1624 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1626 case GLX_RENDER_TYPE_SGIX
:
1628 return GLX_BAD_ATTRIBUTE
;
1629 if (xmvis
->mesa_visual
.rgbMode
)
1630 *value
= GLX_RGBA_BIT
;
1632 *value
= GLX_COLOR_INDEX_BIT
;
1634 case GLX_X_RENDERABLE_SGIX
:
1636 return GLX_BAD_ATTRIBUTE
;
1637 *value
= True
; /* XXX really? */
1639 case GLX_FBCONFIG_ID_SGIX
:
1641 return GLX_BAD_ATTRIBUTE
;
1642 *value
= xmvis
->visinfo
->visualid
;
1644 case GLX_MAX_PBUFFER_WIDTH
:
1646 return GLX_BAD_ATTRIBUTE
;
1647 /* XXX should be same as ctx->Const.MaxRenderbufferSize */
1648 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1650 case GLX_MAX_PBUFFER_HEIGHT
:
1652 return GLX_BAD_ATTRIBUTE
;
1653 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1655 case GLX_MAX_PBUFFER_PIXELS
:
1657 return GLX_BAD_ATTRIBUTE
;
1658 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1659 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1663 return GLX_BAD_ATTRIBUTE
;
1664 *value
= xmvis
->visinfo
->visualid
;
1667 #ifdef GLX_EXT_texture_from_pixmap
1668 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1669 *value
= True
; /*XXX*/
1671 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1673 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1675 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1676 *value
= True
; /*XXX*/
1678 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1679 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1680 GLX_TEXTURE_2D_BIT_EXT
|
1681 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1683 case GLX_Y_INVERTED_EXT
:
1684 *value
= True
; /*XXX*/
1689 return GLX_BAD_ATTRIBUTE
;
1696 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1697 int attrib
, int *value
)
1701 if (!dpy
|| !visinfo
)
1702 return GLX_BAD_ATTRIBUTE
;
1704 xmvis
= find_glx_visual( dpy
, visinfo
);
1706 /* this visual wasn't obtained with glXChooseVisual */
1707 xmvis
= create_glx_visual( dpy
, visinfo
);
1709 /* this visual can't be used for GL rendering */
1710 if (attrib
==GLX_USE_GL
) {
1711 *value
= (int) False
;
1715 return GLX_BAD_VISUAL
;
1720 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1728 XMesaContext xmesa
= XMesaGetCurrentContext();
1729 XMesaFlush( xmesa
);
1737 XMesaContext xmesa
= XMesaGetCurrentContext();
1738 XMesaFlush( xmesa
);
1743 get_extensions( void )
1750 /* GLX 1.1 and later */
1752 glXQueryExtensionsString( Display
*dpy
, int screen
)
1756 return get_extensions();
1761 /* GLX 1.1 and later */
1763 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1765 static char version
[1000];
1766 sprintf(version
, "%d.%d %s",
1767 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, xmesa_get_name());
1773 case GLX_EXTENSIONS
:
1774 return get_extensions();
1786 /* GLX 1.1 and later */
1788 glXGetClientString( Display
*dpy
, int name
)
1790 static char version
[1000];
1791 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1792 CLIENT_MINOR_VERSION
, xmesa_get_name());
1797 case GLX_EXTENSIONS
:
1798 return get_extensions();
1816 glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1817 int attribute
, int *value
)
1819 XMesaVisual v
= (XMesaVisual
) config
;
1823 if (!dpy
|| !config
|| !value
)
1826 return get_config(v
, attribute
, value
, GL_TRUE
);
1830 PUBLIC GLXFBConfig
*
1831 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1833 XVisualInfo
*visuals
, visTemplate
;
1834 const long visMask
= VisualScreenMask
;
1837 /* Get list of all X visuals */
1838 visTemplate
.screen
= screen
;
1839 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1840 if (*nelements
> 0) {
1841 XMesaVisual
*results
= malloc(*nelements
* sizeof(XMesaVisual
));
1846 for (i
= 0; i
< *nelements
; i
++) {
1847 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1853 return (GLXFBConfig
*) results
;
1859 PUBLIC GLXFBConfig
*
1860 glXChooseFBConfig(Display
*dpy
, int screen
,
1861 const int *attribList
, int *nitems
)
1865 /* register ourselves as an extension on this display */
1866 register_with_display(dpy
);
1868 if (!attribList
|| !attribList
[0]) {
1869 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1870 return glXGetFBConfigs(dpy
, screen
, nitems
);
1873 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1875 GLXFBConfig
*config
= malloc(sizeof(XMesaVisual
));
1881 config
[0] = (GLXFBConfig
) xmvis
;
1882 return (GLXFBConfig
*) config
;
1891 PUBLIC XVisualInfo
*
1892 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1894 if (dpy
&& config
) {
1895 XMesaVisual xmvis
= (XMesaVisual
) config
;
1897 return xmvis
->vishandle
;
1899 /* create a new vishandle - the cached one may be stale */
1900 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1901 if (xmvis
->vishandle
) {
1902 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1904 return xmvis
->vishandle
;
1914 glXCreateWindow(Display
*dpy
, GLXFBConfig config
, Window win
,
1915 const int *attribList
)
1917 XMesaVisual xmvis
= (XMesaVisual
) config
;
1922 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1927 (void) attribList
; /* Ignored in GLX 1.3 */
1929 return win
; /* A hack for now */
1934 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1936 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1938 XMesaDestroyBuffer(b
);
1939 /* don't destroy X window */
1945 glXCreatePixmap(Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1946 const int *attribList
)
1948 XMesaVisual v
= (XMesaVisual
) config
;
1951 int target
= 0, format
= 0, mipmap
= 0;
1954 if (!dpy
|| !config
|| !pixmap
)
1957 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1959 case GLX_TEXTURE_FORMAT_EXT
:
1962 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1963 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1964 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1972 case GLX_TEXTURE_TARGET_EXT
:
1975 case GLX_TEXTURE_1D_EXT
:
1976 case GLX_TEXTURE_2D_EXT
:
1977 case GLX_TEXTURE_RECTANGLE_EXT
:
1985 case GLX_MIPMAP_TEXTURE_EXT
:
1996 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1997 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1998 &value
, GL_TRUE
) != Success
2000 return 0; /* error! */
2003 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2004 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2005 &value
, GL_TRUE
) != Success
2007 return 0; /* error! */
2011 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2012 &value
, GL_TRUE
) != Success
2014 return 0; /* error! */
2017 if (target
== GLX_TEXTURE_1D_EXT
) {
2018 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2019 &value
, GL_TRUE
) != Success
2020 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2021 return 0; /* error! */
2024 else if (target
== GLX_TEXTURE_2D_EXT
) {
2025 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2026 &value
, GL_TRUE
) != Success
2027 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2028 return 0; /* error! */
2031 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2032 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2033 &value
, GL_TRUE
) != Success
2034 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2035 return 0; /* error! */
2039 if (format
|| target
|| mipmap
) {
2040 /* texture from pixmap */
2041 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2044 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2055 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2057 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
2059 XMesaDestroyBuffer(b
);
2060 /* don't destroy X pixmap */
2065 glXCreatePbuffer(Display
*dpy
, GLXFBConfig config
, const int *attribList
)
2067 XMesaVisual xmvis
= (XMesaVisual
) config
;
2070 int width
= 0, height
= 0;
2071 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2075 for (attrib
= attribList
; *attrib
; attrib
++) {
2077 case GLX_PBUFFER_WIDTH
:
2081 case GLX_PBUFFER_HEIGHT
:
2085 case GLX_PRESERVED_CONTENTS
:
2087 preserveContents
= *attrib
;
2089 case GLX_LARGEST_PBUFFER
:
2091 useLargest
= *attrib
;
2098 if (width
== 0 || height
== 0)
2101 if (width
> PBUFFER_MAX_SIZE
|| height
> PBUFFER_MAX_SIZE
) {
2102 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2103 * allocate the largest possible buffer.
2106 width
= PBUFFER_MAX_SIZE
;
2107 height
= PBUFFER_MAX_SIZE
;
2111 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2112 /* A GLXPbuffer handle must be an X Drawable because that's what
2113 * glXMakeCurrent takes.
2116 xmbuf
->largestPbuffer
= useLargest
;
2117 xmbuf
->preservedContents
= preserveContents
;
2118 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2127 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2129 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2131 XMesaDestroyBuffer(b
);
2137 glXQueryDrawable(Display
*dpy
, GLXDrawable draw
, int attribute
,
2138 unsigned int *value
)
2140 GLuint width
, height
;
2141 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2143 generate_error(dpy
, GLXBadDrawable
, draw
, X_GLXGetDrawableAttributes
, False
);
2147 /* make sure buffer's dimensions are up to date */
2148 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2150 switch (attribute
) {
2157 case GLX_PRESERVED_CONTENTS
:
2158 *value
= xmbuf
->preservedContents
;
2160 case GLX_LARGEST_PBUFFER
:
2161 *value
= xmbuf
->largestPbuffer
;
2163 case GLX_FBCONFIG_ID
:
2164 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2166 #ifdef GLX_EXT_texture_from_pixmap
2167 case GLX_TEXTURE_FORMAT_EXT
:
2168 *value
= xmbuf
->TextureFormat
;
2170 case GLX_TEXTURE_TARGET_EXT
:
2171 *value
= xmbuf
->TextureTarget
;
2173 case GLX_MIPMAP_TEXTURE_EXT
:
2174 *value
= xmbuf
->TextureMipmap
;
2179 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, true);
2186 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2187 int renderType
, GLXContext shareCtx
, Bool direct
)
2189 XMesaVisual xmvis
= (XMesaVisual
) config
;
2191 if (!dpy
|| !config
||
2192 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2195 return create_context(dpy
, xmvis
,
2196 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2198 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2203 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2205 GLXContext glxCtx
= ctx
;
2206 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2211 switch (attribute
) {
2212 case GLX_FBCONFIG_ID
:
2213 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2215 case GLX_RENDER_TYPE
:
2216 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2217 *value
= GLX_RGBA_TYPE
;
2219 *value
= GLX_COLOR_INDEX_TYPE
;
2225 return GLX_BAD_ATTRIBUTE
;
2232 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2234 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2236 xmbuf
->selectedEvents
= mask
;
2241 glXGetSelectedEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2243 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2245 *mask
= xmbuf
->selectedEvents
;
2252 /*** GLX_SGI_swap_control ***/
2255 glXSwapIntervalSGI(int interval
)
2263 /*** GLX_SGI_video_sync ***/
2265 static unsigned int FrameCounter
= 0;
2268 glXGetVideoSyncSGI(unsigned int *count
)
2270 /* this is a bogus implementation */
2271 *count
= FrameCounter
++;
2276 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2278 if (divisor
<= 0 || remainder
< 0)
2279 return GLX_BAD_VALUE
;
2280 /* this is a bogus implementation */
2282 while (FrameCounter
% divisor
!= remainder
)
2284 *count
= FrameCounter
;
2290 /*** GLX_SGI_make_current_read ***/
2293 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
,
2296 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2301 glXGetCurrentReadDrawableSGI(void)
2308 /*** GLX_SGIX_video_source ***/
2311 PUBLIC GLXVideoSourceSGIX
2312 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
,
2313 VLPath path
, int nodeClass
, VLNode drainNode
)
2325 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2334 /*** GLX_EXT_import_context ***/
2337 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2344 glXGetContextIDEXT(const GLXContext context
)
2351 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2359 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
,
2371 /*** GLX_SGIX_fbconfig ***/
2374 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2375 int attribute
, int *value
)
2377 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2380 PUBLIC GLXFBConfigSGIX
*
2381 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
,
2384 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
,
2385 attrib_list
, nelements
);
2390 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2393 XMesaVisual xmvis
= (XMesaVisual
) config
;
2394 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2395 return xmbuf
->ws
.drawable
; /* need to return an X ID */
2400 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2401 int renderType
, GLXContext shareCtx
,
2404 XMesaVisual xmvis
= (XMesaVisual
) config
;
2406 if (!dpy
|| !config
||
2407 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2410 return create_context(dpy
, xmvis
,
2411 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2413 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2417 PUBLIC XVisualInfo
*
2418 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2420 return glXGetVisualFromFBConfig(dpy
, config
);
2424 PUBLIC GLXFBConfigSGIX
2425 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2427 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2429 /* This visual wasn't found with glXChooseVisual() */
2430 xmvis
= create_glx_visual(dpy
, vis
);
2433 return (GLXFBConfigSGIX
) xmvis
;
2438 /*** GLX_SGIX_pbuffer ***/
2440 PUBLIC GLXPbufferSGIX
2441 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2442 unsigned int width
, unsigned int height
,
2445 XMesaVisual xmvis
= (XMesaVisual
) config
;
2448 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2452 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2454 case GLX_PRESERVED_CONTENTS_SGIX
:
2456 preserveContents
= *attrib
; /* ignored */
2458 case GLX_LARGEST_PBUFFER_SGIX
:
2460 useLargest
= *attrib
; /* ignored */
2467 /* not used at this time */
2469 (void) preserveContents
;
2471 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2472 /* A GLXPbuffer handle must be an X Drawable because that's what
2473 * glXMakeCurrent takes.
2475 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2480 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2482 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2484 XMesaDestroyBuffer(xmbuf
);
2490 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
,
2491 unsigned int *value
)
2493 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2496 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2500 switch (attribute
) {
2501 case GLX_PRESERVED_CONTENTS_SGIX
:
2504 case GLX_LARGEST_PBUFFER_SGIX
:
2505 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2507 case GLX_WIDTH_SGIX
:
2508 *value
= xmesa_buffer_width(xmbuf
);
2510 case GLX_HEIGHT_SGIX
:
2511 *value
= xmesa_buffer_height(xmbuf
);
2513 case GLX_EVENT_MASK_SGIX
:
2514 *value
= 0; /* XXX might be wrong */
2524 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2526 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2528 /* Note: we'll never generate clobber events */
2529 xmbuf
->selectedEvents
= mask
;
2535 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
,
2536 unsigned long *mask
)
2538 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2540 *mask
= xmbuf
->selectedEvents
;
2549 /*** GLX_SGI_cushion ***/
2552 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2561 /*** GLX_SGIX_video_resize ***/
2564 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
,
2575 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2576 int x
, int y
, int w
, int h
)
2589 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2590 int *x
, int *y
, int *w
, int *h
)
2603 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
,
2604 int *dx
, int *dy
, int *dw
, int *dh
)
2617 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2628 /*** GLX_SGIX_dmbuffer **/
2630 #if defined(_DM_BUFFER_H_)
2632 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
,
2633 DMparams
*params
, DMbuffer dmbuffer
)
2644 /*** GLX_SGIX_swap_group ***/
2647 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2656 /*** GLX_SGIX_swap_barrier ***/
2659 glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2667 glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2677 /*** GLX_SUN_get_transparent_index ***/
2680 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
,
2686 (void) pTransparent
;
2692 /*** GLX_MESA_release_buffers ***/
2695 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2696 * (a window or pixmap) prior to destroying the GLXDrawable.
2699 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2701 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2703 XMesaDestroyBuffer(b
);
2709 /*** GLX_EXT_texture_from_pixmap ***/
2712 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2713 const int *attrib_list
)
2715 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2717 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2721 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2723 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2725 XMesaReleaseTexImage(dpy
, b
, buffer
);
2730 /*** GLX_ARB_create_context ***/
2734 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
2735 GLXContext shareCtx
, Bool direct
,
2736 const int *attrib_list
)
2738 XMesaVisual xmvis
= (XMesaVisual
) config
;
2739 int majorVersion
= 1, minorVersion
= 0;
2740 int contextFlags
= 0x0;
2741 int profileMask
= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
;
2742 int renderType
= GLX_RGBA_TYPE
;
2745 const int contextFlagsAll
= (GLX_CONTEXT_DEBUG_BIT_ARB
|
2746 GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
);
2749 /* parse attrib_list */
2750 for (i
= 0; !done
&& attrib_list
&& attrib_list
[i
]; i
++) {
2751 switch (attrib_list
[i
]) {
2752 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2753 majorVersion
= attrib_list
[++i
];
2755 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2756 minorVersion
= attrib_list
[++i
];
2758 case GLX_CONTEXT_FLAGS_ARB
:
2759 contextFlags
= attrib_list
[++i
];
2761 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2762 profileMask
= attrib_list
[++i
];
2764 case GLX_RENDER_TYPE
:
2765 renderType
= attrib_list
[++i
];
2773 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2778 /* check contextFlags */
2779 if (contextFlags
& ~contextFlagsAll
) {
2780 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2784 /* check profileMask */
2785 if (profileMask
!= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
&&
2786 profileMask
!= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
&&
2787 profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
) {
2788 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAttribsARB
, False
);
2792 /* check renderType */
2793 if (renderType
!= GLX_RGBA_TYPE
&&
2794 renderType
!= GLX_COLOR_INDEX_TYPE
) {
2795 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2800 if (majorVersion
<= 0 ||
2802 (profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2803 ((majorVersion
== 1 && minorVersion
> 5) ||
2804 (majorVersion
== 2 && minorVersion
> 1) ||
2805 (majorVersion
== 3 && minorVersion
> 3) ||
2806 (majorVersion
== 4 && minorVersion
> 5) ||
2807 majorVersion
> 4))) {
2808 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2811 if (profileMask
== GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2812 ((majorVersion
== 1 && minorVersion
> 1) ||
2813 (majorVersion
== 2 && minorVersion
> 0) ||
2814 (majorVersion
== 3 && minorVersion
> 1) ||
2815 majorVersion
> 3)) {
2816 /* GLX_EXT_create_context_es2_profile says nothing to justifying a
2817 * different error code for invalid ES versions, but this is what NVIDIA
2818 * does and piglit expects.
2820 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAttribsARB
, False
);
2824 if ((contextFlags
& GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
) &&
2826 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2830 if (renderType
== GLX_COLOR_INDEX_TYPE
&& majorVersion
>= 3) {
2831 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2835 ctx
= create_context(dpy
, xmvis
,
2836 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2838 majorVersion
, minorVersion
,
2839 profileMask
, contextFlags
);
2841 generate_error(dpy
, GLXBadFBConfig
, 0, X_GLXCreateContextAttribsARB
, False
);