2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 * "Fake" GLX API implemented in terms of the XMesa*() functions.
33 #define GLX_GLXEXT_PROTOTYPES
39 #include <GL/glxproto.h>
43 /* An "Atrribs/Attribs" typo was fixed in glxproto.h in Nov 2014.
44 * This is in case we don't have the updated header.
46 #if !defined(X_GLXCreateContextAttribsARB) && \
47 defined(X_GLXCreateContextAtrribsARB)
48 #define X_GLXCreateContextAttribsARB X_GLXCreateContextAtrribsARB
51 /* This indicates the client-side GLX API and GLX encoder version. */
52 #define CLIENT_MAJOR_VERSION 1
53 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
55 /* This indicates the server-side GLX decoder version.
56 * GLX 1.4 indicates OpenGL 1.3 support
58 #define SERVER_MAJOR_VERSION 1
59 #define SERVER_MINOR_VERSION 4
61 /* Who implemented this GLX? */
62 #define VENDOR "Brian Paul"
65 "GLX_MESA_copy_sub_buffer " \
66 "GLX_MESA_pixmap_colormap " \
67 "GLX_MESA_release_buffers " \
68 "GLX_ARB_create_context " \
69 "GLX_ARB_create_context_profile " \
70 "GLX_ARB_get_proc_address " \
71 "GLX_EXT_create_context_es_profile " \
72 "GLX_EXT_create_context_es2_profile " \
73 "GLX_EXT_texture_from_pixmap " \
74 "GLX_EXT_visual_info " \
75 "GLX_EXT_visual_rating " \
76 /*"GLX_SGI_video_sync "*/ \
77 "GLX_SGIX_fbconfig " \
80 #define DEFAULT_DIRECT GL_TRUE
83 /** XXX this could be based on gallium's max texture size */
84 #define PBUFFER_MAX_SIZE 16384
88 * The GLXContext typedef is defined as a pointer to this structure.
90 struct __GLXcontextRec
94 GLXDrawable currentDrawable
;
95 GLXDrawable currentReadable
;
98 XMesaContext xmesaContext
;
103 static pipe_tsd ContextTSD
;
105 /** Set current context for calling thread */
107 SetCurrentContext(GLXContext c
)
109 pipe_tsd_set(&ContextTSD
, c
);
112 /** Get current context for calling thread */
114 GetCurrentContext(void)
116 return pipe_tsd_get(&ContextTSD
);
121 /**********************************************************************/
122 /*** GLX Visual Code ***/
123 /**********************************************************************/
128 static XMesaVisual
*VisualTable
= NULL
;
129 static int NumVisuals
= 0;
133 /* Macro to handle c_class vs class field name in XVisualInfo struct */
134 #if defined(__cplusplus) || defined(c_plusplus)
135 #define CLASS c_class
143 * Test if the given XVisualInfo is usable for Mesa rendering.
146 is_usable_visual( XVisualInfo
*vinfo
)
148 switch (vinfo
->CLASS
) {
151 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
155 /* Any StaticColor/PseudoColor visual of at least 4 bits */
156 if (vinfo
->depth
>=4) {
164 /* Any depth of TrueColor or DirectColor works in RGB mode */
167 /* This should never happen */
174 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
175 * configuration in our list of GLX visuals.
178 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
179 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
180 GLboolean stereoFlag
,
181 GLint depth_size
, GLint stencil_size
,
182 GLint accumRedSize
, GLint accumGreenSize
,
183 GLint accumBlueSize
, GLint accumAlphaSize
,
184 GLint level
, GLint numAuxBuffers
, GLint num_samples
)
186 GLboolean ximageFlag
= GL_TRUE
;
189 GLboolean comparePointers
;
192 /* Check if the MESA_BACK_BUFFER env var is set */
193 char *backbuffer
= getenv("MESA_BACK_BUFFER");
195 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
196 ximageFlag
= GL_FALSE
;
198 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
199 ximageFlag
= GL_TRUE
;
202 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
208 /* stereo not supported */
212 if (stencil_size
> 0 && depth_size
> 0)
215 /* Comparing IDs uses less memory but sometimes fails. */
216 /* XXX revisit this after 3.0 is finished. */
217 if (getenv("MESA_GLX_VISUAL_HACK"))
218 comparePointers
= GL_TRUE
;
220 comparePointers
= GL_FALSE
;
222 /* Force the visual to have an alpha channel */
223 if (rgbFlag
&& getenv("MESA_GLX_FORCE_ALPHA"))
226 /* First check if a matching visual is already in the list */
227 for (i
=0; i
<NumVisuals
; i
++) {
228 XMesaVisual v
= VisualTable
[i
];
229 if (v
->display
== dpy
230 && v
->mesa_visual
.level
== level
231 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
232 && v
->mesa_visual
.samples
== num_samples
233 && v
->ximage_flag
== ximageFlag
234 && v
->mesa_visual
.rgbMode
== rgbFlag
235 && v
->mesa_visual
.doubleBufferMode
== dbFlag
236 && v
->mesa_visual
.stereoMode
== stereoFlag
237 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
238 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
239 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
240 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
241 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
242 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
243 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
244 /* now either compare XVisualInfo pointers or visual IDs */
245 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
246 || (comparePointers
&& v
->vishandle
== vinfo
)) {
252 /* Create a new visual and add it to the list. */
254 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
255 stereoFlag
, ximageFlag
,
256 depth_size
, stencil_size
,
257 accumRedSize
, accumBlueSize
,
258 accumBlueSize
, accumAlphaSize
, num_samples
, level
,
261 /* Save a copy of the pointer now so we can find this visual again
262 * if we need to search for it in find_glx_visual().
264 xmvis
->vishandle
= vinfo
;
265 /* Allocate more space for additional visual */
266 VisualTable
= realloc(VisualTable
, sizeof(XMesaVisual
) * (NumVisuals
+ 1));
267 /* add xmvis to the list */
268 VisualTable
[NumVisuals
] = xmvis
;
270 /* XXX minor hack, because XMesaCreateVisual doesn't support an
271 * aux buffers parameter.
273 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
280 * Return the default number of bits for the Z buffer.
281 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
282 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
283 * XXX probably do the same thing for stencil, accum, etc.
286 default_depth_bits(void)
289 const char *zEnv
= getenv("MESA_GLX_DEPTH_BITS");
298 default_alpha_bits(void)
301 const char *aEnv
= getenv("MESA_GLX_ALPHA_BITS");
310 default_accum_bits(void)
318 * Create a GLX visual from a regular XVisualInfo.
319 * This is called when Fake GLX is given an XVisualInfo which wasn't
320 * returned by glXChooseVisual. Since this is the first time we're
321 * considering this visual we'll take a guess at reasonable values
322 * for depth buffer size, stencil size, accum size, etc.
323 * This is the best we can do with a client-side emulation of GLX.
326 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
328 GLint zBits
= default_depth_bits();
329 GLint accBits
= default_accum_bits();
330 GLboolean alphaFlag
= default_alpha_bits() > 0;
332 if (is_usable_visual( visinfo
)) {
333 /* Configure this visual as RGB, double-buffered, depth-buffered. */
334 /* This is surely wrong for some people's needs but what else */
335 /* can be done? They should use glXChooseVisual(). */
336 return save_glx_visual( dpy
, visinfo
,
338 alphaFlag
, /* alpha */
339 GL_TRUE
, /* double */
340 GL_FALSE
, /* stereo */
342 8, /* stencil bits */
353 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
361 * Find the GLX visual associated with an XVisualInfo.
364 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
368 /* try to match visual id */
369 for (i
=0;i
<NumVisuals
;i
++) {
370 if (VisualTable
[i
]->display
==dpy
371 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
372 return VisualTable
[i
];
376 /* if that fails, try to match pointers */
377 for (i
=0;i
<NumVisuals
;i
++) {
378 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
379 return VisualTable
[i
];
388 * Try to get an X visual which matches the given arguments.
391 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
393 XVisualInfo temp
, *vis
;
396 unsigned int default_depth
;
399 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
404 default_depth
= DefaultDepth(dpy
,scr
);
405 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
407 if (depth
==default_depth
&& xclass
==default_class
) {
408 /* try to get root window's visual */
409 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
410 mask
|= VisualIDMask
;
413 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
415 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
416 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
417 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
419 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
420 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
421 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
422 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
436 * Retrieve the value of the given environment variable and find
437 * the X visual which matches it.
438 * Input: dpy - the display
439 * screen - the screen number
440 * varname - the name of the environment variable
441 * Return: an XVisualInfo pointer to NULL if error.
444 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
446 char value
[100], type
[100];
447 int depth
, xclass
= -1;
450 if (!getenv( varname
)) {
454 strncpy( value
, getenv(varname
), 100 );
457 sscanf( value
, "%s %d", type
, &depth
);
459 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
460 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
461 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
462 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
463 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
464 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
466 if (xclass
>-1 && depth
>0) {
467 vis
= get_visual( dpy
, scr
, depth
, xclass
);
473 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
482 * Select an X visual which satisfies the RGBA flag and minimum depth.
484 * screen - X display and screen number
485 * min_depth - minimum visual depth
486 * preferred_class - preferred GLX visual class or DONT_CARE
487 * Return: pointer to an XVisualInfo or NULL.
490 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
491 int preferred_class
)
494 int xclass
, visclass
= 0;
497 /* First see if the MESA_RGB_VISUAL env var is defined */
498 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
502 /* Otherwise, search for a suitable visual */
503 if (preferred_class
==DONT_CARE
) {
504 for (xclass
=0;xclass
<6;xclass
++) {
506 case 0: visclass
= TrueColor
; break;
507 case 1: visclass
= DirectColor
; break;
508 case 2: visclass
= PseudoColor
; break;
509 case 3: visclass
= StaticColor
; break;
510 case 4: visclass
= GrayScale
; break;
511 case 5: visclass
= StaticGray
; break;
514 /* start with shallowest */
515 for (depth
=0;depth
<=32;depth
++) {
516 if (visclass
==TrueColor
&& depth
==8) {
517 /* Special case: try to get 8-bit PseudoColor before */
518 /* 8-bit TrueColor */
519 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
524 vis
= get_visual( dpy
, screen
, depth
, visclass
);
531 /* start with deepest */
532 for (depth
=32;depth
>=min_depth
;depth
--) {
533 if (visclass
==TrueColor
&& depth
==8) {
534 /* Special case: try to get 8-bit PseudoColor before */
535 /* 8-bit TrueColor */
536 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
541 vis
= get_visual( dpy
, screen
, depth
, visclass
);
550 /* search for a specific visual class */
551 switch (preferred_class
) {
552 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
553 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
554 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
555 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
556 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
557 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
558 default: return NULL
;
561 /* start with shallowest */
562 for (depth
=0;depth
<=32;depth
++) {
563 vis
= get_visual( dpy
, screen
, depth
, visclass
);
570 /* start with deepest */
571 for (depth
=32;depth
>=min_depth
;depth
--) {
572 vis
= get_visual( dpy
, screen
, depth
, visclass
);
580 /* didn't find a visual */
587 /**********************************************************************/
588 /*** Display-related functions ***/
589 /**********************************************************************/
593 * Free all XMesaVisuals which are associated with the given display.
596 destroy_visuals_on_display(Display
*dpy
)
599 for (i
= 0; i
< NumVisuals
; i
++) {
600 if (VisualTable
[i
]->display
== dpy
) {
601 /* remove this visual */
603 free(VisualTable
[i
]);
604 for (j
= i
; j
< NumVisuals
- 1; j
++)
605 VisualTable
[j
] = VisualTable
[j
+ 1];
613 * Called from XCloseDisplay() to let us free our display-related data.
616 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
618 xmesa_destroy_buffers_on_display(dpy
);
619 destroy_visuals_on_display(dpy
);
620 xmesa_close_display(dpy
);
626 * Look for the named extension on given display and return a pointer
627 * to the _XExtension data, or NULL if extension not found.
630 lookup_extension(Display
*dpy
, const char *extName
)
633 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
634 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
643 * Whenever we're given a new Display pointer, call this function to
644 * register our close_display_callback function.
647 register_with_display(Display
*dpy
)
649 const char *extName
= "MesaGLX";
652 ext
= lookup_extension(dpy
, extName
);
654 XExtCodes
*c
= XAddExtension(dpy
);
655 ext
= dpy
->ext_procs
; /* new extension is at head of list */
656 assert(c
->extension
== ext
->codes
.extension
);
658 ext
->name
= strdup(extName
);
659 ext
->close_display
= close_display_callback
;
668 generate_error(Display
*dpy
,
669 unsigned char error_code
,
671 unsigned char minor_code
,
674 XErrorHandler handler
;
680 handler
= XSetErrorHandler(NULL
);
681 XSetErrorHandler(handler
);
686 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_opcode
, &first_event
, &first_error
)) {
693 error_code
+= first_error
;
696 memset(&event
, 0, sizeof event
);
698 event
.xerror
.type
= X_Error
;
699 event
.xerror
.display
= dpy
;
700 event
.xerror
.resourceid
= resourceid
;
701 event
.xerror
.serial
= NextRequest(dpy
) - 1;
702 event
.xerror
.error_code
= error_code
;
703 event
.xerror
.request_code
= major_opcode
;
704 event
.xerror
.minor_code
= minor_code
;
706 return handler(dpy
, &event
.xerror
);
710 /**********************************************************************/
711 /*** Begin Fake GLX API Functions ***/
712 /**********************************************************************/
716 * Helper used by glXChooseVisual and glXChooseFBConfig.
717 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
719 * In either case, the attribute list is terminated with the value 'None'.
722 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
724 const GLboolean rgbModeDefault
= fbConfig
;
725 const int *parselist
;
727 int min_red
=0, min_green
=0, min_blue
=0;
728 GLboolean rgb_flag
= rgbModeDefault
;
729 GLboolean alpha_flag
= GL_FALSE
;
730 GLboolean double_flag
= GL_FALSE
;
731 GLboolean stereo_flag
= GL_FALSE
;
732 GLint depth_size
= 0;
733 GLint stencil_size
= 0;
734 GLint accumRedSize
= 0;
735 GLint accumGreenSize
= 0;
736 GLint accumBlueSize
= 0;
737 GLint accumAlphaSize
= 0;
739 int visual_type
= DONT_CARE
;
740 GLint caveat
= DONT_CARE
;
741 XMesaVisual xmvis
= NULL
;
742 int desiredVisualID
= -1;
744 GLint num_samples
= 0;
753 parselist
[1] == GLX_DONT_CARE
&&
754 parselist
[0] != GLX_LEVEL
) {
755 /* For glXChooseFBConfig(), skip attributes whose value is
756 * GLX_DONT_CARE, unless it's GLX_LEVEL (which can legitimately be
759 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
760 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
766 switch (*parselist
) {
777 case GLX_BUFFER_SIZE
:
783 level
= *parselist
++;
795 case GLX_DOUBLEBUFFER
:
798 double_flag
= *parselist
++;
801 double_flag
= GL_TRUE
;
807 stereo_flag
= *parselist
++;
810 stereo_flag
= GL_TRUE
;
813 case GLX_AUX_BUFFERS
:
815 numAux
= *parselist
++;
816 if (numAux
> MAX_AUX_BUFFERS
)
821 min_red
= *parselist
++;
825 min_green
= *parselist
++;
829 min_blue
= *parselist
++;
834 GLint size
= *parselist
++;
835 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
840 depth_size
= *parselist
++;
842 case GLX_STENCIL_SIZE
:
844 stencil_size
= *parselist
++;
846 case GLX_ACCUM_RED_SIZE
:
849 GLint size
= *parselist
++;
850 accumRedSize
= MAX2( accumRedSize
, size
);
853 case GLX_ACCUM_GREEN_SIZE
:
856 GLint size
= *parselist
++;
857 accumGreenSize
= MAX2( accumGreenSize
, size
);
860 case GLX_ACCUM_BLUE_SIZE
:
863 GLint size
= *parselist
++;
864 accumBlueSize
= MAX2( accumBlueSize
, size
);
867 case GLX_ACCUM_ALPHA_SIZE
:
870 GLint size
= *parselist
++;
871 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
876 * GLX_EXT_visual_info extension
878 case GLX_X_VISUAL_TYPE_EXT
:
880 visual_type
= *parselist
++;
882 case GLX_TRANSPARENT_TYPE_EXT
:
886 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
890 case GLX_TRANSPARENT_RED_VALUE_EXT
:
891 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
892 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
893 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
900 * GLX_EXT_visual_info extension
902 case GLX_VISUAL_CAVEAT_EXT
:
904 caveat
= *parselist
++; /* ignored for now */
908 * GLX_ARB_multisample
910 case GLX_SAMPLE_BUFFERS_ARB
:
915 case GLX_SAMPLES_ARB
:
917 num_samples
= *parselist
++;
923 case GLX_RENDER_TYPE
:
927 if (*parselist
& GLX_RGBA_BIT
) {
930 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
933 else if (*parselist
== 0) {
938 case GLX_DRAWABLE_TYPE
:
942 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
943 return NULL
; /* bad bit */
947 case GLX_FBCONFIG_ID
:
952 desiredVisualID
= *parselist
++;
954 case GLX_X_RENDERABLE
:
955 case GLX_MAX_PBUFFER_WIDTH
:
956 case GLX_MAX_PBUFFER_HEIGHT
:
957 case GLX_MAX_PBUFFER_PIXELS
:
959 return NULL
; /* invalid config option */
960 parselist
+= 2; /* ignore the parameter */
963 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
964 parselist
++; /*skip*/
966 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
967 parselist
++; /*skip*/
969 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
970 parselist
++; /*skip*/
972 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
974 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
975 GLX_TEXTURE_2D_BIT_EXT
|
976 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
981 case GLX_Y_INVERTED_EXT
:
982 parselist
++; /*skip*/
990 /* undefined attribute */
991 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1001 * Since we're only simulating the GLX extension this function will never
1002 * find any real GL visuals. Instead, all we can do is try to find an RGB
1003 * or CI visual of appropriate depth. Other requested attributes such as
1004 * double buffering, depth buffer, etc. will be associated with the X
1005 * visual and stored in the VisualTable[].
1007 if (desiredVisualID
!= -1) {
1008 /* try to get a specific visual, by visualID */
1011 temp
.visualid
= desiredVisualID
;
1012 temp
.screen
= screen
;
1013 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1015 /* give the visual some useful GLX attributes */
1016 double_flag
= GL_TRUE
;
1020 else if (level
==0) {
1021 /* normal color planes */
1022 /* Get an RGB visual */
1023 int min_rgb
= min_red
+ min_green
+ min_blue
;
1024 if (min_rgb
>1 && min_rgb
<8) {
1025 /* a special case to be sure we can get a monochrome visual */
1028 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
1031 _mesa_warning(NULL
, "overlay not supported");
1036 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1037 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1038 * largest depth buffer size, which is 32bits/value. Instead, we
1039 * return 16 to maintain performance with earlier versions of Mesa.
1041 if (stencil_size
> 0)
1042 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
1043 else if (depth_size
> 24)
1045 else if (depth_size
> 16)
1047 else if (depth_size
> 0) {
1048 depth_size
= default_depth_bits();
1052 alpha_flag
= default_alpha_bits() > 0;
1055 /* we only support one size of stencil and accum buffers. */
1056 if (stencil_size
> 0)
1059 if (accumRedSize
> 0 ||
1060 accumGreenSize
> 0 ||
1061 accumBlueSize
> 0 ||
1062 accumAlphaSize
> 0) {
1066 accumBlueSize
= default_accum_bits();
1068 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1071 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1072 stereo_flag
, depth_size
, stencil_size
,
1073 accumRedSize
, accumGreenSize
,
1074 accumBlueSize
, accumAlphaSize
, level
, numAux
,
1082 PUBLIC XVisualInfo
*
1083 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1087 /* register ourselves as an extension on this display */
1088 register_with_display(dpy
);
1090 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1092 /* create a new vishandle - the cached one may be stale */
1093 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1094 if (xmvis
->vishandle
) {
1095 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1097 return xmvis
->vishandle
;
1105 * Helper function used by other glXCreateContext functions.
1108 create_context(Display
*dpy
, XMesaVisual xmvis
,
1109 XMesaContext shareCtx
, Bool direct
,
1110 unsigned major
, unsigned minor
,
1111 unsigned profileMask
, unsigned contextFlags
)
1118 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1122 /* deallocate unused windows/buffers */
1124 XMesaGarbageCollect();
1127 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
, shareCtx
, major
, minor
,
1128 profileMask
, contextFlags
);
1129 if (!glxCtx
->xmesaContext
) {
1134 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1135 glxCtx
->currentDpy
= dpy
;
1136 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1143 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1144 GLXContext shareCtx
, Bool direct
)
1148 xmvis
= find_glx_visual( dpy
, visinfo
);
1150 /* This visual wasn't found with glXChooseVisual() */
1151 xmvis
= create_glx_visual( dpy
, visinfo
);
1153 /* unusable visual */
1158 return create_context(dpy
, xmvis
,
1159 shareCtx
? shareCtx
->xmesaContext
: NULL
,
1161 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
1165 /* XXX these may have to be removed due to thread-safety issues. */
1166 static GLXContext MakeCurrent_PrevContext
= 0;
1167 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1168 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1169 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1170 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1173 /* GLX 1.3 and later */
1175 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1176 GLXDrawable read
, GLXContext ctx
)
1178 GLXContext glxCtx
= ctx
;
1179 static boolean firsttime
= 1, no_rast
= 0;
1182 no_rast
= getenv("SP_NO_RAST") != NULL
;
1186 if (ctx
&& draw
&& read
) {
1187 XMesaBuffer drawBuffer
, readBuffer
;
1188 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1190 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1191 if (ctx
== MakeCurrent_PrevContext
1192 && draw
== MakeCurrent_PrevDrawable
) {
1193 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1196 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1199 /* drawable must be a new window! */
1200 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1202 /* Out of memory, or context/drawable depth mismatch */
1207 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1208 if (ctx
== MakeCurrent_PrevContext
1209 && read
== MakeCurrent_PrevReadable
) {
1210 readBuffer
= MakeCurrent_PrevReadBuffer
;
1213 readBuffer
= XMesaFindBuffer( dpy
, read
);
1216 /* drawable must be a new window! */
1217 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1219 /* Out of memory, or context/drawable depth mismatch */
1225 MakeCurrent_PrevContext
== ctx
&&
1226 MakeCurrent_PrevDrawable
== draw
&&
1227 MakeCurrent_PrevReadable
== read
&&
1228 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1229 MakeCurrent_PrevReadBuffer
== readBuffer
)
1232 MakeCurrent_PrevContext
= ctx
;
1233 MakeCurrent_PrevDrawable
= draw
;
1234 MakeCurrent_PrevReadable
= read
;
1235 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1236 MakeCurrent_PrevReadBuffer
= readBuffer
;
1238 /* Now make current! */
1239 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1240 ctx
->currentDpy
= dpy
;
1241 ctx
->currentDrawable
= draw
;
1242 ctx
->currentReadable
= read
;
1243 SetCurrentContext(ctx
);
1250 else if (!ctx
&& !draw
&& !read
) {
1251 /* release current context w/out assigning new one. */
1252 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1253 MakeCurrent_PrevContext
= 0;
1254 MakeCurrent_PrevDrawable
= 0;
1255 MakeCurrent_PrevReadable
= 0;
1256 MakeCurrent_PrevDrawBuffer
= 0;
1257 MakeCurrent_PrevReadBuffer
= 0;
1258 SetCurrentContext(NULL
);
1262 /* The args must either all be non-zero or all zero.
1271 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1273 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1278 glXGetCurrentContext(void)
1280 return GetCurrentContext();
1285 glXGetCurrentDisplay(void)
1287 GLXContext glxCtx
= glXGetCurrentContext();
1289 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1294 glXGetCurrentDisplayEXT(void)
1296 return glXGetCurrentDisplay();
1301 glXGetCurrentDrawable(void)
1303 GLXContext gc
= glXGetCurrentContext();
1304 return gc
? gc
->currentDrawable
: 0;
1309 glXGetCurrentReadDrawable(void)
1311 GLXContext gc
= glXGetCurrentContext();
1312 return gc
? gc
->currentReadable
: 0;
1317 glXGetCurrentReadDrawableSGI(void)
1319 return glXGetCurrentReadDrawable();
1324 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1329 v
= find_glx_visual( dpy
, visinfo
);
1331 v
= create_glx_visual( dpy
, visinfo
);
1333 /* unusable visual */
1338 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1342 return b
->ws
.drawable
;
1346 /*** GLX_MESA_pixmap_colormap ***/
1349 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1350 Pixmap pixmap
, Colormap cmap
)
1355 v
= find_glx_visual( dpy
, visinfo
);
1357 v
= create_glx_visual( dpy
, visinfo
);
1359 /* unusable visual */
1364 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1368 return b
->ws
.drawable
;
1373 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1375 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1377 XMesaDestroyBuffer(b
);
1379 else if (getenv("MESA_DEBUG")) {
1380 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1386 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1387 unsigned long mask
)
1389 XMesaContext xm_src
= src
->xmesaContext
;
1390 XMesaContext xm_dst
= dst
->xmesaContext
;
1392 if (MakeCurrent_PrevContext
== src
) {
1395 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1400 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1403 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1404 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1410 return True
; /* we're faking GLX so always return success */
1415 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1418 GLXContext glxCtx
= ctx
;
1420 MakeCurrent_PrevContext
= 0;
1421 MakeCurrent_PrevDrawable
= 0;
1422 MakeCurrent_PrevReadable
= 0;
1423 MakeCurrent_PrevDrawBuffer
= 0;
1424 MakeCurrent_PrevReadBuffer
= 0;
1425 XMesaDestroyContext( glxCtx
->xmesaContext
);
1426 XMesaGarbageCollect();
1433 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1435 return ctx
? ctx
->isDirect
: False
;
1441 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1443 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1444 static boolean firsttime
= 1, no_rast
= 0;
1447 no_rast
= getenv("SP_NO_RAST") != NULL
;
1455 XMesaSwapBuffers(buffer
);
1457 else if (getenv("MESA_DEBUG")) {
1458 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1465 /*** GLX_MESA_copy_sub_buffer ***/
1468 glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
1469 int x
, int y
, int width
, int height
)
1471 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1473 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1475 else if (getenv("MESA_DEBUG")) {
1476 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1482 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1485 /* Return GLX version, not Mesa version */
1486 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1487 *maj
= CLIENT_MAJOR_VERSION
;
1488 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1494 * Query the GLX attributes of the given XVisualInfo.
1497 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1503 return GLX_BAD_ATTRIBUTE
;
1504 *value
= (int) True
;
1506 case GLX_BUFFER_SIZE
:
1507 *value
= xmvis
->visinfo
->depth
;
1510 *value
= xmvis
->mesa_visual
.level
;
1514 return GLX_BAD_ATTRIBUTE
;
1515 if (xmvis
->mesa_visual
.rgbMode
) {
1522 case GLX_DOUBLEBUFFER
:
1523 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1526 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1528 case GLX_AUX_BUFFERS
:
1529 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1532 *value
= xmvis
->mesa_visual
.redBits
;
1534 case GLX_GREEN_SIZE
:
1535 *value
= xmvis
->mesa_visual
.greenBits
;
1538 *value
= xmvis
->mesa_visual
.blueBits
;
1540 case GLX_ALPHA_SIZE
:
1541 *value
= xmvis
->mesa_visual
.alphaBits
;
1543 case GLX_DEPTH_SIZE
:
1544 *value
= xmvis
->mesa_visual
.depthBits
;
1546 case GLX_STENCIL_SIZE
:
1547 *value
= xmvis
->mesa_visual
.stencilBits
;
1549 case GLX_ACCUM_RED_SIZE
:
1550 *value
= xmvis
->mesa_visual
.accumRedBits
;
1552 case GLX_ACCUM_GREEN_SIZE
:
1553 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1555 case GLX_ACCUM_BLUE_SIZE
:
1556 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1558 case GLX_ACCUM_ALPHA_SIZE
:
1559 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1563 * GLX_EXT_visual_info extension
1565 case GLX_X_VISUAL_TYPE_EXT
:
1566 switch (xmvis
->visinfo
->CLASS
) {
1567 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1568 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1569 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1570 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1571 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1572 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1575 case GLX_TRANSPARENT_TYPE_EXT
:
1577 *value
= GLX_NONE_EXT
;
1579 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1582 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1585 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1588 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1591 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1596 * GLX_EXT_visual_info extension
1598 case GLX_VISUAL_CAVEAT_EXT
:
1599 /* test for zero, just in case */
1600 if (xmvis
->mesa_visual
.visualRating
> 0)
1601 *value
= xmvis
->mesa_visual
.visualRating
;
1603 *value
= GLX_NONE_EXT
;
1607 * GLX_ARB_multisample
1609 case GLX_SAMPLE_BUFFERS_ARB
:
1610 *value
= xmvis
->mesa_visual
.sampleBuffers
;
1612 case GLX_SAMPLES_ARB
:
1613 *value
= xmvis
->mesa_visual
.samples
;
1619 case GLX_SCREEN_EXT
:
1621 return GLX_BAD_ATTRIBUTE
;
1622 *value
= xmvis
->visinfo
->screen
;
1624 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1626 return GLX_BAD_ATTRIBUTE
;
1627 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1629 case GLX_RENDER_TYPE_SGIX
:
1631 return GLX_BAD_ATTRIBUTE
;
1632 if (xmvis
->mesa_visual
.rgbMode
)
1633 *value
= GLX_RGBA_BIT
;
1635 *value
= GLX_COLOR_INDEX_BIT
;
1637 case GLX_X_RENDERABLE_SGIX
:
1639 return GLX_BAD_ATTRIBUTE
;
1640 *value
= True
; /* XXX really? */
1642 case GLX_FBCONFIG_ID_SGIX
:
1644 return GLX_BAD_ATTRIBUTE
;
1645 *value
= xmvis
->visinfo
->visualid
;
1647 case GLX_MAX_PBUFFER_WIDTH
:
1649 return GLX_BAD_ATTRIBUTE
;
1650 /* XXX should be same as ctx->Const.MaxRenderbufferSize */
1651 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1653 case GLX_MAX_PBUFFER_HEIGHT
:
1655 return GLX_BAD_ATTRIBUTE
;
1656 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1658 case GLX_MAX_PBUFFER_PIXELS
:
1660 return GLX_BAD_ATTRIBUTE
;
1661 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1662 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1666 return GLX_BAD_ATTRIBUTE
;
1667 *value
= xmvis
->visinfo
->visualid
;
1670 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1671 *value
= True
; /*XXX*/
1673 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1675 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1677 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1678 *value
= True
; /*XXX*/
1680 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1681 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1682 GLX_TEXTURE_2D_BIT_EXT
|
1683 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1685 case GLX_Y_INVERTED_EXT
:
1686 *value
= True
; /*XXX*/
1690 return GLX_BAD_ATTRIBUTE
;
1697 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1698 int attrib
, int *value
)
1702 if (!dpy
|| !visinfo
)
1703 return GLX_BAD_ATTRIBUTE
;
1705 xmvis
= find_glx_visual( dpy
, visinfo
);
1707 /* this visual wasn't obtained with glXChooseVisual */
1708 xmvis
= create_glx_visual( dpy
, visinfo
);
1710 /* this visual can't be used for GL rendering */
1711 if (attrib
==GLX_USE_GL
) {
1712 *value
= (int) False
;
1716 return GLX_BAD_VISUAL
;
1721 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1729 XMesaContext xmesa
= XMesaGetCurrentContext();
1730 XMesaFlush( xmesa
);
1738 XMesaContext xmesa
= XMesaGetCurrentContext();
1739 XMesaFlush( xmesa
);
1744 get_extensions( void )
1751 /* GLX 1.1 and later */
1753 glXQueryExtensionsString( Display
*dpy
, int screen
)
1757 return get_extensions();
1762 /* GLX 1.1 and later */
1764 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1766 static char version
[1000];
1767 sprintf(version
, "%d.%d %s",
1768 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, xmesa_get_name());
1774 case GLX_EXTENSIONS
:
1775 return get_extensions();
1787 /* GLX 1.1 and later */
1789 glXGetClientString( Display
*dpy
, int name
)
1791 static char version
[1000];
1792 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1793 CLIENT_MINOR_VERSION
, xmesa_get_name());
1798 case GLX_EXTENSIONS
:
1799 return get_extensions();
1817 glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1818 int attribute
, int *value
)
1820 XMesaVisual v
= (XMesaVisual
) config
;
1824 if (!dpy
|| !config
|| !value
)
1827 return get_config(v
, attribute
, value
, GL_TRUE
);
1831 PUBLIC GLXFBConfig
*
1832 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1834 XVisualInfo
*visuals
, visTemplate
;
1835 const long visMask
= VisualScreenMask
;
1838 /* Get list of all X visuals */
1839 visTemplate
.screen
= screen
;
1840 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1841 if (*nelements
> 0) {
1842 XMesaVisual
*results
= malloc(*nelements
* sizeof(XMesaVisual
));
1847 for (i
= 0; i
< *nelements
; i
++) {
1848 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1854 return (GLXFBConfig
*) results
;
1860 PUBLIC GLXFBConfig
*
1861 glXChooseFBConfig(Display
*dpy
, int screen
,
1862 const int *attribList
, int *nitems
)
1866 /* register ourselves as an extension on this display */
1867 register_with_display(dpy
);
1869 if (!attribList
|| !attribList
[0]) {
1870 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1871 return glXGetFBConfigs(dpy
, screen
, nitems
);
1874 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1876 GLXFBConfig
*config
= malloc(sizeof(XMesaVisual
));
1882 config
[0] = (GLXFBConfig
) xmvis
;
1883 return (GLXFBConfig
*) config
;
1892 PUBLIC XVisualInfo
*
1893 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1895 if (dpy
&& config
) {
1896 XMesaVisual xmvis
= (XMesaVisual
) config
;
1898 return xmvis
->vishandle
;
1900 /* create a new vishandle - the cached one may be stale */
1901 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1902 if (xmvis
->vishandle
) {
1903 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1905 return xmvis
->vishandle
;
1915 glXCreateWindow(Display
*dpy
, GLXFBConfig config
, Window win
,
1916 const int *attribList
)
1918 XMesaVisual xmvis
= (XMesaVisual
) config
;
1923 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1928 (void) attribList
; /* Ignored in GLX 1.3 */
1930 return win
; /* A hack for now */
1935 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1937 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1939 XMesaDestroyBuffer(b
);
1940 /* don't destroy X window */
1946 glXCreatePixmap(Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1947 const int *attribList
)
1949 XMesaVisual v
= (XMesaVisual
) config
;
1952 int target
= 0, format
= 0, mipmap
= 0;
1955 if (!dpy
|| !config
|| !pixmap
)
1958 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1960 case GLX_TEXTURE_FORMAT_EXT
:
1963 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1964 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1965 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1973 case GLX_TEXTURE_TARGET_EXT
:
1976 case GLX_TEXTURE_1D_EXT
:
1977 case GLX_TEXTURE_2D_EXT
:
1978 case GLX_TEXTURE_RECTANGLE_EXT
:
1986 case GLX_MIPMAP_TEXTURE_EXT
:
1997 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1998 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1999 &value
, GL_TRUE
) != Success
2001 return 0; /* error! */
2004 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2005 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2006 &value
, GL_TRUE
) != Success
2008 return 0; /* error! */
2012 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2013 &value
, GL_TRUE
) != Success
2015 return 0; /* error! */
2018 if (target
== GLX_TEXTURE_1D_EXT
) {
2019 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2020 &value
, GL_TRUE
) != Success
2021 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2022 return 0; /* error! */
2025 else if (target
== GLX_TEXTURE_2D_EXT
) {
2026 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2027 &value
, GL_TRUE
) != Success
2028 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2029 return 0; /* error! */
2032 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2033 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2034 &value
, GL_TRUE
) != Success
2035 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2036 return 0; /* error! */
2040 if (format
|| target
|| mipmap
) {
2041 /* texture from pixmap */
2042 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2045 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2056 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2058 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
2060 XMesaDestroyBuffer(b
);
2061 /* don't destroy X pixmap */
2066 glXCreatePbuffer(Display
*dpy
, GLXFBConfig config
, const int *attribList
)
2068 XMesaVisual xmvis
= (XMesaVisual
) config
;
2071 int width
= 0, height
= 0;
2072 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2076 for (attrib
= attribList
; *attrib
; attrib
++) {
2078 case GLX_PBUFFER_WIDTH
:
2082 case GLX_PBUFFER_HEIGHT
:
2086 case GLX_PRESERVED_CONTENTS
:
2088 preserveContents
= *attrib
;
2090 case GLX_LARGEST_PBUFFER
:
2092 useLargest
= *attrib
;
2099 if (width
== 0 || height
== 0)
2102 if (width
> PBUFFER_MAX_SIZE
|| height
> PBUFFER_MAX_SIZE
) {
2103 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2104 * allocate the largest possible buffer.
2107 width
= PBUFFER_MAX_SIZE
;
2108 height
= PBUFFER_MAX_SIZE
;
2112 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2113 /* A GLXPbuffer handle must be an X Drawable because that's what
2114 * glXMakeCurrent takes.
2117 xmbuf
->largestPbuffer
= useLargest
;
2118 xmbuf
->preservedContents
= preserveContents
;
2119 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2128 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2130 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2132 XMesaDestroyBuffer(b
);
2138 glXQueryDrawable(Display
*dpy
, GLXDrawable draw
, int attribute
,
2139 unsigned int *value
)
2141 GLuint width
, height
;
2142 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2144 generate_error(dpy
, GLXBadDrawable
, draw
, X_GLXGetDrawableAttributes
, False
);
2148 /* make sure buffer's dimensions are up to date */
2149 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2151 switch (attribute
) {
2158 case GLX_PRESERVED_CONTENTS
:
2159 *value
= xmbuf
->preservedContents
;
2161 case GLX_LARGEST_PBUFFER
:
2162 *value
= xmbuf
->largestPbuffer
;
2164 case GLX_FBCONFIG_ID
:
2165 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2167 case GLX_TEXTURE_FORMAT_EXT
:
2168 *value
= xmbuf
->TextureFormat
;
2170 case GLX_TEXTURE_TARGET_EXT
:
2171 *value
= xmbuf
->TextureTarget
;
2173 case GLX_MIPMAP_TEXTURE_EXT
:
2174 *value
= xmbuf
->TextureMipmap
;
2178 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, true);
2185 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2186 int renderType
, GLXContext shareCtx
, Bool direct
)
2188 XMesaVisual xmvis
= (XMesaVisual
) config
;
2190 if (!dpy
|| !config
||
2191 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2194 return create_context(dpy
, xmvis
,
2195 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2197 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2202 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2204 GLXContext glxCtx
= ctx
;
2205 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2210 switch (attribute
) {
2211 case GLX_FBCONFIG_ID
:
2212 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2214 case GLX_RENDER_TYPE
:
2215 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2216 *value
= GLX_RGBA_TYPE
;
2218 *value
= GLX_COLOR_INDEX_TYPE
;
2224 return GLX_BAD_ATTRIBUTE
;
2231 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2233 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2235 xmbuf
->selectedEvents
= mask
;
2240 glXGetSelectedEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2242 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2244 *mask
= xmbuf
->selectedEvents
;
2251 /*** GLX_SGI_swap_control ***/
2254 glXSwapIntervalSGI(int interval
)
2262 /*** GLX_SGI_video_sync ***/
2264 static unsigned int FrameCounter
= 0;
2267 glXGetVideoSyncSGI(unsigned int *count
)
2269 /* this is a bogus implementation */
2270 *count
= FrameCounter
++;
2275 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2277 if (divisor
<= 0 || remainder
< 0)
2278 return GLX_BAD_VALUE
;
2279 /* this is a bogus implementation */
2281 while (FrameCounter
% divisor
!= remainder
)
2283 *count
= FrameCounter
;
2289 /*** GLX_SGI_make_current_read ***/
2292 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
,
2295 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2300 glXGetCurrentReadDrawableSGI(void)
2307 /*** GLX_SGIX_video_source ***/
2310 PUBLIC GLXVideoSourceSGIX
2311 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
,
2312 VLPath path
, int nodeClass
, VLNode drainNode
)
2324 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2333 /*** GLX_EXT_import_context ***/
2336 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2343 glXGetContextIDEXT(const GLXContext context
)
2350 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2358 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
,
2370 /*** GLX_SGIX_fbconfig ***/
2373 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2374 int attribute
, int *value
)
2376 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2379 PUBLIC GLXFBConfigSGIX
*
2380 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
,
2383 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
,
2384 attrib_list
, nelements
);
2389 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2392 XMesaVisual xmvis
= (XMesaVisual
) config
;
2393 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2394 return xmbuf
->ws
.drawable
; /* need to return an X ID */
2399 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2400 int renderType
, GLXContext shareCtx
,
2403 XMesaVisual xmvis
= (XMesaVisual
) config
;
2405 if (!dpy
|| !config
||
2406 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2409 return create_context(dpy
, xmvis
,
2410 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2412 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2416 PUBLIC XVisualInfo
*
2417 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2419 return glXGetVisualFromFBConfig(dpy
, config
);
2423 PUBLIC GLXFBConfigSGIX
2424 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2426 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2428 /* This visual wasn't found with glXChooseVisual() */
2429 xmvis
= create_glx_visual(dpy
, vis
);
2432 return (GLXFBConfigSGIX
) xmvis
;
2437 /*** GLX_SGIX_pbuffer ***/
2439 PUBLIC GLXPbufferSGIX
2440 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2441 unsigned int width
, unsigned int height
,
2444 XMesaVisual xmvis
= (XMesaVisual
) config
;
2447 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2451 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2453 case GLX_PRESERVED_CONTENTS_SGIX
:
2455 preserveContents
= *attrib
; /* ignored */
2457 case GLX_LARGEST_PBUFFER_SGIX
:
2459 useLargest
= *attrib
; /* ignored */
2466 /* not used at this time */
2468 (void) preserveContents
;
2470 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2471 /* A GLXPbuffer handle must be an X Drawable because that's what
2472 * glXMakeCurrent takes.
2474 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2479 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2481 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2483 XMesaDestroyBuffer(xmbuf
);
2489 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
,
2490 unsigned int *value
)
2492 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2495 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2499 switch (attribute
) {
2500 case GLX_PRESERVED_CONTENTS_SGIX
:
2503 case GLX_LARGEST_PBUFFER_SGIX
:
2504 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2506 case GLX_WIDTH_SGIX
:
2507 *value
= xmesa_buffer_width(xmbuf
);
2509 case GLX_HEIGHT_SGIX
:
2510 *value
= xmesa_buffer_height(xmbuf
);
2512 case GLX_EVENT_MASK_SGIX
:
2513 *value
= 0; /* XXX might be wrong */
2523 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2525 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2527 /* Note: we'll never generate clobber events */
2528 xmbuf
->selectedEvents
= mask
;
2534 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
,
2535 unsigned long *mask
)
2537 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2539 *mask
= xmbuf
->selectedEvents
;
2548 /*** GLX_SGI_cushion ***/
2551 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2560 /*** GLX_SGIX_video_resize ***/
2563 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
,
2574 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2575 int x
, int y
, int w
, int h
)
2588 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2589 int *x
, int *y
, int *w
, int *h
)
2602 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
,
2603 int *dx
, int *dy
, int *dw
, int *dh
)
2616 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2627 /*** GLX_SGIX_dmbuffer **/
2629 #if defined(_DM_BUFFER_H_)
2631 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
,
2632 DMparams
*params
, DMbuffer dmbuffer
)
2643 /*** GLX_SGIX_swap_group ***/
2646 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2655 /*** GLX_SGIX_swap_barrier ***/
2658 glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2666 glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2676 /*** GLX_SUN_get_transparent_index ***/
2679 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
,
2685 (void) pTransparent
;
2691 /*** GLX_MESA_release_buffers ***/
2694 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2695 * (a window or pixmap) prior to destroying the GLXDrawable.
2698 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2700 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2702 XMesaDestroyBuffer(b
);
2708 /*** GLX_EXT_texture_from_pixmap ***/
2711 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2712 const int *attrib_list
)
2714 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2716 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2720 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2722 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2724 XMesaReleaseTexImage(dpy
, b
, buffer
);
2729 /*** GLX_ARB_create_context ***/
2733 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
2734 GLXContext shareCtx
, Bool direct
,
2735 const int *attrib_list
)
2737 XMesaVisual xmvis
= (XMesaVisual
) config
;
2738 int majorVersion
= 1, minorVersion
= 0;
2739 int contextFlags
= 0x0;
2740 int profileMask
= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
;
2741 int renderType
= GLX_RGBA_TYPE
;
2744 const int contextFlagsAll
= (GLX_CONTEXT_DEBUG_BIT_ARB
|
2745 GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
);
2748 /* parse attrib_list */
2749 for (i
= 0; !done
&& attrib_list
&& attrib_list
[i
]; i
++) {
2750 switch (attrib_list
[i
]) {
2751 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2752 majorVersion
= attrib_list
[++i
];
2754 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2755 minorVersion
= attrib_list
[++i
];
2757 case GLX_CONTEXT_FLAGS_ARB
:
2758 contextFlags
= attrib_list
[++i
];
2760 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2761 profileMask
= attrib_list
[++i
];
2763 case GLX_RENDER_TYPE
:
2764 renderType
= attrib_list
[++i
];
2772 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2777 /* check contextFlags */
2778 if (contextFlags
& ~contextFlagsAll
) {
2779 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2783 /* check profileMask */
2784 if (profileMask
!= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
&&
2785 profileMask
!= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
&&
2786 profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
) {
2787 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAttribsARB
, False
);
2791 /* check renderType */
2792 if (renderType
!= GLX_RGBA_TYPE
&&
2793 renderType
!= GLX_COLOR_INDEX_TYPE
) {
2794 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2799 if (majorVersion
<= 0 ||
2801 (profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2802 ((majorVersion
== 1 && minorVersion
> 5) ||
2803 (majorVersion
== 2 && minorVersion
> 1) ||
2804 (majorVersion
== 3 && minorVersion
> 3) ||
2805 (majorVersion
== 4 && minorVersion
> 5) ||
2806 majorVersion
> 4))) {
2807 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2810 if (profileMask
== GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2811 ((majorVersion
== 1 && minorVersion
> 1) ||
2812 (majorVersion
== 2 && minorVersion
> 0) ||
2813 (majorVersion
== 3 && minorVersion
> 1) ||
2814 majorVersion
> 3)) {
2815 /* GLX_EXT_create_context_es2_profile says nothing to justifying a
2816 * different error code for invalid ES versions, but this is what NVIDIA
2817 * does and piglit expects.
2819 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAttribsARB
, False
);
2823 if ((contextFlags
& GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
) &&
2825 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2829 if (renderType
== GLX_COLOR_INDEX_TYPE
&& majorVersion
>= 3) {
2830 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2834 ctx
= create_context(dpy
, xmvis
,
2835 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2837 majorVersion
, minorVersion
,
2838 profileMask
, contextFlags
);
2840 generate_error(dpy
, GLXBadFBConfig
, 0, X_GLXCreateContextAttribsARB
, False
);