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
, GLuint 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;
746 if (xmesa_init( dpy
) != 0) {
747 _mesa_warning(NULL
, "Failed to initialize display");
756 parselist
[1] == GLX_DONT_CARE
&&
757 parselist
[0] != GLX_LEVEL
) {
758 /* For glXChooseFBConfig(), skip attributes whose value is
759 * GLX_DONT_CARE, unless it's GLX_LEVEL (which can legitimately be
762 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
763 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
769 switch (*parselist
) {
780 case GLX_BUFFER_SIZE
:
786 level
= *parselist
++;
798 case GLX_DOUBLEBUFFER
:
801 double_flag
= *parselist
++;
804 double_flag
= GL_TRUE
;
810 stereo_flag
= *parselist
++;
813 stereo_flag
= GL_TRUE
;
816 case GLX_AUX_BUFFERS
:
818 numAux
= *parselist
++;
819 if (numAux
> MAX_AUX_BUFFERS
)
824 min_red
= *parselist
++;
828 min_green
= *parselist
++;
832 min_blue
= *parselist
++;
837 GLint size
= *parselist
++;
838 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
843 depth_size
= *parselist
++;
845 case GLX_STENCIL_SIZE
:
847 stencil_size
= *parselist
++;
849 case GLX_ACCUM_RED_SIZE
:
852 GLint size
= *parselist
++;
853 accumRedSize
= MAX2( accumRedSize
, size
);
856 case GLX_ACCUM_GREEN_SIZE
:
859 GLint size
= *parselist
++;
860 accumGreenSize
= MAX2( accumGreenSize
, size
);
863 case GLX_ACCUM_BLUE_SIZE
:
866 GLint size
= *parselist
++;
867 accumBlueSize
= MAX2( accumBlueSize
, size
);
870 case GLX_ACCUM_ALPHA_SIZE
:
873 GLint size
= *parselist
++;
874 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
879 * GLX_EXT_visual_info extension
881 case GLX_X_VISUAL_TYPE_EXT
:
883 visual_type
= *parselist
++;
885 case GLX_TRANSPARENT_TYPE_EXT
:
889 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
893 case GLX_TRANSPARENT_RED_VALUE_EXT
:
894 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
895 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
896 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
903 * GLX_EXT_visual_info extension
905 case GLX_VISUAL_CAVEAT_EXT
:
907 caveat
= *parselist
++; /* ignored for now */
911 * GLX_ARB_multisample
913 case GLX_SAMPLE_BUFFERS_ARB
:
918 case GLX_SAMPLES_ARB
:
920 num_samples
= *parselist
++;
926 case GLX_RENDER_TYPE
:
930 if (*parselist
& GLX_RGBA_BIT
) {
933 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
936 else if (*parselist
== 0) {
941 case GLX_DRAWABLE_TYPE
:
945 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
946 return NULL
; /* bad bit */
950 case GLX_FBCONFIG_ID
:
955 desiredVisualID
= *parselist
++;
957 case GLX_X_RENDERABLE
:
958 case GLX_MAX_PBUFFER_WIDTH
:
959 case GLX_MAX_PBUFFER_HEIGHT
:
960 case GLX_MAX_PBUFFER_PIXELS
:
962 return NULL
; /* invalid config option */
963 parselist
+= 2; /* ignore the parameter */
966 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
967 parselist
++; /*skip*/
969 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
970 parselist
++; /*skip*/
972 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
973 parselist
++; /*skip*/
975 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
977 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
978 GLX_TEXTURE_2D_BIT_EXT
|
979 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
984 case GLX_Y_INVERTED_EXT
:
985 parselist
++; /*skip*/
993 /* undefined attribute */
994 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1002 if (num_samples
< 0) {
1003 _mesa_warning(NULL
, "GLX_SAMPLES_ARB: number of samples must not be negative");
1008 * Since we're only simulating the GLX extension this function will never
1009 * find any real GL visuals. Instead, all we can do is try to find an RGB
1010 * or CI visual of appropriate depth. Other requested attributes such as
1011 * double buffering, depth buffer, etc. will be associated with the X
1012 * visual and stored in the VisualTable[].
1014 if (desiredVisualID
!= -1) {
1015 /* try to get a specific visual, by visualID */
1018 temp
.visualid
= desiredVisualID
;
1019 temp
.screen
= screen
;
1020 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1022 /* give the visual some useful GLX attributes */
1023 double_flag
= GL_TRUE
;
1027 else if (level
==0) {
1028 /* normal color planes */
1029 /* Get an RGB visual */
1030 int min_rgb
= min_red
+ min_green
+ min_blue
;
1031 if (min_rgb
>1 && min_rgb
<8) {
1032 /* a special case to be sure we can get a monochrome visual */
1035 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
1038 _mesa_warning(NULL
, "overlay not supported");
1043 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1044 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1045 * largest depth buffer size, which is 32bits/value. Instead, we
1046 * return 16 to maintain performance with earlier versions of Mesa.
1048 if (stencil_size
> 0)
1049 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
1050 else if (depth_size
> 24)
1052 else if (depth_size
> 16)
1054 else if (depth_size
> 0) {
1055 depth_size
= default_depth_bits();
1059 alpha_flag
= default_alpha_bits() > 0;
1062 /* we only support one size of stencil and accum buffers. */
1063 if (stencil_size
> 0)
1066 if (accumRedSize
> 0 ||
1067 accumGreenSize
> 0 ||
1068 accumBlueSize
> 0 ||
1069 accumAlphaSize
> 0) {
1073 accumBlueSize
= default_accum_bits();
1075 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1078 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1079 stereo_flag
, depth_size
, stencil_size
,
1080 accumRedSize
, accumGreenSize
,
1081 accumBlueSize
, accumAlphaSize
, level
, numAux
,
1089 PUBLIC XVisualInfo
*
1090 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1094 /* register ourselves as an extension on this display */
1095 register_with_display(dpy
);
1097 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1099 /* create a new vishandle - the cached one may be stale */
1100 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1101 if (xmvis
->vishandle
) {
1102 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1104 return xmvis
->vishandle
;
1112 * Helper function used by other glXCreateContext functions.
1115 create_context(Display
*dpy
, XMesaVisual xmvis
,
1116 XMesaContext shareCtx
, Bool direct
,
1117 unsigned major
, unsigned minor
,
1118 unsigned profileMask
, unsigned contextFlags
)
1125 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1129 /* deallocate unused windows/buffers */
1131 XMesaGarbageCollect();
1134 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
, shareCtx
, major
, minor
,
1135 profileMask
, contextFlags
);
1136 if (!glxCtx
->xmesaContext
) {
1141 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1142 glxCtx
->currentDpy
= dpy
;
1143 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1150 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1151 GLXContext shareCtx
, Bool direct
)
1155 xmvis
= find_glx_visual( dpy
, visinfo
);
1157 /* This visual wasn't found with glXChooseVisual() */
1158 xmvis
= create_glx_visual( dpy
, visinfo
);
1160 /* unusable visual */
1165 return create_context(dpy
, xmvis
,
1166 shareCtx
? shareCtx
->xmesaContext
: NULL
,
1168 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
1172 /* XXX these may have to be removed due to thread-safety issues. */
1173 static GLXContext MakeCurrent_PrevContext
= 0;
1174 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1175 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1176 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1177 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1180 /* GLX 1.3 and later */
1182 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1183 GLXDrawable read
, GLXContext ctx
)
1185 GLXContext glxCtx
= ctx
;
1186 static boolean firsttime
= 1, no_rast
= 0;
1189 no_rast
= getenv("SP_NO_RAST") != NULL
;
1193 if (ctx
&& draw
&& read
) {
1194 XMesaBuffer drawBuffer
, readBuffer
;
1195 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1197 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1198 if (ctx
== MakeCurrent_PrevContext
1199 && draw
== MakeCurrent_PrevDrawable
) {
1200 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1203 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1206 /* drawable must be a new window! */
1207 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1209 /* Out of memory, or context/drawable depth mismatch */
1214 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1215 if (ctx
== MakeCurrent_PrevContext
1216 && read
== MakeCurrent_PrevReadable
) {
1217 readBuffer
= MakeCurrent_PrevReadBuffer
;
1220 readBuffer
= XMesaFindBuffer( dpy
, read
);
1223 /* drawable must be a new window! */
1224 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1226 /* Out of memory, or context/drawable depth mismatch */
1232 MakeCurrent_PrevContext
== ctx
&&
1233 MakeCurrent_PrevDrawable
== draw
&&
1234 MakeCurrent_PrevReadable
== read
&&
1235 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1236 MakeCurrent_PrevReadBuffer
== readBuffer
)
1239 MakeCurrent_PrevContext
= ctx
;
1240 MakeCurrent_PrevDrawable
= draw
;
1241 MakeCurrent_PrevReadable
= read
;
1242 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1243 MakeCurrent_PrevReadBuffer
= readBuffer
;
1245 /* Now make current! */
1246 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1247 ctx
->currentDpy
= dpy
;
1248 ctx
->currentDrawable
= draw
;
1249 ctx
->currentReadable
= read
;
1250 SetCurrentContext(ctx
);
1257 else if (!ctx
&& !draw
&& !read
) {
1258 /* release current context w/out assigning new one. */
1259 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1260 MakeCurrent_PrevContext
= 0;
1261 MakeCurrent_PrevDrawable
= 0;
1262 MakeCurrent_PrevReadable
= 0;
1263 MakeCurrent_PrevDrawBuffer
= 0;
1264 MakeCurrent_PrevReadBuffer
= 0;
1265 SetCurrentContext(NULL
);
1269 /* The args must either all be non-zero or all zero.
1278 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1280 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1285 glXGetCurrentContext(void)
1287 return GetCurrentContext();
1292 glXGetCurrentDisplay(void)
1294 GLXContext glxCtx
= glXGetCurrentContext();
1296 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1301 glXGetCurrentDisplayEXT(void)
1303 return glXGetCurrentDisplay();
1308 glXGetCurrentDrawable(void)
1310 GLXContext gc
= glXGetCurrentContext();
1311 return gc
? gc
->currentDrawable
: 0;
1316 glXGetCurrentReadDrawable(void)
1318 GLXContext gc
= glXGetCurrentContext();
1319 return gc
? gc
->currentReadable
: 0;
1324 glXGetCurrentReadDrawableSGI(void)
1326 return glXGetCurrentReadDrawable();
1331 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1336 v
= find_glx_visual( dpy
, visinfo
);
1338 v
= create_glx_visual( dpy
, visinfo
);
1340 /* unusable visual */
1345 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1349 return b
->ws
.drawable
;
1353 /*** GLX_MESA_pixmap_colormap ***/
1356 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1357 Pixmap pixmap
, Colormap cmap
)
1362 v
= find_glx_visual( dpy
, visinfo
);
1364 v
= create_glx_visual( dpy
, visinfo
);
1366 /* unusable visual */
1371 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1375 return b
->ws
.drawable
;
1380 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1382 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1384 XMesaDestroyBuffer(b
);
1386 else if (getenv("MESA_DEBUG")) {
1387 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1393 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1394 unsigned long mask
)
1396 XMesaContext xm_src
= src
->xmesaContext
;
1397 XMesaContext xm_dst
= dst
->xmesaContext
;
1399 if (MakeCurrent_PrevContext
== src
) {
1402 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1407 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1410 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1411 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1417 return True
; /* we're faking GLX so always return success */
1422 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1425 GLXContext glxCtx
= ctx
;
1427 MakeCurrent_PrevContext
= 0;
1428 MakeCurrent_PrevDrawable
= 0;
1429 MakeCurrent_PrevReadable
= 0;
1430 MakeCurrent_PrevDrawBuffer
= 0;
1431 MakeCurrent_PrevReadBuffer
= 0;
1432 XMesaDestroyContext( glxCtx
->xmesaContext
);
1433 XMesaGarbageCollect();
1440 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1442 return ctx
? ctx
->isDirect
: False
;
1448 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1450 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1451 static boolean firsttime
= 1, no_rast
= 0;
1454 no_rast
= getenv("SP_NO_RAST") != NULL
;
1462 XMesaSwapBuffers(buffer
);
1464 else if (getenv("MESA_DEBUG")) {
1465 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1472 /*** GLX_MESA_copy_sub_buffer ***/
1475 glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
1476 int x
, int y
, int width
, int height
)
1478 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1480 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1482 else if (getenv("MESA_DEBUG")) {
1483 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1489 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1492 /* Return GLX version, not Mesa version */
1493 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1494 *maj
= CLIENT_MAJOR_VERSION
;
1495 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1501 * Query the GLX attributes of the given XVisualInfo.
1504 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1510 return GLX_BAD_ATTRIBUTE
;
1511 *value
= (int) True
;
1513 case GLX_BUFFER_SIZE
:
1514 *value
= xmvis
->visinfo
->depth
;
1517 *value
= xmvis
->mesa_visual
.level
;
1521 return GLX_BAD_ATTRIBUTE
;
1522 if (xmvis
->mesa_visual
.rgbMode
) {
1529 case GLX_DOUBLEBUFFER
:
1530 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1533 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1535 case GLX_AUX_BUFFERS
:
1536 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1539 *value
= xmvis
->mesa_visual
.redBits
;
1541 case GLX_GREEN_SIZE
:
1542 *value
= xmvis
->mesa_visual
.greenBits
;
1545 *value
= xmvis
->mesa_visual
.blueBits
;
1547 case GLX_ALPHA_SIZE
:
1548 *value
= xmvis
->mesa_visual
.alphaBits
;
1550 case GLX_DEPTH_SIZE
:
1551 *value
= xmvis
->mesa_visual
.depthBits
;
1553 case GLX_STENCIL_SIZE
:
1554 *value
= xmvis
->mesa_visual
.stencilBits
;
1556 case GLX_ACCUM_RED_SIZE
:
1557 *value
= xmvis
->mesa_visual
.accumRedBits
;
1559 case GLX_ACCUM_GREEN_SIZE
:
1560 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1562 case GLX_ACCUM_BLUE_SIZE
:
1563 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1565 case GLX_ACCUM_ALPHA_SIZE
:
1566 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1570 * GLX_EXT_visual_info extension
1572 case GLX_X_VISUAL_TYPE_EXT
:
1573 switch (xmvis
->visinfo
->CLASS
) {
1574 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1575 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1576 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1577 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1578 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1579 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1582 case GLX_TRANSPARENT_TYPE_EXT
:
1584 *value
= GLX_NONE_EXT
;
1586 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1589 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1592 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1595 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1598 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1603 * GLX_EXT_visual_info extension
1605 case GLX_VISUAL_CAVEAT_EXT
:
1606 /* test for zero, just in case */
1607 if (xmvis
->mesa_visual
.visualRating
> 0)
1608 *value
= xmvis
->mesa_visual
.visualRating
;
1610 *value
= GLX_NONE_EXT
;
1614 * GLX_ARB_multisample
1616 case GLX_SAMPLE_BUFFERS_ARB
:
1617 *value
= xmvis
->mesa_visual
.sampleBuffers
;
1619 case GLX_SAMPLES_ARB
:
1620 *value
= xmvis
->mesa_visual
.samples
;
1626 case GLX_SCREEN_EXT
:
1628 return GLX_BAD_ATTRIBUTE
;
1629 *value
= xmvis
->visinfo
->screen
;
1631 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1633 return GLX_BAD_ATTRIBUTE
;
1634 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1636 case GLX_RENDER_TYPE_SGIX
:
1638 return GLX_BAD_ATTRIBUTE
;
1639 if (xmvis
->mesa_visual
.rgbMode
)
1640 *value
= GLX_RGBA_BIT
;
1642 *value
= GLX_COLOR_INDEX_BIT
;
1644 case GLX_X_RENDERABLE_SGIX
:
1646 return GLX_BAD_ATTRIBUTE
;
1647 *value
= True
; /* XXX really? */
1649 case GLX_FBCONFIG_ID_SGIX
:
1651 return GLX_BAD_ATTRIBUTE
;
1652 *value
= xmvis
->visinfo
->visualid
;
1654 case GLX_MAX_PBUFFER_WIDTH
:
1656 return GLX_BAD_ATTRIBUTE
;
1657 /* XXX should be same as ctx->Const.MaxRenderbufferSize */
1658 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1660 case GLX_MAX_PBUFFER_HEIGHT
:
1662 return GLX_BAD_ATTRIBUTE
;
1663 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1665 case GLX_MAX_PBUFFER_PIXELS
:
1667 return GLX_BAD_ATTRIBUTE
;
1668 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1669 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1673 return GLX_BAD_ATTRIBUTE
;
1674 *value
= xmvis
->visinfo
->visualid
;
1677 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1678 *value
= True
; /*XXX*/
1680 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1682 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1684 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1685 *value
= True
; /*XXX*/
1687 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1688 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1689 GLX_TEXTURE_2D_BIT_EXT
|
1690 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1692 case GLX_Y_INVERTED_EXT
:
1693 *value
= True
; /*XXX*/
1697 return GLX_BAD_ATTRIBUTE
;
1704 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1705 int attrib
, int *value
)
1709 if (!dpy
|| !visinfo
)
1710 return GLX_BAD_ATTRIBUTE
;
1712 xmvis
= find_glx_visual( dpy
, visinfo
);
1714 /* this visual wasn't obtained with glXChooseVisual */
1715 xmvis
= create_glx_visual( dpy
, visinfo
);
1717 /* this visual can't be used for GL rendering */
1718 if (attrib
==GLX_USE_GL
) {
1719 *value
= (int) False
;
1723 return GLX_BAD_VISUAL
;
1728 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1736 XMesaContext xmesa
= XMesaGetCurrentContext();
1737 XMesaFlush( xmesa
);
1745 XMesaContext xmesa
= XMesaGetCurrentContext();
1746 XMesaFlush( xmesa
);
1751 get_extensions( void )
1758 /* GLX 1.1 and later */
1760 glXQueryExtensionsString( Display
*dpy
, int screen
)
1764 return get_extensions();
1769 /* GLX 1.1 and later */
1771 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1773 static char version
[1000];
1774 sprintf(version
, "%d.%d %s",
1775 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, xmesa_get_name());
1781 case GLX_EXTENSIONS
:
1782 return get_extensions();
1794 /* GLX 1.1 and later */
1796 glXGetClientString( Display
*dpy
, int name
)
1798 static char version
[1000];
1799 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1800 CLIENT_MINOR_VERSION
, xmesa_get_name());
1805 case GLX_EXTENSIONS
:
1806 return get_extensions();
1824 glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1825 int attribute
, int *value
)
1827 XMesaVisual v
= (XMesaVisual
) config
;
1831 if (!dpy
|| !config
|| !value
)
1834 return get_config(v
, attribute
, value
, GL_TRUE
);
1838 PUBLIC GLXFBConfig
*
1839 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1841 XVisualInfo
*visuals
, visTemplate
;
1842 const long visMask
= VisualScreenMask
;
1845 /* Get list of all X visuals */
1846 visTemplate
.screen
= screen
;
1847 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1848 if (*nelements
> 0) {
1849 XMesaVisual
*results
= malloc(*nelements
* sizeof(XMesaVisual
));
1854 for (i
= 0; i
< *nelements
; i
++) {
1855 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1861 return (GLXFBConfig
*) results
;
1867 PUBLIC GLXFBConfig
*
1868 glXChooseFBConfig(Display
*dpy
, int screen
,
1869 const int *attribList
, int *nitems
)
1873 /* register ourselves as an extension on this display */
1874 register_with_display(dpy
);
1876 if (!attribList
|| !attribList
[0]) {
1877 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1878 return glXGetFBConfigs(dpy
, screen
, nitems
);
1881 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1883 GLXFBConfig
*config
= malloc(sizeof(XMesaVisual
));
1889 config
[0] = (GLXFBConfig
) xmvis
;
1890 return (GLXFBConfig
*) config
;
1899 PUBLIC XVisualInfo
*
1900 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1902 if (dpy
&& config
) {
1903 XMesaVisual xmvis
= (XMesaVisual
) config
;
1905 return xmvis
->vishandle
;
1907 /* create a new vishandle - the cached one may be stale */
1908 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1909 if (xmvis
->vishandle
) {
1910 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1912 return xmvis
->vishandle
;
1922 glXCreateWindow(Display
*dpy
, GLXFBConfig config
, Window win
,
1923 const int *attribList
)
1925 XMesaVisual xmvis
= (XMesaVisual
) config
;
1930 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1935 (void) attribList
; /* Ignored in GLX 1.3 */
1937 return win
; /* A hack for now */
1942 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1944 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1946 XMesaDestroyBuffer(b
);
1947 /* don't destroy X window */
1953 glXCreatePixmap(Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1954 const int *attribList
)
1956 XMesaVisual v
= (XMesaVisual
) config
;
1959 int target
= 0, format
= 0, mipmap
= 0;
1962 if (!dpy
|| !config
|| !pixmap
)
1965 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1967 case GLX_TEXTURE_FORMAT_EXT
:
1970 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1971 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1972 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1980 case GLX_TEXTURE_TARGET_EXT
:
1983 case GLX_TEXTURE_1D_EXT
:
1984 case GLX_TEXTURE_2D_EXT
:
1985 case GLX_TEXTURE_RECTANGLE_EXT
:
1993 case GLX_MIPMAP_TEXTURE_EXT
:
2004 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
2005 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
2006 &value
, GL_TRUE
) != Success
2008 return 0; /* error! */
2011 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2012 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2013 &value
, GL_TRUE
) != Success
2015 return 0; /* error! */
2019 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2020 &value
, GL_TRUE
) != Success
2022 return 0; /* error! */
2025 if (target
== GLX_TEXTURE_1D_EXT
) {
2026 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2027 &value
, GL_TRUE
) != Success
2028 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2029 return 0; /* error! */
2032 else if (target
== GLX_TEXTURE_2D_EXT
) {
2033 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2034 &value
, GL_TRUE
) != Success
2035 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2036 return 0; /* error! */
2039 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2040 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2041 &value
, GL_TRUE
) != Success
2042 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2043 return 0; /* error! */
2047 if (format
|| target
|| mipmap
) {
2048 /* texture from pixmap */
2049 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2052 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2063 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2065 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
2067 XMesaDestroyBuffer(b
);
2068 /* don't destroy X pixmap */
2073 glXCreatePbuffer(Display
*dpy
, GLXFBConfig config
, const int *attribList
)
2075 XMesaVisual xmvis
= (XMesaVisual
) config
;
2078 int width
= 0, height
= 0;
2079 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2083 for (attrib
= attribList
; *attrib
; attrib
++) {
2085 case GLX_PBUFFER_WIDTH
:
2089 case GLX_PBUFFER_HEIGHT
:
2093 case GLX_PRESERVED_CONTENTS
:
2095 preserveContents
= *attrib
;
2097 case GLX_LARGEST_PBUFFER
:
2099 useLargest
= *attrib
;
2106 if (width
== 0 || height
== 0)
2109 if (width
> PBUFFER_MAX_SIZE
|| height
> PBUFFER_MAX_SIZE
) {
2110 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2111 * allocate the largest possible buffer.
2114 width
= PBUFFER_MAX_SIZE
;
2115 height
= PBUFFER_MAX_SIZE
;
2119 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2120 /* A GLXPbuffer handle must be an X Drawable because that's what
2121 * glXMakeCurrent takes.
2124 xmbuf
->largestPbuffer
= useLargest
;
2125 xmbuf
->preservedContents
= preserveContents
;
2126 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2135 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2137 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2139 XMesaDestroyBuffer(b
);
2145 glXQueryDrawable(Display
*dpy
, GLXDrawable draw
, int attribute
,
2146 unsigned int *value
)
2148 GLuint width
, height
;
2149 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2151 generate_error(dpy
, GLXBadDrawable
, draw
, X_GLXGetDrawableAttributes
, False
);
2155 /* make sure buffer's dimensions are up to date */
2156 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2158 switch (attribute
) {
2165 case GLX_PRESERVED_CONTENTS
:
2166 *value
= xmbuf
->preservedContents
;
2168 case GLX_LARGEST_PBUFFER
:
2169 *value
= xmbuf
->largestPbuffer
;
2171 case GLX_FBCONFIG_ID
:
2172 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2174 case GLX_TEXTURE_FORMAT_EXT
:
2175 *value
= xmbuf
->TextureFormat
;
2177 case GLX_TEXTURE_TARGET_EXT
:
2178 *value
= xmbuf
->TextureTarget
;
2180 case GLX_MIPMAP_TEXTURE_EXT
:
2181 *value
= xmbuf
->TextureMipmap
;
2185 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, true);
2192 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2193 int renderType
, GLXContext shareCtx
, Bool direct
)
2195 XMesaVisual xmvis
= (XMesaVisual
) config
;
2197 if (!dpy
|| !config
||
2198 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2201 return create_context(dpy
, xmvis
,
2202 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2204 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2209 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2211 GLXContext glxCtx
= ctx
;
2212 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2217 switch (attribute
) {
2218 case GLX_FBCONFIG_ID
:
2219 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2221 case GLX_RENDER_TYPE
:
2222 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2223 *value
= GLX_RGBA_TYPE
;
2225 *value
= GLX_COLOR_INDEX_TYPE
;
2231 return GLX_BAD_ATTRIBUTE
;
2238 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2240 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2242 xmbuf
->selectedEvents
= mask
;
2247 glXGetSelectedEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2249 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2251 *mask
= xmbuf
->selectedEvents
;
2258 /*** GLX_SGI_swap_control ***/
2261 glXSwapIntervalSGI(int interval
)
2269 /*** GLX_SGI_video_sync ***/
2271 static unsigned int FrameCounter
= 0;
2274 glXGetVideoSyncSGI(unsigned int *count
)
2276 /* this is a bogus implementation */
2277 *count
= FrameCounter
++;
2282 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2284 if (divisor
<= 0 || remainder
< 0)
2285 return GLX_BAD_VALUE
;
2286 /* this is a bogus implementation */
2288 while (FrameCounter
% divisor
!= remainder
)
2290 *count
= FrameCounter
;
2296 /*** GLX_SGI_make_current_read ***/
2299 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
,
2302 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2307 glXGetCurrentReadDrawableSGI(void)
2314 /*** GLX_SGIX_video_source ***/
2317 PUBLIC GLXVideoSourceSGIX
2318 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
,
2319 VLPath path
, int nodeClass
, VLNode drainNode
)
2331 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2340 /*** GLX_EXT_import_context ***/
2343 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2350 glXGetContextIDEXT(const GLXContext context
)
2357 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2365 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
,
2377 /*** GLX_SGIX_fbconfig ***/
2380 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2381 int attribute
, int *value
)
2383 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2386 PUBLIC GLXFBConfigSGIX
*
2387 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
,
2390 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
,
2391 attrib_list
, nelements
);
2396 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2399 XMesaVisual xmvis
= (XMesaVisual
) config
;
2400 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2401 return xmbuf
->ws
.drawable
; /* need to return an X ID */
2406 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2407 int renderType
, GLXContext shareCtx
,
2410 XMesaVisual xmvis
= (XMesaVisual
) config
;
2412 if (!dpy
|| !config
||
2413 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2416 return create_context(dpy
, xmvis
,
2417 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2419 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2423 PUBLIC XVisualInfo
*
2424 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2426 return glXGetVisualFromFBConfig(dpy
, config
);
2430 PUBLIC GLXFBConfigSGIX
2431 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2433 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2435 /* This visual wasn't found with glXChooseVisual() */
2436 xmvis
= create_glx_visual(dpy
, vis
);
2439 return (GLXFBConfigSGIX
) xmvis
;
2444 /*** GLX_SGIX_pbuffer ***/
2446 PUBLIC GLXPbufferSGIX
2447 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2448 unsigned int width
, unsigned int height
,
2451 XMesaVisual xmvis
= (XMesaVisual
) config
;
2454 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2458 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2460 case GLX_PRESERVED_CONTENTS_SGIX
:
2462 preserveContents
= *attrib
; /* ignored */
2464 case GLX_LARGEST_PBUFFER_SGIX
:
2466 useLargest
= *attrib
; /* ignored */
2473 /* not used at this time */
2475 (void) preserveContents
;
2477 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2478 /* A GLXPbuffer handle must be an X Drawable because that's what
2479 * glXMakeCurrent takes.
2481 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2486 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2488 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2490 XMesaDestroyBuffer(xmbuf
);
2496 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
,
2497 unsigned int *value
)
2499 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2502 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2506 switch (attribute
) {
2507 case GLX_PRESERVED_CONTENTS_SGIX
:
2510 case GLX_LARGEST_PBUFFER_SGIX
:
2511 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2513 case GLX_WIDTH_SGIX
:
2514 *value
= xmesa_buffer_width(xmbuf
);
2516 case GLX_HEIGHT_SGIX
:
2517 *value
= xmesa_buffer_height(xmbuf
);
2519 case GLX_EVENT_MASK_SGIX
:
2520 *value
= 0; /* XXX might be wrong */
2530 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2532 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2534 /* Note: we'll never generate clobber events */
2535 xmbuf
->selectedEvents
= mask
;
2541 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
,
2542 unsigned long *mask
)
2544 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2546 *mask
= xmbuf
->selectedEvents
;
2555 /*** GLX_SGI_cushion ***/
2558 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2567 /*** GLX_SGIX_video_resize ***/
2570 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
,
2581 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2582 int x
, int y
, int w
, int h
)
2595 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2596 int *x
, int *y
, int *w
, int *h
)
2609 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
,
2610 int *dx
, int *dy
, int *dw
, int *dh
)
2623 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2634 /*** GLX_SGIX_dmbuffer **/
2636 #if defined(_DM_BUFFER_H_)
2638 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
,
2639 DMparams
*params
, DMbuffer dmbuffer
)
2650 /*** GLX_SGIX_swap_group ***/
2653 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2662 /*** GLX_SUN_get_transparent_index ***/
2665 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
,
2671 (void) pTransparent
;
2677 /*** GLX_MESA_release_buffers ***/
2680 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2681 * (a window or pixmap) prior to destroying the GLXDrawable.
2684 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2686 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2688 XMesaDestroyBuffer(b
);
2694 /*** GLX_EXT_texture_from_pixmap ***/
2697 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2698 const int *attrib_list
)
2700 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2702 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2706 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2708 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2710 XMesaReleaseTexImage(dpy
, b
, buffer
);
2715 /*** GLX_ARB_create_context ***/
2719 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
2720 GLXContext shareCtx
, Bool direct
,
2721 const int *attrib_list
)
2723 XMesaVisual xmvis
= (XMesaVisual
) config
;
2724 int majorVersion
= 1, minorVersion
= 0;
2725 int contextFlags
= 0x0;
2726 int profileMask
= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
;
2727 int renderType
= GLX_RGBA_TYPE
;
2730 const int contextFlagsAll
= (GLX_CONTEXT_DEBUG_BIT_ARB
|
2731 GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
);
2734 /* parse attrib_list */
2735 for (i
= 0; !done
&& attrib_list
&& attrib_list
[i
]; i
++) {
2736 switch (attrib_list
[i
]) {
2737 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2738 majorVersion
= attrib_list
[++i
];
2740 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2741 minorVersion
= attrib_list
[++i
];
2743 case GLX_CONTEXT_FLAGS_ARB
:
2744 contextFlags
= attrib_list
[++i
];
2746 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2747 profileMask
= attrib_list
[++i
];
2749 case GLX_RENDER_TYPE
:
2750 renderType
= attrib_list
[++i
];
2758 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2763 /* check contextFlags */
2764 if (contextFlags
& ~contextFlagsAll
) {
2765 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2769 /* check profileMask */
2770 if (profileMask
!= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
&&
2771 profileMask
!= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
&&
2772 profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
) {
2773 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAttribsARB
, False
);
2777 /* check renderType */
2778 if (renderType
!= GLX_RGBA_TYPE
&&
2779 renderType
!= GLX_COLOR_INDEX_TYPE
) {
2780 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2785 if (majorVersion
<= 0 ||
2787 (profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2788 ((majorVersion
== 1 && minorVersion
> 5) ||
2789 (majorVersion
== 2 && minorVersion
> 1) ||
2790 (majorVersion
== 3 && minorVersion
> 3) ||
2791 (majorVersion
== 4 && minorVersion
> 5) ||
2792 majorVersion
> 4))) {
2793 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2796 if (profileMask
== GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2797 ((majorVersion
== 1 && minorVersion
> 1) ||
2798 (majorVersion
== 2 && minorVersion
> 0) ||
2799 (majorVersion
== 3 && minorVersion
> 1) ||
2800 majorVersion
> 3)) {
2801 /* GLX_EXT_create_context_es2_profile says nothing to justifying a
2802 * different error code for invalid ES versions, but this is what NVIDIA
2803 * does and piglit expects.
2805 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAttribsARB
, False
);
2809 if ((contextFlags
& GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
) &&
2811 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2815 if (renderType
== GLX_COLOR_INDEX_TYPE
&& majorVersion
>= 3) {
2816 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2820 ctx
= create_context(dpy
, xmvis
,
2821 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2823 majorVersion
, minorVersion
,
2824 profileMask
, contextFlags
);
2826 generate_error(dpy
, GLXBadFBConfig
, 0, X_GLXCreateContextAttribsARB
, False
);