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
37 #include <GL/glxproto.h>
42 /* This indicates the client-side GLX API and GLX encoder version. */
43 #define CLIENT_MAJOR_VERSION 1
44 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
46 /* This indicates the server-side GLX decoder version.
47 * GLX 1.4 indicates OpenGL 1.3 support
49 #define SERVER_MAJOR_VERSION 1
50 #define SERVER_MINOR_VERSION 4
52 /* Who implemented this GLX? */
53 #define VENDOR "Brian Paul"
56 "GLX_MESA_copy_sub_buffer " \
57 "GLX_MESA_pixmap_colormap " \
58 "GLX_MESA_release_buffers " \
59 "GLX_ARB_create_context " \
60 "GLX_ARB_create_context_profile " \
61 "GLX_ARB_get_proc_address " \
62 "GLX_EXT_create_context_es_profile " \
63 "GLX_EXT_create_context_es2_profile " \
64 "GLX_EXT_texture_from_pixmap " \
65 "GLX_EXT_visual_info " \
66 "GLX_EXT_visual_rating " \
67 /*"GLX_SGI_video_sync "*/ \
68 "GLX_SGIX_fbconfig " \
71 #define DEFAULT_DIRECT GL_TRUE
74 /** XXX this could be based on gallium's max texture size */
75 #define PBUFFER_MAX_SIZE 16384
79 * The GLXContext typedef is defined as a pointer to this structure.
81 struct __GLXcontextRec
85 GLXDrawable currentDrawable
;
86 GLXDrawable currentReadable
;
89 XMesaContext xmesaContext
;
94 static pipe_tsd ContextTSD
;
96 /** Set current context for calling thread */
98 SetCurrentContext(GLXContext c
)
100 pipe_tsd_set(&ContextTSD
, c
);
103 /** Get current context for calling thread */
105 GetCurrentContext(void)
107 return pipe_tsd_get(&ContextTSD
);
112 /**********************************************************************/
113 /*** GLX Visual Code ***/
114 /**********************************************************************/
119 static XMesaVisual
*VisualTable
= NULL
;
120 static int NumVisuals
= 0;
124 /* Macro to handle c_class vs class field name in XVisualInfo struct */
125 #if defined(__cplusplus) || defined(c_plusplus)
126 #define CLASS c_class
134 * Test if the given XVisualInfo is usable for Mesa rendering.
137 is_usable_visual( XVisualInfo
*vinfo
)
139 switch (vinfo
->CLASS
) {
142 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
146 /* Any StaticColor/PseudoColor visual of at least 4 bits */
147 if (vinfo
->depth
>=4) {
155 /* Any depth of TrueColor or DirectColor works in RGB mode */
158 /* This should never happen */
165 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
166 * configuration in our list of GLX visuals.
169 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
170 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
171 GLboolean stereoFlag
,
172 GLint depth_size
, GLint stencil_size
,
173 GLint accumRedSize
, GLint accumGreenSize
,
174 GLint accumBlueSize
, GLint accumAlphaSize
,
175 GLint level
, GLint numAuxBuffers
)
177 GLboolean ximageFlag
= GL_TRUE
;
180 GLboolean comparePointers
;
183 /* Check if the MESA_BACK_BUFFER env var is set */
184 char *backbuffer
= getenv("MESA_BACK_BUFFER");
186 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
187 ximageFlag
= GL_FALSE
;
189 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
190 ximageFlag
= GL_TRUE
;
193 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
199 /* stereo not supported */
203 if (stencil_size
> 0 && depth_size
> 0)
206 /* Comparing IDs uses less memory but sometimes fails. */
207 /* XXX revisit this after 3.0 is finished. */
208 if (getenv("MESA_GLX_VISUAL_HACK"))
209 comparePointers
= GL_TRUE
;
211 comparePointers
= GL_FALSE
;
213 /* Force the visual to have an alpha channel */
214 if (rgbFlag
&& getenv("MESA_GLX_FORCE_ALPHA"))
217 /* First check if a matching visual is already in the list */
218 for (i
=0; i
<NumVisuals
; i
++) {
219 XMesaVisual v
= VisualTable
[i
];
220 if (v
->display
== dpy
221 && v
->mesa_visual
.level
== level
222 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
223 && v
->ximage_flag
== ximageFlag
224 && v
->mesa_visual
.rgbMode
== rgbFlag
225 && v
->mesa_visual
.doubleBufferMode
== dbFlag
226 && v
->mesa_visual
.stereoMode
== stereoFlag
227 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
228 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
229 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
230 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
231 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
232 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
233 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
234 /* now either compare XVisualInfo pointers or visual IDs */
235 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
236 || (comparePointers
&& v
->vishandle
== vinfo
)) {
242 /* Create a new visual and add it to the list. */
244 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
245 stereoFlag
, ximageFlag
,
246 depth_size
, stencil_size
,
247 accumRedSize
, accumBlueSize
,
248 accumBlueSize
, accumAlphaSize
, 0, level
,
251 /* Save a copy of the pointer now so we can find this visual again
252 * if we need to search for it in find_glx_visual().
254 xmvis
->vishandle
= vinfo
;
255 /* Allocate more space for additional visual */
256 VisualTable
= (XMesaVisual
*) realloc( VisualTable
,
257 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
258 /* add xmvis to the list */
259 VisualTable
[NumVisuals
] = xmvis
;
261 /* XXX minor hack, because XMesaCreateVisual doesn't support an
262 * aux buffers parameter.
264 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
271 * Return the default number of bits for the Z buffer.
272 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
273 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
274 * XXX probably do the same thing for stencil, accum, etc.
277 default_depth_bits(void)
280 const char *zEnv
= getenv("MESA_GLX_DEPTH_BITS");
289 default_alpha_bits(void)
292 const char *aEnv
= getenv("MESA_GLX_ALPHA_BITS");
301 default_accum_bits(void)
309 * Create a GLX visual from a regular XVisualInfo.
310 * This is called when Fake GLX is given an XVisualInfo which wasn't
311 * returned by glXChooseVisual. Since this is the first time we're
312 * considering this visual we'll take a guess at reasonable values
313 * for depth buffer size, stencil size, accum size, etc.
314 * This is the best we can do with a client-side emulation of GLX.
317 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
319 GLint zBits
= default_depth_bits();
320 GLint accBits
= default_accum_bits();
321 GLboolean alphaFlag
= default_alpha_bits() > 0;
323 if (is_usable_visual( visinfo
)) {
324 /* Configure this visual as RGB, double-buffered, depth-buffered. */
325 /* This is surely wrong for some people's needs but what else */
326 /* can be done? They should use glXChooseVisual(). */
327 return save_glx_visual( dpy
, visinfo
,
329 alphaFlag
, /* alpha */
330 GL_TRUE
, /* double */
331 GL_FALSE
, /* stereo */
333 8, /* stencil bits */
343 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
351 * Find the GLX visual associated with an XVisualInfo.
354 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
358 /* try to match visual id */
359 for (i
=0;i
<NumVisuals
;i
++) {
360 if (VisualTable
[i
]->display
==dpy
361 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
362 return VisualTable
[i
];
366 /* if that fails, try to match pointers */
367 for (i
=0;i
<NumVisuals
;i
++) {
368 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
369 return VisualTable
[i
];
378 * Try to get an X visual which matches the given arguments.
381 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
383 XVisualInfo temp
, *vis
;
386 unsigned int default_depth
;
389 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
394 default_depth
= DefaultDepth(dpy
,scr
);
395 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
397 if (depth
==default_depth
&& xclass
==default_class
) {
398 /* try to get root window's visual */
399 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
400 mask
|= VisualIDMask
;
403 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
405 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
406 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
407 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
409 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
410 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
411 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
412 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
426 * Retrieve the value of the given environment variable and find
427 * the X visual which matches it.
428 * Input: dpy - the display
429 * screen - the screen number
430 * varname - the name of the environment variable
431 * Return: an XVisualInfo pointer to NULL if error.
434 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
436 char value
[100], type
[100];
437 int depth
, xclass
= -1;
440 if (!getenv( varname
)) {
444 strncpy( value
, getenv(varname
), 100 );
447 sscanf( value
, "%s %d", type
, &depth
);
449 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
450 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
451 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
452 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
453 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
454 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
456 if (xclass
>-1 && depth
>0) {
457 vis
= get_visual( dpy
, scr
, depth
, xclass
);
463 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
472 * Select an X visual which satisfies the RGBA flag and minimum depth.
474 * screen - X display and screen number
475 * min_depth - minimum visual depth
476 * preferred_class - preferred GLX visual class or DONT_CARE
477 * Return: pointer to an XVisualInfo or NULL.
480 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
481 int preferred_class
)
484 int xclass
, visclass
= 0;
487 /* First see if the MESA_RGB_VISUAL env var is defined */
488 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
492 /* Otherwise, search for a suitable visual */
493 if (preferred_class
==DONT_CARE
) {
494 for (xclass
=0;xclass
<6;xclass
++) {
496 case 0: visclass
= TrueColor
; break;
497 case 1: visclass
= DirectColor
; break;
498 case 2: visclass
= PseudoColor
; break;
499 case 3: visclass
= StaticColor
; break;
500 case 4: visclass
= GrayScale
; break;
501 case 5: visclass
= StaticGray
; break;
504 /* start with shallowest */
505 for (depth
=0;depth
<=32;depth
++) {
506 if (visclass
==TrueColor
&& depth
==8) {
507 /* Special case: try to get 8-bit PseudoColor before */
508 /* 8-bit TrueColor */
509 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
514 vis
= get_visual( dpy
, screen
, depth
, visclass
);
521 /* start with deepest */
522 for (depth
=32;depth
>=min_depth
;depth
--) {
523 if (visclass
==TrueColor
&& depth
==8) {
524 /* Special case: try to get 8-bit PseudoColor before */
525 /* 8-bit TrueColor */
526 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
531 vis
= get_visual( dpy
, screen
, depth
, visclass
);
540 /* search for a specific visual class */
541 switch (preferred_class
) {
542 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
543 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
544 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
545 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
546 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
547 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
548 default: return NULL
;
551 /* start with shallowest */
552 for (depth
=0;depth
<=32;depth
++) {
553 vis
= get_visual( dpy
, screen
, depth
, visclass
);
560 /* start with deepest */
561 for (depth
=32;depth
>=min_depth
;depth
--) {
562 vis
= get_visual( dpy
, screen
, depth
, visclass
);
570 /* didn't find a visual */
577 /**********************************************************************/
578 /*** Display-related functions ***/
579 /**********************************************************************/
583 * Free all XMesaVisuals which are associated with the given display.
586 destroy_visuals_on_display(Display
*dpy
)
589 for (i
= 0; i
< NumVisuals
; i
++) {
590 if (VisualTable
[i
]->display
== dpy
) {
591 /* remove this visual */
593 free(VisualTable
[i
]);
594 for (j
= i
; j
< NumVisuals
- 1; j
++)
595 VisualTable
[j
] = VisualTable
[j
+ 1];
603 * Called from XCloseDisplay() to let us free our display-related data.
606 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
608 xmesa_destroy_buffers_on_display(dpy
);
609 destroy_visuals_on_display(dpy
);
615 * Look for the named extension on given display and return a pointer
616 * to the _XExtension data, or NULL if extension not found.
619 lookup_extension(Display
*dpy
, const char *extName
)
622 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
623 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
632 * Whenever we're given a new Display pointer, call this function to
633 * register our close_display_callback function.
636 register_with_display(Display
*dpy
)
638 const char *extName
= "MesaGLX";
641 ext
= lookup_extension(dpy
, extName
);
643 XExtCodes
*c
= XAddExtension(dpy
);
644 ext
= dpy
->ext_procs
; /* new extension is at head of list */
645 assert(c
->extension
== ext
->codes
.extension
);
647 ext
->name
= _mesa_strdup(extName
);
648 ext
->close_display
= close_display_callback
;
657 generate_error(Display
*dpy
,
658 unsigned char error_code
,
660 unsigned char minor_code
,
663 XErrorHandler handler
;
669 handler
= XSetErrorHandler(NULL
);
670 XSetErrorHandler(handler
);
675 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_opcode
, &first_event
, &first_error
)) {
682 error_code
+= first_error
;
685 memset(&event
, 0, sizeof event
);
687 event
.xerror
.type
= X_Error
;
688 event
.xerror
.display
= dpy
;
689 event
.xerror
.resourceid
= resourceid
;
690 event
.xerror
.serial
= NextRequest(dpy
) - 1;
691 event
.xerror
.error_code
= error_code
;
692 event
.xerror
.request_code
= major_opcode
;
693 event
.xerror
.minor_code
= minor_code
;
695 return handler(dpy
, &event
.xerror
);
699 /**********************************************************************/
700 /*** Begin Fake GLX API Functions ***/
701 /**********************************************************************/
705 * Helper used by glXChooseVisual and glXChooseFBConfig.
706 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
708 * In either case, the attribute list is terminated with the value 'None'.
711 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
713 const GLboolean rgbModeDefault
= fbConfig
;
714 const int *parselist
;
716 int min_red
=0, min_green
=0, min_blue
=0;
717 GLboolean rgb_flag
= rgbModeDefault
;
718 GLboolean alpha_flag
= GL_FALSE
;
719 GLboolean double_flag
= GL_FALSE
;
720 GLboolean stereo_flag
= GL_FALSE
;
721 GLint depth_size
= 0;
722 GLint stencil_size
= 0;
723 GLint accumRedSize
= 0;
724 GLint accumGreenSize
= 0;
725 GLint accumBlueSize
= 0;
726 GLint accumAlphaSize
= 0;
728 int visual_type
= DONT_CARE
;
729 GLint caveat
= DONT_CARE
;
730 XMesaVisual xmvis
= NULL
;
731 int desiredVisualID
= -1;
741 parselist
[1] == GLX_DONT_CARE
&&
742 parselist
[0] != GLX_LEVEL
) {
743 /* For glXChooseFBConfig(), skip attributes whose value is
744 * GLX_DONT_CARE, unless it's GLX_LEVEL (which can legitimately be
747 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
748 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
754 switch (*parselist
) {
765 case GLX_BUFFER_SIZE
:
771 level
= *parselist
++;
783 case GLX_DOUBLEBUFFER
:
786 double_flag
= *parselist
++;
789 double_flag
= GL_TRUE
;
795 stereo_flag
= *parselist
++;
798 stereo_flag
= GL_TRUE
;
801 case GLX_AUX_BUFFERS
:
803 numAux
= *parselist
++;
804 if (numAux
> MAX_AUX_BUFFERS
)
809 min_red
= *parselist
++;
813 min_green
= *parselist
++;
817 min_blue
= *parselist
++;
822 GLint size
= *parselist
++;
823 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
828 depth_size
= *parselist
++;
830 case GLX_STENCIL_SIZE
:
832 stencil_size
= *parselist
++;
834 case GLX_ACCUM_RED_SIZE
:
837 GLint size
= *parselist
++;
838 accumRedSize
= MAX2( accumRedSize
, size
);
841 case GLX_ACCUM_GREEN_SIZE
:
844 GLint size
= *parselist
++;
845 accumGreenSize
= MAX2( accumGreenSize
, size
);
848 case GLX_ACCUM_BLUE_SIZE
:
851 GLint size
= *parselist
++;
852 accumBlueSize
= MAX2( accumBlueSize
, size
);
855 case GLX_ACCUM_ALPHA_SIZE
:
858 GLint size
= *parselist
++;
859 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
864 * GLX_EXT_visual_info extension
866 case GLX_X_VISUAL_TYPE_EXT
:
868 visual_type
= *parselist
++;
870 case GLX_TRANSPARENT_TYPE_EXT
:
874 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
878 case GLX_TRANSPARENT_RED_VALUE_EXT
:
879 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
880 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
881 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
888 * GLX_EXT_visual_info extension
890 case GLX_VISUAL_CAVEAT_EXT
:
892 caveat
= *parselist
++; /* ignored for now */
896 * GLX_ARB_multisample
898 case GLX_SAMPLE_BUFFERS_ARB
:
899 case GLX_SAMPLES_ARB
:
901 if (*parselist
++ != 0) {
902 /* ms not supported */
910 case GLX_RENDER_TYPE
:
914 if (*parselist
& GLX_RGBA_BIT
) {
917 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
920 else if (*parselist
== 0) {
925 case GLX_DRAWABLE_TYPE
:
929 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
930 return NULL
; /* bad bit */
934 case GLX_FBCONFIG_ID
:
939 desiredVisualID
= *parselist
++;
941 case GLX_X_RENDERABLE
:
942 case GLX_MAX_PBUFFER_WIDTH
:
943 case GLX_MAX_PBUFFER_HEIGHT
:
944 case GLX_MAX_PBUFFER_PIXELS
:
946 return NULL
; /* invalid config option */
947 parselist
+= 2; /* ignore the parameter */
950 #ifdef GLX_EXT_texture_from_pixmap
951 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
952 parselist
++; /*skip*/
954 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
955 parselist
++; /*skip*/
957 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
958 parselist
++; /*skip*/
960 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
962 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
963 GLX_TEXTURE_2D_BIT_EXT
|
964 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
969 case GLX_Y_INVERTED_EXT
:
970 parselist
++; /*skip*/
979 /* undefined attribute */
980 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
990 * Since we're only simulating the GLX extension this function will never
991 * find any real GL visuals. Instead, all we can do is try to find an RGB
992 * or CI visual of appropriate depth. Other requested attributes such as
993 * double buffering, depth buffer, etc. will be associated with the X
994 * visual and stored in the VisualTable[].
996 if (desiredVisualID
!= -1) {
997 /* try to get a specific visual, by visualID */
1000 temp
.visualid
= desiredVisualID
;
1001 temp
.screen
= screen
;
1002 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1004 /* give the visual some useful GLX attributes */
1005 double_flag
= GL_TRUE
;
1009 else if (level
==0) {
1010 /* normal color planes */
1011 /* Get an RGB visual */
1012 int min_rgb
= min_red
+ min_green
+ min_blue
;
1013 if (min_rgb
>1 && min_rgb
<8) {
1014 /* a special case to be sure we can get a monochrome visual */
1017 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
1020 _mesa_warning(NULL
, "overlay not supported");
1025 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1026 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1027 * largest depth buffer size, which is 32bits/value. Instead, we
1028 * return 16 to maintain performance with earlier versions of Mesa.
1030 if (stencil_size
> 0)
1031 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
1032 else if (depth_size
> 24)
1034 else if (depth_size
> 16)
1036 else if (depth_size
> 0) {
1037 depth_size
= default_depth_bits();
1041 alpha_flag
= default_alpha_bits() > 0;
1044 /* we only support one size of stencil and accum buffers. */
1045 if (stencil_size
> 0)
1048 if (accumRedSize
> 0 ||
1049 accumGreenSize
> 0 ||
1050 accumBlueSize
> 0 ||
1051 accumAlphaSize
> 0) {
1055 accumBlueSize
= default_accum_bits();
1057 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1060 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1061 stereo_flag
, depth_size
, stencil_size
,
1062 accumRedSize
, accumGreenSize
,
1063 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1070 PUBLIC XVisualInfo
*
1071 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1075 /* register ourselves as an extension on this display */
1076 register_with_display(dpy
);
1078 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1080 /* create a new vishandle - the cached one may be stale */
1081 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1082 if (xmvis
->vishandle
) {
1083 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1085 return xmvis
->vishandle
;
1093 * Helper function used by other glXCreateContext functions.
1096 create_context(Display
*dpy
, XMesaVisual xmvis
,
1097 XMesaContext shareCtx
, Bool direct
,
1098 unsigned major
, unsigned minor
,
1099 unsigned profileMask
, unsigned contextFlags
)
1106 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1110 /* deallocate unused windows/buffers */
1112 XMesaGarbageCollect();
1115 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
, shareCtx
, major
, minor
,
1116 profileMask
, contextFlags
);
1117 if (!glxCtx
->xmesaContext
) {
1122 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1123 glxCtx
->currentDpy
= dpy
;
1124 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1131 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1132 GLXContext shareCtx
, Bool direct
)
1136 xmvis
= find_glx_visual( dpy
, visinfo
);
1138 /* This visual wasn't found with glXChooseVisual() */
1139 xmvis
= create_glx_visual( dpy
, visinfo
);
1141 /* unusable visual */
1146 return create_context(dpy
, xmvis
,
1147 shareCtx
? shareCtx
->xmesaContext
: NULL
,
1149 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
1153 /* XXX these may have to be removed due to thread-safety issues. */
1154 static GLXContext MakeCurrent_PrevContext
= 0;
1155 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1156 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1157 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1158 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1161 /* GLX 1.3 and later */
1163 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1164 GLXDrawable read
, GLXContext ctx
)
1166 GLXContext glxCtx
= ctx
;
1167 static boolean firsttime
= 1, no_rast
= 0;
1170 no_rast
= getenv("SP_NO_RAST") != NULL
;
1174 if (ctx
&& draw
&& read
) {
1175 XMesaBuffer drawBuffer
, readBuffer
;
1176 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1178 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1179 if (ctx
== MakeCurrent_PrevContext
1180 && draw
== MakeCurrent_PrevDrawable
) {
1181 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1184 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1187 /* drawable must be a new window! */
1188 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1190 /* Out of memory, or context/drawable depth mismatch */
1195 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1196 if (ctx
== MakeCurrent_PrevContext
1197 && read
== MakeCurrent_PrevReadable
) {
1198 readBuffer
= MakeCurrent_PrevReadBuffer
;
1201 readBuffer
= XMesaFindBuffer( dpy
, read
);
1204 /* drawable must be a new window! */
1205 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1207 /* Out of memory, or context/drawable depth mismatch */
1213 MakeCurrent_PrevContext
== ctx
&&
1214 MakeCurrent_PrevDrawable
== draw
&&
1215 MakeCurrent_PrevReadable
== read
&&
1216 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1217 MakeCurrent_PrevReadBuffer
== readBuffer
)
1220 MakeCurrent_PrevContext
= ctx
;
1221 MakeCurrent_PrevDrawable
= draw
;
1222 MakeCurrent_PrevReadable
= read
;
1223 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1224 MakeCurrent_PrevReadBuffer
= readBuffer
;
1226 /* Now make current! */
1227 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1228 ctx
->currentDpy
= dpy
;
1229 ctx
->currentDrawable
= draw
;
1230 ctx
->currentReadable
= read
;
1231 SetCurrentContext(ctx
);
1238 else if (!ctx
&& !draw
&& !read
) {
1239 /* release current context w/out assigning new one. */
1240 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1241 MakeCurrent_PrevContext
= 0;
1242 MakeCurrent_PrevDrawable
= 0;
1243 MakeCurrent_PrevReadable
= 0;
1244 MakeCurrent_PrevDrawBuffer
= 0;
1245 MakeCurrent_PrevReadBuffer
= 0;
1246 SetCurrentContext(NULL
);
1250 /* The args must either all be non-zero or all zero.
1259 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1261 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1266 glXGetCurrentContext(void)
1268 return GetCurrentContext();
1273 glXGetCurrentDisplay(void)
1275 GLXContext glxCtx
= glXGetCurrentContext();
1277 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1282 glXGetCurrentDisplayEXT(void)
1284 return glXGetCurrentDisplay();
1289 glXGetCurrentDrawable(void)
1291 GLXContext gc
= glXGetCurrentContext();
1292 return gc
? gc
->currentDrawable
: 0;
1297 glXGetCurrentReadDrawable(void)
1299 GLXContext gc
= glXGetCurrentContext();
1300 return gc
? gc
->currentReadable
: 0;
1305 glXGetCurrentReadDrawableSGI(void)
1307 return glXGetCurrentReadDrawable();
1312 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1317 v
= find_glx_visual( dpy
, visinfo
);
1319 v
= create_glx_visual( dpy
, visinfo
);
1321 /* unusable visual */
1326 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1330 return b
->ws
.drawable
;
1334 /*** GLX_MESA_pixmap_colormap ***/
1337 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1338 Pixmap pixmap
, Colormap cmap
)
1343 v
= find_glx_visual( dpy
, visinfo
);
1345 v
= create_glx_visual( dpy
, visinfo
);
1347 /* unusable visual */
1352 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1356 return b
->ws
.drawable
;
1361 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1363 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1365 XMesaDestroyBuffer(b
);
1367 else if (getenv("MESA_DEBUG")) {
1368 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1374 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1375 unsigned long mask
)
1377 XMesaContext xm_src
= src
->xmesaContext
;
1378 XMesaContext xm_dst
= dst
->xmesaContext
;
1380 if (MakeCurrent_PrevContext
== src
) {
1383 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1388 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1391 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1392 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1398 return True
; /* we're faking GLX so always return success */
1403 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1406 GLXContext glxCtx
= ctx
;
1408 MakeCurrent_PrevContext
= 0;
1409 MakeCurrent_PrevDrawable
= 0;
1410 MakeCurrent_PrevReadable
= 0;
1411 MakeCurrent_PrevDrawBuffer
= 0;
1412 MakeCurrent_PrevReadBuffer
= 0;
1413 XMesaDestroyContext( glxCtx
->xmesaContext
);
1414 XMesaGarbageCollect();
1421 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1423 return ctx
? ctx
->isDirect
: False
;
1429 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1431 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1432 static boolean firsttime
= 1, no_rast
= 0;
1435 no_rast
= getenv("SP_NO_RAST") != NULL
;
1443 XMesaSwapBuffers(buffer
);
1445 else if (getenv("MESA_DEBUG")) {
1446 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1453 /*** GLX_MESA_copy_sub_buffer ***/
1456 glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
1457 int x
, int y
, int width
, int height
)
1459 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1461 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1463 else if (getenv("MESA_DEBUG")) {
1464 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1470 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1473 /* Return GLX version, not Mesa version */
1474 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1475 *maj
= CLIENT_MAJOR_VERSION
;
1476 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1482 * Query the GLX attributes of the given XVisualInfo.
1485 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1491 return GLX_BAD_ATTRIBUTE
;
1492 *value
= (int) True
;
1494 case GLX_BUFFER_SIZE
:
1495 *value
= xmvis
->visinfo
->depth
;
1498 *value
= xmvis
->mesa_visual
.level
;
1502 return GLX_BAD_ATTRIBUTE
;
1503 if (xmvis
->mesa_visual
.rgbMode
) {
1510 case GLX_DOUBLEBUFFER
:
1511 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1514 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1516 case GLX_AUX_BUFFERS
:
1517 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1520 *value
= xmvis
->mesa_visual
.redBits
;
1522 case GLX_GREEN_SIZE
:
1523 *value
= xmvis
->mesa_visual
.greenBits
;
1526 *value
= xmvis
->mesa_visual
.blueBits
;
1528 case GLX_ALPHA_SIZE
:
1529 *value
= xmvis
->mesa_visual
.alphaBits
;
1531 case GLX_DEPTH_SIZE
:
1532 *value
= xmvis
->mesa_visual
.depthBits
;
1534 case GLX_STENCIL_SIZE
:
1535 *value
= xmvis
->mesa_visual
.stencilBits
;
1537 case GLX_ACCUM_RED_SIZE
:
1538 *value
= xmvis
->mesa_visual
.accumRedBits
;
1540 case GLX_ACCUM_GREEN_SIZE
:
1541 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1543 case GLX_ACCUM_BLUE_SIZE
:
1544 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1546 case GLX_ACCUM_ALPHA_SIZE
:
1547 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1551 * GLX_EXT_visual_info extension
1553 case GLX_X_VISUAL_TYPE_EXT
:
1554 switch (xmvis
->visinfo
->CLASS
) {
1555 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1556 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1557 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1558 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1559 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1560 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1563 case GLX_TRANSPARENT_TYPE_EXT
:
1565 *value
= GLX_NONE_EXT
;
1567 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1570 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1573 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1576 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1579 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1584 * GLX_EXT_visual_info extension
1586 case GLX_VISUAL_CAVEAT_EXT
:
1587 /* test for zero, just in case */
1588 if (xmvis
->mesa_visual
.visualRating
> 0)
1589 *value
= xmvis
->mesa_visual
.visualRating
;
1591 *value
= GLX_NONE_EXT
;
1595 * GLX_ARB_multisample
1597 case GLX_SAMPLE_BUFFERS_ARB
:
1600 case GLX_SAMPLES_ARB
:
1607 case GLX_SCREEN_EXT
:
1609 return GLX_BAD_ATTRIBUTE
;
1610 *value
= xmvis
->visinfo
->screen
;
1612 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1614 return GLX_BAD_ATTRIBUTE
;
1615 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1617 case GLX_RENDER_TYPE_SGIX
:
1619 return GLX_BAD_ATTRIBUTE
;
1620 if (xmvis
->mesa_visual
.rgbMode
)
1621 *value
= GLX_RGBA_BIT
;
1623 *value
= GLX_COLOR_INDEX_BIT
;
1625 case GLX_X_RENDERABLE_SGIX
:
1627 return GLX_BAD_ATTRIBUTE
;
1628 *value
= True
; /* XXX really? */
1630 case GLX_FBCONFIG_ID_SGIX
:
1632 return GLX_BAD_ATTRIBUTE
;
1633 *value
= xmvis
->visinfo
->visualid
;
1635 case GLX_MAX_PBUFFER_WIDTH
:
1637 return GLX_BAD_ATTRIBUTE
;
1638 /* XXX or MAX_WIDTH? */
1639 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1641 case GLX_MAX_PBUFFER_HEIGHT
:
1643 return GLX_BAD_ATTRIBUTE
;
1644 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1646 case GLX_MAX_PBUFFER_PIXELS
:
1648 return GLX_BAD_ATTRIBUTE
;
1649 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1650 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1654 return GLX_BAD_ATTRIBUTE
;
1655 *value
= xmvis
->visinfo
->visualid
;
1658 #ifdef GLX_EXT_texture_from_pixmap
1659 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1660 *value
= True
; /*XXX*/
1662 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1664 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1666 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1667 *value
= True
; /*XXX*/
1669 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1670 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1671 GLX_TEXTURE_2D_BIT_EXT
|
1672 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1674 case GLX_Y_INVERTED_EXT
:
1675 *value
= True
; /*XXX*/
1680 return GLX_BAD_ATTRIBUTE
;
1687 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1688 int attrib
, int *value
)
1692 if (!dpy
|| !visinfo
)
1693 return GLX_BAD_ATTRIBUTE
;
1695 xmvis
= find_glx_visual( dpy
, visinfo
);
1697 /* this visual wasn't obtained with glXChooseVisual */
1698 xmvis
= create_glx_visual( dpy
, visinfo
);
1700 /* this visual can't be used for GL rendering */
1701 if (attrib
==GLX_USE_GL
) {
1702 *value
= (int) False
;
1706 return GLX_BAD_VISUAL
;
1711 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1719 XMesaContext xmesa
= XMesaGetCurrentContext();
1720 XMesaFlush( xmesa
);
1728 XMesaContext xmesa
= XMesaGetCurrentContext();
1729 XMesaFlush( xmesa
);
1734 get_extensions( void )
1741 /* GLX 1.1 and later */
1743 glXQueryExtensionsString( Display
*dpy
, int screen
)
1747 return get_extensions();
1752 /* GLX 1.1 and later */
1754 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1756 static char version
[1000];
1757 sprintf(version
, "%d.%d %s",
1758 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, xmesa_get_name());
1764 case GLX_EXTENSIONS
:
1765 return get_extensions();
1777 /* GLX 1.1 and later */
1779 glXGetClientString( Display
*dpy
, int name
)
1781 static char version
[1000];
1782 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1783 CLIENT_MINOR_VERSION
, xmesa_get_name());
1788 case GLX_EXTENSIONS
:
1789 return get_extensions();
1807 glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1808 int attribute
, int *value
)
1810 XMesaVisual v
= (XMesaVisual
) config
;
1814 if (!dpy
|| !config
|| !value
)
1817 return get_config(v
, attribute
, value
, GL_TRUE
);
1821 PUBLIC GLXFBConfig
*
1822 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1824 XVisualInfo
*visuals
, visTemplate
;
1825 const long visMask
= VisualScreenMask
;
1828 /* Get list of all X visuals */
1829 visTemplate
.screen
= screen
;
1830 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1831 if (*nelements
> 0) {
1832 XMesaVisual
*results
;
1833 results
= (XMesaVisual
*) 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
= (GLXFBConfig
*) 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
= (XVisualInfo
*) 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
);