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>
44 /* This indicates the client-side GLX API and GLX encoder version. */
45 #define CLIENT_MAJOR_VERSION 1
46 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
48 /* This indicates the server-side GLX decoder version.
49 * GLX 1.4 indicates OpenGL 1.3 support
51 #define SERVER_MAJOR_VERSION 1
52 #define SERVER_MINOR_VERSION 4
54 /* Who implemented this GLX? */
55 #define VENDOR "Brian Paul"
58 "GLX_MESA_copy_sub_buffer " \
59 "GLX_MESA_pixmap_colormap " \
60 "GLX_MESA_release_buffers " \
61 "GLX_ARB_create_context " \
62 "GLX_ARB_create_context_profile " \
63 "GLX_ARB_get_proc_address " \
64 "GLX_EXT_create_context_es_profile " \
65 "GLX_EXT_create_context_es2_profile " \
66 "GLX_EXT_texture_from_pixmap " \
67 "GLX_EXT_visual_info " \
68 "GLX_EXT_visual_rating " \
69 /*"GLX_SGI_video_sync "*/ \
70 "GLX_SGIX_fbconfig " \
73 #define DEFAULT_DIRECT GL_TRUE
76 /** XXX this could be based on gallium's max texture size */
77 #define PBUFFER_MAX_SIZE 16384
81 * The GLXContext typedef is defined as a pointer to this structure.
83 struct __GLXcontextRec
87 GLXDrawable currentDrawable
;
88 GLXDrawable currentReadable
;
91 XMesaContext xmesaContext
;
96 static pipe_tsd ContextTSD
;
98 /** Set current context for calling thread */
100 SetCurrentContext(GLXContext c
)
102 pipe_tsd_set(&ContextTSD
, c
);
105 /** Get current context for calling thread */
107 GetCurrentContext(void)
109 return pipe_tsd_get(&ContextTSD
);
114 /**********************************************************************/
115 /*** GLX Visual Code ***/
116 /**********************************************************************/
121 static XMesaVisual
*VisualTable
= NULL
;
122 static int NumVisuals
= 0;
126 /* Macro to handle c_class vs class field name in XVisualInfo struct */
127 #if defined(__cplusplus) || defined(c_plusplus)
128 #define CLASS c_class
136 * Test if the given XVisualInfo is usable for Mesa rendering.
139 is_usable_visual( XVisualInfo
*vinfo
)
141 switch (vinfo
->CLASS
) {
144 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
148 /* Any StaticColor/PseudoColor visual of at least 4 bits */
149 if (vinfo
->depth
>=4) {
157 /* Any depth of TrueColor or DirectColor works in RGB mode */
160 /* This should never happen */
167 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
168 * configuration in our list of GLX visuals.
171 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
172 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
173 GLboolean stereoFlag
,
174 GLint depth_size
, GLint stencil_size
,
175 GLint accumRedSize
, GLint accumGreenSize
,
176 GLint accumBlueSize
, GLint accumAlphaSize
,
177 GLint level
, GLint numAuxBuffers
)
179 GLboolean ximageFlag
= GL_TRUE
;
182 GLboolean comparePointers
;
185 /* Check if the MESA_BACK_BUFFER env var is set */
186 char *backbuffer
= getenv("MESA_BACK_BUFFER");
188 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
189 ximageFlag
= GL_FALSE
;
191 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
192 ximageFlag
= GL_TRUE
;
195 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
201 /* stereo not supported */
205 if (stencil_size
> 0 && depth_size
> 0)
208 /* Comparing IDs uses less memory but sometimes fails. */
209 /* XXX revisit this after 3.0 is finished. */
210 if (getenv("MESA_GLX_VISUAL_HACK"))
211 comparePointers
= GL_TRUE
;
213 comparePointers
= GL_FALSE
;
215 /* Force the visual to have an alpha channel */
216 if (rgbFlag
&& getenv("MESA_GLX_FORCE_ALPHA"))
219 /* First check if a matching visual is already in the list */
220 for (i
=0; i
<NumVisuals
; i
++) {
221 XMesaVisual v
= VisualTable
[i
];
222 if (v
->display
== dpy
223 && v
->mesa_visual
.level
== level
224 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
225 && v
->ximage_flag
== ximageFlag
226 && v
->mesa_visual
.rgbMode
== rgbFlag
227 && v
->mesa_visual
.doubleBufferMode
== dbFlag
228 && v
->mesa_visual
.stereoMode
== stereoFlag
229 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
230 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
231 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
232 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
233 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
234 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
235 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
236 /* now either compare XVisualInfo pointers or visual IDs */
237 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
238 || (comparePointers
&& v
->vishandle
== vinfo
)) {
244 /* Create a new visual and add it to the list. */
246 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
247 stereoFlag
, ximageFlag
,
248 depth_size
, stencil_size
,
249 accumRedSize
, accumBlueSize
,
250 accumBlueSize
, accumAlphaSize
, 0, level
,
253 /* Save a copy of the pointer now so we can find this visual again
254 * if we need to search for it in find_glx_visual().
256 xmvis
->vishandle
= vinfo
;
257 /* Allocate more space for additional visual */
258 VisualTable
= realloc(VisualTable
, sizeof(XMesaVisual
) * (NumVisuals
+ 1));
259 /* add xmvis to the list */
260 VisualTable
[NumVisuals
] = xmvis
;
262 /* XXX minor hack, because XMesaCreateVisual doesn't support an
263 * aux buffers parameter.
265 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
272 * Return the default number of bits for the Z buffer.
273 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
274 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
275 * XXX probably do the same thing for stencil, accum, etc.
278 default_depth_bits(void)
281 const char *zEnv
= getenv("MESA_GLX_DEPTH_BITS");
290 default_alpha_bits(void)
293 const char *aEnv
= getenv("MESA_GLX_ALPHA_BITS");
302 default_accum_bits(void)
310 * Create a GLX visual from a regular XVisualInfo.
311 * This is called when Fake GLX is given an XVisualInfo which wasn't
312 * returned by glXChooseVisual. Since this is the first time we're
313 * considering this visual we'll take a guess at reasonable values
314 * for depth buffer size, stencil size, accum size, etc.
315 * This is the best we can do with a client-side emulation of GLX.
318 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
320 GLint zBits
= default_depth_bits();
321 GLint accBits
= default_accum_bits();
322 GLboolean alphaFlag
= default_alpha_bits() > 0;
324 if (is_usable_visual( visinfo
)) {
325 /* Configure this visual as RGB, double-buffered, depth-buffered. */
326 /* This is surely wrong for some people's needs but what else */
327 /* can be done? They should use glXChooseVisual(). */
328 return save_glx_visual( dpy
, visinfo
,
330 alphaFlag
, /* alpha */
331 GL_TRUE
, /* double */
332 GL_FALSE
, /* stereo */
334 8, /* stencil bits */
344 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
352 * Find the GLX visual associated with an XVisualInfo.
355 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
359 /* try to match visual id */
360 for (i
=0;i
<NumVisuals
;i
++) {
361 if (VisualTable
[i
]->display
==dpy
362 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
363 return VisualTable
[i
];
367 /* if that fails, try to match pointers */
368 for (i
=0;i
<NumVisuals
;i
++) {
369 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
370 return VisualTable
[i
];
379 * Try to get an X visual which matches the given arguments.
382 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
384 XVisualInfo temp
, *vis
;
387 unsigned int default_depth
;
390 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
395 default_depth
= DefaultDepth(dpy
,scr
);
396 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
398 if (depth
==default_depth
&& xclass
==default_class
) {
399 /* try to get root window's visual */
400 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
401 mask
|= VisualIDMask
;
404 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
406 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
407 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
408 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
410 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
411 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
412 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
413 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
427 * Retrieve the value of the given environment variable and find
428 * the X visual which matches it.
429 * Input: dpy - the display
430 * screen - the screen number
431 * varname - the name of the environment variable
432 * Return: an XVisualInfo pointer to NULL if error.
435 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
437 char value
[100], type
[100];
438 int depth
, xclass
= -1;
441 if (!getenv( varname
)) {
445 strncpy( value
, getenv(varname
), 100 );
448 sscanf( value
, "%s %d", type
, &depth
);
450 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
451 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
452 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
453 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
454 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
455 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
457 if (xclass
>-1 && depth
>0) {
458 vis
= get_visual( dpy
, scr
, depth
, xclass
);
464 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
473 * Select an X visual which satisfies the RGBA flag and minimum depth.
475 * screen - X display and screen number
476 * min_depth - minimum visual depth
477 * preferred_class - preferred GLX visual class or DONT_CARE
478 * Return: pointer to an XVisualInfo or NULL.
481 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
482 int preferred_class
)
485 int xclass
, visclass
= 0;
488 /* First see if the MESA_RGB_VISUAL env var is defined */
489 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
493 /* Otherwise, search for a suitable visual */
494 if (preferred_class
==DONT_CARE
) {
495 for (xclass
=0;xclass
<6;xclass
++) {
497 case 0: visclass
= TrueColor
; break;
498 case 1: visclass
= DirectColor
; break;
499 case 2: visclass
= PseudoColor
; break;
500 case 3: visclass
= StaticColor
; break;
501 case 4: visclass
= GrayScale
; break;
502 case 5: visclass
= StaticGray
; break;
505 /* start with shallowest */
506 for (depth
=0;depth
<=32;depth
++) {
507 if (visclass
==TrueColor
&& depth
==8) {
508 /* Special case: try to get 8-bit PseudoColor before */
509 /* 8-bit TrueColor */
510 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
515 vis
= get_visual( dpy
, screen
, depth
, visclass
);
522 /* start with deepest */
523 for (depth
=32;depth
>=min_depth
;depth
--) {
524 if (visclass
==TrueColor
&& depth
==8) {
525 /* Special case: try to get 8-bit PseudoColor before */
526 /* 8-bit TrueColor */
527 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
532 vis
= get_visual( dpy
, screen
, depth
, visclass
);
541 /* search for a specific visual class */
542 switch (preferred_class
) {
543 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
544 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
545 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
546 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
547 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
548 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
549 default: return NULL
;
552 /* start with shallowest */
553 for (depth
=0;depth
<=32;depth
++) {
554 vis
= get_visual( dpy
, screen
, depth
, visclass
);
561 /* start with deepest */
562 for (depth
=32;depth
>=min_depth
;depth
--) {
563 vis
= get_visual( dpy
, screen
, depth
, visclass
);
571 /* didn't find a visual */
578 /**********************************************************************/
579 /*** Display-related functions ***/
580 /**********************************************************************/
584 * Free all XMesaVisuals which are associated with the given display.
587 destroy_visuals_on_display(Display
*dpy
)
590 for (i
= 0; i
< NumVisuals
; i
++) {
591 if (VisualTable
[i
]->display
== dpy
) {
592 /* remove this visual */
594 free(VisualTable
[i
]);
595 for (j
= i
; j
< NumVisuals
- 1; j
++)
596 VisualTable
[j
] = VisualTable
[j
+ 1];
604 * Called from XCloseDisplay() to let us free our display-related data.
607 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
609 xmesa_destroy_buffers_on_display(dpy
);
610 destroy_visuals_on_display(dpy
);
616 * Look for the named extension on given display and return a pointer
617 * to the _XExtension data, or NULL if extension not found.
620 lookup_extension(Display
*dpy
, const char *extName
)
623 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
624 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
633 * Whenever we're given a new Display pointer, call this function to
634 * register our close_display_callback function.
637 register_with_display(Display
*dpy
)
639 const char *extName
= "MesaGLX";
642 ext
= lookup_extension(dpy
, extName
);
644 XExtCodes
*c
= XAddExtension(dpy
);
645 ext
= dpy
->ext_procs
; /* new extension is at head of list */
646 assert(c
->extension
== ext
->codes
.extension
);
648 ext
->name
= strdup(extName
);
649 ext
->close_display
= close_display_callback
;
658 generate_error(Display
*dpy
,
659 unsigned char error_code
,
661 unsigned char minor_code
,
664 XErrorHandler handler
;
670 handler
= XSetErrorHandler(NULL
);
671 XSetErrorHandler(handler
);
676 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_opcode
, &first_event
, &first_error
)) {
683 error_code
+= first_error
;
686 memset(&event
, 0, sizeof event
);
688 event
.xerror
.type
= X_Error
;
689 event
.xerror
.display
= dpy
;
690 event
.xerror
.resourceid
= resourceid
;
691 event
.xerror
.serial
= NextRequest(dpy
) - 1;
692 event
.xerror
.error_code
= error_code
;
693 event
.xerror
.request_code
= major_opcode
;
694 event
.xerror
.minor_code
= minor_code
;
696 return handler(dpy
, &event
.xerror
);
700 /**********************************************************************/
701 /*** Begin Fake GLX API Functions ***/
702 /**********************************************************************/
706 * Helper used by glXChooseVisual and glXChooseFBConfig.
707 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
709 * In either case, the attribute list is terminated with the value 'None'.
712 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
714 const GLboolean rgbModeDefault
= fbConfig
;
715 const int *parselist
;
717 int min_red
=0, min_green
=0, min_blue
=0;
718 GLboolean rgb_flag
= rgbModeDefault
;
719 GLboolean alpha_flag
= GL_FALSE
;
720 GLboolean double_flag
= GL_FALSE
;
721 GLboolean stereo_flag
= GL_FALSE
;
722 GLint depth_size
= 0;
723 GLint stencil_size
= 0;
724 GLint accumRedSize
= 0;
725 GLint accumGreenSize
= 0;
726 GLint accumBlueSize
= 0;
727 GLint accumAlphaSize
= 0;
729 int visual_type
= DONT_CARE
;
730 GLint caveat
= DONT_CARE
;
731 XMesaVisual xmvis
= NULL
;
732 int desiredVisualID
= -1;
742 parselist
[1] == GLX_DONT_CARE
&&
743 parselist
[0] != GLX_LEVEL
) {
744 /* For glXChooseFBConfig(), skip attributes whose value is
745 * GLX_DONT_CARE, unless it's GLX_LEVEL (which can legitimately be
748 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
749 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
755 switch (*parselist
) {
766 case GLX_BUFFER_SIZE
:
772 level
= *parselist
++;
784 case GLX_DOUBLEBUFFER
:
787 double_flag
= *parselist
++;
790 double_flag
= GL_TRUE
;
796 stereo_flag
= *parselist
++;
799 stereo_flag
= GL_TRUE
;
802 case GLX_AUX_BUFFERS
:
804 numAux
= *parselist
++;
805 if (numAux
> MAX_AUX_BUFFERS
)
810 min_red
= *parselist
++;
814 min_green
= *parselist
++;
818 min_blue
= *parselist
++;
823 GLint size
= *parselist
++;
824 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
829 depth_size
= *parselist
++;
831 case GLX_STENCIL_SIZE
:
833 stencil_size
= *parselist
++;
835 case GLX_ACCUM_RED_SIZE
:
838 GLint size
= *parselist
++;
839 accumRedSize
= MAX2( accumRedSize
, size
);
842 case GLX_ACCUM_GREEN_SIZE
:
845 GLint size
= *parselist
++;
846 accumGreenSize
= MAX2( accumGreenSize
, size
);
849 case GLX_ACCUM_BLUE_SIZE
:
852 GLint size
= *parselist
++;
853 accumBlueSize
= MAX2( accumBlueSize
, size
);
856 case GLX_ACCUM_ALPHA_SIZE
:
859 GLint size
= *parselist
++;
860 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
865 * GLX_EXT_visual_info extension
867 case GLX_X_VISUAL_TYPE_EXT
:
869 visual_type
= *parselist
++;
871 case GLX_TRANSPARENT_TYPE_EXT
:
875 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
879 case GLX_TRANSPARENT_RED_VALUE_EXT
:
880 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
881 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
882 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
889 * GLX_EXT_visual_info extension
891 case GLX_VISUAL_CAVEAT_EXT
:
893 caveat
= *parselist
++; /* ignored for now */
897 * GLX_ARB_multisample
899 case GLX_SAMPLE_BUFFERS_ARB
:
900 case GLX_SAMPLES_ARB
:
902 if (*parselist
++ != 0) {
903 /* ms not supported */
911 case GLX_RENDER_TYPE
:
915 if (*parselist
& GLX_RGBA_BIT
) {
918 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
921 else if (*parselist
== 0) {
926 case GLX_DRAWABLE_TYPE
:
930 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
931 return NULL
; /* bad bit */
935 case GLX_FBCONFIG_ID
:
940 desiredVisualID
= *parselist
++;
942 case GLX_X_RENDERABLE
:
943 case GLX_MAX_PBUFFER_WIDTH
:
944 case GLX_MAX_PBUFFER_HEIGHT
:
945 case GLX_MAX_PBUFFER_PIXELS
:
947 return NULL
; /* invalid config option */
948 parselist
+= 2; /* ignore the parameter */
951 #ifdef GLX_EXT_texture_from_pixmap
952 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
953 parselist
++; /*skip*/
955 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
956 parselist
++; /*skip*/
958 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
959 parselist
++; /*skip*/
961 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
963 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
964 GLX_TEXTURE_2D_BIT_EXT
|
965 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
970 case GLX_Y_INVERTED_EXT
:
971 parselist
++; /*skip*/
980 /* undefined attribute */
981 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
991 * Since we're only simulating the GLX extension this function will never
992 * find any real GL visuals. Instead, all we can do is try to find an RGB
993 * or CI visual of appropriate depth. Other requested attributes such as
994 * double buffering, depth buffer, etc. will be associated with the X
995 * visual and stored in the VisualTable[].
997 if (desiredVisualID
!= -1) {
998 /* try to get a specific visual, by visualID */
1001 temp
.visualid
= desiredVisualID
;
1002 temp
.screen
= screen
;
1003 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1005 /* give the visual some useful GLX attributes */
1006 double_flag
= GL_TRUE
;
1010 else if (level
==0) {
1011 /* normal color planes */
1012 /* Get an RGB visual */
1013 int min_rgb
= min_red
+ min_green
+ min_blue
;
1014 if (min_rgb
>1 && min_rgb
<8) {
1015 /* a special case to be sure we can get a monochrome visual */
1018 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
1021 _mesa_warning(NULL
, "overlay not supported");
1026 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1027 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1028 * largest depth buffer size, which is 32bits/value. Instead, we
1029 * return 16 to maintain performance with earlier versions of Mesa.
1031 if (stencil_size
> 0)
1032 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
1033 else if (depth_size
> 24)
1035 else if (depth_size
> 16)
1037 else if (depth_size
> 0) {
1038 depth_size
= default_depth_bits();
1042 alpha_flag
= default_alpha_bits() > 0;
1045 /* we only support one size of stencil and accum buffers. */
1046 if (stencil_size
> 0)
1049 if (accumRedSize
> 0 ||
1050 accumGreenSize
> 0 ||
1051 accumBlueSize
> 0 ||
1052 accumAlphaSize
> 0) {
1056 accumBlueSize
= default_accum_bits();
1058 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1061 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1062 stereo_flag
, depth_size
, stencil_size
,
1063 accumRedSize
, accumGreenSize
,
1064 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1071 PUBLIC XVisualInfo
*
1072 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1076 /* register ourselves as an extension on this display */
1077 register_with_display(dpy
);
1079 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1081 /* create a new vishandle - the cached one may be stale */
1082 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1083 if (xmvis
->vishandle
) {
1084 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1086 return xmvis
->vishandle
;
1094 * Helper function used by other glXCreateContext functions.
1097 create_context(Display
*dpy
, XMesaVisual xmvis
,
1098 XMesaContext shareCtx
, Bool direct
,
1099 unsigned major
, unsigned minor
,
1100 unsigned profileMask
, unsigned contextFlags
)
1107 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1111 /* deallocate unused windows/buffers */
1113 XMesaGarbageCollect();
1116 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
, shareCtx
, major
, minor
,
1117 profileMask
, contextFlags
);
1118 if (!glxCtx
->xmesaContext
) {
1123 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1124 glxCtx
->currentDpy
= dpy
;
1125 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1132 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1133 GLXContext shareCtx
, Bool direct
)
1137 xmvis
= find_glx_visual( dpy
, visinfo
);
1139 /* This visual wasn't found with glXChooseVisual() */
1140 xmvis
= create_glx_visual( dpy
, visinfo
);
1142 /* unusable visual */
1147 return create_context(dpy
, xmvis
,
1148 shareCtx
? shareCtx
->xmesaContext
: NULL
,
1150 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
1154 /* XXX these may have to be removed due to thread-safety issues. */
1155 static GLXContext MakeCurrent_PrevContext
= 0;
1156 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1157 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1158 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1159 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1162 /* GLX 1.3 and later */
1164 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1165 GLXDrawable read
, GLXContext ctx
)
1167 GLXContext glxCtx
= ctx
;
1168 static boolean firsttime
= 1, no_rast
= 0;
1171 no_rast
= getenv("SP_NO_RAST") != NULL
;
1175 if (ctx
&& draw
&& read
) {
1176 XMesaBuffer drawBuffer
, readBuffer
;
1177 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1179 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1180 if (ctx
== MakeCurrent_PrevContext
1181 && draw
== MakeCurrent_PrevDrawable
) {
1182 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1185 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1188 /* drawable must be a new window! */
1189 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1191 /* Out of memory, or context/drawable depth mismatch */
1196 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1197 if (ctx
== MakeCurrent_PrevContext
1198 && read
== MakeCurrent_PrevReadable
) {
1199 readBuffer
= MakeCurrent_PrevReadBuffer
;
1202 readBuffer
= XMesaFindBuffer( dpy
, read
);
1205 /* drawable must be a new window! */
1206 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1208 /* Out of memory, or context/drawable depth mismatch */
1214 MakeCurrent_PrevContext
== ctx
&&
1215 MakeCurrent_PrevDrawable
== draw
&&
1216 MakeCurrent_PrevReadable
== read
&&
1217 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1218 MakeCurrent_PrevReadBuffer
== readBuffer
)
1221 MakeCurrent_PrevContext
= ctx
;
1222 MakeCurrent_PrevDrawable
= draw
;
1223 MakeCurrent_PrevReadable
= read
;
1224 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1225 MakeCurrent_PrevReadBuffer
= readBuffer
;
1227 /* Now make current! */
1228 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1229 ctx
->currentDpy
= dpy
;
1230 ctx
->currentDrawable
= draw
;
1231 ctx
->currentReadable
= read
;
1232 SetCurrentContext(ctx
);
1239 else if (!ctx
&& !draw
&& !read
) {
1240 /* release current context w/out assigning new one. */
1241 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1242 MakeCurrent_PrevContext
= 0;
1243 MakeCurrent_PrevDrawable
= 0;
1244 MakeCurrent_PrevReadable
= 0;
1245 MakeCurrent_PrevDrawBuffer
= 0;
1246 MakeCurrent_PrevReadBuffer
= 0;
1247 SetCurrentContext(NULL
);
1251 /* The args must either all be non-zero or all zero.
1260 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1262 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1267 glXGetCurrentContext(void)
1269 return GetCurrentContext();
1274 glXGetCurrentDisplay(void)
1276 GLXContext glxCtx
= glXGetCurrentContext();
1278 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1283 glXGetCurrentDisplayEXT(void)
1285 return glXGetCurrentDisplay();
1290 glXGetCurrentDrawable(void)
1292 GLXContext gc
= glXGetCurrentContext();
1293 return gc
? gc
->currentDrawable
: 0;
1298 glXGetCurrentReadDrawable(void)
1300 GLXContext gc
= glXGetCurrentContext();
1301 return gc
? gc
->currentReadable
: 0;
1306 glXGetCurrentReadDrawableSGI(void)
1308 return glXGetCurrentReadDrawable();
1313 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1318 v
= find_glx_visual( dpy
, visinfo
);
1320 v
= create_glx_visual( dpy
, visinfo
);
1322 /* unusable visual */
1327 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1331 return b
->ws
.drawable
;
1335 /*** GLX_MESA_pixmap_colormap ***/
1338 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1339 Pixmap pixmap
, Colormap cmap
)
1344 v
= find_glx_visual( dpy
, visinfo
);
1346 v
= create_glx_visual( dpy
, visinfo
);
1348 /* unusable visual */
1353 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1357 return b
->ws
.drawable
;
1362 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1364 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1366 XMesaDestroyBuffer(b
);
1368 else if (getenv("MESA_DEBUG")) {
1369 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1375 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1376 unsigned long mask
)
1378 XMesaContext xm_src
= src
->xmesaContext
;
1379 XMesaContext xm_dst
= dst
->xmesaContext
;
1381 if (MakeCurrent_PrevContext
== src
) {
1384 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1389 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1392 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1393 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1399 return True
; /* we're faking GLX so always return success */
1404 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1407 GLXContext glxCtx
= ctx
;
1409 MakeCurrent_PrevContext
= 0;
1410 MakeCurrent_PrevDrawable
= 0;
1411 MakeCurrent_PrevReadable
= 0;
1412 MakeCurrent_PrevDrawBuffer
= 0;
1413 MakeCurrent_PrevReadBuffer
= 0;
1414 XMesaDestroyContext( glxCtx
->xmesaContext
);
1415 XMesaGarbageCollect();
1422 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1424 return ctx
? ctx
->isDirect
: False
;
1430 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1432 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1433 static boolean firsttime
= 1, no_rast
= 0;
1436 no_rast
= getenv("SP_NO_RAST") != NULL
;
1444 XMesaSwapBuffers(buffer
);
1446 else if (getenv("MESA_DEBUG")) {
1447 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1454 /*** GLX_MESA_copy_sub_buffer ***/
1457 glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
1458 int x
, int y
, int width
, int height
)
1460 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1462 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1464 else if (getenv("MESA_DEBUG")) {
1465 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1471 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1474 /* Return GLX version, not Mesa version */
1475 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1476 *maj
= CLIENT_MAJOR_VERSION
;
1477 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1483 * Query the GLX attributes of the given XVisualInfo.
1486 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1492 return GLX_BAD_ATTRIBUTE
;
1493 *value
= (int) True
;
1495 case GLX_BUFFER_SIZE
:
1496 *value
= xmvis
->visinfo
->depth
;
1499 *value
= xmvis
->mesa_visual
.level
;
1503 return GLX_BAD_ATTRIBUTE
;
1504 if (xmvis
->mesa_visual
.rgbMode
) {
1511 case GLX_DOUBLEBUFFER
:
1512 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1515 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1517 case GLX_AUX_BUFFERS
:
1518 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1521 *value
= xmvis
->mesa_visual
.redBits
;
1523 case GLX_GREEN_SIZE
:
1524 *value
= xmvis
->mesa_visual
.greenBits
;
1527 *value
= xmvis
->mesa_visual
.blueBits
;
1529 case GLX_ALPHA_SIZE
:
1530 *value
= xmvis
->mesa_visual
.alphaBits
;
1532 case GLX_DEPTH_SIZE
:
1533 *value
= xmvis
->mesa_visual
.depthBits
;
1535 case GLX_STENCIL_SIZE
:
1536 *value
= xmvis
->mesa_visual
.stencilBits
;
1538 case GLX_ACCUM_RED_SIZE
:
1539 *value
= xmvis
->mesa_visual
.accumRedBits
;
1541 case GLX_ACCUM_GREEN_SIZE
:
1542 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1544 case GLX_ACCUM_BLUE_SIZE
:
1545 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1547 case GLX_ACCUM_ALPHA_SIZE
:
1548 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1552 * GLX_EXT_visual_info extension
1554 case GLX_X_VISUAL_TYPE_EXT
:
1555 switch (xmvis
->visinfo
->CLASS
) {
1556 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1557 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1558 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1559 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1560 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1561 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1564 case GLX_TRANSPARENT_TYPE_EXT
:
1566 *value
= GLX_NONE_EXT
;
1568 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1571 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1574 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1577 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1580 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1585 * GLX_EXT_visual_info extension
1587 case GLX_VISUAL_CAVEAT_EXT
:
1588 /* test for zero, just in case */
1589 if (xmvis
->mesa_visual
.visualRating
> 0)
1590 *value
= xmvis
->mesa_visual
.visualRating
;
1592 *value
= GLX_NONE_EXT
;
1596 * GLX_ARB_multisample
1598 case GLX_SAMPLE_BUFFERS_ARB
:
1601 case GLX_SAMPLES_ARB
:
1608 case GLX_SCREEN_EXT
:
1610 return GLX_BAD_ATTRIBUTE
;
1611 *value
= xmvis
->visinfo
->screen
;
1613 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1615 return GLX_BAD_ATTRIBUTE
;
1616 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1618 case GLX_RENDER_TYPE_SGIX
:
1620 return GLX_BAD_ATTRIBUTE
;
1621 if (xmvis
->mesa_visual
.rgbMode
)
1622 *value
= GLX_RGBA_BIT
;
1624 *value
= GLX_COLOR_INDEX_BIT
;
1626 case GLX_X_RENDERABLE_SGIX
:
1628 return GLX_BAD_ATTRIBUTE
;
1629 *value
= True
; /* XXX really? */
1631 case GLX_FBCONFIG_ID_SGIX
:
1633 return GLX_BAD_ATTRIBUTE
;
1634 *value
= xmvis
->visinfo
->visualid
;
1636 case GLX_MAX_PBUFFER_WIDTH
:
1638 return GLX_BAD_ATTRIBUTE
;
1639 /* XXX should be same as ctx->Const.MaxRenderbufferSize */
1640 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1642 case GLX_MAX_PBUFFER_HEIGHT
:
1644 return GLX_BAD_ATTRIBUTE
;
1645 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1647 case GLX_MAX_PBUFFER_PIXELS
:
1649 return GLX_BAD_ATTRIBUTE
;
1650 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1651 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1655 return GLX_BAD_ATTRIBUTE
;
1656 *value
= xmvis
->visinfo
->visualid
;
1659 #ifdef GLX_EXT_texture_from_pixmap
1660 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1661 *value
= True
; /*XXX*/
1663 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1665 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1667 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1668 *value
= True
; /*XXX*/
1670 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1671 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1672 GLX_TEXTURE_2D_BIT_EXT
|
1673 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1675 case GLX_Y_INVERTED_EXT
:
1676 *value
= True
; /*XXX*/
1681 return GLX_BAD_ATTRIBUTE
;
1688 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1689 int attrib
, int *value
)
1693 if (!dpy
|| !visinfo
)
1694 return GLX_BAD_ATTRIBUTE
;
1696 xmvis
= find_glx_visual( dpy
, visinfo
);
1698 /* this visual wasn't obtained with glXChooseVisual */
1699 xmvis
= create_glx_visual( dpy
, visinfo
);
1701 /* this visual can't be used for GL rendering */
1702 if (attrib
==GLX_USE_GL
) {
1703 *value
= (int) False
;
1707 return GLX_BAD_VISUAL
;
1712 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1720 XMesaContext xmesa
= XMesaGetCurrentContext();
1721 XMesaFlush( xmesa
);
1729 XMesaContext xmesa
= XMesaGetCurrentContext();
1730 XMesaFlush( xmesa
);
1735 get_extensions( void )
1742 /* GLX 1.1 and later */
1744 glXQueryExtensionsString( Display
*dpy
, int screen
)
1748 return get_extensions();
1753 /* GLX 1.1 and later */
1755 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1757 static char version
[1000];
1758 sprintf(version
, "%d.%d %s",
1759 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, xmesa_get_name());
1765 case GLX_EXTENSIONS
:
1766 return get_extensions();
1778 /* GLX 1.1 and later */
1780 glXGetClientString( Display
*dpy
, int name
)
1782 static char version
[1000];
1783 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1784 CLIENT_MINOR_VERSION
, xmesa_get_name());
1789 case GLX_EXTENSIONS
:
1790 return get_extensions();
1808 glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1809 int attribute
, int *value
)
1811 XMesaVisual v
= (XMesaVisual
) config
;
1815 if (!dpy
|| !config
|| !value
)
1818 return get_config(v
, attribute
, value
, GL_TRUE
);
1822 PUBLIC GLXFBConfig
*
1823 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1825 XVisualInfo
*visuals
, visTemplate
;
1826 const long visMask
= VisualScreenMask
;
1829 /* Get list of all X visuals */
1830 visTemplate
.screen
= screen
;
1831 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1832 if (*nelements
> 0) {
1833 XMesaVisual
*results
= malloc(*nelements
* sizeof(XMesaVisual
));
1838 for (i
= 0; i
< *nelements
; i
++) {
1839 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1845 return (GLXFBConfig
*) results
;
1851 PUBLIC GLXFBConfig
*
1852 glXChooseFBConfig(Display
*dpy
, int screen
,
1853 const int *attribList
, int *nitems
)
1857 /* register ourselves as an extension on this display */
1858 register_with_display(dpy
);
1860 if (!attribList
|| !attribList
[0]) {
1861 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1862 return glXGetFBConfigs(dpy
, screen
, nitems
);
1865 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1867 GLXFBConfig
*config
= malloc(sizeof(XMesaVisual
));
1873 config
[0] = (GLXFBConfig
) xmvis
;
1874 return (GLXFBConfig
*) config
;
1883 PUBLIC XVisualInfo
*
1884 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1886 if (dpy
&& config
) {
1887 XMesaVisual xmvis
= (XMesaVisual
) config
;
1889 return xmvis
->vishandle
;
1891 /* create a new vishandle - the cached one may be stale */
1892 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1893 if (xmvis
->vishandle
) {
1894 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1896 return xmvis
->vishandle
;
1906 glXCreateWindow(Display
*dpy
, GLXFBConfig config
, Window win
,
1907 const int *attribList
)
1909 XMesaVisual xmvis
= (XMesaVisual
) config
;
1914 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1919 (void) attribList
; /* Ignored in GLX 1.3 */
1921 return win
; /* A hack for now */
1926 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1928 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1930 XMesaDestroyBuffer(b
);
1931 /* don't destroy X window */
1937 glXCreatePixmap(Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1938 const int *attribList
)
1940 XMesaVisual v
= (XMesaVisual
) config
;
1943 int target
= 0, format
= 0, mipmap
= 0;
1946 if (!dpy
|| !config
|| !pixmap
)
1949 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1951 case GLX_TEXTURE_FORMAT_EXT
:
1954 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1955 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1956 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1964 case GLX_TEXTURE_TARGET_EXT
:
1967 case GLX_TEXTURE_1D_EXT
:
1968 case GLX_TEXTURE_2D_EXT
:
1969 case GLX_TEXTURE_RECTANGLE_EXT
:
1977 case GLX_MIPMAP_TEXTURE_EXT
:
1988 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1989 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1990 &value
, GL_TRUE
) != Success
1992 return 0; /* error! */
1995 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
1996 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
1997 &value
, GL_TRUE
) != Success
1999 return 0; /* error! */
2003 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2004 &value
, GL_TRUE
) != Success
2006 return 0; /* error! */
2009 if (target
== GLX_TEXTURE_1D_EXT
) {
2010 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2011 &value
, GL_TRUE
) != Success
2012 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2013 return 0; /* error! */
2016 else if (target
== GLX_TEXTURE_2D_EXT
) {
2017 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2018 &value
, GL_TRUE
) != Success
2019 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2020 return 0; /* error! */
2023 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2024 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2025 &value
, GL_TRUE
) != Success
2026 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2027 return 0; /* error! */
2031 if (format
|| target
|| mipmap
) {
2032 /* texture from pixmap */
2033 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2036 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2047 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2049 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
2051 XMesaDestroyBuffer(b
);
2052 /* don't destroy X pixmap */
2057 glXCreatePbuffer(Display
*dpy
, GLXFBConfig config
, const int *attribList
)
2059 XMesaVisual xmvis
= (XMesaVisual
) config
;
2062 int width
= 0, height
= 0;
2063 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2067 for (attrib
= attribList
; *attrib
; attrib
++) {
2069 case GLX_PBUFFER_WIDTH
:
2073 case GLX_PBUFFER_HEIGHT
:
2077 case GLX_PRESERVED_CONTENTS
:
2079 preserveContents
= *attrib
;
2081 case GLX_LARGEST_PBUFFER
:
2083 useLargest
= *attrib
;
2090 if (width
== 0 || height
== 0)
2093 if (width
> PBUFFER_MAX_SIZE
|| height
> PBUFFER_MAX_SIZE
) {
2094 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2095 * allocate the largest possible buffer.
2098 width
= PBUFFER_MAX_SIZE
;
2099 height
= PBUFFER_MAX_SIZE
;
2103 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2104 /* A GLXPbuffer handle must be an X Drawable because that's what
2105 * glXMakeCurrent takes.
2108 xmbuf
->largestPbuffer
= useLargest
;
2109 xmbuf
->preservedContents
= preserveContents
;
2110 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2119 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2121 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2123 XMesaDestroyBuffer(b
);
2129 glXQueryDrawable(Display
*dpy
, GLXDrawable draw
, int attribute
,
2130 unsigned int *value
)
2132 GLuint width
, height
;
2133 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2135 generate_error(dpy
, GLXBadDrawable
, draw
, X_GLXGetDrawableAttributes
, False
);
2139 /* make sure buffer's dimensions are up to date */
2140 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2142 switch (attribute
) {
2149 case GLX_PRESERVED_CONTENTS
:
2150 *value
= xmbuf
->preservedContents
;
2152 case GLX_LARGEST_PBUFFER
:
2153 *value
= xmbuf
->largestPbuffer
;
2155 case GLX_FBCONFIG_ID
:
2156 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2158 #ifdef GLX_EXT_texture_from_pixmap
2159 case GLX_TEXTURE_FORMAT_EXT
:
2160 *value
= xmbuf
->TextureFormat
;
2162 case GLX_TEXTURE_TARGET_EXT
:
2163 *value
= xmbuf
->TextureTarget
;
2165 case GLX_MIPMAP_TEXTURE_EXT
:
2166 *value
= xmbuf
->TextureMipmap
;
2171 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAtrribsARB
, true);
2178 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2179 int renderType
, GLXContext shareCtx
, Bool direct
)
2181 XMesaVisual xmvis
= (XMesaVisual
) config
;
2183 if (!dpy
|| !config
||
2184 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2187 return create_context(dpy
, xmvis
,
2188 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2190 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2195 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2197 GLXContext glxCtx
= ctx
;
2198 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2203 switch (attribute
) {
2204 case GLX_FBCONFIG_ID
:
2205 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2207 case GLX_RENDER_TYPE
:
2208 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2209 *value
= GLX_RGBA_TYPE
;
2211 *value
= GLX_COLOR_INDEX_TYPE
;
2217 return GLX_BAD_ATTRIBUTE
;
2224 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2226 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2228 xmbuf
->selectedEvents
= mask
;
2233 glXGetSelectedEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2235 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2237 *mask
= xmbuf
->selectedEvents
;
2244 /*** GLX_SGI_swap_control ***/
2247 glXSwapIntervalSGI(int interval
)
2255 /*** GLX_SGI_video_sync ***/
2257 static unsigned int FrameCounter
= 0;
2260 glXGetVideoSyncSGI(unsigned int *count
)
2262 /* this is a bogus implementation */
2263 *count
= FrameCounter
++;
2268 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2270 if (divisor
<= 0 || remainder
< 0)
2271 return GLX_BAD_VALUE
;
2272 /* this is a bogus implementation */
2274 while (FrameCounter
% divisor
!= remainder
)
2276 *count
= FrameCounter
;
2282 /*** GLX_SGI_make_current_read ***/
2285 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
,
2288 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2293 glXGetCurrentReadDrawableSGI(void)
2300 /*** GLX_SGIX_video_source ***/
2303 PUBLIC GLXVideoSourceSGIX
2304 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
,
2305 VLPath path
, int nodeClass
, VLNode drainNode
)
2317 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2326 /*** GLX_EXT_import_context ***/
2329 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2336 glXGetContextIDEXT(const GLXContext context
)
2343 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2351 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
,
2363 /*** GLX_SGIX_fbconfig ***/
2366 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2367 int attribute
, int *value
)
2369 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2372 PUBLIC GLXFBConfigSGIX
*
2373 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
,
2376 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
,
2377 attrib_list
, nelements
);
2382 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2385 XMesaVisual xmvis
= (XMesaVisual
) config
;
2386 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2387 return xmbuf
->ws
.drawable
; /* need to return an X ID */
2392 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2393 int renderType
, GLXContext shareCtx
,
2396 XMesaVisual xmvis
= (XMesaVisual
) config
;
2398 if (!dpy
|| !config
||
2399 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2402 return create_context(dpy
, xmvis
,
2403 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2405 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2409 PUBLIC XVisualInfo
*
2410 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2412 return glXGetVisualFromFBConfig(dpy
, config
);
2416 PUBLIC GLXFBConfigSGIX
2417 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2419 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2421 /* This visual wasn't found with glXChooseVisual() */
2422 xmvis
= create_glx_visual(dpy
, vis
);
2425 return (GLXFBConfigSGIX
) xmvis
;
2430 /*** GLX_SGIX_pbuffer ***/
2432 PUBLIC GLXPbufferSGIX
2433 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2434 unsigned int width
, unsigned int height
,
2437 XMesaVisual xmvis
= (XMesaVisual
) config
;
2440 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2444 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2446 case GLX_PRESERVED_CONTENTS_SGIX
:
2448 preserveContents
= *attrib
; /* ignored */
2450 case GLX_LARGEST_PBUFFER_SGIX
:
2452 useLargest
= *attrib
; /* ignored */
2459 /* not used at this time */
2461 (void) preserveContents
;
2463 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2464 /* A GLXPbuffer handle must be an X Drawable because that's what
2465 * glXMakeCurrent takes.
2467 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2472 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2474 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2476 XMesaDestroyBuffer(xmbuf
);
2482 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
,
2483 unsigned int *value
)
2485 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2488 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2492 switch (attribute
) {
2493 case GLX_PRESERVED_CONTENTS_SGIX
:
2496 case GLX_LARGEST_PBUFFER_SGIX
:
2497 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2499 case GLX_WIDTH_SGIX
:
2500 *value
= xmesa_buffer_width(xmbuf
);
2502 case GLX_HEIGHT_SGIX
:
2503 *value
= xmesa_buffer_height(xmbuf
);
2505 case GLX_EVENT_MASK_SGIX
:
2506 *value
= 0; /* XXX might be wrong */
2516 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2518 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2520 /* Note: we'll never generate clobber events */
2521 xmbuf
->selectedEvents
= mask
;
2527 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
,
2528 unsigned long *mask
)
2530 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2532 *mask
= xmbuf
->selectedEvents
;
2541 /*** GLX_SGI_cushion ***/
2544 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2553 /*** GLX_SGIX_video_resize ***/
2556 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
,
2567 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2568 int x
, int y
, int w
, int h
)
2581 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2582 int *x
, int *y
, int *w
, int *h
)
2595 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
,
2596 int *dx
, int *dy
, int *dw
, int *dh
)
2609 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2620 /*** GLX_SGIX_dmbuffer **/
2622 #if defined(_DM_BUFFER_H_)
2624 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
,
2625 DMparams
*params
, DMbuffer dmbuffer
)
2636 /*** GLX_SGIX_swap_group ***/
2639 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2648 /*** GLX_SGIX_swap_barrier ***/
2651 glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2659 glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2669 /*** GLX_SUN_get_transparent_index ***/
2672 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
,
2678 (void) pTransparent
;
2684 /*** GLX_MESA_release_buffers ***/
2687 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2688 * (a window or pixmap) prior to destroying the GLXDrawable.
2691 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2693 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2695 XMesaDestroyBuffer(b
);
2701 /*** GLX_EXT_texture_from_pixmap ***/
2704 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2705 const int *attrib_list
)
2707 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2709 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2713 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2715 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2717 XMesaReleaseTexImage(dpy
, b
, buffer
);
2722 /*** GLX_ARB_create_context ***/
2726 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
2727 GLXContext shareCtx
, Bool direct
,
2728 const int *attrib_list
)
2730 XMesaVisual xmvis
= (XMesaVisual
) config
;
2731 int majorVersion
= 1, minorVersion
= 0;
2732 int contextFlags
= 0x0;
2733 int profileMask
= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
;
2734 int renderType
= GLX_RGBA_TYPE
;
2737 const int contextFlagsAll
= (GLX_CONTEXT_DEBUG_BIT_ARB
|
2738 GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
);
2741 /* parse attrib_list */
2742 for (i
= 0; !done
&& attrib_list
&& attrib_list
[i
]; i
++) {
2743 switch (attrib_list
[i
]) {
2744 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2745 majorVersion
= attrib_list
[++i
];
2747 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2748 minorVersion
= attrib_list
[++i
];
2750 case GLX_CONTEXT_FLAGS_ARB
:
2751 contextFlags
= attrib_list
[++i
];
2753 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2754 profileMask
= attrib_list
[++i
];
2756 case GLX_RENDER_TYPE
:
2757 renderType
= attrib_list
[++i
];
2765 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAtrribsARB
, True
);
2770 /* check contextFlags */
2771 if (contextFlags
& ~contextFlagsAll
) {
2772 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAtrribsARB
, True
);
2776 /* check profileMask */
2777 if (profileMask
!= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
&&
2778 profileMask
!= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
&&
2779 profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
) {
2780 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAtrribsARB
, False
);
2784 /* check renderType */
2785 if (renderType
!= GLX_RGBA_TYPE
&&
2786 renderType
!= GLX_COLOR_INDEX_TYPE
) {
2787 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAtrribsARB
, True
);
2792 if (majorVersion
<= 0 ||
2794 (profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2795 ((majorVersion
== 1 && minorVersion
> 5) ||
2796 (majorVersion
== 2 && minorVersion
> 1) ||
2797 (majorVersion
== 3 && minorVersion
> 3) ||
2798 (majorVersion
== 4 && minorVersion
> 5) ||
2799 majorVersion
> 4))) {
2800 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAtrribsARB
, True
);
2803 if (profileMask
== GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2804 ((majorVersion
== 1 && minorVersion
> 1) ||
2805 (majorVersion
== 2 && minorVersion
> 0) ||
2806 (majorVersion
== 3 && minorVersion
> 1) ||
2807 majorVersion
> 3)) {
2808 /* GLX_EXT_create_context_es2_profile says nothing to justifying a
2809 * different error code for invalid ES versions, but this is what NVIDIA
2810 * does and piglit expects.
2812 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAtrribsARB
, False
);
2816 if ((contextFlags
& GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
) &&
2818 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAtrribsARB
, True
);
2822 if (renderType
== GLX_COLOR_INDEX_TYPE
&& majorVersion
>= 3) {
2823 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAtrribsARB
, True
);
2827 ctx
= create_context(dpy
, xmvis
,
2828 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2830 majorVersion
, minorVersion
,
2831 profileMask
, contextFlags
);
2833 generate_error(dpy
, GLXBadFBConfig
, 0, X_GLXCreateContextAtrribsARB
, False
);