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 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR 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_get_proc_address " \
57 "GLX_EXT_texture_from_pixmap " \
58 "GLX_EXT_visual_info " \
59 "GLX_EXT_visual_rating " \
60 /*"GLX_SGI_video_sync "*/ \
61 "GLX_SGIX_fbconfig " \
64 #define DEFAULT_DIRECT GL_TRUE
69 * The GLXContext typedef is defined as a pointer to this structure.
71 struct __GLXcontextRec
75 GLXDrawable currentDrawable
;
76 GLXDrawable currentReadable
;
79 XMesaContext xmesaContext
;
84 static pipe_tsd ContextTSD
;
86 /** Set current context for calling thread */
88 SetCurrentContext(GLXContext c
)
90 pipe_tsd_set(&ContextTSD
, c
);
93 /** Get current context for calling thread */
95 GetCurrentContext(void)
97 return pipe_tsd_get(&ContextTSD
);
102 /**********************************************************************/
103 /*** GLX Visual Code ***/
104 /**********************************************************************/
109 static XMesaVisual
*VisualTable
= NULL
;
110 static int NumVisuals
= 0;
114 /* Macro to handle c_class vs class field name in XVisualInfo struct */
115 #if defined(__cplusplus) || defined(c_plusplus)
116 #define CLASS c_class
124 * Test if the given XVisualInfo is usable for Mesa rendering.
127 is_usable_visual( XVisualInfo
*vinfo
)
129 switch (vinfo
->CLASS
) {
132 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
136 /* Any StaticColor/PseudoColor visual of at least 4 bits */
137 if (vinfo
->depth
>=4) {
145 /* Any depth of TrueColor or DirectColor works in RGB mode */
148 /* This should never happen */
155 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
156 * configuration in our list of GLX visuals.
159 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
160 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
161 GLboolean stereoFlag
,
162 GLint depth_size
, GLint stencil_size
,
163 GLint accumRedSize
, GLint accumGreenSize
,
164 GLint accumBlueSize
, GLint accumAlphaSize
,
165 GLint level
, GLint numAuxBuffers
)
167 GLboolean ximageFlag
= GL_TRUE
;
170 GLboolean comparePointers
;
173 /* Check if the MESA_BACK_BUFFER env var is set */
174 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
176 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
177 ximageFlag
= GL_FALSE
;
179 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
180 ximageFlag
= GL_TRUE
;
183 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
189 /* stereo not supported */
193 if (stencil_size
> 0 && depth_size
> 0)
196 /* Comparing IDs uses less memory but sometimes fails. */
197 /* XXX revisit this after 3.0 is finished. */
198 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
199 comparePointers
= GL_TRUE
;
201 comparePointers
= GL_FALSE
;
203 /* Force the visual to have an alpha channel */
204 if (rgbFlag
&& _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
207 /* First check if a matching visual is already in the list */
208 for (i
=0; i
<NumVisuals
; i
++) {
209 XMesaVisual v
= VisualTable
[i
];
210 if (v
->display
== dpy
211 && v
->mesa_visual
.level
== level
212 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
213 && v
->ximage_flag
== ximageFlag
214 && v
->mesa_visual
.rgbMode
== rgbFlag
215 && v
->mesa_visual
.doubleBufferMode
== dbFlag
216 && v
->mesa_visual
.stereoMode
== stereoFlag
217 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
218 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
219 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
220 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
221 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
222 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
223 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
224 /* now either compare XVisualInfo pointers or visual IDs */
225 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
226 || (comparePointers
&& v
->vishandle
== vinfo
)) {
232 /* Create a new visual and add it to the list. */
234 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
235 stereoFlag
, ximageFlag
,
236 depth_size
, stencil_size
,
237 accumRedSize
, accumBlueSize
,
238 accumBlueSize
, accumAlphaSize
, 0, level
,
241 /* Save a copy of the pointer now so we can find this visual again
242 * if we need to search for it in find_glx_visual().
244 xmvis
->vishandle
= vinfo
;
245 /* Allocate more space for additional visual */
246 VisualTable
= (XMesaVisual
*) _mesa_realloc( VisualTable
,
247 sizeof(XMesaVisual
) * NumVisuals
,
248 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
249 /* add xmvis to the list */
250 VisualTable
[NumVisuals
] = xmvis
;
252 /* XXX minor hack, because XMesaCreateVisual doesn't support an
253 * aux buffers parameter.
255 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
262 * Return the default number of bits for the Z buffer.
263 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
264 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
265 * XXX probably do the same thing for stencil, accum, etc.
268 default_depth_bits(void)
271 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
275 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
280 default_alpha_bits(void)
283 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
292 default_accum_bits(void)
300 * Create a GLX visual from a regular XVisualInfo.
301 * This is called when Fake GLX is given an XVisualInfo which wasn't
302 * returned by glXChooseVisual. Since this is the first time we're
303 * considering this visual we'll take a guess at reasonable values
304 * for depth buffer size, stencil size, accum size, etc.
305 * This is the best we can do with a client-side emulation of GLX.
308 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
310 GLint zBits
= default_depth_bits();
311 GLint accBits
= default_accum_bits();
312 GLboolean alphaFlag
= default_alpha_bits() > 0;
314 if (is_usable_visual( visinfo
)) {
315 /* Configure this visual as RGB, double-buffered, depth-buffered. */
316 /* This is surely wrong for some people's needs but what else */
317 /* can be done? They should use glXChooseVisual(). */
318 return save_glx_visual( dpy
, visinfo
,
320 alphaFlag
, /* alpha */
321 GL_TRUE
, /* double */
322 GL_FALSE
, /* stereo */
334 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
342 * Find the GLX visual associated with an XVisualInfo.
345 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
349 /* try to match visual id */
350 for (i
=0;i
<NumVisuals
;i
++) {
351 if (VisualTable
[i
]->display
==dpy
352 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
353 return VisualTable
[i
];
357 /* if that fails, try to match pointers */
358 for (i
=0;i
<NumVisuals
;i
++) {
359 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
360 return VisualTable
[i
];
369 * Try to get an X visual which matches the given arguments.
372 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
374 XVisualInfo temp
, *vis
;
377 unsigned int default_depth
;
380 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
385 default_depth
= DefaultDepth(dpy
,scr
);
386 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
388 if (depth
==default_depth
&& xclass
==default_class
) {
389 /* try to get root window's visual */
390 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
391 mask
|= VisualIDMask
;
394 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
396 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
397 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
398 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
400 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
401 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
402 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
403 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
417 * Retrieve the value of the given environment variable and find
418 * the X visual which matches it.
419 * Input: dpy - the display
420 * screen - the screen number
421 * varname - the name of the environment variable
422 * Return: an XVisualInfo pointer to NULL if error.
425 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
427 char value
[100], type
[100];
428 int depth
, xclass
= -1;
431 if (!_mesa_getenv( varname
)) {
435 strncpy( value
, _mesa_getenv(varname
), 100 );
438 sscanf( value
, "%s %d", type
, &depth
);
440 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
441 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
442 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
443 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
444 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
445 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
447 if (xclass
>-1 && depth
>0) {
448 vis
= get_visual( dpy
, scr
, depth
, xclass
);
454 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
463 * Select an X visual which satisfies the RGBA flag and minimum depth.
465 * screen - X display and screen number
466 * min_depth - minimum visual depth
467 * preferred_class - preferred GLX visual class or DONT_CARE
468 * Return: pointer to an XVisualInfo or NULL.
471 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
472 int preferred_class
)
475 int xclass
, visclass
= 0;
478 /* First see if the MESA_RGB_VISUAL env var is defined */
479 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
483 /* Otherwise, search for a suitable visual */
484 if (preferred_class
==DONT_CARE
) {
485 for (xclass
=0;xclass
<6;xclass
++) {
487 case 0: visclass
= TrueColor
; break;
488 case 1: visclass
= DirectColor
; break;
489 case 2: visclass
= PseudoColor
; break;
490 case 3: visclass
= StaticColor
; break;
491 case 4: visclass
= GrayScale
; break;
492 case 5: visclass
= StaticGray
; break;
495 /* start with shallowest */
496 for (depth
=0;depth
<=32;depth
++) {
497 if (visclass
==TrueColor
&& depth
==8) {
498 /* Special case: try to get 8-bit PseudoColor before */
499 /* 8-bit TrueColor */
500 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
505 vis
= get_visual( dpy
, screen
, depth
, visclass
);
512 /* start with deepest */
513 for (depth
=32;depth
>=min_depth
;depth
--) {
514 if (visclass
==TrueColor
&& depth
==8) {
515 /* Special case: try to get 8-bit PseudoColor before */
516 /* 8-bit TrueColor */
517 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
522 vis
= get_visual( dpy
, screen
, depth
, visclass
);
531 /* search for a specific visual class */
532 switch (preferred_class
) {
533 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
534 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
535 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
536 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
537 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
538 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
539 default: return NULL
;
542 /* start with shallowest */
543 for (depth
=0;depth
<=32;depth
++) {
544 vis
= get_visual( dpy
, screen
, depth
, visclass
);
551 /* start with deepest */
552 for (depth
=32;depth
>=min_depth
;depth
--) {
553 vis
= get_visual( dpy
, screen
, depth
, visclass
);
561 /* didn't find a visual */
568 /**********************************************************************/
569 /*** Display-related functions ***/
570 /**********************************************************************/
574 * Free all XMesaVisuals which are associated with the given display.
577 destroy_visuals_on_display(Display
*dpy
)
580 for (i
= 0; i
< NumVisuals
; i
++) {
581 if (VisualTable
[i
]->display
== dpy
) {
582 /* remove this visual */
584 free(VisualTable
[i
]);
585 for (j
= i
; j
< NumVisuals
- 1; j
++)
586 VisualTable
[j
] = VisualTable
[j
+ 1];
594 * Called from XCloseDisplay() to let us free our display-related data.
597 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
599 xmesa_destroy_buffers_on_display(dpy
);
600 destroy_visuals_on_display(dpy
);
606 * Look for the named extension on given display and return a pointer
607 * to the _XExtension data, or NULL if extension not found.
610 lookup_extension(Display
*dpy
, const char *extName
)
613 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
614 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
623 * Whenever we're given a new Display pointer, call this function to
624 * register our close_display_callback function.
627 register_with_display(Display
*dpy
)
629 const char *extName
= "MesaGLX";
632 ext
= lookup_extension(dpy
, extName
);
634 XExtCodes
*c
= XAddExtension(dpy
);
635 ext
= dpy
->ext_procs
; /* new extension is at head of list */
636 assert(c
->extension
== ext
->codes
.extension
);
638 ext
->name
= _mesa_strdup(extName
);
639 ext
->close_display
= close_display_callback
;
644 /**********************************************************************/
645 /*** Begin Fake GLX API Functions ***/
646 /**********************************************************************/
650 * Helper used by glXChooseVisual and glXChooseFBConfig.
651 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
653 * In either case, the attribute list is terminated with the value 'None'.
656 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
658 const GLboolean rgbModeDefault
= fbConfig
;
659 const int *parselist
;
662 int min_red
=0, min_green
=0, min_blue
=0;
663 GLboolean rgb_flag
= rgbModeDefault
;
664 GLboolean alpha_flag
= GL_FALSE
;
665 GLboolean double_flag
= GL_FALSE
;
666 GLboolean stereo_flag
= GL_FALSE
;
667 GLint depth_size
= 0;
668 GLint stencil_size
= 0;
669 GLint accumRedSize
= 0;
670 GLint accumGreenSize
= 0;
671 GLint accumBlueSize
= 0;
672 GLint accumAlphaSize
= 0;
674 int visual_type
= DONT_CARE
;
675 int trans_type
= DONT_CARE
;
676 int trans_value
= DONT_CARE
;
677 GLint caveat
= DONT_CARE
;
678 XMesaVisual xmvis
= NULL
;
679 int desiredVisualID
= -1;
688 switch (*parselist
) {
699 case GLX_BUFFER_SIZE
:
701 min_ci
= *parselist
++;
705 level
= *parselist
++;
717 case GLX_DOUBLEBUFFER
:
720 double_flag
= *parselist
++;
723 double_flag
= GL_TRUE
;
729 stereo_flag
= *parselist
++;
732 stereo_flag
= GL_TRUE
;
735 case GLX_AUX_BUFFERS
:
737 numAux
= *parselist
++;
738 if (numAux
> MAX_AUX_BUFFERS
)
743 min_red
= *parselist
++;
747 min_green
= *parselist
++;
751 min_blue
= *parselist
++;
756 GLint size
= *parselist
++;
757 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
762 depth_size
= *parselist
++;
764 case GLX_STENCIL_SIZE
:
766 stencil_size
= *parselist
++;
768 case GLX_ACCUM_RED_SIZE
:
771 GLint size
= *parselist
++;
772 accumRedSize
= MAX2( accumRedSize
, size
);
775 case GLX_ACCUM_GREEN_SIZE
:
778 GLint size
= *parselist
++;
779 accumGreenSize
= MAX2( accumGreenSize
, size
);
782 case GLX_ACCUM_BLUE_SIZE
:
785 GLint size
= *parselist
++;
786 accumBlueSize
= MAX2( accumBlueSize
, size
);
789 case GLX_ACCUM_ALPHA_SIZE
:
792 GLint size
= *parselist
++;
793 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
798 * GLX_EXT_visual_info extension
800 case GLX_X_VISUAL_TYPE_EXT
:
802 visual_type
= *parselist
++;
804 case GLX_TRANSPARENT_TYPE_EXT
:
806 trans_type
= *parselist
++;
808 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
810 trans_value
= *parselist
++;
812 case GLX_TRANSPARENT_RED_VALUE_EXT
:
813 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
814 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
815 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
822 * GLX_EXT_visual_info extension
824 case GLX_VISUAL_CAVEAT_EXT
:
826 caveat
= *parselist
++; /* ignored for now */
830 * GLX_ARB_multisample
832 case GLX_SAMPLE_BUFFERS_ARB
:
833 /* ms not supported */
835 case GLX_SAMPLES_ARB
:
836 /* ms not supported */
842 case GLX_RENDER_TYPE
:
846 if (*parselist
& GLX_RGBA_BIT
) {
849 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
852 else if (*parselist
== 0) {
857 case GLX_DRAWABLE_TYPE
:
861 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
862 return NULL
; /* bad bit */
866 case GLX_FBCONFIG_ID
:
870 desiredVisualID
= *parselist
++;
872 case GLX_X_RENDERABLE
:
879 #ifdef GLX_EXT_texture_from_pixmap
880 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
881 parselist
++; /*skip*/
883 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
884 parselist
++; /*skip*/
886 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
887 parselist
++; /*skip*/
889 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
891 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
892 GLX_TEXTURE_2D_BIT_EXT
|
893 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
898 case GLX_Y_INVERTED_EXT
:
899 parselist
++; /*skip*/
908 /* undefined attribute */
909 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
919 * Since we're only simulating the GLX extension this function will never
920 * find any real GL visuals. Instead, all we can do is try to find an RGB
921 * or CI visual of appropriate depth. Other requested attributes such as
922 * double buffering, depth buffer, etc. will be associated with the X
923 * visual and stored in the VisualTable[].
925 if (desiredVisualID
!= -1) {
926 /* try to get a specific visual, by visualID */
929 temp
.visualid
= desiredVisualID
;
930 temp
.screen
= screen
;
931 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
933 /* give the visual some useful GLX attributes */
934 double_flag
= GL_TRUE
;
939 /* normal color planes */
940 /* Get an RGB visual */
941 int min_rgb
= min_red
+ min_green
+ min_blue
;
942 if (min_rgb
>1 && min_rgb
<8) {
943 /* a special case to be sure we can get a monochrome visual */
946 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
949 _mesa_warning(NULL
, "overlay not supported");
954 /* Note: we're not exactly obeying the glXChooseVisual rules here.
955 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
956 * largest depth buffer size, which is 32bits/value. Instead, we
957 * return 16 to maintain performance with earlier versions of Mesa.
959 if (stencil_size
> 0)
960 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
961 else if (depth_size
> 24)
963 else if (depth_size
> 16)
965 else if (depth_size
> 0) {
966 depth_size
= default_depth_bits();
970 alpha_flag
= default_alpha_bits() > 0;
973 /* we only support one size of stencil and accum buffers. */
974 if (stencil_size
> 0)
975 stencil_size
= STENCIL_BITS
;
977 if (accumRedSize
> 0 ||
978 accumGreenSize
> 0 ||
980 accumAlphaSize
> 0) {
984 accumBlueSize
= default_accum_bits();
986 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
989 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
990 stereo_flag
, depth_size
, stencil_size
,
991 accumRedSize
, accumGreenSize
,
992 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1000 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1004 /* register ourselves as an extension on this display */
1005 register_with_display(dpy
);
1007 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1009 /* create a new vishandle - the cached one may be stale */
1010 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1011 if (xmvis
->vishandle
) {
1012 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1014 return xmvis
->vishandle
;
1022 * Helper function used by other glXCreateContext functions.
1025 create_context(Display
*dpy
, XMesaVisual xmvis
,
1026 XMesaContext shareCtx
, Bool direct
,
1027 unsigned major
, unsigned minor
,
1028 unsigned profileMask
, unsigned contextFlags
)
1035 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1039 /* deallocate unused windows/buffers */
1041 XMesaGarbageCollect();
1044 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
, shareCtx
, major
, minor
,
1045 profileMask
, contextFlags
);
1046 if (!glxCtx
->xmesaContext
) {
1051 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1052 glxCtx
->currentDpy
= dpy
;
1053 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1060 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1061 GLXContext shareCtx
, Bool direct
)
1065 xmvis
= find_glx_visual( dpy
, visinfo
);
1067 /* This visual wasn't found with glXChooseVisual() */
1068 xmvis
= create_glx_visual( dpy
, visinfo
);
1070 /* unusable visual */
1075 return create_context(dpy
, xmvis
,
1076 shareCtx
? shareCtx
->xmesaContext
: NULL
,
1078 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
1082 /* XXX these may have to be removed due to thread-safety issues. */
1083 static GLXContext MakeCurrent_PrevContext
= 0;
1084 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1085 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1086 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1087 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1090 /* GLX 1.3 and later */
1092 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1093 GLXDrawable read
, GLXContext ctx
)
1095 GLXContext glxCtx
= ctx
;
1096 static boolean firsttime
= 1, no_rast
= 0;
1099 no_rast
= getenv("SP_NO_RAST") != NULL
;
1103 if (ctx
&& draw
&& read
) {
1104 XMesaBuffer drawBuffer
, readBuffer
;
1105 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1107 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1108 if (ctx
== MakeCurrent_PrevContext
1109 && draw
== MakeCurrent_PrevDrawable
) {
1110 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1113 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1116 /* drawable must be a new window! */
1117 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1119 /* Out of memory, or context/drawable depth mismatch */
1124 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1125 if (ctx
== MakeCurrent_PrevContext
1126 && read
== MakeCurrent_PrevReadable
) {
1127 readBuffer
= MakeCurrent_PrevReadBuffer
;
1130 readBuffer
= XMesaFindBuffer( dpy
, read
);
1133 /* drawable must be a new window! */
1134 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1136 /* Out of memory, or context/drawable depth mismatch */
1142 MakeCurrent_PrevContext
== ctx
&&
1143 MakeCurrent_PrevDrawable
== draw
&&
1144 MakeCurrent_PrevReadable
== read
&&
1145 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1146 MakeCurrent_PrevReadBuffer
== readBuffer
)
1149 MakeCurrent_PrevContext
= ctx
;
1150 MakeCurrent_PrevDrawable
= draw
;
1151 MakeCurrent_PrevReadable
= read
;
1152 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1153 MakeCurrent_PrevReadBuffer
= readBuffer
;
1155 /* Now make current! */
1156 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1157 ctx
->currentDpy
= dpy
;
1158 ctx
->currentDrawable
= draw
;
1159 ctx
->currentReadable
= read
;
1160 SetCurrentContext(ctx
);
1167 else if (!ctx
&& !draw
&& !read
) {
1168 /* release current context w/out assigning new one. */
1169 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1170 MakeCurrent_PrevContext
= 0;
1171 MakeCurrent_PrevDrawable
= 0;
1172 MakeCurrent_PrevReadable
= 0;
1173 MakeCurrent_PrevDrawBuffer
= 0;
1174 MakeCurrent_PrevReadBuffer
= 0;
1175 SetCurrentContext(NULL
);
1179 /* The args must either all be non-zero or all zero.
1188 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1190 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1195 glXGetCurrentContext(void)
1197 return GetCurrentContext();
1202 glXGetCurrentDisplay(void)
1204 GLXContext glxCtx
= glXGetCurrentContext();
1206 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1211 glXGetCurrentDisplayEXT(void)
1213 return glXGetCurrentDisplay();
1218 glXGetCurrentDrawable(void)
1220 GLXContext gc
= glXGetCurrentContext();
1221 return gc
? gc
->currentDrawable
: 0;
1226 glXGetCurrentReadDrawable(void)
1228 GLXContext gc
= glXGetCurrentContext();
1229 return gc
? gc
->currentReadable
: 0;
1234 glXGetCurrentReadDrawableSGI(void)
1236 return glXGetCurrentReadDrawable();
1241 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1246 v
= find_glx_visual( dpy
, visinfo
);
1248 v
= create_glx_visual( dpy
, visinfo
);
1250 /* unusable visual */
1255 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1263 /*** GLX_MESA_pixmap_colormap ***/
1266 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1267 Pixmap pixmap
, Colormap cmap
)
1272 v
= find_glx_visual( dpy
, visinfo
);
1274 v
= create_glx_visual( dpy
, visinfo
);
1276 /* unusable visual */
1281 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1290 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1292 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1294 XMesaDestroyBuffer(b
);
1296 else if (_mesa_getenv("MESA_DEBUG")) {
1297 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1303 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1304 unsigned long mask
)
1306 XMesaContext xm_src
= src
->xmesaContext
;
1307 XMesaContext xm_dst
= dst
->xmesaContext
;
1309 if (MakeCurrent_PrevContext
== src
) {
1312 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1317 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1320 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1321 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1327 return True
; /* we're faking GLX so always return success */
1332 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1334 GLXContext glxCtx
= ctx
;
1336 MakeCurrent_PrevContext
= 0;
1337 MakeCurrent_PrevDrawable
= 0;
1338 MakeCurrent_PrevReadable
= 0;
1339 MakeCurrent_PrevDrawBuffer
= 0;
1340 MakeCurrent_PrevReadBuffer
= 0;
1341 XMesaDestroyContext( glxCtx
->xmesaContext
);
1342 XMesaGarbageCollect();
1348 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1350 GLXContext glxCtx
= ctx
;
1352 return glxCtx
->isDirect
;
1358 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1360 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1361 static boolean firsttime
= 1, no_rast
= 0;
1364 no_rast
= getenv("SP_NO_RAST") != NULL
;
1372 XMesaSwapBuffers(buffer
);
1374 else if (_mesa_getenv("MESA_DEBUG")) {
1375 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1382 /*** GLX_MESA_copy_sub_buffer ***/
1385 glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
1386 int x
, int y
, int width
, int height
)
1388 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1390 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1392 else if (_mesa_getenv("MESA_DEBUG")) {
1393 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1399 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1402 /* Return GLX version, not Mesa version */
1403 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1404 *maj
= CLIENT_MAJOR_VERSION
;
1405 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1411 * Query the GLX attributes of the given XVisualInfo.
1414 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1420 return GLX_BAD_ATTRIBUTE
;
1421 *value
= (int) True
;
1423 case GLX_BUFFER_SIZE
:
1424 *value
= xmvis
->visinfo
->depth
;
1427 *value
= xmvis
->mesa_visual
.level
;
1431 return GLX_BAD_ATTRIBUTE
;
1432 if (xmvis
->mesa_visual
.rgbMode
) {
1439 case GLX_DOUBLEBUFFER
:
1440 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1443 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1445 case GLX_AUX_BUFFERS
:
1446 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1449 *value
= xmvis
->mesa_visual
.redBits
;
1451 case GLX_GREEN_SIZE
:
1452 *value
= xmvis
->mesa_visual
.greenBits
;
1455 *value
= xmvis
->mesa_visual
.blueBits
;
1457 case GLX_ALPHA_SIZE
:
1458 *value
= xmvis
->mesa_visual
.alphaBits
;
1460 case GLX_DEPTH_SIZE
:
1461 *value
= xmvis
->mesa_visual
.depthBits
;
1463 case GLX_STENCIL_SIZE
:
1464 *value
= xmvis
->mesa_visual
.stencilBits
;
1466 case GLX_ACCUM_RED_SIZE
:
1467 *value
= xmvis
->mesa_visual
.accumRedBits
;
1469 case GLX_ACCUM_GREEN_SIZE
:
1470 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1472 case GLX_ACCUM_BLUE_SIZE
:
1473 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1475 case GLX_ACCUM_ALPHA_SIZE
:
1476 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1480 * GLX_EXT_visual_info extension
1482 case GLX_X_VISUAL_TYPE_EXT
:
1483 switch (xmvis
->visinfo
->CLASS
) {
1484 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1485 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1486 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1487 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1488 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1489 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1492 case GLX_TRANSPARENT_TYPE_EXT
:
1494 *value
= GLX_NONE_EXT
;
1496 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1499 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1502 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1505 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1508 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1513 * GLX_EXT_visual_info extension
1515 case GLX_VISUAL_CAVEAT_EXT
:
1516 /* test for zero, just in case */
1517 if (xmvis
->mesa_visual
.visualRating
> 0)
1518 *value
= xmvis
->mesa_visual
.visualRating
;
1520 *value
= GLX_NONE_EXT
;
1524 * GLX_ARB_multisample
1526 case GLX_SAMPLE_BUFFERS_ARB
:
1529 case GLX_SAMPLES_ARB
:
1536 case GLX_SCREEN_EXT
:
1538 return GLX_BAD_ATTRIBUTE
;
1539 *value
= xmvis
->visinfo
->screen
;
1541 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1543 return GLX_BAD_ATTRIBUTE
;
1544 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1546 case GLX_RENDER_TYPE_SGIX
:
1548 return GLX_BAD_ATTRIBUTE
;
1549 if (xmvis
->mesa_visual
.rgbMode
)
1550 *value
= GLX_RGBA_BIT
;
1552 *value
= GLX_COLOR_INDEX_BIT
;
1554 case GLX_X_RENDERABLE_SGIX
:
1556 return GLX_BAD_ATTRIBUTE
;
1557 *value
= True
; /* XXX really? */
1559 case GLX_FBCONFIG_ID_SGIX
:
1561 return GLX_BAD_ATTRIBUTE
;
1562 *value
= xmvis
->visinfo
->visualid
;
1564 case GLX_MAX_PBUFFER_WIDTH
:
1566 return GLX_BAD_ATTRIBUTE
;
1567 /* XXX or MAX_WIDTH? */
1568 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1570 case GLX_MAX_PBUFFER_HEIGHT
:
1572 return GLX_BAD_ATTRIBUTE
;
1573 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1575 case GLX_MAX_PBUFFER_PIXELS
:
1577 return GLX_BAD_ATTRIBUTE
;
1578 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1579 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1583 return GLX_BAD_ATTRIBUTE
;
1584 *value
= xmvis
->visinfo
->visualid
;
1587 #ifdef GLX_EXT_texture_from_pixmap
1588 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1589 *value
= True
; /*XXX*/
1591 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1593 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1595 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1596 *value
= True
; /*XXX*/
1598 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1599 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1600 GLX_TEXTURE_2D_BIT_EXT
|
1601 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1603 case GLX_Y_INVERTED_EXT
:
1604 *value
= True
; /*XXX*/
1609 return GLX_BAD_ATTRIBUTE
;
1616 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1617 int attrib
, int *value
)
1621 if (!dpy
|| !visinfo
)
1622 return GLX_BAD_ATTRIBUTE
;
1624 xmvis
= find_glx_visual( dpy
, visinfo
);
1626 /* this visual wasn't obtained with glXChooseVisual */
1627 xmvis
= create_glx_visual( dpy
, visinfo
);
1629 /* this visual can't be used for GL rendering */
1630 if (attrib
==GLX_USE_GL
) {
1631 *value
= (int) False
;
1635 return GLX_BAD_VISUAL
;
1640 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1648 XMesaContext xmesa
= XMesaGetCurrentContext();
1649 XMesaFlush( xmesa
);
1657 XMesaContext xmesa
= XMesaGetCurrentContext();
1658 XMesaFlush( xmesa
);
1663 get_extensions( void )
1670 /* GLX 1.1 and later */
1672 glXQueryExtensionsString( Display
*dpy
, int screen
)
1676 return get_extensions();
1681 /* GLX 1.1 and later */
1683 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1685 static char version
[1000];
1686 sprintf(version
, "%d.%d %s",
1687 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, xmesa_get_name());
1693 case GLX_EXTENSIONS
:
1694 return get_extensions();
1706 /* GLX 1.1 and later */
1708 glXGetClientString( Display
*dpy
, int name
)
1710 static char version
[1000];
1711 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1712 CLIENT_MINOR_VERSION
, xmesa_get_name());
1717 case GLX_EXTENSIONS
:
1718 return get_extensions();
1736 glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1737 int attribute
, int *value
)
1739 XMesaVisual v
= (XMesaVisual
) config
;
1743 if (!dpy
|| !config
|| !value
)
1746 return get_config(v
, attribute
, value
, GL_TRUE
);
1750 PUBLIC GLXFBConfig
*
1751 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1753 XVisualInfo
*visuals
, visTemplate
;
1754 const long visMask
= VisualScreenMask
;
1757 /* Get list of all X visuals */
1758 visTemplate
.screen
= screen
;
1759 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1760 if (*nelements
> 0) {
1761 XMesaVisual
*results
;
1762 results
= (XMesaVisual
*) malloc(*nelements
* sizeof(XMesaVisual
));
1767 for (i
= 0; i
< *nelements
; i
++) {
1768 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1774 return (GLXFBConfig
*) results
;
1780 PUBLIC GLXFBConfig
*
1781 glXChooseFBConfig(Display
*dpy
, int screen
,
1782 const int *attribList
, int *nitems
)
1786 if (!attribList
|| !attribList
[0]) {
1787 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1788 return glXGetFBConfigs(dpy
, screen
, nitems
);
1791 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1793 GLXFBConfig
*config
= (GLXFBConfig
*) malloc(sizeof(XMesaVisual
));
1799 config
[0] = (GLXFBConfig
) xmvis
;
1800 return (GLXFBConfig
*) config
;
1809 PUBLIC XVisualInfo
*
1810 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1812 if (dpy
&& config
) {
1813 XMesaVisual xmvis
= (XMesaVisual
) config
;
1815 return xmvis
->vishandle
;
1817 /* create a new vishandle - the cached one may be stale */
1818 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1819 if (xmvis
->vishandle
) {
1820 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1822 return xmvis
->vishandle
;
1832 glXCreateWindow(Display
*dpy
, GLXFBConfig config
, Window win
,
1833 const int *attribList
)
1835 XMesaVisual xmvis
= (XMesaVisual
) config
;
1840 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1845 (void) attribList
; /* Ignored in GLX 1.3 */
1847 return win
; /* A hack for now */
1852 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1854 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1856 XMesaDestroyBuffer(b
);
1857 /* don't destroy X window */
1863 glXCreatePixmap(Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1864 const int *attribList
)
1866 XMesaVisual v
= (XMesaVisual
) config
;
1869 int target
= 0, format
= 0, mipmap
= 0;
1872 if (!dpy
|| !config
|| !pixmap
)
1875 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1877 case GLX_TEXTURE_FORMAT_EXT
:
1880 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1881 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1882 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1890 case GLX_TEXTURE_TARGET_EXT
:
1893 case GLX_TEXTURE_1D_EXT
:
1894 case GLX_TEXTURE_2D_EXT
:
1895 case GLX_TEXTURE_RECTANGLE_EXT
:
1903 case GLX_MIPMAP_TEXTURE_EXT
:
1914 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1915 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1916 &value
, GL_TRUE
) != Success
1918 return 0; /* error! */
1921 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
1922 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
1923 &value
, GL_TRUE
) != Success
1925 return 0; /* error! */
1929 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
1930 &value
, GL_TRUE
) != Success
1932 return 0; /* error! */
1935 if (target
== GLX_TEXTURE_1D_EXT
) {
1936 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1937 &value
, GL_TRUE
) != Success
1938 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
1939 return 0; /* error! */
1942 else if (target
== GLX_TEXTURE_2D_EXT
) {
1943 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1944 &value
, GL_TRUE
) != Success
1945 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
1946 return 0; /* error! */
1949 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
1950 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1951 &value
, GL_TRUE
) != Success
1952 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
1953 return 0; /* error! */
1957 if (format
|| target
|| mipmap
) {
1958 /* texture from pixmap */
1959 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
1962 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1973 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
1975 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
1977 XMesaDestroyBuffer(b
);
1978 /* don't destroy X pixmap */
1983 glXCreatePbuffer(Display
*dpy
, GLXFBConfig config
, const int *attribList
)
1985 XMesaVisual xmvis
= (XMesaVisual
) config
;
1988 int width
= 0, height
= 0;
1989 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
1993 for (attrib
= attribList
; *attrib
; attrib
++) {
1995 case GLX_PBUFFER_WIDTH
:
1999 case GLX_PBUFFER_HEIGHT
:
2003 case GLX_PRESERVED_CONTENTS
:
2005 preserveContents
= *attrib
;
2007 case GLX_LARGEST_PBUFFER
:
2009 useLargest
= *attrib
;
2016 if (width
== 0 || height
== 0)
2019 if (width
> MAX_WIDTH
|| height
> MAX_HEIGHT
) {
2020 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2021 * allocate the largest possible buffer.
2025 height
= MAX_HEIGHT
;
2029 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2030 /* A GLXPbuffer handle must be an X Drawable because that's what
2031 * glXMakeCurrent takes.
2034 xmbuf
->largestPbuffer
= useLargest
;
2035 xmbuf
->preservedContents
= preserveContents
;
2036 return (GLXPbuffer
) xmbuf
->drawable
;
2045 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2047 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2049 XMesaDestroyBuffer(b
);
2055 glXQueryDrawable(Display
*dpy
, GLXDrawable draw
, int attribute
,
2056 unsigned int *value
)
2058 GLuint width
, height
;
2059 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2063 /* make sure buffer's dimensions are up to date */
2064 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2066 switch (attribute
) {
2073 case GLX_PRESERVED_CONTENTS
:
2074 *value
= xmbuf
->preservedContents
;
2076 case GLX_LARGEST_PBUFFER
:
2077 *value
= xmbuf
->largestPbuffer
;
2079 case GLX_FBCONFIG_ID
:
2080 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2082 #ifdef GLX_EXT_texture_from_pixmap
2083 case GLX_TEXTURE_FORMAT_EXT
:
2084 *value
= xmbuf
->TextureFormat
;
2086 case GLX_TEXTURE_TARGET_EXT
:
2087 *value
= xmbuf
->TextureTarget
;
2089 case GLX_MIPMAP_TEXTURE_EXT
:
2090 *value
= xmbuf
->TextureMipmap
;
2095 return; /* raise BadValue error */
2101 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2102 int renderType
, GLXContext shareCtx
, Bool direct
)
2104 XMesaVisual xmvis
= (XMesaVisual
) config
;
2106 if (!dpy
|| !config
||
2107 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2110 return create_context(dpy
, xmvis
,
2111 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2113 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2118 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2120 GLXContext glxCtx
= ctx
;
2121 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2126 switch (attribute
) {
2127 case GLX_FBCONFIG_ID
:
2128 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2130 case GLX_RENDER_TYPE
:
2131 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2132 *value
= GLX_RGBA_TYPE
;
2134 *value
= GLX_COLOR_INDEX_TYPE
;
2140 return GLX_BAD_ATTRIBUTE
;
2147 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2149 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2151 xmbuf
->selectedEvents
= mask
;
2156 glXGetSelectedEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2158 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2160 *mask
= xmbuf
->selectedEvents
;
2167 /*** GLX_SGI_swap_control ***/
2170 glXSwapIntervalSGI(int interval
)
2178 /*** GLX_SGI_video_sync ***/
2180 static unsigned int FrameCounter
= 0;
2183 glXGetVideoSyncSGI(unsigned int *count
)
2185 /* this is a bogus implementation */
2186 *count
= FrameCounter
++;
2191 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2193 if (divisor
<= 0 || remainder
< 0)
2194 return GLX_BAD_VALUE
;
2195 /* this is a bogus implementation */
2197 while (FrameCounter
% divisor
!= remainder
)
2199 *count
= FrameCounter
;
2205 /*** GLX_SGI_make_current_read ***/
2208 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
,
2211 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2216 glXGetCurrentReadDrawableSGI(void)
2223 /*** GLX_SGIX_video_source ***/
2226 PUBLIC GLXVideoSourceSGIX
2227 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
,
2228 VLPath path
, int nodeClass
, VLNode drainNode
)
2240 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2249 /*** GLX_EXT_import_context ***/
2252 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2259 glXGetContextIDEXT(const GLXContext context
)
2266 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2274 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
,
2286 /*** GLX_SGIX_fbconfig ***/
2289 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2290 int attribute
, int *value
)
2292 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2295 PUBLIC GLXFBConfigSGIX
*
2296 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
,
2299 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
,
2300 attrib_list
, nelements
);
2305 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2308 XMesaVisual xmvis
= (XMesaVisual
) config
;
2309 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2310 return xmbuf
->drawable
; /* need to return an X ID */
2315 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2316 int renderType
, GLXContext shareCtx
,
2319 XMesaVisual xmvis
= (XMesaVisual
) config
;
2321 if (!dpy
|| !config
||
2322 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2325 return create_context(dpy
, xmvis
,
2326 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2328 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2332 PUBLIC XVisualInfo
*
2333 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2335 return glXGetVisualFromFBConfig(dpy
, config
);
2339 PUBLIC GLXFBConfigSGIX
2340 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2342 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2344 /* This visual wasn't found with glXChooseVisual() */
2345 xmvis
= create_glx_visual(dpy
, vis
);
2348 return (GLXFBConfigSGIX
) xmvis
;
2353 /*** GLX_SGIX_pbuffer ***/
2355 PUBLIC GLXPbufferSGIX
2356 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2357 unsigned int width
, unsigned int height
,
2360 XMesaVisual xmvis
= (XMesaVisual
) config
;
2363 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2367 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2369 case GLX_PRESERVED_CONTENTS_SGIX
:
2371 preserveContents
= *attrib
; /* ignored */
2373 case GLX_LARGEST_PBUFFER_SGIX
:
2375 useLargest
= *attrib
; /* ignored */
2382 /* not used at this time */
2384 (void) preserveContents
;
2386 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2387 /* A GLXPbuffer handle must be an X Drawable because that's what
2388 * glXMakeCurrent takes.
2390 return (GLXPbuffer
) xmbuf
->drawable
;
2395 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2397 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2399 XMesaDestroyBuffer(xmbuf
);
2405 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
,
2406 unsigned int *value
)
2408 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2411 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2415 switch (attribute
) {
2416 case GLX_PRESERVED_CONTENTS_SGIX
:
2419 case GLX_LARGEST_PBUFFER_SGIX
:
2420 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2422 case GLX_WIDTH_SGIX
:
2423 *value
= xmesa_buffer_width(xmbuf
);
2425 case GLX_HEIGHT_SGIX
:
2426 *value
= xmesa_buffer_height(xmbuf
);
2428 case GLX_EVENT_MASK_SGIX
:
2429 *value
= 0; /* XXX might be wrong */
2439 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2441 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2443 /* Note: we'll never generate clobber events */
2444 xmbuf
->selectedEvents
= mask
;
2450 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
,
2451 unsigned long *mask
)
2453 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2455 *mask
= xmbuf
->selectedEvents
;
2464 /*** GLX_SGI_cushion ***/
2467 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2476 /*** GLX_SGIX_video_resize ***/
2479 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
,
2490 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2491 int x
, int y
, int w
, int h
)
2504 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2505 int *x
, int *y
, int *w
, int *h
)
2518 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
,
2519 int *dx
, int *dy
, int *dw
, int *dh
)
2532 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2543 /*** GLX_SGIX_dmbuffer **/
2545 #if defined(_DM_BUFFER_H_)
2547 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
,
2548 DMparams
*params
, DMbuffer dmbuffer
)
2559 /*** GLX_SGIX_swap_group ***/
2562 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2571 /*** GLX_SGIX_swap_barrier ***/
2574 glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2582 glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2592 /*** GLX_SUN_get_transparent_index ***/
2595 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
,
2601 (void) pTransparent
;
2607 /*** GLX_MESA_release_buffers ***/
2610 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2611 * (a window or pixmap) prior to destroying the GLXDrawable.
2614 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2616 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2618 XMesaDestroyBuffer(b
);
2624 /*** GLX_EXT_texture_from_pixmap ***/
2627 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2628 const int *attrib_list
)
2630 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2632 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2636 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2638 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2640 XMesaReleaseTexImage(dpy
, b
, buffer
);
2645 /*** GLX_ARB_create_context ***/
2648 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
2649 GLXContext shareCtx
, Bool direct
,
2650 const int *attrib_list
)
2652 XMesaVisual xmvis
= (XMesaVisual
) config
;
2653 int majorVersion
= 1, minorVersion
= 0;
2654 int contextFlags
= 0x0;
2655 int profileMask
= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
;
2656 int renderType
= GLX_RGBA_TYPE
;
2659 const int contextFlagsAll
= (GLX_CONTEXT_DEBUG_BIT_ARB
|
2660 GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
);
2662 /* parse attrib_list */
2663 for (i
= 0; !done
&& attrib_list
[i
]; i
++) {
2664 switch (attrib_list
[i
]) {
2665 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2666 majorVersion
= attrib_list
[++i
];
2668 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2669 minorVersion
= attrib_list
[++i
];
2671 case GLX_CONTEXT_FLAGS_ARB
:
2672 contextFlags
= attrib_list
[++i
];
2674 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2675 profileMask
= attrib_list
[++i
];
2677 case GLX_RENDER_TYPE
:
2678 renderType
= attrib_list
[++i
];
2686 /* XXX generate BadValue X Error */
2691 /* check contextFlags */
2692 if (contextFlags
& ~contextFlagsAll
) {
2693 return NULL
; /* generate BadValue X Error */
2696 /* check profileMask */
2697 if (profileMask
!= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
&&
2698 profileMask
!= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
) {
2699 return NULL
; /* generate BadValue X Error */
2702 /* check version (generate BadMatch if bad) */
2703 switch (majorVersion
) {
2705 if (minorVersion
< 0 || minorVersion
> 5)
2709 if (minorVersion
< 0 || minorVersion
> 1)
2713 if (minorVersion
< 0 || minorVersion
> 2)
2717 if (minorVersion
< 0 || minorVersion
> 0)
2724 if ((contextFlags
& GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
) &&
2726 return NULL
; /* generate GLXBadProfileARB */
2728 if (renderType
== GLX_COLOR_INDEX_TYPE
&& majorVersion
>= 3)
2729 return NULL
; /* generate BadMatch */
2731 return create_context(dpy
, xmvis
,
2732 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2734 majorVersion
, minorVersion
,
2735 profileMask
, contextFlags
);