2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
29 * "Fake" GLX API implemented in terms of the XMesa*() functions.
34 #define GLX_GLXEXT_PROTOTYPES
40 /* This indicates the client-side GLX API and GLX encoder version. */
41 #define CLIENT_MAJOR_VERSION 1
42 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
44 /* This indicates the server-side GLX decoder version.
45 * GLX 1.4 indicates OpenGL 1.3 support
47 #define SERVER_MAJOR_VERSION 1
48 #define SERVER_MINOR_VERSION 4
50 /* Who implemented this GLX? */
51 #define VENDOR "Brian Paul"
54 "GLX_MESA_copy_sub_buffer " \
55 "GLX_MESA_pixmap_colormap " \
56 "GLX_MESA_release_buffers " \
57 "GLX_ARB_create_context " \
58 "GLX_ARB_create_context_profile " \
59 "GLX_ARB_get_proc_address " \
60 "GLX_EXT_texture_from_pixmap " \
61 "GLX_EXT_visual_info " \
62 "GLX_EXT_visual_rating " \
63 /*"GLX_SGI_video_sync "*/ \
64 "GLX_SGIX_fbconfig " \
67 #define DEFAULT_DIRECT GL_TRUE
70 /** XXX this could be based on gallium's max texture size */
71 #define PBUFFER_MAX_SIZE 16384
75 * The GLXContext typedef is defined as a pointer to this structure.
77 struct __GLXcontextRec
81 GLXDrawable currentDrawable
;
82 GLXDrawable currentReadable
;
85 XMesaContext xmesaContext
;
90 static pipe_tsd ContextTSD
;
92 /** Set current context for calling thread */
94 SetCurrentContext(GLXContext c
)
96 pipe_tsd_set(&ContextTSD
, c
);
99 /** Get current context for calling thread */
101 GetCurrentContext(void)
103 return pipe_tsd_get(&ContextTSD
);
108 /**********************************************************************/
109 /*** GLX Visual Code ***/
110 /**********************************************************************/
115 static XMesaVisual
*VisualTable
= NULL
;
116 static int NumVisuals
= 0;
120 /* Macro to handle c_class vs class field name in XVisualInfo struct */
121 #if defined(__cplusplus) || defined(c_plusplus)
122 #define CLASS c_class
130 * Test if the given XVisualInfo is usable for Mesa rendering.
133 is_usable_visual( XVisualInfo
*vinfo
)
135 switch (vinfo
->CLASS
) {
138 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
142 /* Any StaticColor/PseudoColor visual of at least 4 bits */
143 if (vinfo
->depth
>=4) {
151 /* Any depth of TrueColor or DirectColor works in RGB mode */
154 /* This should never happen */
161 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
162 * configuration in our list of GLX visuals.
165 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
166 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
167 GLboolean stereoFlag
,
168 GLint depth_size
, GLint stencil_size
,
169 GLint accumRedSize
, GLint accumGreenSize
,
170 GLint accumBlueSize
, GLint accumAlphaSize
,
171 GLint level
, GLint numAuxBuffers
)
173 GLboolean ximageFlag
= GL_TRUE
;
176 GLboolean comparePointers
;
179 /* Check if the MESA_BACK_BUFFER env var is set */
180 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
182 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
183 ximageFlag
= GL_FALSE
;
185 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
186 ximageFlag
= GL_TRUE
;
189 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
195 /* stereo not supported */
199 if (stencil_size
> 0 && depth_size
> 0)
202 /* Comparing IDs uses less memory but sometimes fails. */
203 /* XXX revisit this after 3.0 is finished. */
204 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
205 comparePointers
= GL_TRUE
;
207 comparePointers
= GL_FALSE
;
209 /* Force the visual to have an alpha channel */
210 if (rgbFlag
&& _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
213 /* First check if a matching visual is already in the list */
214 for (i
=0; i
<NumVisuals
; i
++) {
215 XMesaVisual v
= VisualTable
[i
];
216 if (v
->display
== dpy
217 && v
->mesa_visual
.level
== level
218 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
219 && v
->ximage_flag
== ximageFlag
220 && v
->mesa_visual
.rgbMode
== rgbFlag
221 && v
->mesa_visual
.doubleBufferMode
== dbFlag
222 && v
->mesa_visual
.stereoMode
== stereoFlag
223 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
224 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
225 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
226 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
227 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
228 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
229 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
230 /* now either compare XVisualInfo pointers or visual IDs */
231 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
232 || (comparePointers
&& v
->vishandle
== vinfo
)) {
238 /* Create a new visual and add it to the list. */
240 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
241 stereoFlag
, ximageFlag
,
242 depth_size
, stencil_size
,
243 accumRedSize
, accumBlueSize
,
244 accumBlueSize
, accumAlphaSize
, 0, level
,
247 /* Save a copy of the pointer now so we can find this visual again
248 * if we need to search for it in find_glx_visual().
250 xmvis
->vishandle
= vinfo
;
251 /* Allocate more space for additional visual */
252 VisualTable
= (XMesaVisual
*) _mesa_realloc( VisualTable
,
253 sizeof(XMesaVisual
) * NumVisuals
,
254 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
255 /* add xmvis to the list */
256 VisualTable
[NumVisuals
] = xmvis
;
258 /* XXX minor hack, because XMesaCreateVisual doesn't support an
259 * aux buffers parameter.
261 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
268 * Return the default number of bits for the Z buffer.
269 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
270 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
271 * XXX probably do the same thing for stencil, accum, etc.
274 default_depth_bits(void)
277 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
286 default_alpha_bits(void)
289 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
298 default_accum_bits(void)
306 * Create a GLX visual from a regular XVisualInfo.
307 * This is called when Fake GLX is given an XVisualInfo which wasn't
308 * returned by glXChooseVisual. Since this is the first time we're
309 * considering this visual we'll take a guess at reasonable values
310 * for depth buffer size, stencil size, accum size, etc.
311 * This is the best we can do with a client-side emulation of GLX.
314 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
316 GLint zBits
= default_depth_bits();
317 GLint accBits
= default_accum_bits();
318 GLboolean alphaFlag
= default_alpha_bits() > 0;
320 if (is_usable_visual( visinfo
)) {
321 /* Configure this visual as RGB, double-buffered, depth-buffered. */
322 /* This is surely wrong for some people's needs but what else */
323 /* can be done? They should use glXChooseVisual(). */
324 return save_glx_visual( dpy
, visinfo
,
326 alphaFlag
, /* alpha */
327 GL_TRUE
, /* double */
328 GL_FALSE
, /* stereo */
330 8, /* stencil bits */
340 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
348 * Find the GLX visual associated with an XVisualInfo.
351 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
355 /* try to match visual id */
356 for (i
=0;i
<NumVisuals
;i
++) {
357 if (VisualTable
[i
]->display
==dpy
358 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
359 return VisualTable
[i
];
363 /* if that fails, try to match pointers */
364 for (i
=0;i
<NumVisuals
;i
++) {
365 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
366 return VisualTable
[i
];
375 * Try to get an X visual which matches the given arguments.
378 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
380 XVisualInfo temp
, *vis
;
383 unsigned int default_depth
;
386 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
391 default_depth
= DefaultDepth(dpy
,scr
);
392 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
394 if (depth
==default_depth
&& xclass
==default_class
) {
395 /* try to get root window's visual */
396 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
397 mask
|= VisualIDMask
;
400 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
402 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
403 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
404 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
406 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
407 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
408 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
409 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
423 * Retrieve the value of the given environment variable and find
424 * the X visual which matches it.
425 * Input: dpy - the display
426 * screen - the screen number
427 * varname - the name of the environment variable
428 * Return: an XVisualInfo pointer to NULL if error.
431 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
433 char value
[100], type
[100];
434 int depth
, xclass
= -1;
437 if (!_mesa_getenv( varname
)) {
441 strncpy( value
, _mesa_getenv(varname
), 100 );
444 sscanf( value
, "%s %d", type
, &depth
);
446 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
447 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
448 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
449 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
450 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
451 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
453 if (xclass
>-1 && depth
>0) {
454 vis
= get_visual( dpy
, scr
, depth
, xclass
);
460 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
469 * Select an X visual which satisfies the RGBA flag and minimum depth.
471 * screen - X display and screen number
472 * min_depth - minimum visual depth
473 * preferred_class - preferred GLX visual class or DONT_CARE
474 * Return: pointer to an XVisualInfo or NULL.
477 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
478 int preferred_class
)
481 int xclass
, visclass
= 0;
484 /* First see if the MESA_RGB_VISUAL env var is defined */
485 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
489 /* Otherwise, search for a suitable visual */
490 if (preferred_class
==DONT_CARE
) {
491 for (xclass
=0;xclass
<6;xclass
++) {
493 case 0: visclass
= TrueColor
; break;
494 case 1: visclass
= DirectColor
; break;
495 case 2: visclass
= PseudoColor
; break;
496 case 3: visclass
= StaticColor
; break;
497 case 4: visclass
= GrayScale
; break;
498 case 5: visclass
= StaticGray
; break;
501 /* start with shallowest */
502 for (depth
=0;depth
<=32;depth
++) {
503 if (visclass
==TrueColor
&& depth
==8) {
504 /* Special case: try to get 8-bit PseudoColor before */
505 /* 8-bit TrueColor */
506 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
511 vis
= get_visual( dpy
, screen
, depth
, visclass
);
518 /* start with deepest */
519 for (depth
=32;depth
>=min_depth
;depth
--) {
520 if (visclass
==TrueColor
&& depth
==8) {
521 /* Special case: try to get 8-bit PseudoColor before */
522 /* 8-bit TrueColor */
523 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
528 vis
= get_visual( dpy
, screen
, depth
, visclass
);
537 /* search for a specific visual class */
538 switch (preferred_class
) {
539 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
540 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
541 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
542 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
543 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
544 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
545 default: return NULL
;
548 /* start with shallowest */
549 for (depth
=0;depth
<=32;depth
++) {
550 vis
= get_visual( dpy
, screen
, depth
, visclass
);
557 /* start with deepest */
558 for (depth
=32;depth
>=min_depth
;depth
--) {
559 vis
= get_visual( dpy
, screen
, depth
, visclass
);
567 /* didn't find a visual */
574 /**********************************************************************/
575 /*** Display-related functions ***/
576 /**********************************************************************/
580 * Free all XMesaVisuals which are associated with the given display.
583 destroy_visuals_on_display(Display
*dpy
)
586 for (i
= 0; i
< NumVisuals
; i
++) {
587 if (VisualTable
[i
]->display
== dpy
) {
588 /* remove this visual */
590 free(VisualTable
[i
]);
591 for (j
= i
; j
< NumVisuals
- 1; j
++)
592 VisualTable
[j
] = VisualTable
[j
+ 1];
600 * Called from XCloseDisplay() to let us free our display-related data.
603 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
605 xmesa_destroy_buffers_on_display(dpy
);
606 destroy_visuals_on_display(dpy
);
612 * Look for the named extension on given display and return a pointer
613 * to the _XExtension data, or NULL if extension not found.
616 lookup_extension(Display
*dpy
, const char *extName
)
619 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
620 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
629 * Whenever we're given a new Display pointer, call this function to
630 * register our close_display_callback function.
633 register_with_display(Display
*dpy
)
635 const char *extName
= "MesaGLX";
638 ext
= lookup_extension(dpy
, extName
);
640 XExtCodes
*c
= XAddExtension(dpy
);
641 ext
= dpy
->ext_procs
; /* new extension is at head of list */
642 assert(c
->extension
== ext
->codes
.extension
);
644 ext
->name
= _mesa_strdup(extName
);
645 ext
->close_display
= close_display_callback
;
650 /**********************************************************************/
651 /*** Begin Fake GLX API Functions ***/
652 /**********************************************************************/
656 * Helper used by glXChooseVisual and glXChooseFBConfig.
657 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
659 * In either case, the attribute list is terminated with the value 'None'.
662 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
664 const GLboolean rgbModeDefault
= fbConfig
;
665 const int *parselist
;
667 int min_red
=0, min_green
=0, min_blue
=0;
668 GLboolean rgb_flag
= rgbModeDefault
;
669 GLboolean alpha_flag
= GL_FALSE
;
670 GLboolean double_flag
= GL_FALSE
;
671 GLboolean stereo_flag
= GL_FALSE
;
672 GLint depth_size
= 0;
673 GLint stencil_size
= 0;
674 GLint accumRedSize
= 0;
675 GLint accumGreenSize
= 0;
676 GLint accumBlueSize
= 0;
677 GLint accumAlphaSize
= 0;
679 int visual_type
= DONT_CARE
;
680 GLint caveat
= DONT_CARE
;
681 XMesaVisual xmvis
= NULL
;
682 int desiredVisualID
= -1;
692 parselist
[1] == GLX_DONT_CARE
&&
693 parselist
[0] != GLX_LEVEL
) {
694 /* For glXChooseFBConfig(), skip attributes whose value is
695 * GLX_DONT_CARE, unless it's GLX_LEVEL (which can legitimately be
698 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
699 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
705 switch (*parselist
) {
716 case GLX_BUFFER_SIZE
:
722 level
= *parselist
++;
734 case GLX_DOUBLEBUFFER
:
737 double_flag
= *parselist
++;
740 double_flag
= GL_TRUE
;
746 stereo_flag
= *parselist
++;
749 stereo_flag
= GL_TRUE
;
752 case GLX_AUX_BUFFERS
:
754 numAux
= *parselist
++;
755 if (numAux
> MAX_AUX_BUFFERS
)
760 min_red
= *parselist
++;
764 min_green
= *parselist
++;
768 min_blue
= *parselist
++;
773 GLint size
= *parselist
++;
774 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
779 depth_size
= *parselist
++;
781 case GLX_STENCIL_SIZE
:
783 stencil_size
= *parselist
++;
785 case GLX_ACCUM_RED_SIZE
:
788 GLint size
= *parselist
++;
789 accumRedSize
= MAX2( accumRedSize
, size
);
792 case GLX_ACCUM_GREEN_SIZE
:
795 GLint size
= *parselist
++;
796 accumGreenSize
= MAX2( accumGreenSize
, size
);
799 case GLX_ACCUM_BLUE_SIZE
:
802 GLint size
= *parselist
++;
803 accumBlueSize
= MAX2( accumBlueSize
, size
);
806 case GLX_ACCUM_ALPHA_SIZE
:
809 GLint size
= *parselist
++;
810 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
815 * GLX_EXT_visual_info extension
817 case GLX_X_VISUAL_TYPE_EXT
:
819 visual_type
= *parselist
++;
821 case GLX_TRANSPARENT_TYPE_EXT
:
825 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
829 case GLX_TRANSPARENT_RED_VALUE_EXT
:
830 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
831 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
832 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
839 * GLX_EXT_visual_info extension
841 case GLX_VISUAL_CAVEAT_EXT
:
843 caveat
= *parselist
++; /* ignored for now */
847 * GLX_ARB_multisample
849 case GLX_SAMPLE_BUFFERS_ARB
:
850 case GLX_SAMPLES_ARB
:
852 if (*parselist
++ != 0) {
853 /* ms not supported */
861 case GLX_RENDER_TYPE
:
865 if (*parselist
& GLX_RGBA_BIT
) {
868 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
871 else if (*parselist
== 0) {
876 case GLX_DRAWABLE_TYPE
:
880 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
881 return NULL
; /* bad bit */
885 case GLX_FBCONFIG_ID
:
890 desiredVisualID
= *parselist
++;
892 case GLX_X_RENDERABLE
:
893 case GLX_MAX_PBUFFER_WIDTH
:
894 case GLX_MAX_PBUFFER_HEIGHT
:
895 case GLX_MAX_PBUFFER_PIXELS
:
897 return NULL
; /* invalid config option */
898 parselist
+= 2; /* ignore the parameter */
901 #ifdef GLX_EXT_texture_from_pixmap
902 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
903 parselist
++; /*skip*/
905 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
906 parselist
++; /*skip*/
908 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
909 parselist
++; /*skip*/
911 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
913 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
914 GLX_TEXTURE_2D_BIT_EXT
|
915 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
920 case GLX_Y_INVERTED_EXT
:
921 parselist
++; /*skip*/
930 /* undefined attribute */
931 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
941 * Since we're only simulating the GLX extension this function will never
942 * find any real GL visuals. Instead, all we can do is try to find an RGB
943 * or CI visual of appropriate depth. Other requested attributes such as
944 * double buffering, depth buffer, etc. will be associated with the X
945 * visual and stored in the VisualTable[].
947 if (desiredVisualID
!= -1) {
948 /* try to get a specific visual, by visualID */
951 temp
.visualid
= desiredVisualID
;
952 temp
.screen
= screen
;
953 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
955 /* give the visual some useful GLX attributes */
956 double_flag
= GL_TRUE
;
961 /* normal color planes */
962 /* Get an RGB visual */
963 int min_rgb
= min_red
+ min_green
+ min_blue
;
964 if (min_rgb
>1 && min_rgb
<8) {
965 /* a special case to be sure we can get a monochrome visual */
968 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
971 _mesa_warning(NULL
, "overlay not supported");
976 /* Note: we're not exactly obeying the glXChooseVisual rules here.
977 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
978 * largest depth buffer size, which is 32bits/value. Instead, we
979 * return 16 to maintain performance with earlier versions of Mesa.
981 if (stencil_size
> 0)
982 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
983 else if (depth_size
> 24)
985 else if (depth_size
> 16)
987 else if (depth_size
> 0) {
988 depth_size
= default_depth_bits();
992 alpha_flag
= default_alpha_bits() > 0;
995 /* we only support one size of stencil and accum buffers. */
996 if (stencil_size
> 0)
999 if (accumRedSize
> 0 ||
1000 accumGreenSize
> 0 ||
1001 accumBlueSize
> 0 ||
1002 accumAlphaSize
> 0) {
1006 accumBlueSize
= default_accum_bits();
1008 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1011 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1012 stereo_flag
, depth_size
, stencil_size
,
1013 accumRedSize
, accumGreenSize
,
1014 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1021 PUBLIC XVisualInfo
*
1022 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1026 /* register ourselves as an extension on this display */
1027 register_with_display(dpy
);
1029 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1031 /* create a new vishandle - the cached one may be stale */
1032 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1033 if (xmvis
->vishandle
) {
1034 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1036 return xmvis
->vishandle
;
1044 * Helper function used by other glXCreateContext functions.
1047 create_context(Display
*dpy
, XMesaVisual xmvis
,
1048 XMesaContext shareCtx
, Bool direct
,
1049 unsigned major
, unsigned minor
,
1050 unsigned profileMask
, unsigned contextFlags
)
1057 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1061 /* deallocate unused windows/buffers */
1063 XMesaGarbageCollect();
1066 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
, shareCtx
, major
, minor
,
1067 profileMask
, contextFlags
);
1068 if (!glxCtx
->xmesaContext
) {
1073 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1074 glxCtx
->currentDpy
= dpy
;
1075 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1082 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1083 GLXContext shareCtx
, Bool direct
)
1087 xmvis
= find_glx_visual( dpy
, visinfo
);
1089 /* This visual wasn't found with glXChooseVisual() */
1090 xmvis
= create_glx_visual( dpy
, visinfo
);
1092 /* unusable visual */
1097 return create_context(dpy
, xmvis
,
1098 shareCtx
? shareCtx
->xmesaContext
: NULL
,
1100 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
1104 /* XXX these may have to be removed due to thread-safety issues. */
1105 static GLXContext MakeCurrent_PrevContext
= 0;
1106 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1107 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1108 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1109 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1112 /* GLX 1.3 and later */
1114 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1115 GLXDrawable read
, GLXContext ctx
)
1117 GLXContext glxCtx
= ctx
;
1118 static boolean firsttime
= 1, no_rast
= 0;
1121 no_rast
= getenv("SP_NO_RAST") != NULL
;
1125 if (ctx
&& draw
&& read
) {
1126 XMesaBuffer drawBuffer
, readBuffer
;
1127 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1129 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1130 if (ctx
== MakeCurrent_PrevContext
1131 && draw
== MakeCurrent_PrevDrawable
) {
1132 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1135 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1138 /* drawable must be a new window! */
1139 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1141 /* Out of memory, or context/drawable depth mismatch */
1146 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1147 if (ctx
== MakeCurrent_PrevContext
1148 && read
== MakeCurrent_PrevReadable
) {
1149 readBuffer
= MakeCurrent_PrevReadBuffer
;
1152 readBuffer
= XMesaFindBuffer( dpy
, read
);
1155 /* drawable must be a new window! */
1156 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1158 /* Out of memory, or context/drawable depth mismatch */
1164 MakeCurrent_PrevContext
== ctx
&&
1165 MakeCurrent_PrevDrawable
== draw
&&
1166 MakeCurrent_PrevReadable
== read
&&
1167 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1168 MakeCurrent_PrevReadBuffer
== readBuffer
)
1171 MakeCurrent_PrevContext
= ctx
;
1172 MakeCurrent_PrevDrawable
= draw
;
1173 MakeCurrent_PrevReadable
= read
;
1174 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1175 MakeCurrent_PrevReadBuffer
= readBuffer
;
1177 /* Now make current! */
1178 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1179 ctx
->currentDpy
= dpy
;
1180 ctx
->currentDrawable
= draw
;
1181 ctx
->currentReadable
= read
;
1182 SetCurrentContext(ctx
);
1189 else if (!ctx
&& !draw
&& !read
) {
1190 /* release current context w/out assigning new one. */
1191 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1192 MakeCurrent_PrevContext
= 0;
1193 MakeCurrent_PrevDrawable
= 0;
1194 MakeCurrent_PrevReadable
= 0;
1195 MakeCurrent_PrevDrawBuffer
= 0;
1196 MakeCurrent_PrevReadBuffer
= 0;
1197 SetCurrentContext(NULL
);
1201 /* The args must either all be non-zero or all zero.
1210 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1212 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1217 glXGetCurrentContext(void)
1219 return GetCurrentContext();
1224 glXGetCurrentDisplay(void)
1226 GLXContext glxCtx
= glXGetCurrentContext();
1228 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1233 glXGetCurrentDisplayEXT(void)
1235 return glXGetCurrentDisplay();
1240 glXGetCurrentDrawable(void)
1242 GLXContext gc
= glXGetCurrentContext();
1243 return gc
? gc
->currentDrawable
: 0;
1248 glXGetCurrentReadDrawable(void)
1250 GLXContext gc
= glXGetCurrentContext();
1251 return gc
? gc
->currentReadable
: 0;
1256 glXGetCurrentReadDrawableSGI(void)
1258 return glXGetCurrentReadDrawable();
1263 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1268 v
= find_glx_visual( dpy
, visinfo
);
1270 v
= create_glx_visual( dpy
, visinfo
);
1272 /* unusable visual */
1277 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1281 return b
->ws
.drawable
;
1285 /*** GLX_MESA_pixmap_colormap ***/
1288 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1289 Pixmap pixmap
, Colormap cmap
)
1294 v
= find_glx_visual( dpy
, visinfo
);
1296 v
= create_glx_visual( dpy
, visinfo
);
1298 /* unusable visual */
1303 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1307 return b
->ws
.drawable
;
1312 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1314 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1316 XMesaDestroyBuffer(b
);
1318 else if (_mesa_getenv("MESA_DEBUG")) {
1319 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1325 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1326 unsigned long mask
)
1328 XMesaContext xm_src
= src
->xmesaContext
;
1329 XMesaContext xm_dst
= dst
->xmesaContext
;
1331 if (MakeCurrent_PrevContext
== src
) {
1334 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1339 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1342 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1343 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1349 return True
; /* we're faking GLX so always return success */
1354 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1357 GLXContext glxCtx
= ctx
;
1359 MakeCurrent_PrevContext
= 0;
1360 MakeCurrent_PrevDrawable
= 0;
1361 MakeCurrent_PrevReadable
= 0;
1362 MakeCurrent_PrevDrawBuffer
= 0;
1363 MakeCurrent_PrevReadBuffer
= 0;
1364 XMesaDestroyContext( glxCtx
->xmesaContext
);
1365 XMesaGarbageCollect();
1372 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1374 return ctx
? ctx
->isDirect
: False
;
1380 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1382 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1383 static boolean firsttime
= 1, no_rast
= 0;
1386 no_rast
= getenv("SP_NO_RAST") != NULL
;
1394 XMesaSwapBuffers(buffer
);
1396 else if (_mesa_getenv("MESA_DEBUG")) {
1397 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1404 /*** GLX_MESA_copy_sub_buffer ***/
1407 glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
1408 int x
, int y
, int width
, int height
)
1410 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1412 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1414 else if (_mesa_getenv("MESA_DEBUG")) {
1415 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1421 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1424 /* Return GLX version, not Mesa version */
1425 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1426 *maj
= CLIENT_MAJOR_VERSION
;
1427 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1433 * Query the GLX attributes of the given XVisualInfo.
1436 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1442 return GLX_BAD_ATTRIBUTE
;
1443 *value
= (int) True
;
1445 case GLX_BUFFER_SIZE
:
1446 *value
= xmvis
->visinfo
->depth
;
1449 *value
= xmvis
->mesa_visual
.level
;
1453 return GLX_BAD_ATTRIBUTE
;
1454 if (xmvis
->mesa_visual
.rgbMode
) {
1461 case GLX_DOUBLEBUFFER
:
1462 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1465 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1467 case GLX_AUX_BUFFERS
:
1468 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1471 *value
= xmvis
->mesa_visual
.redBits
;
1473 case GLX_GREEN_SIZE
:
1474 *value
= xmvis
->mesa_visual
.greenBits
;
1477 *value
= xmvis
->mesa_visual
.blueBits
;
1479 case GLX_ALPHA_SIZE
:
1480 *value
= xmvis
->mesa_visual
.alphaBits
;
1482 case GLX_DEPTH_SIZE
:
1483 *value
= xmvis
->mesa_visual
.depthBits
;
1485 case GLX_STENCIL_SIZE
:
1486 *value
= xmvis
->mesa_visual
.stencilBits
;
1488 case GLX_ACCUM_RED_SIZE
:
1489 *value
= xmvis
->mesa_visual
.accumRedBits
;
1491 case GLX_ACCUM_GREEN_SIZE
:
1492 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1494 case GLX_ACCUM_BLUE_SIZE
:
1495 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1497 case GLX_ACCUM_ALPHA_SIZE
:
1498 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1502 * GLX_EXT_visual_info extension
1504 case GLX_X_VISUAL_TYPE_EXT
:
1505 switch (xmvis
->visinfo
->CLASS
) {
1506 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1507 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1508 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1509 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1510 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1511 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1514 case GLX_TRANSPARENT_TYPE_EXT
:
1516 *value
= GLX_NONE_EXT
;
1518 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1521 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1524 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1527 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1530 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1535 * GLX_EXT_visual_info extension
1537 case GLX_VISUAL_CAVEAT_EXT
:
1538 /* test for zero, just in case */
1539 if (xmvis
->mesa_visual
.visualRating
> 0)
1540 *value
= xmvis
->mesa_visual
.visualRating
;
1542 *value
= GLX_NONE_EXT
;
1546 * GLX_ARB_multisample
1548 case GLX_SAMPLE_BUFFERS_ARB
:
1551 case GLX_SAMPLES_ARB
:
1558 case GLX_SCREEN_EXT
:
1560 return GLX_BAD_ATTRIBUTE
;
1561 *value
= xmvis
->visinfo
->screen
;
1563 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1565 return GLX_BAD_ATTRIBUTE
;
1566 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1568 case GLX_RENDER_TYPE_SGIX
:
1570 return GLX_BAD_ATTRIBUTE
;
1571 if (xmvis
->mesa_visual
.rgbMode
)
1572 *value
= GLX_RGBA_BIT
;
1574 *value
= GLX_COLOR_INDEX_BIT
;
1576 case GLX_X_RENDERABLE_SGIX
:
1578 return GLX_BAD_ATTRIBUTE
;
1579 *value
= True
; /* XXX really? */
1581 case GLX_FBCONFIG_ID_SGIX
:
1583 return GLX_BAD_ATTRIBUTE
;
1584 *value
= xmvis
->visinfo
->visualid
;
1586 case GLX_MAX_PBUFFER_WIDTH
:
1588 return GLX_BAD_ATTRIBUTE
;
1589 /* XXX or MAX_WIDTH? */
1590 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1592 case GLX_MAX_PBUFFER_HEIGHT
:
1594 return GLX_BAD_ATTRIBUTE
;
1595 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1597 case GLX_MAX_PBUFFER_PIXELS
:
1599 return GLX_BAD_ATTRIBUTE
;
1600 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1601 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1605 return GLX_BAD_ATTRIBUTE
;
1606 *value
= xmvis
->visinfo
->visualid
;
1609 #ifdef GLX_EXT_texture_from_pixmap
1610 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1611 *value
= True
; /*XXX*/
1613 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1615 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1617 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1618 *value
= True
; /*XXX*/
1620 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1621 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1622 GLX_TEXTURE_2D_BIT_EXT
|
1623 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1625 case GLX_Y_INVERTED_EXT
:
1626 *value
= True
; /*XXX*/
1631 return GLX_BAD_ATTRIBUTE
;
1638 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1639 int attrib
, int *value
)
1643 if (!dpy
|| !visinfo
)
1644 return GLX_BAD_ATTRIBUTE
;
1646 xmvis
= find_glx_visual( dpy
, visinfo
);
1648 /* this visual wasn't obtained with glXChooseVisual */
1649 xmvis
= create_glx_visual( dpy
, visinfo
);
1651 /* this visual can't be used for GL rendering */
1652 if (attrib
==GLX_USE_GL
) {
1653 *value
= (int) False
;
1657 return GLX_BAD_VISUAL
;
1662 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1670 XMesaContext xmesa
= XMesaGetCurrentContext();
1671 XMesaFlush( xmesa
);
1679 XMesaContext xmesa
= XMesaGetCurrentContext();
1680 XMesaFlush( xmesa
);
1685 get_extensions( void )
1692 /* GLX 1.1 and later */
1694 glXQueryExtensionsString( Display
*dpy
, int screen
)
1698 return get_extensions();
1703 /* GLX 1.1 and later */
1705 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1707 static char version
[1000];
1708 sprintf(version
, "%d.%d %s",
1709 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, xmesa_get_name());
1715 case GLX_EXTENSIONS
:
1716 return get_extensions();
1728 /* GLX 1.1 and later */
1730 glXGetClientString( Display
*dpy
, int name
)
1732 static char version
[1000];
1733 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1734 CLIENT_MINOR_VERSION
, xmesa_get_name());
1739 case GLX_EXTENSIONS
:
1740 return get_extensions();
1758 glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1759 int attribute
, int *value
)
1761 XMesaVisual v
= (XMesaVisual
) config
;
1765 if (!dpy
|| !config
|| !value
)
1768 return get_config(v
, attribute
, value
, GL_TRUE
);
1772 PUBLIC GLXFBConfig
*
1773 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1775 XVisualInfo
*visuals
, visTemplate
;
1776 const long visMask
= VisualScreenMask
;
1779 /* Get list of all X visuals */
1780 visTemplate
.screen
= screen
;
1781 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1782 if (*nelements
> 0) {
1783 XMesaVisual
*results
;
1784 results
= (XMesaVisual
*) malloc(*nelements
* sizeof(XMesaVisual
));
1789 for (i
= 0; i
< *nelements
; i
++) {
1790 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1796 return (GLXFBConfig
*) results
;
1802 PUBLIC GLXFBConfig
*
1803 glXChooseFBConfig(Display
*dpy
, int screen
,
1804 const int *attribList
, int *nitems
)
1808 /* register ourselves as an extension on this display */
1809 register_with_display(dpy
);
1811 if (!attribList
|| !attribList
[0]) {
1812 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1813 return glXGetFBConfigs(dpy
, screen
, nitems
);
1816 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1818 GLXFBConfig
*config
= (GLXFBConfig
*) malloc(sizeof(XMesaVisual
));
1824 config
[0] = (GLXFBConfig
) xmvis
;
1825 return (GLXFBConfig
*) config
;
1834 PUBLIC XVisualInfo
*
1835 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1837 if (dpy
&& config
) {
1838 XMesaVisual xmvis
= (XMesaVisual
) config
;
1840 return xmvis
->vishandle
;
1842 /* create a new vishandle - the cached one may be stale */
1843 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1844 if (xmvis
->vishandle
) {
1845 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1847 return xmvis
->vishandle
;
1857 glXCreateWindow(Display
*dpy
, GLXFBConfig config
, Window win
,
1858 const int *attribList
)
1860 XMesaVisual xmvis
= (XMesaVisual
) config
;
1865 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1870 (void) attribList
; /* Ignored in GLX 1.3 */
1872 return win
; /* A hack for now */
1877 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1879 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1881 XMesaDestroyBuffer(b
);
1882 /* don't destroy X window */
1888 glXCreatePixmap(Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1889 const int *attribList
)
1891 XMesaVisual v
= (XMesaVisual
) config
;
1894 int target
= 0, format
= 0, mipmap
= 0;
1897 if (!dpy
|| !config
|| !pixmap
)
1900 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1902 case GLX_TEXTURE_FORMAT_EXT
:
1905 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1906 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1907 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1915 case GLX_TEXTURE_TARGET_EXT
:
1918 case GLX_TEXTURE_1D_EXT
:
1919 case GLX_TEXTURE_2D_EXT
:
1920 case GLX_TEXTURE_RECTANGLE_EXT
:
1928 case GLX_MIPMAP_TEXTURE_EXT
:
1939 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1940 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1941 &value
, GL_TRUE
) != Success
1943 return 0; /* error! */
1946 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
1947 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
1948 &value
, GL_TRUE
) != Success
1950 return 0; /* error! */
1954 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
1955 &value
, GL_TRUE
) != Success
1957 return 0; /* error! */
1960 if (target
== GLX_TEXTURE_1D_EXT
) {
1961 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1962 &value
, GL_TRUE
) != Success
1963 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
1964 return 0; /* error! */
1967 else if (target
== GLX_TEXTURE_2D_EXT
) {
1968 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1969 &value
, GL_TRUE
) != Success
1970 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
1971 return 0; /* error! */
1974 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
1975 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1976 &value
, GL_TRUE
) != Success
1977 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
1978 return 0; /* error! */
1982 if (format
|| target
|| mipmap
) {
1983 /* texture from pixmap */
1984 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
1987 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1998 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2000 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
2002 XMesaDestroyBuffer(b
);
2003 /* don't destroy X pixmap */
2008 glXCreatePbuffer(Display
*dpy
, GLXFBConfig config
, const int *attribList
)
2010 XMesaVisual xmvis
= (XMesaVisual
) config
;
2013 int width
= 0, height
= 0;
2014 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2018 for (attrib
= attribList
; *attrib
; attrib
++) {
2020 case GLX_PBUFFER_WIDTH
:
2024 case GLX_PBUFFER_HEIGHT
:
2028 case GLX_PRESERVED_CONTENTS
:
2030 preserveContents
= *attrib
;
2032 case GLX_LARGEST_PBUFFER
:
2034 useLargest
= *attrib
;
2041 if (width
== 0 || height
== 0)
2044 if (width
> PBUFFER_MAX_SIZE
|| height
> PBUFFER_MAX_SIZE
) {
2045 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2046 * allocate the largest possible buffer.
2049 width
= PBUFFER_MAX_SIZE
;
2050 height
= PBUFFER_MAX_SIZE
;
2054 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2055 /* A GLXPbuffer handle must be an X Drawable because that's what
2056 * glXMakeCurrent takes.
2059 xmbuf
->largestPbuffer
= useLargest
;
2060 xmbuf
->preservedContents
= preserveContents
;
2061 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2070 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2072 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2074 XMesaDestroyBuffer(b
);
2080 glXQueryDrawable(Display
*dpy
, GLXDrawable draw
, int attribute
,
2081 unsigned int *value
)
2083 GLuint width
, height
;
2084 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2088 /* make sure buffer's dimensions are up to date */
2089 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2091 switch (attribute
) {
2098 case GLX_PRESERVED_CONTENTS
:
2099 *value
= xmbuf
->preservedContents
;
2101 case GLX_LARGEST_PBUFFER
:
2102 *value
= xmbuf
->largestPbuffer
;
2104 case GLX_FBCONFIG_ID
:
2105 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2107 #ifdef GLX_EXT_texture_from_pixmap
2108 case GLX_TEXTURE_FORMAT_EXT
:
2109 *value
= xmbuf
->TextureFormat
;
2111 case GLX_TEXTURE_TARGET_EXT
:
2112 *value
= xmbuf
->TextureTarget
;
2114 case GLX_MIPMAP_TEXTURE_EXT
:
2115 *value
= xmbuf
->TextureMipmap
;
2120 return; /* raise BadValue error */
2126 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2127 int renderType
, GLXContext shareCtx
, Bool direct
)
2129 XMesaVisual xmvis
= (XMesaVisual
) config
;
2131 if (!dpy
|| !config
||
2132 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2135 return create_context(dpy
, xmvis
,
2136 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2138 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2143 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2145 GLXContext glxCtx
= ctx
;
2146 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2151 switch (attribute
) {
2152 case GLX_FBCONFIG_ID
:
2153 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2155 case GLX_RENDER_TYPE
:
2156 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2157 *value
= GLX_RGBA_TYPE
;
2159 *value
= GLX_COLOR_INDEX_TYPE
;
2165 return GLX_BAD_ATTRIBUTE
;
2172 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2174 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2176 xmbuf
->selectedEvents
= mask
;
2181 glXGetSelectedEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2183 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2185 *mask
= xmbuf
->selectedEvents
;
2192 /*** GLX_SGI_swap_control ***/
2195 glXSwapIntervalSGI(int interval
)
2203 /*** GLX_SGI_video_sync ***/
2205 static unsigned int FrameCounter
= 0;
2208 glXGetVideoSyncSGI(unsigned int *count
)
2210 /* this is a bogus implementation */
2211 *count
= FrameCounter
++;
2216 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2218 if (divisor
<= 0 || remainder
< 0)
2219 return GLX_BAD_VALUE
;
2220 /* this is a bogus implementation */
2222 while (FrameCounter
% divisor
!= remainder
)
2224 *count
= FrameCounter
;
2230 /*** GLX_SGI_make_current_read ***/
2233 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
,
2236 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2241 glXGetCurrentReadDrawableSGI(void)
2248 /*** GLX_SGIX_video_source ***/
2251 PUBLIC GLXVideoSourceSGIX
2252 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
,
2253 VLPath path
, int nodeClass
, VLNode drainNode
)
2265 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2274 /*** GLX_EXT_import_context ***/
2277 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2284 glXGetContextIDEXT(const GLXContext context
)
2291 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2299 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
,
2311 /*** GLX_SGIX_fbconfig ***/
2314 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2315 int attribute
, int *value
)
2317 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2320 PUBLIC GLXFBConfigSGIX
*
2321 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
,
2324 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
,
2325 attrib_list
, nelements
);
2330 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2333 XMesaVisual xmvis
= (XMesaVisual
) config
;
2334 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2335 return xmbuf
->ws
.drawable
; /* need to return an X ID */
2340 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2341 int renderType
, GLXContext shareCtx
,
2344 XMesaVisual xmvis
= (XMesaVisual
) config
;
2346 if (!dpy
|| !config
||
2347 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2350 return create_context(dpy
, xmvis
,
2351 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2353 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2357 PUBLIC XVisualInfo
*
2358 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2360 return glXGetVisualFromFBConfig(dpy
, config
);
2364 PUBLIC GLXFBConfigSGIX
2365 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2367 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2369 /* This visual wasn't found with glXChooseVisual() */
2370 xmvis
= create_glx_visual(dpy
, vis
);
2373 return (GLXFBConfigSGIX
) xmvis
;
2378 /*** GLX_SGIX_pbuffer ***/
2380 PUBLIC GLXPbufferSGIX
2381 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2382 unsigned int width
, unsigned int height
,
2385 XMesaVisual xmvis
= (XMesaVisual
) config
;
2388 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2392 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2394 case GLX_PRESERVED_CONTENTS_SGIX
:
2396 preserveContents
= *attrib
; /* ignored */
2398 case GLX_LARGEST_PBUFFER_SGIX
:
2400 useLargest
= *attrib
; /* ignored */
2407 /* not used at this time */
2409 (void) preserveContents
;
2411 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2412 /* A GLXPbuffer handle must be an X Drawable because that's what
2413 * glXMakeCurrent takes.
2415 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2420 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2422 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2424 XMesaDestroyBuffer(xmbuf
);
2430 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
,
2431 unsigned int *value
)
2433 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2436 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2440 switch (attribute
) {
2441 case GLX_PRESERVED_CONTENTS_SGIX
:
2444 case GLX_LARGEST_PBUFFER_SGIX
:
2445 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2447 case GLX_WIDTH_SGIX
:
2448 *value
= xmesa_buffer_width(xmbuf
);
2450 case GLX_HEIGHT_SGIX
:
2451 *value
= xmesa_buffer_height(xmbuf
);
2453 case GLX_EVENT_MASK_SGIX
:
2454 *value
= 0; /* XXX might be wrong */
2464 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2466 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2468 /* Note: we'll never generate clobber events */
2469 xmbuf
->selectedEvents
= mask
;
2475 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
,
2476 unsigned long *mask
)
2478 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2480 *mask
= xmbuf
->selectedEvents
;
2489 /*** GLX_SGI_cushion ***/
2492 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2501 /*** GLX_SGIX_video_resize ***/
2504 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
,
2515 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2516 int x
, int y
, int w
, int h
)
2529 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2530 int *x
, int *y
, int *w
, int *h
)
2543 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
,
2544 int *dx
, int *dy
, int *dw
, int *dh
)
2557 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2568 /*** GLX_SGIX_dmbuffer **/
2570 #if defined(_DM_BUFFER_H_)
2572 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
,
2573 DMparams
*params
, DMbuffer dmbuffer
)
2584 /*** GLX_SGIX_swap_group ***/
2587 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2596 /*** GLX_SGIX_swap_barrier ***/
2599 glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2607 glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2617 /*** GLX_SUN_get_transparent_index ***/
2620 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
,
2626 (void) pTransparent
;
2632 /*** GLX_MESA_release_buffers ***/
2635 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2636 * (a window or pixmap) prior to destroying the GLXDrawable.
2639 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2641 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2643 XMesaDestroyBuffer(b
);
2649 /*** GLX_EXT_texture_from_pixmap ***/
2652 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2653 const int *attrib_list
)
2655 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2657 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2661 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2663 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2665 XMesaReleaseTexImage(dpy
, b
, buffer
);
2670 /*** GLX_ARB_create_context ***/
2673 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
2674 GLXContext shareCtx
, Bool direct
,
2675 const int *attrib_list
)
2677 XMesaVisual xmvis
= (XMesaVisual
) config
;
2678 int majorVersion
= 1, minorVersion
= 0;
2679 int contextFlags
= 0x0;
2680 int profileMask
= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
;
2681 int renderType
= GLX_RGBA_TYPE
;
2684 const int contextFlagsAll
= (GLX_CONTEXT_DEBUG_BIT_ARB
|
2685 GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
);
2687 /* parse attrib_list */
2688 for (i
= 0; !done
&& attrib_list
&& attrib_list
[i
]; i
++) {
2689 switch (attrib_list
[i
]) {
2690 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2691 majorVersion
= attrib_list
[++i
];
2693 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2694 minorVersion
= attrib_list
[++i
];
2696 case GLX_CONTEXT_FLAGS_ARB
:
2697 contextFlags
= attrib_list
[++i
];
2699 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2700 profileMask
= attrib_list
[++i
];
2702 case GLX_RENDER_TYPE
:
2703 renderType
= attrib_list
[++i
];
2711 /* XXX generate BadValue X Error */
2716 /* check contextFlags */
2717 if (contextFlags
& ~contextFlagsAll
) {
2718 return NULL
; /* generate BadValue X Error */
2721 /* check profileMask */
2722 if (profileMask
!= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
&&
2723 profileMask
!= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
) {
2724 return NULL
; /* generate BadValue X Error */
2727 /* check version (generate BadMatch if bad) */
2728 switch (majorVersion
) {
2730 if (minorVersion
< 0 || minorVersion
> 5)
2734 if (minorVersion
< 0 || minorVersion
> 1)
2738 if (minorVersion
< 0 || minorVersion
> 2)
2742 if (minorVersion
< 0 || minorVersion
> 0)
2749 if ((contextFlags
& GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
) &&
2751 return NULL
; /* generate GLXBadProfileARB */
2753 if (renderType
== GLX_COLOR_INDEX_TYPE
&& majorVersion
>= 3)
2754 return NULL
; /* generate BadMatch */
2756 return create_context(dpy
, xmvis
,
2757 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2759 majorVersion
, minorVersion
,
2760 profileMask
, contextFlags
);