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>
42 #include "main/imports.h"
43 #include "main/errors.h"
44 #include "util/u_math.h"
46 /* An "Atrribs/Attribs" typo was fixed in glxproto.h in Nov 2014.
47 * This is in case we don't have the updated header.
49 #if !defined(X_GLXCreateContextAttribsARB) && \
50 defined(X_GLXCreateContextAtrribsARB)
51 #define X_GLXCreateContextAttribsARB X_GLXCreateContextAtrribsARB
54 /* This indicates the client-side GLX API and GLX encoder version. */
55 #define CLIENT_MAJOR_VERSION 1
56 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
58 /* This indicates the server-side GLX decoder version.
59 * GLX 1.4 indicates OpenGL 1.3 support
61 #define SERVER_MAJOR_VERSION 1
62 #define SERVER_MINOR_VERSION 4
64 /* Who implemented this GLX? */
65 #define VENDOR "Brian Paul"
68 "GLX_MESA_copy_sub_buffer " \
69 "GLX_MESA_pixmap_colormap " \
70 "GLX_MESA_release_buffers " \
71 "GLX_ARB_create_context " \
72 "GLX_ARB_create_context_profile " \
73 "GLX_ARB_get_proc_address " \
74 "GLX_EXT_create_context_es_profile " \
75 "GLX_EXT_create_context_es2_profile " \
76 "GLX_EXT_texture_from_pixmap " \
77 "GLX_EXT_visual_info " \
78 "GLX_EXT_visual_rating " \
79 /*"GLX_SGI_video_sync "*/ \
80 "GLX_SGIX_fbconfig " \
83 #define DEFAULT_DIRECT GL_TRUE
86 /** XXX this could be based on gallium's max texture size */
87 #define PBUFFER_MAX_SIZE 16384
91 * The GLXContext typedef is defined as a pointer to this structure.
93 struct __GLXcontextRec
97 GLXDrawable currentDrawable
;
98 GLXDrawable currentReadable
;
101 XMesaContext xmesaContext
;
106 static pipe_tsd ContextTSD
;
108 /** Set current context for calling thread */
110 SetCurrentContext(GLXContext c
)
112 pipe_tsd_set(&ContextTSD
, c
);
115 /** Get current context for calling thread */
117 GetCurrentContext(void)
119 return pipe_tsd_get(&ContextTSD
);
124 /**********************************************************************/
125 /*** GLX Visual Code ***/
126 /**********************************************************************/
131 static XMesaVisual
*VisualTable
= NULL
;
132 static int NumVisuals
= 0;
136 /* Macro to handle c_class vs class field name in XVisualInfo struct */
137 #if defined(__cplusplus) || defined(c_plusplus)
138 #define CLASS c_class
146 * Test if the given XVisualInfo is usable for Mesa rendering.
149 is_usable_visual( XVisualInfo
*vinfo
)
151 switch (vinfo
->CLASS
) {
154 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
158 /* Any StaticColor/PseudoColor visual of at least 4 bits */
159 if (vinfo
->depth
>=4) {
167 /* Any depth of TrueColor or DirectColor works in RGB mode */
170 /* This should never happen */
177 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
178 * configuration in our list of GLX visuals.
181 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
182 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
183 GLboolean stereoFlag
,
184 GLint depth_size
, GLint stencil_size
,
185 GLint accumRedSize
, GLint accumGreenSize
,
186 GLint accumBlueSize
, GLint accumAlphaSize
,
187 GLint level
, GLint numAuxBuffers
, GLuint num_samples
)
189 GLboolean ximageFlag
= GL_TRUE
;
192 GLboolean comparePointers
;
195 /* Check if the MESA_BACK_BUFFER env var is set */
196 char *backbuffer
= getenv("MESA_BACK_BUFFER");
198 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
199 ximageFlag
= GL_FALSE
;
201 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
202 ximageFlag
= GL_TRUE
;
205 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
211 /* stereo not supported */
215 if (stencil_size
> 0 && depth_size
> 0)
218 /* Comparing IDs uses less memory but sometimes fails. */
219 /* XXX revisit this after 3.0 is finished. */
220 if (getenv("MESA_GLX_VISUAL_HACK"))
221 comparePointers
= GL_TRUE
;
223 comparePointers
= GL_FALSE
;
225 /* Force the visual to have an alpha channel */
226 if (rgbFlag
&& getenv("MESA_GLX_FORCE_ALPHA"))
229 /* First check if a matching visual is already in the list */
230 for (i
=0; i
<NumVisuals
; i
++) {
231 XMesaVisual v
= VisualTable
[i
];
232 if (v
->display
== dpy
233 && v
->mesa_visual
.level
== level
234 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
235 && v
->mesa_visual
.samples
== num_samples
236 && v
->ximage_flag
== ximageFlag
237 && v
->mesa_visual
.rgbMode
== rgbFlag
238 && v
->mesa_visual
.doubleBufferMode
== dbFlag
239 && v
->mesa_visual
.stereoMode
== stereoFlag
240 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
241 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
242 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
243 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
244 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
245 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
246 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
247 /* now either compare XVisualInfo pointers or visual IDs */
248 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
249 || (comparePointers
&& v
->vishandle
== vinfo
)) {
255 /* Create a new visual and add it to the list. */
257 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
258 stereoFlag
, ximageFlag
,
259 depth_size
, stencil_size
,
260 accumRedSize
, accumBlueSize
,
261 accumBlueSize
, accumAlphaSize
, num_samples
, level
,
264 /* Save a copy of the pointer now so we can find this visual again
265 * if we need to search for it in find_glx_visual().
267 xmvis
->vishandle
= vinfo
;
268 /* Allocate more space for additional visual */
269 VisualTable
= realloc(VisualTable
, sizeof(XMesaVisual
) * (NumVisuals
+ 1));
270 /* add xmvis to the list */
271 VisualTable
[NumVisuals
] = xmvis
;
273 /* XXX minor hack, because XMesaCreateVisual doesn't support an
274 * aux buffers parameter.
276 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
283 * Return the default number of bits for the Z buffer.
284 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
285 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
286 * XXX probably do the same thing for stencil, accum, etc.
289 default_depth_bits(void)
292 const char *zEnv
= getenv("MESA_GLX_DEPTH_BITS");
301 default_alpha_bits(void)
304 const char *aEnv
= getenv("MESA_GLX_ALPHA_BITS");
313 default_accum_bits(void)
321 * Create a GLX visual from a regular XVisualInfo.
322 * This is called when Fake GLX is given an XVisualInfo which wasn't
323 * returned by glXChooseVisual. Since this is the first time we're
324 * considering this visual we'll take a guess at reasonable values
325 * for depth buffer size, stencil size, accum size, etc.
326 * This is the best we can do with a client-side emulation of GLX.
329 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
331 GLint zBits
= default_depth_bits();
332 GLint accBits
= default_accum_bits();
333 GLboolean alphaFlag
= default_alpha_bits() > 0;
335 if (is_usable_visual( visinfo
)) {
336 /* Configure this visual as RGB, double-buffered, depth-buffered. */
337 /* This is surely wrong for some people's needs but what else */
338 /* can be done? They should use glXChooseVisual(). */
339 return save_glx_visual( dpy
, visinfo
,
341 alphaFlag
, /* alpha */
342 GL_TRUE
, /* double */
343 GL_FALSE
, /* stereo */
345 8, /* stencil bits */
356 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
364 * Find the GLX visual associated with an XVisualInfo.
367 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
371 /* try to match visual id */
372 for (i
=0;i
<NumVisuals
;i
++) {
373 if (VisualTable
[i
]->display
==dpy
374 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
375 return VisualTable
[i
];
379 /* if that fails, try to match pointers */
380 for (i
=0;i
<NumVisuals
;i
++) {
381 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
382 return VisualTable
[i
];
391 * Try to get an X visual which matches the given arguments.
394 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
396 XVisualInfo temp
, *vis
;
399 unsigned int default_depth
;
402 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
407 default_depth
= DefaultDepth(dpy
,scr
);
408 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
410 if (depth
==default_depth
&& xclass
==default_class
) {
411 /* try to get root window's visual */
412 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
413 mask
|= VisualIDMask
;
416 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
418 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
419 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
420 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
422 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
423 if (util_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
424 util_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
425 util_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
439 * Retrieve the value of the given environment variable and find
440 * the X visual which matches it.
441 * Input: dpy - the display
442 * screen - the screen number
443 * varname - the name of the environment variable
444 * Return: an XVisualInfo pointer to NULL if error.
447 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
449 char value
[100], type
[100];
450 int depth
, xclass
= -1;
453 if (!getenv( varname
)) {
457 strncpy( value
, getenv(varname
), 100 );
460 sscanf( value
, "%s %d", type
, &depth
);
462 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
463 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
464 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
465 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
466 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
467 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
469 if (xclass
>-1 && depth
>0) {
470 vis
= get_visual( dpy
, scr
, depth
, xclass
);
476 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
485 * Select an X visual which satisfies the RGBA flag and minimum depth.
487 * screen - X display and screen number
488 * min_depth - minimum visual depth
489 * preferred_class - preferred GLX visual class or DONT_CARE
490 * Return: pointer to an XVisualInfo or NULL.
493 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
494 int preferred_class
)
497 int xclass
, visclass
= 0;
500 /* First see if the MESA_RGB_VISUAL env var is defined */
501 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
505 /* Otherwise, search for a suitable visual */
506 if (preferred_class
==DONT_CARE
) {
507 for (xclass
=0;xclass
<6;xclass
++) {
509 case 0: visclass
= TrueColor
; break;
510 case 1: visclass
= DirectColor
; break;
511 case 2: visclass
= PseudoColor
; break;
512 case 3: visclass
= StaticColor
; break;
513 case 4: visclass
= GrayScale
; break;
514 case 5: visclass
= StaticGray
; break;
517 /* start with shallowest */
518 for (depth
=0;depth
<=32;depth
++) {
519 if (visclass
==TrueColor
&& depth
==8) {
520 /* Special case: try to get 8-bit PseudoColor before */
521 /* 8-bit TrueColor */
522 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
527 vis
= get_visual( dpy
, screen
, depth
, visclass
);
534 /* start with deepest */
535 for (depth
=32;depth
>=min_depth
;depth
--) {
536 if (visclass
==TrueColor
&& depth
==8) {
537 /* Special case: try to get 8-bit PseudoColor before */
538 /* 8-bit TrueColor */
539 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
544 vis
= get_visual( dpy
, screen
, depth
, visclass
);
553 /* search for a specific visual class */
554 switch (preferred_class
) {
555 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
556 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
557 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
558 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
559 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
560 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
561 default: return NULL
;
564 /* start with shallowest */
565 for (depth
=0;depth
<=32;depth
++) {
566 vis
= get_visual( dpy
, screen
, depth
, visclass
);
573 /* start with deepest */
574 for (depth
=32;depth
>=min_depth
;depth
--) {
575 vis
= get_visual( dpy
, screen
, depth
, visclass
);
583 /* didn't find a visual */
590 /**********************************************************************/
591 /*** Display-related functions ***/
592 /**********************************************************************/
596 * Free all XMesaVisuals which are associated with the given display.
599 destroy_visuals_on_display(Display
*dpy
)
602 for (i
= 0; i
< NumVisuals
; i
++) {
603 if (VisualTable
[i
]->display
== dpy
) {
604 /* remove this visual */
606 free(VisualTable
[i
]);
607 for (j
= i
; j
< NumVisuals
- 1; j
++)
608 VisualTable
[j
] = VisualTable
[j
+ 1];
616 * Called from XCloseDisplay() to let us free our display-related data.
619 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
621 xmesa_destroy_buffers_on_display(dpy
);
622 destroy_visuals_on_display(dpy
);
623 xmesa_close_display(dpy
);
629 * Look for the named extension on given display and return a pointer
630 * to the _XExtension data, or NULL if extension not found.
633 lookup_extension(Display
*dpy
, const char *extName
)
636 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
637 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
646 * Whenever we're given a new Display pointer, call this function to
647 * register our close_display_callback function.
650 register_with_display(Display
*dpy
)
652 const char *extName
= "MesaGLX";
655 ext
= lookup_extension(dpy
, extName
);
657 XExtCodes
*c
= XAddExtension(dpy
);
658 ext
= dpy
->ext_procs
; /* new extension is at head of list */
659 assert(c
->extension
== ext
->codes
.extension
);
661 ext
->name
= strdup(extName
);
662 ext
->close_display
= close_display_callback
;
671 generate_error(Display
*dpy
,
672 unsigned char error_code
,
674 unsigned char minor_code
,
677 XErrorHandler handler
;
683 handler
= XSetErrorHandler(NULL
);
684 XSetErrorHandler(handler
);
689 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_opcode
, &first_event
, &first_error
)) {
696 error_code
+= first_error
;
699 memset(&event
, 0, sizeof event
);
701 event
.xerror
.type
= X_Error
;
702 event
.xerror
.display
= dpy
;
703 event
.xerror
.resourceid
= resourceid
;
704 event
.xerror
.serial
= NextRequest(dpy
) - 1;
705 event
.xerror
.error_code
= error_code
;
706 event
.xerror
.request_code
= major_opcode
;
707 event
.xerror
.minor_code
= minor_code
;
709 return handler(dpy
, &event
.xerror
);
713 /**********************************************************************/
714 /*** Begin Fake GLX API Functions ***/
715 /**********************************************************************/
719 * Helper used by glXChooseVisual and glXChooseFBConfig.
720 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
722 * In either case, the attribute list is terminated with the value 'None'.
725 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
727 const GLboolean rgbModeDefault
= fbConfig
;
728 const int *parselist
;
730 int min_red
=0, min_green
=0, min_blue
=0;
731 GLboolean rgb_flag
= rgbModeDefault
;
732 GLboolean alpha_flag
= GL_FALSE
;
733 GLboolean double_flag
= GL_FALSE
;
734 GLboolean stereo_flag
= GL_FALSE
;
735 GLint depth_size
= 0;
736 GLint stencil_size
= 0;
737 GLint accumRedSize
= 0;
738 GLint accumGreenSize
= 0;
739 GLint accumBlueSize
= 0;
740 GLint accumAlphaSize
= 0;
742 int visual_type
= DONT_CARE
;
743 GLint caveat
= DONT_CARE
;
744 XMesaVisual xmvis
= NULL
;
745 int desiredVisualID
= -1;
747 GLint num_samples
= 0;
749 if (xmesa_init( dpy
) != 0) {
750 _mesa_warning(NULL
, "Failed to initialize display");
759 parselist
[1] == GLX_DONT_CARE
&&
760 parselist
[0] != GLX_LEVEL
) {
761 /* For glXChooseFBConfig(), skip attributes whose value is
762 * GLX_DONT_CARE, unless it's GLX_LEVEL (which can legitimately be
765 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
766 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
772 switch (*parselist
) {
783 case GLX_BUFFER_SIZE
:
789 level
= *parselist
++;
801 case GLX_DOUBLEBUFFER
:
804 double_flag
= *parselist
++;
807 double_flag
= GL_TRUE
;
813 stereo_flag
= *parselist
++;
816 stereo_flag
= GL_TRUE
;
819 case GLX_AUX_BUFFERS
:
821 numAux
= *parselist
++;
822 if (numAux
> MAX_AUX_BUFFERS
)
827 min_red
= *parselist
++;
831 min_green
= *parselist
++;
835 min_blue
= *parselist
++;
840 GLint size
= *parselist
++;
841 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
846 depth_size
= *parselist
++;
848 case GLX_STENCIL_SIZE
:
850 stencil_size
= *parselist
++;
852 case GLX_ACCUM_RED_SIZE
:
855 GLint size
= *parselist
++;
856 accumRedSize
= MAX2( accumRedSize
, size
);
859 case GLX_ACCUM_GREEN_SIZE
:
862 GLint size
= *parselist
++;
863 accumGreenSize
= MAX2( accumGreenSize
, size
);
866 case GLX_ACCUM_BLUE_SIZE
:
869 GLint size
= *parselist
++;
870 accumBlueSize
= MAX2( accumBlueSize
, size
);
873 case GLX_ACCUM_ALPHA_SIZE
:
876 GLint size
= *parselist
++;
877 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
882 * GLX_EXT_visual_info extension
884 case GLX_X_VISUAL_TYPE_EXT
:
886 visual_type
= *parselist
++;
888 case GLX_TRANSPARENT_TYPE_EXT
:
892 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
896 case GLX_TRANSPARENT_RED_VALUE_EXT
:
897 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
898 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
899 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
906 * GLX_EXT_visual_info extension
908 case GLX_VISUAL_CAVEAT_EXT
:
910 caveat
= *parselist
++; /* ignored for now */
914 * GLX_ARB_multisample
916 case GLX_SAMPLE_BUFFERS_ARB
:
921 case GLX_SAMPLES_ARB
:
923 num_samples
= *parselist
++;
929 case GLX_RENDER_TYPE
:
933 if (*parselist
& GLX_RGBA_BIT
) {
936 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
939 else if (*parselist
== 0) {
944 case GLX_DRAWABLE_TYPE
:
948 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
949 return NULL
; /* bad bit */
953 case GLX_FBCONFIG_ID
:
958 desiredVisualID
= *parselist
++;
960 case GLX_X_RENDERABLE
:
961 case GLX_MAX_PBUFFER_WIDTH
:
962 case GLX_MAX_PBUFFER_HEIGHT
:
963 case GLX_MAX_PBUFFER_PIXELS
:
965 return NULL
; /* invalid config option */
966 parselist
+= 2; /* ignore the parameter */
969 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
970 parselist
++; /*skip*/
972 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
973 parselist
++; /*skip*/
975 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
976 parselist
++; /*skip*/
978 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
980 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
981 GLX_TEXTURE_2D_BIT_EXT
|
982 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
987 case GLX_Y_INVERTED_EXT
:
988 parselist
++; /*skip*/
996 /* undefined attribute */
997 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1005 if (num_samples
< 0) {
1006 _mesa_warning(NULL
, "GLX_SAMPLES_ARB: number of samples must not be negative");
1011 * Since we're only simulating the GLX extension this function will never
1012 * find any real GL visuals. Instead, all we can do is try to find an RGB
1013 * or CI visual of appropriate depth. Other requested attributes such as
1014 * double buffering, depth buffer, etc. will be associated with the X
1015 * visual and stored in the VisualTable[].
1017 if (desiredVisualID
!= -1) {
1018 /* try to get a specific visual, by visualID */
1021 temp
.visualid
= desiredVisualID
;
1022 temp
.screen
= screen
;
1023 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1025 /* give the visual some useful GLX attributes */
1026 double_flag
= GL_TRUE
;
1030 else if (level
==0) {
1031 /* normal color planes */
1032 /* Get an RGB visual */
1033 int min_rgb
= min_red
+ min_green
+ min_blue
;
1034 if (min_rgb
>1 && min_rgb
<8) {
1035 /* a special case to be sure we can get a monochrome visual */
1038 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
1041 _mesa_warning(NULL
, "overlay not supported");
1046 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1047 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1048 * largest depth buffer size, which is 32bits/value. Instead, we
1049 * return 16 to maintain performance with earlier versions of Mesa.
1051 if (stencil_size
> 0)
1052 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
1053 else if (depth_size
> 24)
1055 else if (depth_size
> 16)
1057 else if (depth_size
> 0) {
1058 depth_size
= default_depth_bits();
1062 alpha_flag
= default_alpha_bits() > 0;
1065 /* we only support one size of stencil and accum buffers. */
1066 if (stencil_size
> 0)
1069 if (accumRedSize
> 0 ||
1070 accumGreenSize
> 0 ||
1071 accumBlueSize
> 0 ||
1072 accumAlphaSize
> 0) {
1076 accumBlueSize
= default_accum_bits();
1078 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1081 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1082 stereo_flag
, depth_size
, stencil_size
,
1083 accumRedSize
, accumGreenSize
,
1084 accumBlueSize
, accumAlphaSize
, level
, numAux
,
1092 PUBLIC XVisualInfo
*
1093 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1097 /* register ourselves as an extension on this display */
1098 register_with_display(dpy
);
1100 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1102 /* create a new vishandle - the cached one may be stale */
1103 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1104 if (xmvis
->vishandle
) {
1105 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1107 return xmvis
->vishandle
;
1115 * Helper function used by other glXCreateContext functions.
1118 create_context(Display
*dpy
, XMesaVisual xmvis
,
1119 XMesaContext shareCtx
, Bool direct
,
1120 unsigned major
, unsigned minor
,
1121 unsigned profileMask
, unsigned contextFlags
)
1128 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1132 /* deallocate unused windows/buffers */
1134 XMesaGarbageCollect();
1137 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
, shareCtx
, major
, minor
,
1138 profileMask
, contextFlags
);
1139 if (!glxCtx
->xmesaContext
) {
1144 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1145 glxCtx
->currentDpy
= dpy
;
1146 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1153 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1154 GLXContext shareCtx
, Bool direct
)
1158 xmvis
= find_glx_visual( dpy
, visinfo
);
1160 /* This visual wasn't found with glXChooseVisual() */
1161 xmvis
= create_glx_visual( dpy
, visinfo
);
1163 /* unusable visual */
1168 return create_context(dpy
, xmvis
,
1169 shareCtx
? shareCtx
->xmesaContext
: NULL
,
1171 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
1175 /* XXX these may have to be removed due to thread-safety issues. */
1176 static GLXContext MakeCurrent_PrevContext
= 0;
1177 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1178 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1179 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1180 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1183 /* GLX 1.3 and later */
1185 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1186 GLXDrawable read
, GLXContext ctx
)
1188 GLXContext glxCtx
= ctx
;
1189 static boolean firsttime
= 1, no_rast
= 0;
1192 no_rast
= getenv("SP_NO_RAST") != NULL
;
1196 if (ctx
&& draw
&& read
) {
1197 XMesaBuffer drawBuffer
, readBuffer
;
1198 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1200 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1201 if (ctx
== MakeCurrent_PrevContext
1202 && draw
== MakeCurrent_PrevDrawable
) {
1203 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1206 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1209 /* drawable must be a new window! */
1210 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1212 /* Out of memory, or context/drawable depth mismatch */
1217 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1218 if (ctx
== MakeCurrent_PrevContext
1219 && read
== MakeCurrent_PrevReadable
) {
1220 readBuffer
= MakeCurrent_PrevReadBuffer
;
1223 readBuffer
= XMesaFindBuffer( dpy
, read
);
1226 /* drawable must be a new window! */
1227 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1229 /* Out of memory, or context/drawable depth mismatch */
1235 MakeCurrent_PrevContext
== ctx
&&
1236 MakeCurrent_PrevDrawable
== draw
&&
1237 MakeCurrent_PrevReadable
== read
&&
1238 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1239 MakeCurrent_PrevReadBuffer
== readBuffer
)
1242 MakeCurrent_PrevContext
= ctx
;
1243 MakeCurrent_PrevDrawable
= draw
;
1244 MakeCurrent_PrevReadable
= read
;
1245 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1246 MakeCurrent_PrevReadBuffer
= readBuffer
;
1248 /* Now make current! */
1249 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1250 ctx
->currentDpy
= dpy
;
1251 ctx
->currentDrawable
= draw
;
1252 ctx
->currentReadable
= read
;
1253 SetCurrentContext(ctx
);
1260 else if (!ctx
&& !draw
&& !read
) {
1261 /* release current context w/out assigning new one. */
1262 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1263 MakeCurrent_PrevContext
= 0;
1264 MakeCurrent_PrevDrawable
= 0;
1265 MakeCurrent_PrevReadable
= 0;
1266 MakeCurrent_PrevDrawBuffer
= 0;
1267 MakeCurrent_PrevReadBuffer
= 0;
1268 SetCurrentContext(NULL
);
1272 /* The args must either all be non-zero or all zero.
1281 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1283 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1288 glXGetCurrentContext(void)
1290 return GetCurrentContext();
1295 glXGetCurrentDisplay(void)
1297 GLXContext glxCtx
= glXGetCurrentContext();
1299 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1304 glXGetCurrentDisplayEXT(void)
1306 return glXGetCurrentDisplay();
1311 glXGetCurrentDrawable(void)
1313 GLXContext gc
= glXGetCurrentContext();
1314 return gc
? gc
->currentDrawable
: 0;
1319 glXGetCurrentReadDrawable(void)
1321 GLXContext gc
= glXGetCurrentContext();
1322 return gc
? gc
->currentReadable
: 0;
1327 glXGetCurrentReadDrawableSGI(void)
1329 return glXGetCurrentReadDrawable();
1334 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1339 v
= find_glx_visual( dpy
, visinfo
);
1341 v
= create_glx_visual( dpy
, visinfo
);
1343 /* unusable visual */
1348 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1352 return b
->ws
.drawable
;
1356 /*** GLX_MESA_pixmap_colormap ***/
1359 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1360 Pixmap pixmap
, Colormap cmap
)
1365 v
= find_glx_visual( dpy
, visinfo
);
1367 v
= create_glx_visual( dpy
, visinfo
);
1369 /* unusable visual */
1374 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1378 return b
->ws
.drawable
;
1383 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1385 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1387 XMesaDestroyBuffer(b
);
1389 else if (getenv("MESA_DEBUG")) {
1390 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1396 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1397 unsigned long mask
)
1399 XMesaContext xm_src
= src
->xmesaContext
;
1400 XMesaContext xm_dst
= dst
->xmesaContext
;
1402 if (MakeCurrent_PrevContext
== src
) {
1405 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1410 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1413 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1414 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1420 return True
; /* we're faking GLX so always return success */
1425 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1428 GLXContext glxCtx
= ctx
;
1430 MakeCurrent_PrevContext
= 0;
1431 MakeCurrent_PrevDrawable
= 0;
1432 MakeCurrent_PrevReadable
= 0;
1433 MakeCurrent_PrevDrawBuffer
= 0;
1434 MakeCurrent_PrevReadBuffer
= 0;
1435 XMesaDestroyContext( glxCtx
->xmesaContext
);
1436 XMesaGarbageCollect();
1443 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1445 return ctx
? ctx
->isDirect
: False
;
1451 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1453 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1454 static boolean firsttime
= 1, no_rast
= 0;
1457 no_rast
= getenv("SP_NO_RAST") != NULL
;
1465 XMesaSwapBuffers(buffer
);
1467 else if (getenv("MESA_DEBUG")) {
1468 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1475 /*** GLX_MESA_copy_sub_buffer ***/
1478 glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
1479 int x
, int y
, int width
, int height
)
1481 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1483 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1485 else if (getenv("MESA_DEBUG")) {
1486 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1492 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1495 /* Return GLX version, not Mesa version */
1496 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1497 *maj
= CLIENT_MAJOR_VERSION
;
1498 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1504 * Query the GLX attributes of the given XVisualInfo.
1507 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1513 return GLX_BAD_ATTRIBUTE
;
1514 *value
= (int) True
;
1516 case GLX_BUFFER_SIZE
:
1517 *value
= xmvis
->visinfo
->depth
;
1520 *value
= xmvis
->mesa_visual
.level
;
1524 return GLX_BAD_ATTRIBUTE
;
1525 if (xmvis
->mesa_visual
.rgbMode
) {
1532 case GLX_DOUBLEBUFFER
:
1533 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1536 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1538 case GLX_AUX_BUFFERS
:
1539 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1542 *value
= xmvis
->mesa_visual
.redBits
;
1544 case GLX_GREEN_SIZE
:
1545 *value
= xmvis
->mesa_visual
.greenBits
;
1548 *value
= xmvis
->mesa_visual
.blueBits
;
1550 case GLX_ALPHA_SIZE
:
1551 *value
= xmvis
->mesa_visual
.alphaBits
;
1553 case GLX_DEPTH_SIZE
:
1554 *value
= xmvis
->mesa_visual
.depthBits
;
1556 case GLX_STENCIL_SIZE
:
1557 *value
= xmvis
->mesa_visual
.stencilBits
;
1559 case GLX_ACCUM_RED_SIZE
:
1560 *value
= xmvis
->mesa_visual
.accumRedBits
;
1562 case GLX_ACCUM_GREEN_SIZE
:
1563 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1565 case GLX_ACCUM_BLUE_SIZE
:
1566 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1568 case GLX_ACCUM_ALPHA_SIZE
:
1569 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1573 * GLX_EXT_visual_info extension
1575 case GLX_X_VISUAL_TYPE_EXT
:
1576 switch (xmvis
->visinfo
->CLASS
) {
1577 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1578 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1579 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1580 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1581 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1582 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1585 case GLX_TRANSPARENT_TYPE_EXT
:
1587 *value
= GLX_NONE_EXT
;
1589 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1592 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1595 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1598 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1601 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1606 * GLX_EXT_visual_info extension
1608 case GLX_VISUAL_CAVEAT_EXT
:
1609 /* test for zero, just in case */
1610 if (xmvis
->mesa_visual
.visualRating
> 0)
1611 *value
= xmvis
->mesa_visual
.visualRating
;
1613 *value
= GLX_NONE_EXT
;
1617 * GLX_ARB_multisample
1619 case GLX_SAMPLE_BUFFERS_ARB
:
1620 *value
= xmvis
->mesa_visual
.sampleBuffers
;
1622 case GLX_SAMPLES_ARB
:
1623 *value
= xmvis
->mesa_visual
.samples
;
1629 case GLX_SCREEN_EXT
:
1631 return GLX_BAD_ATTRIBUTE
;
1632 *value
= xmvis
->visinfo
->screen
;
1634 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1636 return GLX_BAD_ATTRIBUTE
;
1637 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1639 case GLX_RENDER_TYPE_SGIX
:
1641 return GLX_BAD_ATTRIBUTE
;
1642 if (xmvis
->mesa_visual
.rgbMode
)
1643 *value
= GLX_RGBA_BIT
;
1645 *value
= GLX_COLOR_INDEX_BIT
;
1647 case GLX_X_RENDERABLE_SGIX
:
1649 return GLX_BAD_ATTRIBUTE
;
1650 *value
= True
; /* XXX really? */
1652 case GLX_FBCONFIG_ID_SGIX
:
1654 return GLX_BAD_ATTRIBUTE
;
1655 *value
= xmvis
->visinfo
->visualid
;
1657 case GLX_MAX_PBUFFER_WIDTH
:
1659 return GLX_BAD_ATTRIBUTE
;
1660 /* XXX should be same as ctx->Const.MaxRenderbufferSize */
1661 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1663 case GLX_MAX_PBUFFER_HEIGHT
:
1665 return GLX_BAD_ATTRIBUTE
;
1666 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1668 case GLX_MAX_PBUFFER_PIXELS
:
1670 return GLX_BAD_ATTRIBUTE
;
1671 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1672 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1676 return GLX_BAD_ATTRIBUTE
;
1677 *value
= xmvis
->visinfo
->visualid
;
1680 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1681 *value
= True
; /*XXX*/
1683 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1685 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1687 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1688 *value
= True
; /*XXX*/
1690 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1691 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1692 GLX_TEXTURE_2D_BIT_EXT
|
1693 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1695 case GLX_Y_INVERTED_EXT
:
1696 *value
= True
; /*XXX*/
1700 return GLX_BAD_ATTRIBUTE
;
1707 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1708 int attrib
, int *value
)
1712 if (!dpy
|| !visinfo
)
1713 return GLX_BAD_ATTRIBUTE
;
1715 xmvis
= find_glx_visual( dpy
, visinfo
);
1717 /* this visual wasn't obtained with glXChooseVisual */
1718 xmvis
= create_glx_visual( dpy
, visinfo
);
1720 /* this visual can't be used for GL rendering */
1721 if (attrib
==GLX_USE_GL
) {
1722 *value
= (int) False
;
1726 return GLX_BAD_VISUAL
;
1731 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1739 XMesaContext xmesa
= XMesaGetCurrentContext();
1740 XMesaFlush( xmesa
);
1748 XMesaContext xmesa
= XMesaGetCurrentContext();
1749 XMesaFlush( xmesa
);
1754 get_extensions( void )
1761 /* GLX 1.1 and later */
1763 glXQueryExtensionsString( Display
*dpy
, int screen
)
1767 return get_extensions();
1772 /* GLX 1.1 and later */
1774 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1776 static char version
[1000];
1777 sprintf(version
, "%d.%d %s",
1778 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, xmesa_get_name());
1784 case GLX_EXTENSIONS
:
1785 return get_extensions();
1797 /* GLX 1.1 and later */
1799 glXGetClientString( Display
*dpy
, int name
)
1801 static char version
[1000];
1802 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1803 CLIENT_MINOR_VERSION
, xmesa_get_name());
1808 case GLX_EXTENSIONS
:
1809 return get_extensions();
1827 glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1828 int attribute
, int *value
)
1830 XMesaVisual v
= (XMesaVisual
) config
;
1834 if (!dpy
|| !config
|| !value
)
1837 return get_config(v
, attribute
, value
, GL_TRUE
);
1841 PUBLIC GLXFBConfig
*
1842 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1844 XVisualInfo
*visuals
, visTemplate
;
1845 const long visMask
= VisualScreenMask
;
1848 /* Get list of all X visuals */
1849 visTemplate
.screen
= screen
;
1850 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1851 if (*nelements
> 0) {
1852 XMesaVisual
*results
= malloc(*nelements
* sizeof(XMesaVisual
));
1857 for (i
= 0; i
< *nelements
; i
++) {
1858 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1864 return (GLXFBConfig
*) results
;
1870 PUBLIC GLXFBConfig
*
1871 glXChooseFBConfig(Display
*dpy
, int screen
,
1872 const int *attribList
, int *nitems
)
1876 /* register ourselves as an extension on this display */
1877 register_with_display(dpy
);
1879 if (!attribList
|| !attribList
[0]) {
1880 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1881 return glXGetFBConfigs(dpy
, screen
, nitems
);
1884 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1886 GLXFBConfig
*config
= malloc(sizeof(XMesaVisual
));
1892 config
[0] = (GLXFBConfig
) xmvis
;
1893 return (GLXFBConfig
*) config
;
1902 PUBLIC XVisualInfo
*
1903 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1905 if (dpy
&& config
) {
1906 XMesaVisual xmvis
= (XMesaVisual
) config
;
1908 return xmvis
->vishandle
;
1910 /* create a new vishandle - the cached one may be stale */
1911 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1912 if (xmvis
->vishandle
) {
1913 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1915 return xmvis
->vishandle
;
1925 glXCreateWindow(Display
*dpy
, GLXFBConfig config
, Window win
,
1926 const int *attribList
)
1928 XMesaVisual xmvis
= (XMesaVisual
) config
;
1933 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1938 (void) attribList
; /* Ignored in GLX 1.3 */
1940 return win
; /* A hack for now */
1945 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1947 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1949 XMesaDestroyBuffer(b
);
1950 /* don't destroy X window */
1956 glXCreatePixmap(Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1957 const int *attribList
)
1959 XMesaVisual v
= (XMesaVisual
) config
;
1962 int target
= 0, format
= 0, mipmap
= 0;
1965 if (!dpy
|| !config
|| !pixmap
)
1968 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1970 case GLX_TEXTURE_FORMAT_EXT
:
1973 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1974 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1975 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1983 case GLX_TEXTURE_TARGET_EXT
:
1986 case GLX_TEXTURE_1D_EXT
:
1987 case GLX_TEXTURE_2D_EXT
:
1988 case GLX_TEXTURE_RECTANGLE_EXT
:
1996 case GLX_MIPMAP_TEXTURE_EXT
:
2007 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
2008 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
2009 &value
, GL_TRUE
) != Success
2011 return 0; /* error! */
2014 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2015 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2016 &value
, GL_TRUE
) != Success
2018 return 0; /* error! */
2022 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2023 &value
, GL_TRUE
) != Success
2025 return 0; /* error! */
2028 if (target
== GLX_TEXTURE_1D_EXT
) {
2029 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2030 &value
, GL_TRUE
) != Success
2031 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2032 return 0; /* error! */
2035 else if (target
== GLX_TEXTURE_2D_EXT
) {
2036 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2037 &value
, GL_TRUE
) != Success
2038 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2039 return 0; /* error! */
2042 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2043 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2044 &value
, GL_TRUE
) != Success
2045 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2046 return 0; /* error! */
2050 if (format
|| target
|| mipmap
) {
2051 /* texture from pixmap */
2052 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2055 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2066 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2068 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
2070 XMesaDestroyBuffer(b
);
2071 /* don't destroy X pixmap */
2076 glXCreatePbuffer(Display
*dpy
, GLXFBConfig config
, const int *attribList
)
2078 XMesaVisual xmvis
= (XMesaVisual
) config
;
2081 int width
= 0, height
= 0;
2082 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2086 for (attrib
= attribList
; *attrib
; attrib
++) {
2088 case GLX_PBUFFER_WIDTH
:
2092 case GLX_PBUFFER_HEIGHT
:
2096 case GLX_PRESERVED_CONTENTS
:
2098 preserveContents
= *attrib
;
2100 case GLX_LARGEST_PBUFFER
:
2102 useLargest
= *attrib
;
2109 if (width
== 0 || height
== 0)
2112 if (width
> PBUFFER_MAX_SIZE
|| height
> PBUFFER_MAX_SIZE
) {
2113 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2114 * allocate the largest possible buffer.
2117 width
= PBUFFER_MAX_SIZE
;
2118 height
= PBUFFER_MAX_SIZE
;
2122 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2123 /* A GLXPbuffer handle must be an X Drawable because that's what
2124 * glXMakeCurrent takes.
2127 xmbuf
->largestPbuffer
= useLargest
;
2128 xmbuf
->preservedContents
= preserveContents
;
2129 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2138 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2140 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2142 XMesaDestroyBuffer(b
);
2148 glXQueryDrawable(Display
*dpy
, GLXDrawable draw
, int attribute
,
2149 unsigned int *value
)
2151 GLuint width
, height
;
2152 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2154 generate_error(dpy
, GLXBadDrawable
, draw
, X_GLXGetDrawableAttributes
, False
);
2158 /* make sure buffer's dimensions are up to date */
2159 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2161 switch (attribute
) {
2168 case GLX_PRESERVED_CONTENTS
:
2169 *value
= xmbuf
->preservedContents
;
2171 case GLX_LARGEST_PBUFFER
:
2172 *value
= xmbuf
->largestPbuffer
;
2174 case GLX_FBCONFIG_ID
:
2175 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2177 case GLX_TEXTURE_FORMAT_EXT
:
2178 *value
= xmbuf
->TextureFormat
;
2180 case GLX_TEXTURE_TARGET_EXT
:
2181 *value
= xmbuf
->TextureTarget
;
2183 case GLX_MIPMAP_TEXTURE_EXT
:
2184 *value
= xmbuf
->TextureMipmap
;
2188 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, true);
2195 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2196 int renderType
, GLXContext shareCtx
, Bool direct
)
2198 XMesaVisual xmvis
= (XMesaVisual
) config
;
2200 if (!dpy
|| !config
||
2201 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2204 return create_context(dpy
, xmvis
,
2205 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2207 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2212 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2214 GLXContext glxCtx
= ctx
;
2215 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2220 switch (attribute
) {
2221 case GLX_FBCONFIG_ID
:
2222 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2224 case GLX_RENDER_TYPE
:
2225 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2226 *value
= GLX_RGBA_TYPE
;
2228 *value
= GLX_COLOR_INDEX_TYPE
;
2234 return GLX_BAD_ATTRIBUTE
;
2241 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2243 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2245 xmbuf
->selectedEvents
= mask
;
2250 glXGetSelectedEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2252 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2254 *mask
= xmbuf
->selectedEvents
;
2261 /*** GLX_SGI_swap_control ***/
2264 glXSwapIntervalSGI(int interval
)
2272 /*** GLX_SGI_video_sync ***/
2274 static unsigned int FrameCounter
= 0;
2277 glXGetVideoSyncSGI(unsigned int *count
)
2279 /* this is a bogus implementation */
2280 *count
= FrameCounter
++;
2285 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2287 if (divisor
<= 0 || remainder
< 0)
2288 return GLX_BAD_VALUE
;
2289 /* this is a bogus implementation */
2291 while (FrameCounter
% divisor
!= remainder
)
2293 *count
= FrameCounter
;
2299 /*** GLX_SGI_make_current_read ***/
2302 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
,
2305 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2310 glXGetCurrentReadDrawableSGI(void)
2317 /*** GLX_SGIX_video_source ***/
2320 PUBLIC GLXVideoSourceSGIX
2321 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
,
2322 VLPath path
, int nodeClass
, VLNode drainNode
)
2334 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2343 /*** GLX_EXT_import_context ***/
2346 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2353 glXGetContextIDEXT(const GLXContext context
)
2360 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2368 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
,
2380 /*** GLX_SGIX_fbconfig ***/
2383 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2384 int attribute
, int *value
)
2386 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2389 PUBLIC GLXFBConfigSGIX
*
2390 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
,
2393 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
,
2394 attrib_list
, nelements
);
2399 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2402 XMesaVisual xmvis
= (XMesaVisual
) config
;
2403 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2404 return xmbuf
->ws
.drawable
; /* need to return an X ID */
2409 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2410 int renderType
, GLXContext shareCtx
,
2413 XMesaVisual xmvis
= (XMesaVisual
) config
;
2415 if (!dpy
|| !config
||
2416 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2419 return create_context(dpy
, xmvis
,
2420 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2422 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2426 PUBLIC XVisualInfo
*
2427 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2429 return glXGetVisualFromFBConfig(dpy
, config
);
2433 PUBLIC GLXFBConfigSGIX
2434 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2436 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2438 /* This visual wasn't found with glXChooseVisual() */
2439 xmvis
= create_glx_visual(dpy
, vis
);
2442 return (GLXFBConfigSGIX
) xmvis
;
2447 /*** GLX_SGIX_pbuffer ***/
2449 PUBLIC GLXPbufferSGIX
2450 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2451 unsigned int width
, unsigned int height
,
2454 XMesaVisual xmvis
= (XMesaVisual
) config
;
2457 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2461 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2463 case GLX_PRESERVED_CONTENTS_SGIX
:
2465 preserveContents
= *attrib
; /* ignored */
2467 case GLX_LARGEST_PBUFFER_SGIX
:
2469 useLargest
= *attrib
; /* ignored */
2476 /* not used at this time */
2478 (void) preserveContents
;
2480 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2481 /* A GLXPbuffer handle must be an X Drawable because that's what
2482 * glXMakeCurrent takes.
2484 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2489 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2491 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2493 XMesaDestroyBuffer(xmbuf
);
2499 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
,
2500 unsigned int *value
)
2502 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2505 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2509 switch (attribute
) {
2510 case GLX_PRESERVED_CONTENTS_SGIX
:
2513 case GLX_LARGEST_PBUFFER_SGIX
:
2514 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2516 case GLX_WIDTH_SGIX
:
2517 *value
= xmesa_buffer_width(xmbuf
);
2519 case GLX_HEIGHT_SGIX
:
2520 *value
= xmesa_buffer_height(xmbuf
);
2522 case GLX_EVENT_MASK_SGIX
:
2523 *value
= 0; /* XXX might be wrong */
2533 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2535 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2537 /* Note: we'll never generate clobber events */
2538 xmbuf
->selectedEvents
= mask
;
2544 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
,
2545 unsigned long *mask
)
2547 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2549 *mask
= xmbuf
->selectedEvents
;
2558 /*** GLX_SGI_cushion ***/
2561 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2570 /*** GLX_SGIX_video_resize ***/
2573 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
,
2584 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2585 int x
, int y
, int w
, int h
)
2598 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2599 int *x
, int *y
, int *w
, int *h
)
2612 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
,
2613 int *dx
, int *dy
, int *dw
, int *dh
)
2626 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2637 /*** GLX_SGIX_dmbuffer **/
2639 #if defined(_DM_BUFFER_H_)
2641 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
,
2642 DMparams
*params
, DMbuffer dmbuffer
)
2653 /*** GLX_SUN_get_transparent_index ***/
2656 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
,
2662 (void) pTransparent
;
2668 /*** GLX_MESA_release_buffers ***/
2671 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2672 * (a window or pixmap) prior to destroying the GLXDrawable.
2675 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2677 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2679 XMesaDestroyBuffer(b
);
2685 /*** GLX_EXT_texture_from_pixmap ***/
2688 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2689 const int *attrib_list
)
2691 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2693 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2697 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2699 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2701 XMesaReleaseTexImage(dpy
, b
, buffer
);
2706 /*** GLX_ARB_create_context ***/
2710 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
2711 GLXContext shareCtx
, Bool direct
,
2712 const int *attrib_list
)
2714 XMesaVisual xmvis
= (XMesaVisual
) config
;
2715 int majorVersion
= 1, minorVersion
= 0;
2716 int contextFlags
= 0x0;
2717 int profileMask
= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
;
2718 int renderType
= GLX_RGBA_TYPE
;
2721 const int contextFlagsAll
= (GLX_CONTEXT_DEBUG_BIT_ARB
|
2722 GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
);
2725 /* parse attrib_list */
2726 for (i
= 0; !done
&& attrib_list
&& attrib_list
[i
]; i
++) {
2727 switch (attrib_list
[i
]) {
2728 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2729 majorVersion
= attrib_list
[++i
];
2731 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2732 minorVersion
= attrib_list
[++i
];
2734 case GLX_CONTEXT_FLAGS_ARB
:
2735 contextFlags
= attrib_list
[++i
];
2737 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2738 profileMask
= attrib_list
[++i
];
2740 case GLX_RENDER_TYPE
:
2741 renderType
= attrib_list
[++i
];
2749 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2754 /* check contextFlags */
2755 if (contextFlags
& ~contextFlagsAll
) {
2756 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2760 /* check profileMask */
2761 if (profileMask
!= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
&&
2762 profileMask
!= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
&&
2763 profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
) {
2764 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAttribsARB
, False
);
2768 /* check renderType */
2769 if (renderType
!= GLX_RGBA_TYPE
&&
2770 renderType
!= GLX_COLOR_INDEX_TYPE
) {
2771 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2776 if (majorVersion
<= 0 ||
2778 (profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2779 ((majorVersion
== 1 && minorVersion
> 5) ||
2780 (majorVersion
== 2 && minorVersion
> 1) ||
2781 (majorVersion
== 3 && minorVersion
> 3) ||
2782 (majorVersion
== 4 && minorVersion
> 5) ||
2783 majorVersion
> 4))) {
2784 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2787 if (profileMask
== GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2788 ((majorVersion
== 1 && minorVersion
> 1) ||
2789 (majorVersion
== 2 && minorVersion
> 0) ||
2790 (majorVersion
== 3 && minorVersion
> 1) ||
2791 majorVersion
> 3)) {
2792 /* GLX_EXT_create_context_es2_profile says nothing to justifying a
2793 * different error code for invalid ES versions, but this is what NVIDIA
2794 * does and piglit expects.
2796 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAttribsARB
, False
);
2800 if ((contextFlags
& GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
) &&
2802 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2806 if (renderType
== GLX_COLOR_INDEX_TYPE
&& majorVersion
>= 3) {
2807 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2811 ctx
= create_context(dpy
, xmvis
,
2812 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2814 majorVersion
, minorVersion
,
2815 profileMask
, contextFlags
);
2817 generate_error(dpy
, GLXBadFBConfig
, 0, X_GLXCreateContextAttribsARB
, False
);