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 /* This indicates the client-side GLX API and GLX encoder version. */
40 #define CLIENT_MAJOR_VERSION 1
41 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
43 /* This indicates the server-side GLX decoder version.
44 * GLX 1.4 indicates OpenGL 1.3 support
46 #define SERVER_MAJOR_VERSION 1
47 #define SERVER_MINOR_VERSION 4
49 /* Who implemented this GLX? */
50 #define VENDOR "Brian Paul"
53 "GLX_MESA_copy_sub_buffer " \
54 "GLX_MESA_pixmap_colormap " \
55 "GLX_MESA_release_buffers " \
56 "GLX_ARB_create_context " \
57 "GLX_ARB_create_context_profile " \
58 "GLX_ARB_get_proc_address " \
59 "GLX_EXT_texture_from_pixmap " \
60 "GLX_EXT_visual_info " \
61 "GLX_EXT_visual_rating " \
62 /*"GLX_SGI_video_sync "*/ \
63 "GLX_SGIX_fbconfig " \
66 #define DEFAULT_DIRECT GL_TRUE
69 /** XXX this could be based on gallium's max texture size */
70 #define PBUFFER_MAX_SIZE 16384
74 * The GLXContext typedef is defined as a pointer to this structure.
76 struct __GLXcontextRec
80 GLXDrawable currentDrawable
;
81 GLXDrawable currentReadable
;
84 XMesaContext xmesaContext
;
89 static pipe_tsd ContextTSD
;
91 /** Set current context for calling thread */
93 SetCurrentContext(GLXContext c
)
95 pipe_tsd_set(&ContextTSD
, c
);
98 /** Get current context for calling thread */
100 GetCurrentContext(void)
102 return pipe_tsd_get(&ContextTSD
);
107 /**********************************************************************/
108 /*** GLX Visual Code ***/
109 /**********************************************************************/
114 static XMesaVisual
*VisualTable
= NULL
;
115 static int NumVisuals
= 0;
119 /* Macro to handle c_class vs class field name in XVisualInfo struct */
120 #if defined(__cplusplus) || defined(c_plusplus)
121 #define CLASS c_class
129 * Test if the given XVisualInfo is usable for Mesa rendering.
132 is_usable_visual( XVisualInfo
*vinfo
)
134 switch (vinfo
->CLASS
) {
137 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
141 /* Any StaticColor/PseudoColor visual of at least 4 bits */
142 if (vinfo
->depth
>=4) {
150 /* Any depth of TrueColor or DirectColor works in RGB mode */
153 /* This should never happen */
160 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
161 * configuration in our list of GLX visuals.
164 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
165 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
166 GLboolean stereoFlag
,
167 GLint depth_size
, GLint stencil_size
,
168 GLint accumRedSize
, GLint accumGreenSize
,
169 GLint accumBlueSize
, GLint accumAlphaSize
,
170 GLint level
, GLint numAuxBuffers
)
172 GLboolean ximageFlag
= GL_TRUE
;
175 GLboolean comparePointers
;
178 /* Check if the MESA_BACK_BUFFER env var is set */
179 char *backbuffer
= getenv("MESA_BACK_BUFFER");
181 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
182 ximageFlag
= GL_FALSE
;
184 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
185 ximageFlag
= GL_TRUE
;
188 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
194 /* stereo not supported */
198 if (stencil_size
> 0 && depth_size
> 0)
201 /* Comparing IDs uses less memory but sometimes fails. */
202 /* XXX revisit this after 3.0 is finished. */
203 if (getenv("MESA_GLX_VISUAL_HACK"))
204 comparePointers
= GL_TRUE
;
206 comparePointers
= GL_FALSE
;
208 /* Force the visual to have an alpha channel */
209 if (rgbFlag
&& getenv("MESA_GLX_FORCE_ALPHA"))
212 /* First check if a matching visual is already in the list */
213 for (i
=0; i
<NumVisuals
; i
++) {
214 XMesaVisual v
= VisualTable
[i
];
215 if (v
->display
== dpy
216 && v
->mesa_visual
.level
== level
217 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
218 && v
->ximage_flag
== ximageFlag
219 && v
->mesa_visual
.rgbMode
== rgbFlag
220 && v
->mesa_visual
.doubleBufferMode
== dbFlag
221 && v
->mesa_visual
.stereoMode
== stereoFlag
222 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
223 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
224 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
225 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
226 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
227 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
228 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
229 /* now either compare XVisualInfo pointers or visual IDs */
230 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
231 || (comparePointers
&& v
->vishandle
== vinfo
)) {
237 /* Create a new visual and add it to the list. */
239 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
240 stereoFlag
, ximageFlag
,
241 depth_size
, stencil_size
,
242 accumRedSize
, accumBlueSize
,
243 accumBlueSize
, accumAlphaSize
, 0, level
,
246 /* Save a copy of the pointer now so we can find this visual again
247 * if we need to search for it in find_glx_visual().
249 xmvis
->vishandle
= vinfo
;
250 /* Allocate more space for additional visual */
251 VisualTable
= (XMesaVisual
*) realloc( VisualTable
,
252 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
253 /* add xmvis to the list */
254 VisualTable
[NumVisuals
] = xmvis
;
256 /* XXX minor hack, because XMesaCreateVisual doesn't support an
257 * aux buffers parameter.
259 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
266 * Return the default number of bits for the Z buffer.
267 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
268 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
269 * XXX probably do the same thing for stencil, accum, etc.
272 default_depth_bits(void)
275 const char *zEnv
= getenv("MESA_GLX_DEPTH_BITS");
284 default_alpha_bits(void)
287 const char *aEnv
= getenv("MESA_GLX_ALPHA_BITS");
296 default_accum_bits(void)
304 * Create a GLX visual from a regular XVisualInfo.
305 * This is called when Fake GLX is given an XVisualInfo which wasn't
306 * returned by glXChooseVisual. Since this is the first time we're
307 * considering this visual we'll take a guess at reasonable values
308 * for depth buffer size, stencil size, accum size, etc.
309 * This is the best we can do with a client-side emulation of GLX.
312 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
314 GLint zBits
= default_depth_bits();
315 GLint accBits
= default_accum_bits();
316 GLboolean alphaFlag
= default_alpha_bits() > 0;
318 if (is_usable_visual( visinfo
)) {
319 /* Configure this visual as RGB, double-buffered, depth-buffered. */
320 /* This is surely wrong for some people's needs but what else */
321 /* can be done? They should use glXChooseVisual(). */
322 return save_glx_visual( dpy
, visinfo
,
324 alphaFlag
, /* alpha */
325 GL_TRUE
, /* double */
326 GL_FALSE
, /* stereo */
328 8, /* stencil bits */
338 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
346 * Find the GLX visual associated with an XVisualInfo.
349 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
353 /* try to match visual id */
354 for (i
=0;i
<NumVisuals
;i
++) {
355 if (VisualTable
[i
]->display
==dpy
356 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
357 return VisualTable
[i
];
361 /* if that fails, try to match pointers */
362 for (i
=0;i
<NumVisuals
;i
++) {
363 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
364 return VisualTable
[i
];
373 * Try to get an X visual which matches the given arguments.
376 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
378 XVisualInfo temp
, *vis
;
381 unsigned int default_depth
;
384 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
389 default_depth
= DefaultDepth(dpy
,scr
);
390 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
392 if (depth
==default_depth
&& xclass
==default_class
) {
393 /* try to get root window's visual */
394 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
395 mask
|= VisualIDMask
;
398 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
400 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
401 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
402 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
404 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
405 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
406 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
407 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
421 * Retrieve the value of the given environment variable and find
422 * the X visual which matches it.
423 * Input: dpy - the display
424 * screen - the screen number
425 * varname - the name of the environment variable
426 * Return: an XVisualInfo pointer to NULL if error.
429 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
431 char value
[100], type
[100];
432 int depth
, xclass
= -1;
435 if (!getenv( varname
)) {
439 strncpy( value
, getenv(varname
), 100 );
442 sscanf( value
, "%s %d", type
, &depth
);
444 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
445 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
446 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
447 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
448 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
449 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
451 if (xclass
>-1 && depth
>0) {
452 vis
= get_visual( dpy
, scr
, depth
, xclass
);
458 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
467 * Select an X visual which satisfies the RGBA flag and minimum depth.
469 * screen - X display and screen number
470 * min_depth - minimum visual depth
471 * preferred_class - preferred GLX visual class or DONT_CARE
472 * Return: pointer to an XVisualInfo or NULL.
475 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
476 int preferred_class
)
479 int xclass
, visclass
= 0;
482 /* First see if the MESA_RGB_VISUAL env var is defined */
483 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
487 /* Otherwise, search for a suitable visual */
488 if (preferred_class
==DONT_CARE
) {
489 for (xclass
=0;xclass
<6;xclass
++) {
491 case 0: visclass
= TrueColor
; break;
492 case 1: visclass
= DirectColor
; break;
493 case 2: visclass
= PseudoColor
; break;
494 case 3: visclass
= StaticColor
; break;
495 case 4: visclass
= GrayScale
; break;
496 case 5: visclass
= StaticGray
; break;
499 /* start with shallowest */
500 for (depth
=0;depth
<=32;depth
++) {
501 if (visclass
==TrueColor
&& depth
==8) {
502 /* Special case: try to get 8-bit PseudoColor before */
503 /* 8-bit TrueColor */
504 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
509 vis
= get_visual( dpy
, screen
, depth
, visclass
);
516 /* start with deepest */
517 for (depth
=32;depth
>=min_depth
;depth
--) {
518 if (visclass
==TrueColor
&& depth
==8) {
519 /* Special case: try to get 8-bit PseudoColor before */
520 /* 8-bit TrueColor */
521 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
526 vis
= get_visual( dpy
, screen
, depth
, visclass
);
535 /* search for a specific visual class */
536 switch (preferred_class
) {
537 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
538 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
539 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
540 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
541 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
542 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
543 default: return NULL
;
546 /* start with shallowest */
547 for (depth
=0;depth
<=32;depth
++) {
548 vis
= get_visual( dpy
, screen
, depth
, visclass
);
555 /* start with deepest */
556 for (depth
=32;depth
>=min_depth
;depth
--) {
557 vis
= get_visual( dpy
, screen
, depth
, visclass
);
565 /* didn't find a visual */
572 /**********************************************************************/
573 /*** Display-related functions ***/
574 /**********************************************************************/
578 * Free all XMesaVisuals which are associated with the given display.
581 destroy_visuals_on_display(Display
*dpy
)
584 for (i
= 0; i
< NumVisuals
; i
++) {
585 if (VisualTable
[i
]->display
== dpy
) {
586 /* remove this visual */
588 free(VisualTable
[i
]);
589 for (j
= i
; j
< NumVisuals
- 1; j
++)
590 VisualTable
[j
] = VisualTable
[j
+ 1];
598 * Called from XCloseDisplay() to let us free our display-related data.
601 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
603 xmesa_destroy_buffers_on_display(dpy
);
604 destroy_visuals_on_display(dpy
);
610 * Look for the named extension on given display and return a pointer
611 * to the _XExtension data, or NULL if extension not found.
614 lookup_extension(Display
*dpy
, const char *extName
)
617 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
618 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
627 * Whenever we're given a new Display pointer, call this function to
628 * register our close_display_callback function.
631 register_with_display(Display
*dpy
)
633 const char *extName
= "MesaGLX";
636 ext
= lookup_extension(dpy
, extName
);
638 XExtCodes
*c
= XAddExtension(dpy
);
639 ext
= dpy
->ext_procs
; /* new extension is at head of list */
640 assert(c
->extension
== ext
->codes
.extension
);
642 ext
->name
= _mesa_strdup(extName
);
643 ext
->close_display
= close_display_callback
;
648 /**********************************************************************/
649 /*** Begin Fake GLX API Functions ***/
650 /**********************************************************************/
654 * Helper used by glXChooseVisual and glXChooseFBConfig.
655 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
657 * In either case, the attribute list is terminated with the value 'None'.
660 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
662 const GLboolean rgbModeDefault
= fbConfig
;
663 const int *parselist
;
665 int min_red
=0, min_green
=0, min_blue
=0;
666 GLboolean rgb_flag
= rgbModeDefault
;
667 GLboolean alpha_flag
= GL_FALSE
;
668 GLboolean double_flag
= GL_FALSE
;
669 GLboolean stereo_flag
= GL_FALSE
;
670 GLint depth_size
= 0;
671 GLint stencil_size
= 0;
672 GLint accumRedSize
= 0;
673 GLint accumGreenSize
= 0;
674 GLint accumBlueSize
= 0;
675 GLint accumAlphaSize
= 0;
677 int visual_type
= DONT_CARE
;
678 GLint caveat
= DONT_CARE
;
679 XMesaVisual xmvis
= NULL
;
680 int desiredVisualID
= -1;
690 parselist
[1] == GLX_DONT_CARE
&&
691 parselist
[0] != GLX_LEVEL
) {
692 /* For glXChooseFBConfig(), skip attributes whose value is
693 * GLX_DONT_CARE, unless it's GLX_LEVEL (which can legitimately be
696 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
697 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
703 switch (*parselist
) {
714 case GLX_BUFFER_SIZE
:
720 level
= *parselist
++;
732 case GLX_DOUBLEBUFFER
:
735 double_flag
= *parselist
++;
738 double_flag
= GL_TRUE
;
744 stereo_flag
= *parselist
++;
747 stereo_flag
= GL_TRUE
;
750 case GLX_AUX_BUFFERS
:
752 numAux
= *parselist
++;
753 if (numAux
> MAX_AUX_BUFFERS
)
758 min_red
= *parselist
++;
762 min_green
= *parselist
++;
766 min_blue
= *parselist
++;
771 GLint size
= *parselist
++;
772 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
777 depth_size
= *parselist
++;
779 case GLX_STENCIL_SIZE
:
781 stencil_size
= *parselist
++;
783 case GLX_ACCUM_RED_SIZE
:
786 GLint size
= *parselist
++;
787 accumRedSize
= MAX2( accumRedSize
, size
);
790 case GLX_ACCUM_GREEN_SIZE
:
793 GLint size
= *parselist
++;
794 accumGreenSize
= MAX2( accumGreenSize
, size
);
797 case GLX_ACCUM_BLUE_SIZE
:
800 GLint size
= *parselist
++;
801 accumBlueSize
= MAX2( accumBlueSize
, size
);
804 case GLX_ACCUM_ALPHA_SIZE
:
807 GLint size
= *parselist
++;
808 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
813 * GLX_EXT_visual_info extension
815 case GLX_X_VISUAL_TYPE_EXT
:
817 visual_type
= *parselist
++;
819 case GLX_TRANSPARENT_TYPE_EXT
:
823 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
827 case GLX_TRANSPARENT_RED_VALUE_EXT
:
828 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
829 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
830 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
837 * GLX_EXT_visual_info extension
839 case GLX_VISUAL_CAVEAT_EXT
:
841 caveat
= *parselist
++; /* ignored for now */
845 * GLX_ARB_multisample
847 case GLX_SAMPLE_BUFFERS_ARB
:
848 case GLX_SAMPLES_ARB
:
850 if (*parselist
++ != 0) {
851 /* ms not supported */
859 case GLX_RENDER_TYPE
:
863 if (*parselist
& GLX_RGBA_BIT
) {
866 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
869 else if (*parselist
== 0) {
874 case GLX_DRAWABLE_TYPE
:
878 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
879 return NULL
; /* bad bit */
883 case GLX_FBCONFIG_ID
:
888 desiredVisualID
= *parselist
++;
890 case GLX_X_RENDERABLE
:
891 case GLX_MAX_PBUFFER_WIDTH
:
892 case GLX_MAX_PBUFFER_HEIGHT
:
893 case GLX_MAX_PBUFFER_PIXELS
:
895 return NULL
; /* invalid config option */
896 parselist
+= 2; /* ignore the parameter */
899 #ifdef GLX_EXT_texture_from_pixmap
900 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
901 parselist
++; /*skip*/
903 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
904 parselist
++; /*skip*/
906 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
907 parselist
++; /*skip*/
909 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
911 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
912 GLX_TEXTURE_2D_BIT_EXT
|
913 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
918 case GLX_Y_INVERTED_EXT
:
919 parselist
++; /*skip*/
928 /* undefined attribute */
929 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
939 * Since we're only simulating the GLX extension this function will never
940 * find any real GL visuals. Instead, all we can do is try to find an RGB
941 * or CI visual of appropriate depth. Other requested attributes such as
942 * double buffering, depth buffer, etc. will be associated with the X
943 * visual and stored in the VisualTable[].
945 if (desiredVisualID
!= -1) {
946 /* try to get a specific visual, by visualID */
949 temp
.visualid
= desiredVisualID
;
950 temp
.screen
= screen
;
951 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
953 /* give the visual some useful GLX attributes */
954 double_flag
= GL_TRUE
;
959 /* normal color planes */
960 /* Get an RGB visual */
961 int min_rgb
= min_red
+ min_green
+ min_blue
;
962 if (min_rgb
>1 && min_rgb
<8) {
963 /* a special case to be sure we can get a monochrome visual */
966 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
969 _mesa_warning(NULL
, "overlay not supported");
974 /* Note: we're not exactly obeying the glXChooseVisual rules here.
975 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
976 * largest depth buffer size, which is 32bits/value. Instead, we
977 * return 16 to maintain performance with earlier versions of Mesa.
979 if (stencil_size
> 0)
980 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
981 else if (depth_size
> 24)
983 else if (depth_size
> 16)
985 else if (depth_size
> 0) {
986 depth_size
= default_depth_bits();
990 alpha_flag
= default_alpha_bits() > 0;
993 /* we only support one size of stencil and accum buffers. */
994 if (stencil_size
> 0)
997 if (accumRedSize
> 0 ||
998 accumGreenSize
> 0 ||
1000 accumAlphaSize
> 0) {
1004 accumBlueSize
= default_accum_bits();
1006 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1009 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1010 stereo_flag
, depth_size
, stencil_size
,
1011 accumRedSize
, accumGreenSize
,
1012 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1019 PUBLIC XVisualInfo
*
1020 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1024 /* register ourselves as an extension on this display */
1025 register_with_display(dpy
);
1027 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1029 /* create a new vishandle - the cached one may be stale */
1030 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1031 if (xmvis
->vishandle
) {
1032 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1034 return xmvis
->vishandle
;
1042 * Helper function used by other glXCreateContext functions.
1045 create_context(Display
*dpy
, XMesaVisual xmvis
,
1046 XMesaContext shareCtx
, Bool direct
,
1047 unsigned major
, unsigned minor
,
1048 unsigned profileMask
, unsigned contextFlags
)
1055 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1059 /* deallocate unused windows/buffers */
1061 XMesaGarbageCollect();
1064 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
, shareCtx
, major
, minor
,
1065 profileMask
, contextFlags
);
1066 if (!glxCtx
->xmesaContext
) {
1071 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1072 glxCtx
->currentDpy
= dpy
;
1073 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1080 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1081 GLXContext shareCtx
, Bool direct
)
1085 xmvis
= find_glx_visual( dpy
, visinfo
);
1087 /* This visual wasn't found with glXChooseVisual() */
1088 xmvis
= create_glx_visual( dpy
, visinfo
);
1090 /* unusable visual */
1095 return create_context(dpy
, xmvis
,
1096 shareCtx
? shareCtx
->xmesaContext
: NULL
,
1098 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
1102 /* XXX these may have to be removed due to thread-safety issues. */
1103 static GLXContext MakeCurrent_PrevContext
= 0;
1104 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1105 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1106 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1107 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1110 /* GLX 1.3 and later */
1112 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1113 GLXDrawable read
, GLXContext ctx
)
1115 GLXContext glxCtx
= ctx
;
1116 static boolean firsttime
= 1, no_rast
= 0;
1119 no_rast
= getenv("SP_NO_RAST") != NULL
;
1123 if (ctx
&& draw
&& read
) {
1124 XMesaBuffer drawBuffer
, readBuffer
;
1125 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1127 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1128 if (ctx
== MakeCurrent_PrevContext
1129 && draw
== MakeCurrent_PrevDrawable
) {
1130 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1133 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1136 /* drawable must be a new window! */
1137 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1139 /* Out of memory, or context/drawable depth mismatch */
1144 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1145 if (ctx
== MakeCurrent_PrevContext
1146 && read
== MakeCurrent_PrevReadable
) {
1147 readBuffer
= MakeCurrent_PrevReadBuffer
;
1150 readBuffer
= XMesaFindBuffer( dpy
, read
);
1153 /* drawable must be a new window! */
1154 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1156 /* Out of memory, or context/drawable depth mismatch */
1162 MakeCurrent_PrevContext
== ctx
&&
1163 MakeCurrent_PrevDrawable
== draw
&&
1164 MakeCurrent_PrevReadable
== read
&&
1165 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1166 MakeCurrent_PrevReadBuffer
== readBuffer
)
1169 MakeCurrent_PrevContext
= ctx
;
1170 MakeCurrent_PrevDrawable
= draw
;
1171 MakeCurrent_PrevReadable
= read
;
1172 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1173 MakeCurrent_PrevReadBuffer
= readBuffer
;
1175 /* Now make current! */
1176 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1177 ctx
->currentDpy
= dpy
;
1178 ctx
->currentDrawable
= draw
;
1179 ctx
->currentReadable
= read
;
1180 SetCurrentContext(ctx
);
1187 else if (!ctx
&& !draw
&& !read
) {
1188 /* release current context w/out assigning new one. */
1189 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1190 MakeCurrent_PrevContext
= 0;
1191 MakeCurrent_PrevDrawable
= 0;
1192 MakeCurrent_PrevReadable
= 0;
1193 MakeCurrent_PrevDrawBuffer
= 0;
1194 MakeCurrent_PrevReadBuffer
= 0;
1195 SetCurrentContext(NULL
);
1199 /* The args must either all be non-zero or all zero.
1208 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1210 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1215 glXGetCurrentContext(void)
1217 return GetCurrentContext();
1222 glXGetCurrentDisplay(void)
1224 GLXContext glxCtx
= glXGetCurrentContext();
1226 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1231 glXGetCurrentDisplayEXT(void)
1233 return glXGetCurrentDisplay();
1238 glXGetCurrentDrawable(void)
1240 GLXContext gc
= glXGetCurrentContext();
1241 return gc
? gc
->currentDrawable
: 0;
1246 glXGetCurrentReadDrawable(void)
1248 GLXContext gc
= glXGetCurrentContext();
1249 return gc
? gc
->currentReadable
: 0;
1254 glXGetCurrentReadDrawableSGI(void)
1256 return glXGetCurrentReadDrawable();
1261 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1266 v
= find_glx_visual( dpy
, visinfo
);
1268 v
= create_glx_visual( dpy
, visinfo
);
1270 /* unusable visual */
1275 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1279 return b
->ws
.drawable
;
1283 /*** GLX_MESA_pixmap_colormap ***/
1286 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1287 Pixmap pixmap
, Colormap cmap
)
1292 v
= find_glx_visual( dpy
, visinfo
);
1294 v
= create_glx_visual( dpy
, visinfo
);
1296 /* unusable visual */
1301 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1305 return b
->ws
.drawable
;
1310 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1312 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1314 XMesaDestroyBuffer(b
);
1316 else if (getenv("MESA_DEBUG")) {
1317 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1323 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1324 unsigned long mask
)
1326 XMesaContext xm_src
= src
->xmesaContext
;
1327 XMesaContext xm_dst
= dst
->xmesaContext
;
1329 if (MakeCurrent_PrevContext
== src
) {
1332 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1337 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1340 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1341 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1347 return True
; /* we're faking GLX so always return success */
1352 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1355 GLXContext glxCtx
= ctx
;
1357 MakeCurrent_PrevContext
= 0;
1358 MakeCurrent_PrevDrawable
= 0;
1359 MakeCurrent_PrevReadable
= 0;
1360 MakeCurrent_PrevDrawBuffer
= 0;
1361 MakeCurrent_PrevReadBuffer
= 0;
1362 XMesaDestroyContext( glxCtx
->xmesaContext
);
1363 XMesaGarbageCollect();
1370 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1372 return ctx
? ctx
->isDirect
: False
;
1378 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1380 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1381 static boolean firsttime
= 1, no_rast
= 0;
1384 no_rast
= getenv("SP_NO_RAST") != NULL
;
1392 XMesaSwapBuffers(buffer
);
1394 else if (getenv("MESA_DEBUG")) {
1395 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1402 /*** GLX_MESA_copy_sub_buffer ***/
1405 glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
1406 int x
, int y
, int width
, int height
)
1408 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1410 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1412 else if (getenv("MESA_DEBUG")) {
1413 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1419 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1422 /* Return GLX version, not Mesa version */
1423 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1424 *maj
= CLIENT_MAJOR_VERSION
;
1425 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1431 * Query the GLX attributes of the given XVisualInfo.
1434 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1440 return GLX_BAD_ATTRIBUTE
;
1441 *value
= (int) True
;
1443 case GLX_BUFFER_SIZE
:
1444 *value
= xmvis
->visinfo
->depth
;
1447 *value
= xmvis
->mesa_visual
.level
;
1451 return GLX_BAD_ATTRIBUTE
;
1452 if (xmvis
->mesa_visual
.rgbMode
) {
1459 case GLX_DOUBLEBUFFER
:
1460 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1463 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1465 case GLX_AUX_BUFFERS
:
1466 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1469 *value
= xmvis
->mesa_visual
.redBits
;
1471 case GLX_GREEN_SIZE
:
1472 *value
= xmvis
->mesa_visual
.greenBits
;
1475 *value
= xmvis
->mesa_visual
.blueBits
;
1477 case GLX_ALPHA_SIZE
:
1478 *value
= xmvis
->mesa_visual
.alphaBits
;
1480 case GLX_DEPTH_SIZE
:
1481 *value
= xmvis
->mesa_visual
.depthBits
;
1483 case GLX_STENCIL_SIZE
:
1484 *value
= xmvis
->mesa_visual
.stencilBits
;
1486 case GLX_ACCUM_RED_SIZE
:
1487 *value
= xmvis
->mesa_visual
.accumRedBits
;
1489 case GLX_ACCUM_GREEN_SIZE
:
1490 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1492 case GLX_ACCUM_BLUE_SIZE
:
1493 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1495 case GLX_ACCUM_ALPHA_SIZE
:
1496 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1500 * GLX_EXT_visual_info extension
1502 case GLX_X_VISUAL_TYPE_EXT
:
1503 switch (xmvis
->visinfo
->CLASS
) {
1504 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1505 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1506 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1507 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1508 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1509 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1512 case GLX_TRANSPARENT_TYPE_EXT
:
1514 *value
= GLX_NONE_EXT
;
1516 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1519 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1522 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1525 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1528 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1533 * GLX_EXT_visual_info extension
1535 case GLX_VISUAL_CAVEAT_EXT
:
1536 /* test for zero, just in case */
1537 if (xmvis
->mesa_visual
.visualRating
> 0)
1538 *value
= xmvis
->mesa_visual
.visualRating
;
1540 *value
= GLX_NONE_EXT
;
1544 * GLX_ARB_multisample
1546 case GLX_SAMPLE_BUFFERS_ARB
:
1549 case GLX_SAMPLES_ARB
:
1556 case GLX_SCREEN_EXT
:
1558 return GLX_BAD_ATTRIBUTE
;
1559 *value
= xmvis
->visinfo
->screen
;
1561 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1563 return GLX_BAD_ATTRIBUTE
;
1564 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1566 case GLX_RENDER_TYPE_SGIX
:
1568 return GLX_BAD_ATTRIBUTE
;
1569 if (xmvis
->mesa_visual
.rgbMode
)
1570 *value
= GLX_RGBA_BIT
;
1572 *value
= GLX_COLOR_INDEX_BIT
;
1574 case GLX_X_RENDERABLE_SGIX
:
1576 return GLX_BAD_ATTRIBUTE
;
1577 *value
= True
; /* XXX really? */
1579 case GLX_FBCONFIG_ID_SGIX
:
1581 return GLX_BAD_ATTRIBUTE
;
1582 *value
= xmvis
->visinfo
->visualid
;
1584 case GLX_MAX_PBUFFER_WIDTH
:
1586 return GLX_BAD_ATTRIBUTE
;
1587 /* XXX or MAX_WIDTH? */
1588 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1590 case GLX_MAX_PBUFFER_HEIGHT
:
1592 return GLX_BAD_ATTRIBUTE
;
1593 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1595 case GLX_MAX_PBUFFER_PIXELS
:
1597 return GLX_BAD_ATTRIBUTE
;
1598 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1599 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1603 return GLX_BAD_ATTRIBUTE
;
1604 *value
= xmvis
->visinfo
->visualid
;
1607 #ifdef GLX_EXT_texture_from_pixmap
1608 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1609 *value
= True
; /*XXX*/
1611 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1613 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1615 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1616 *value
= True
; /*XXX*/
1618 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1619 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1620 GLX_TEXTURE_2D_BIT_EXT
|
1621 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1623 case GLX_Y_INVERTED_EXT
:
1624 *value
= True
; /*XXX*/
1629 return GLX_BAD_ATTRIBUTE
;
1636 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1637 int attrib
, int *value
)
1641 if (!dpy
|| !visinfo
)
1642 return GLX_BAD_ATTRIBUTE
;
1644 xmvis
= find_glx_visual( dpy
, visinfo
);
1646 /* this visual wasn't obtained with glXChooseVisual */
1647 xmvis
= create_glx_visual( dpy
, visinfo
);
1649 /* this visual can't be used for GL rendering */
1650 if (attrib
==GLX_USE_GL
) {
1651 *value
= (int) False
;
1655 return GLX_BAD_VISUAL
;
1660 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1668 XMesaContext xmesa
= XMesaGetCurrentContext();
1669 XMesaFlush( xmesa
);
1677 XMesaContext xmesa
= XMesaGetCurrentContext();
1678 XMesaFlush( xmesa
);
1683 get_extensions( void )
1690 /* GLX 1.1 and later */
1692 glXQueryExtensionsString( Display
*dpy
, int screen
)
1696 return get_extensions();
1701 /* GLX 1.1 and later */
1703 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1705 static char version
[1000];
1706 sprintf(version
, "%d.%d %s",
1707 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, xmesa_get_name());
1713 case GLX_EXTENSIONS
:
1714 return get_extensions();
1726 /* GLX 1.1 and later */
1728 glXGetClientString( Display
*dpy
, int name
)
1730 static char version
[1000];
1731 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1732 CLIENT_MINOR_VERSION
, xmesa_get_name());
1737 case GLX_EXTENSIONS
:
1738 return get_extensions();
1756 glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1757 int attribute
, int *value
)
1759 XMesaVisual v
= (XMesaVisual
) config
;
1763 if (!dpy
|| !config
|| !value
)
1766 return get_config(v
, attribute
, value
, GL_TRUE
);
1770 PUBLIC GLXFBConfig
*
1771 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1773 XVisualInfo
*visuals
, visTemplate
;
1774 const long visMask
= VisualScreenMask
;
1777 /* Get list of all X visuals */
1778 visTemplate
.screen
= screen
;
1779 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1780 if (*nelements
> 0) {
1781 XMesaVisual
*results
;
1782 results
= (XMesaVisual
*) malloc(*nelements
* sizeof(XMesaVisual
));
1787 for (i
= 0; i
< *nelements
; i
++) {
1788 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1794 return (GLXFBConfig
*) results
;
1800 PUBLIC GLXFBConfig
*
1801 glXChooseFBConfig(Display
*dpy
, int screen
,
1802 const int *attribList
, int *nitems
)
1806 /* register ourselves as an extension on this display */
1807 register_with_display(dpy
);
1809 if (!attribList
|| !attribList
[0]) {
1810 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1811 return glXGetFBConfigs(dpy
, screen
, nitems
);
1814 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1816 GLXFBConfig
*config
= (GLXFBConfig
*) malloc(sizeof(XMesaVisual
));
1822 config
[0] = (GLXFBConfig
) xmvis
;
1823 return (GLXFBConfig
*) config
;
1832 PUBLIC XVisualInfo
*
1833 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1835 if (dpy
&& config
) {
1836 XMesaVisual xmvis
= (XMesaVisual
) config
;
1838 return xmvis
->vishandle
;
1840 /* create a new vishandle - the cached one may be stale */
1841 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1842 if (xmvis
->vishandle
) {
1843 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1845 return xmvis
->vishandle
;
1855 glXCreateWindow(Display
*dpy
, GLXFBConfig config
, Window win
,
1856 const int *attribList
)
1858 XMesaVisual xmvis
= (XMesaVisual
) config
;
1863 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1868 (void) attribList
; /* Ignored in GLX 1.3 */
1870 return win
; /* A hack for now */
1875 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1877 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1879 XMesaDestroyBuffer(b
);
1880 /* don't destroy X window */
1886 glXCreatePixmap(Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1887 const int *attribList
)
1889 XMesaVisual v
= (XMesaVisual
) config
;
1892 int target
= 0, format
= 0, mipmap
= 0;
1895 if (!dpy
|| !config
|| !pixmap
)
1898 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1900 case GLX_TEXTURE_FORMAT_EXT
:
1903 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1904 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1905 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1913 case GLX_TEXTURE_TARGET_EXT
:
1916 case GLX_TEXTURE_1D_EXT
:
1917 case GLX_TEXTURE_2D_EXT
:
1918 case GLX_TEXTURE_RECTANGLE_EXT
:
1926 case GLX_MIPMAP_TEXTURE_EXT
:
1937 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1938 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1939 &value
, GL_TRUE
) != Success
1941 return 0; /* error! */
1944 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
1945 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
1946 &value
, GL_TRUE
) != Success
1948 return 0; /* error! */
1952 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
1953 &value
, GL_TRUE
) != Success
1955 return 0; /* error! */
1958 if (target
== GLX_TEXTURE_1D_EXT
) {
1959 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1960 &value
, GL_TRUE
) != Success
1961 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
1962 return 0; /* error! */
1965 else if (target
== GLX_TEXTURE_2D_EXT
) {
1966 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1967 &value
, GL_TRUE
) != Success
1968 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
1969 return 0; /* error! */
1972 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
1973 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1974 &value
, GL_TRUE
) != Success
1975 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
1976 return 0; /* error! */
1980 if (format
|| target
|| mipmap
) {
1981 /* texture from pixmap */
1982 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
1985 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1996 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
1998 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
2000 XMesaDestroyBuffer(b
);
2001 /* don't destroy X pixmap */
2006 glXCreatePbuffer(Display
*dpy
, GLXFBConfig config
, const int *attribList
)
2008 XMesaVisual xmvis
= (XMesaVisual
) config
;
2011 int width
= 0, height
= 0;
2012 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2016 for (attrib
= attribList
; *attrib
; attrib
++) {
2018 case GLX_PBUFFER_WIDTH
:
2022 case GLX_PBUFFER_HEIGHT
:
2026 case GLX_PRESERVED_CONTENTS
:
2028 preserveContents
= *attrib
;
2030 case GLX_LARGEST_PBUFFER
:
2032 useLargest
= *attrib
;
2039 if (width
== 0 || height
== 0)
2042 if (width
> PBUFFER_MAX_SIZE
|| height
> PBUFFER_MAX_SIZE
) {
2043 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2044 * allocate the largest possible buffer.
2047 width
= PBUFFER_MAX_SIZE
;
2048 height
= PBUFFER_MAX_SIZE
;
2052 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2053 /* A GLXPbuffer handle must be an X Drawable because that's what
2054 * glXMakeCurrent takes.
2057 xmbuf
->largestPbuffer
= useLargest
;
2058 xmbuf
->preservedContents
= preserveContents
;
2059 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2068 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2070 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2072 XMesaDestroyBuffer(b
);
2078 glXQueryDrawable(Display
*dpy
, GLXDrawable draw
, int attribute
,
2079 unsigned int *value
)
2081 GLuint width
, height
;
2082 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2086 /* make sure buffer's dimensions are up to date */
2087 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2089 switch (attribute
) {
2096 case GLX_PRESERVED_CONTENTS
:
2097 *value
= xmbuf
->preservedContents
;
2099 case GLX_LARGEST_PBUFFER
:
2100 *value
= xmbuf
->largestPbuffer
;
2102 case GLX_FBCONFIG_ID
:
2103 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2105 #ifdef GLX_EXT_texture_from_pixmap
2106 case GLX_TEXTURE_FORMAT_EXT
:
2107 *value
= xmbuf
->TextureFormat
;
2109 case GLX_TEXTURE_TARGET_EXT
:
2110 *value
= xmbuf
->TextureTarget
;
2112 case GLX_MIPMAP_TEXTURE_EXT
:
2113 *value
= xmbuf
->TextureMipmap
;
2118 return; /* raise BadValue error */
2124 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2125 int renderType
, GLXContext shareCtx
, Bool direct
)
2127 XMesaVisual xmvis
= (XMesaVisual
) config
;
2129 if (!dpy
|| !config
||
2130 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2133 return create_context(dpy
, xmvis
,
2134 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2136 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2141 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2143 GLXContext glxCtx
= ctx
;
2144 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2149 switch (attribute
) {
2150 case GLX_FBCONFIG_ID
:
2151 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2153 case GLX_RENDER_TYPE
:
2154 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2155 *value
= GLX_RGBA_TYPE
;
2157 *value
= GLX_COLOR_INDEX_TYPE
;
2163 return GLX_BAD_ATTRIBUTE
;
2170 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2172 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2174 xmbuf
->selectedEvents
= mask
;
2179 glXGetSelectedEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2181 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2183 *mask
= xmbuf
->selectedEvents
;
2190 /*** GLX_SGI_swap_control ***/
2193 glXSwapIntervalSGI(int interval
)
2201 /*** GLX_SGI_video_sync ***/
2203 static unsigned int FrameCounter
= 0;
2206 glXGetVideoSyncSGI(unsigned int *count
)
2208 /* this is a bogus implementation */
2209 *count
= FrameCounter
++;
2214 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2216 if (divisor
<= 0 || remainder
< 0)
2217 return GLX_BAD_VALUE
;
2218 /* this is a bogus implementation */
2220 while (FrameCounter
% divisor
!= remainder
)
2222 *count
= FrameCounter
;
2228 /*** GLX_SGI_make_current_read ***/
2231 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
,
2234 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2239 glXGetCurrentReadDrawableSGI(void)
2246 /*** GLX_SGIX_video_source ***/
2249 PUBLIC GLXVideoSourceSGIX
2250 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
,
2251 VLPath path
, int nodeClass
, VLNode drainNode
)
2263 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2272 /*** GLX_EXT_import_context ***/
2275 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2282 glXGetContextIDEXT(const GLXContext context
)
2289 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2297 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
,
2309 /*** GLX_SGIX_fbconfig ***/
2312 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2313 int attribute
, int *value
)
2315 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2318 PUBLIC GLXFBConfigSGIX
*
2319 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
,
2322 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
,
2323 attrib_list
, nelements
);
2328 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2331 XMesaVisual xmvis
= (XMesaVisual
) config
;
2332 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2333 return xmbuf
->ws
.drawable
; /* need to return an X ID */
2338 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2339 int renderType
, GLXContext shareCtx
,
2342 XMesaVisual xmvis
= (XMesaVisual
) config
;
2344 if (!dpy
|| !config
||
2345 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2348 return create_context(dpy
, xmvis
,
2349 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2351 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2355 PUBLIC XVisualInfo
*
2356 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2358 return glXGetVisualFromFBConfig(dpy
, config
);
2362 PUBLIC GLXFBConfigSGIX
2363 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2365 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2367 /* This visual wasn't found with glXChooseVisual() */
2368 xmvis
= create_glx_visual(dpy
, vis
);
2371 return (GLXFBConfigSGIX
) xmvis
;
2376 /*** GLX_SGIX_pbuffer ***/
2378 PUBLIC GLXPbufferSGIX
2379 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2380 unsigned int width
, unsigned int height
,
2383 XMesaVisual xmvis
= (XMesaVisual
) config
;
2386 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2390 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2392 case GLX_PRESERVED_CONTENTS_SGIX
:
2394 preserveContents
= *attrib
; /* ignored */
2396 case GLX_LARGEST_PBUFFER_SGIX
:
2398 useLargest
= *attrib
; /* ignored */
2405 /* not used at this time */
2407 (void) preserveContents
;
2409 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2410 /* A GLXPbuffer handle must be an X Drawable because that's what
2411 * glXMakeCurrent takes.
2413 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2418 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2420 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2422 XMesaDestroyBuffer(xmbuf
);
2428 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
,
2429 unsigned int *value
)
2431 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2434 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2438 switch (attribute
) {
2439 case GLX_PRESERVED_CONTENTS_SGIX
:
2442 case GLX_LARGEST_PBUFFER_SGIX
:
2443 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2445 case GLX_WIDTH_SGIX
:
2446 *value
= xmesa_buffer_width(xmbuf
);
2448 case GLX_HEIGHT_SGIX
:
2449 *value
= xmesa_buffer_height(xmbuf
);
2451 case GLX_EVENT_MASK_SGIX
:
2452 *value
= 0; /* XXX might be wrong */
2462 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2464 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2466 /* Note: we'll never generate clobber events */
2467 xmbuf
->selectedEvents
= mask
;
2473 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
,
2474 unsigned long *mask
)
2476 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2478 *mask
= xmbuf
->selectedEvents
;
2487 /*** GLX_SGI_cushion ***/
2490 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2499 /*** GLX_SGIX_video_resize ***/
2502 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
,
2513 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2514 int x
, int y
, int w
, int h
)
2527 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2528 int *x
, int *y
, int *w
, int *h
)
2541 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
,
2542 int *dx
, int *dy
, int *dw
, int *dh
)
2555 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2566 /*** GLX_SGIX_dmbuffer **/
2568 #if defined(_DM_BUFFER_H_)
2570 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
,
2571 DMparams
*params
, DMbuffer dmbuffer
)
2582 /*** GLX_SGIX_swap_group ***/
2585 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2594 /*** GLX_SGIX_swap_barrier ***/
2597 glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2605 glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2615 /*** GLX_SUN_get_transparent_index ***/
2618 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
,
2624 (void) pTransparent
;
2630 /*** GLX_MESA_release_buffers ***/
2633 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2634 * (a window or pixmap) prior to destroying the GLXDrawable.
2637 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2639 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2641 XMesaDestroyBuffer(b
);
2647 /*** GLX_EXT_texture_from_pixmap ***/
2650 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2651 const int *attrib_list
)
2653 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2655 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2659 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2661 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2663 XMesaReleaseTexImage(dpy
, b
, buffer
);
2668 /*** GLX_ARB_create_context ***/
2671 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
2672 GLXContext shareCtx
, Bool direct
,
2673 const int *attrib_list
)
2675 XMesaVisual xmvis
= (XMesaVisual
) config
;
2676 int majorVersion
= 1, minorVersion
= 0;
2677 int contextFlags
= 0x0;
2678 int profileMask
= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
;
2679 int renderType
= GLX_RGBA_TYPE
;
2682 const int contextFlagsAll
= (GLX_CONTEXT_DEBUG_BIT_ARB
|
2683 GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
);
2685 /* parse attrib_list */
2686 for (i
= 0; !done
&& attrib_list
&& attrib_list
[i
]; i
++) {
2687 switch (attrib_list
[i
]) {
2688 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2689 majorVersion
= attrib_list
[++i
];
2691 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2692 minorVersion
= attrib_list
[++i
];
2694 case GLX_CONTEXT_FLAGS_ARB
:
2695 contextFlags
= attrib_list
[++i
];
2697 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2698 profileMask
= attrib_list
[++i
];
2700 case GLX_RENDER_TYPE
:
2701 renderType
= attrib_list
[++i
];
2709 /* XXX generate BadValue X Error */
2714 /* check contextFlags */
2715 if (contextFlags
& ~contextFlagsAll
) {
2716 return NULL
; /* generate BadValue X Error */
2719 /* check profileMask */
2720 if (profileMask
!= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
&&
2721 profileMask
!= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
) {
2722 return NULL
; /* generate BadValue X Error */
2725 /* check version (generate BadMatch if bad) */
2726 if (majorVersion
< 0 || minorVersion
< 0)
2729 if ((contextFlags
& GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
) &&
2731 return NULL
; /* generate GLXBadProfileARB */
2733 if (renderType
== GLX_COLOR_INDEX_TYPE
&& majorVersion
>= 3)
2734 return NULL
; /* generate BadMatch */
2736 return create_context(dpy
, xmvis
,
2737 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2739 majorVersion
, minorVersion
,
2740 profileMask
, contextFlags
);