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
;
198 /* Check if the MESA_BACK_BUFFER env var is set */
199 char *backbuffer
= getenv("MESA_BACK_BUFFER");
201 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
202 ximageFlag
= GL_FALSE
;
204 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
205 ximageFlag
= GL_TRUE
;
208 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
214 /* stereo not supported */
218 if (stencil_size
> 0 && depth_size
> 0)
221 /* Comparing IDs uses less memory but sometimes fails. */
222 /* XXX revisit this after 3.0 is finished. */
223 if (getenv("MESA_GLX_VISUAL_HACK"))
224 comparePointers
= GL_TRUE
;
226 comparePointers
= GL_FALSE
;
228 /* Force the visual to have an alpha channel */
229 if (rgbFlag
&& getenv("MESA_GLX_FORCE_ALPHA"))
232 /* First check if a matching visual is already in the list */
233 for (i
=0; i
<NumVisuals
; i
++) {
234 XMesaVisual v
= VisualTable
[i
];
235 if (v
->display
== dpy
236 && v
->mesa_visual
.level
== level
237 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
238 && v
->mesa_visual
.samples
== num_samples
239 && v
->ximage_flag
== ximageFlag
240 && v
->mesa_visual
.doubleBufferMode
== dbFlag
241 && v
->mesa_visual
.stereoMode
== stereoFlag
242 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
243 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
244 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
245 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
246 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
247 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
248 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
249 /* now either compare XVisualInfo pointers or visual IDs */
250 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
251 || (comparePointers
&& v
->vishandle
== vinfo
)) {
257 /* Create a new visual and add it to the list. */
259 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
260 stereoFlag
, ximageFlag
,
261 depth_size
, stencil_size
,
262 accumRedSize
, accumBlueSize
,
263 accumBlueSize
, accumAlphaSize
, num_samples
, level
,
266 /* Save a copy of the pointer now so we can find this visual again
267 * if we need to search for it in find_glx_visual().
269 xmvis
->vishandle
= vinfo
;
270 /* Allocate more space for additional visual */
271 VisualTable
= realloc(VisualTable
, sizeof(XMesaVisual
) * (NumVisuals
+ 1));
272 /* add xmvis to the list */
273 VisualTable
[NumVisuals
] = xmvis
;
275 /* XXX minor hack, because XMesaCreateVisual doesn't support an
276 * aux buffers parameter.
278 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
285 * Return the default number of bits for the Z buffer.
286 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
287 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
288 * XXX probably do the same thing for stencil, accum, etc.
291 default_depth_bits(void)
294 const char *zEnv
= getenv("MESA_GLX_DEPTH_BITS");
303 default_alpha_bits(void)
306 const char *aEnv
= getenv("MESA_GLX_ALPHA_BITS");
315 default_accum_bits(void)
323 * Create a GLX visual from a regular XVisualInfo.
324 * This is called when Fake GLX is given an XVisualInfo which wasn't
325 * returned by glXChooseVisual. Since this is the first time we're
326 * considering this visual we'll take a guess at reasonable values
327 * for depth buffer size, stencil size, accum size, etc.
328 * This is the best we can do with a client-side emulation of GLX.
331 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
333 GLint zBits
= default_depth_bits();
334 GLint accBits
= default_accum_bits();
335 GLboolean alphaFlag
= default_alpha_bits() > 0;
337 if (is_usable_visual( visinfo
)) {
338 /* Configure this visual as RGB, double-buffered, depth-buffered. */
339 /* This is surely wrong for some people's needs but what else */
340 /* can be done? They should use glXChooseVisual(). */
341 return save_glx_visual( dpy
, visinfo
,
343 alphaFlag
, /* alpha */
344 GL_TRUE
, /* double */
345 GL_FALSE
, /* stereo */
347 8, /* stencil bits */
358 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
366 * Find the GLX visual associated with an XVisualInfo.
369 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
373 /* try to match visual id */
374 for (i
=0;i
<NumVisuals
;i
++) {
375 if (VisualTable
[i
]->display
==dpy
376 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
377 return VisualTable
[i
];
381 /* if that fails, try to match pointers */
382 for (i
=0;i
<NumVisuals
;i
++) {
383 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
384 return VisualTable
[i
];
393 * Try to get an X visual which matches the given arguments.
396 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
398 XVisualInfo temp
, *vis
;
401 unsigned int default_depth
;
404 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
409 default_depth
= DefaultDepth(dpy
,scr
);
410 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
412 if (depth
==default_depth
&& xclass
==default_class
) {
413 /* try to get root window's visual */
414 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
415 mask
|= VisualIDMask
;
418 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
420 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
421 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
422 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
424 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
425 if (util_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
426 util_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
427 util_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
441 * Retrieve the value of the given environment variable and find
442 * the X visual which matches it.
443 * Input: dpy - the display
444 * screen - the screen number
445 * varname - the name of the environment variable
446 * Return: an XVisualInfo pointer to NULL if error.
449 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
451 char value
[100], type
[100];
452 int depth
, xclass
= -1;
455 if (!getenv( varname
)) {
459 strncpy( value
, getenv(varname
), 100 );
462 sscanf( value
, "%s %d", type
, &depth
);
464 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
465 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
466 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
467 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
468 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
469 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
471 if (xclass
>-1 && depth
>0) {
472 vis
= get_visual( dpy
, scr
, depth
, xclass
);
478 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
487 * Select an X visual which satisfies the RGBA flag and minimum depth.
489 * screen - X display and screen number
490 * min_depth - minimum visual depth
491 * preferred_class - preferred GLX visual class or DONT_CARE
492 * Return: pointer to an XVisualInfo or NULL.
495 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
496 int preferred_class
)
499 int xclass
, visclass
= 0;
502 /* First see if the MESA_RGB_VISUAL env var is defined */
503 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
507 /* Otherwise, search for a suitable visual */
508 if (preferred_class
==DONT_CARE
) {
509 for (xclass
=0;xclass
<6;xclass
++) {
511 case 0: visclass
= TrueColor
; break;
512 case 1: visclass
= DirectColor
; break;
513 case 2: visclass
= PseudoColor
; break;
514 case 3: visclass
= StaticColor
; break;
515 case 4: visclass
= GrayScale
; break;
516 case 5: visclass
= StaticGray
; break;
519 /* start with shallowest */
520 for (depth
=0;depth
<=32;depth
++) {
521 if (visclass
==TrueColor
&& depth
==8) {
522 /* Special case: try to get 8-bit PseudoColor before */
523 /* 8-bit TrueColor */
524 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
529 vis
= get_visual( dpy
, screen
, depth
, visclass
);
536 /* start with deepest */
537 for (depth
=32;depth
>=min_depth
;depth
--) {
538 if (visclass
==TrueColor
&& depth
==8) {
539 /* Special case: try to get 8-bit PseudoColor before */
540 /* 8-bit TrueColor */
541 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
546 vis
= get_visual( dpy
, screen
, depth
, visclass
);
555 /* search for a specific visual class */
556 switch (preferred_class
) {
557 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
558 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
559 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
560 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
561 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
562 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
563 default: return NULL
;
566 /* start with shallowest */
567 for (depth
=0;depth
<=32;depth
++) {
568 vis
= get_visual( dpy
, screen
, depth
, visclass
);
575 /* start with deepest */
576 for (depth
=32;depth
>=min_depth
;depth
--) {
577 vis
= get_visual( dpy
, screen
, depth
, visclass
);
585 /* didn't find a visual */
592 /**********************************************************************/
593 /*** Display-related functions ***/
594 /**********************************************************************/
598 * Free all XMesaVisuals which are associated with the given display.
601 destroy_visuals_on_display(Display
*dpy
)
604 for (i
= 0; i
< NumVisuals
; i
++) {
605 if (VisualTable
[i
]->display
== dpy
) {
606 /* remove this visual */
608 free(VisualTable
[i
]);
609 for (j
= i
; j
< NumVisuals
- 1; j
++)
610 VisualTable
[j
] = VisualTable
[j
+ 1];
618 * Called from XCloseDisplay() to let us free our display-related data.
621 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
623 xmesa_destroy_buffers_on_display(dpy
);
624 destroy_visuals_on_display(dpy
);
625 xmesa_close_display(dpy
);
631 * Look for the named extension on given display and return a pointer
632 * to the _XExtension data, or NULL if extension not found.
635 lookup_extension(Display
*dpy
, const char *extName
)
638 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
639 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
648 * Whenever we're given a new Display pointer, call this function to
649 * register our close_display_callback function.
652 register_with_display(Display
*dpy
)
654 const char *extName
= "MesaGLX";
657 ext
= lookup_extension(dpy
, extName
);
659 XExtCodes
*c
= XAddExtension(dpy
);
660 ext
= dpy
->ext_procs
; /* new extension is at head of list */
661 assert(c
->extension
== ext
->codes
.extension
);
663 ext
->name
= strdup(extName
);
664 ext
->close_display
= close_display_callback
;
673 generate_error(Display
*dpy
,
674 unsigned char error_code
,
676 unsigned char minor_code
,
679 XErrorHandler handler
;
685 handler
= XSetErrorHandler(NULL
);
686 XSetErrorHandler(handler
);
691 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_opcode
, &first_event
, &first_error
)) {
698 error_code
+= first_error
;
701 memset(&event
, 0, sizeof event
);
703 event
.xerror
.type
= X_Error
;
704 event
.xerror
.display
= dpy
;
705 event
.xerror
.resourceid
= resourceid
;
706 event
.xerror
.serial
= NextRequest(dpy
) - 1;
707 event
.xerror
.error_code
= error_code
;
708 event
.xerror
.request_code
= major_opcode
;
709 event
.xerror
.minor_code
= minor_code
;
711 return handler(dpy
, &event
.xerror
);
715 /**********************************************************************/
716 /*** Begin Fake GLX API Functions ***/
717 /**********************************************************************/
721 * Helper used by glXChooseVisual and glXChooseFBConfig.
722 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
724 * In either case, the attribute list is terminated with the value 'None'.
727 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
729 const GLboolean rgbModeDefault
= fbConfig
;
730 const int *parselist
;
732 int min_red
=0, min_green
=0, min_blue
=0;
733 GLboolean rgb_flag
= rgbModeDefault
;
734 GLboolean alpha_flag
= GL_FALSE
;
735 GLboolean double_flag
= GL_FALSE
;
736 GLboolean stereo_flag
= GL_FALSE
;
737 GLint depth_size
= 0;
738 GLint stencil_size
= 0;
739 GLint accumRedSize
= 0;
740 GLint accumGreenSize
= 0;
741 GLint accumBlueSize
= 0;
742 GLint accumAlphaSize
= 0;
744 int visual_type
= DONT_CARE
;
745 GLint caveat
= DONT_CARE
;
746 XMesaVisual xmvis
= NULL
;
747 int desiredVisualID
= -1;
749 GLint num_samples
= 0;
751 if (xmesa_init( dpy
) != 0) {
752 _mesa_warning(NULL
, "Failed to initialize display");
761 parselist
[1] == GLX_DONT_CARE
&&
762 parselist
[0] != GLX_LEVEL
) {
763 /* For glXChooseFBConfig(), skip attributes whose value is
764 * GLX_DONT_CARE, unless it's GLX_LEVEL (which can legitimately be
767 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
768 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
774 switch (*parselist
) {
785 case GLX_BUFFER_SIZE
:
791 level
= *parselist
++;
803 case GLX_DOUBLEBUFFER
:
806 double_flag
= *parselist
++;
809 double_flag
= GL_TRUE
;
815 stereo_flag
= *parselist
++;
818 stereo_flag
= GL_TRUE
;
821 case GLX_AUX_BUFFERS
:
823 numAux
= *parselist
++;
824 if (numAux
> MAX_AUX_BUFFERS
)
829 min_red
= *parselist
++;
833 min_green
= *parselist
++;
837 min_blue
= *parselist
++;
842 GLint size
= *parselist
++;
843 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
848 depth_size
= *parselist
++;
850 case GLX_STENCIL_SIZE
:
852 stencil_size
= *parselist
++;
854 case GLX_ACCUM_RED_SIZE
:
857 GLint size
= *parselist
++;
858 accumRedSize
= MAX2( accumRedSize
, size
);
861 case GLX_ACCUM_GREEN_SIZE
:
864 GLint size
= *parselist
++;
865 accumGreenSize
= MAX2( accumGreenSize
, size
);
868 case GLX_ACCUM_BLUE_SIZE
:
871 GLint size
= *parselist
++;
872 accumBlueSize
= MAX2( accumBlueSize
, size
);
875 case GLX_ACCUM_ALPHA_SIZE
:
878 GLint size
= *parselist
++;
879 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
884 * GLX_EXT_visual_info extension
886 case GLX_X_VISUAL_TYPE_EXT
:
888 visual_type
= *parselist
++;
890 case GLX_TRANSPARENT_TYPE_EXT
:
894 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
898 case GLX_TRANSPARENT_RED_VALUE_EXT
:
899 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
900 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
901 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
908 * GLX_EXT_visual_info extension
910 case GLX_VISUAL_CAVEAT_EXT
:
912 caveat
= *parselist
++; /* ignored for now */
916 * GLX_ARB_multisample
918 case GLX_SAMPLE_BUFFERS_ARB
:
923 case GLX_SAMPLES_ARB
:
925 num_samples
= *parselist
++;
931 case GLX_RENDER_TYPE
:
935 if (*parselist
& GLX_RGBA_BIT
) {
938 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
941 else if (*parselist
== 0) {
946 case GLX_DRAWABLE_TYPE
:
950 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
951 return NULL
; /* bad bit */
955 case GLX_FBCONFIG_ID
:
960 desiredVisualID
= *parselist
++;
962 case GLX_X_RENDERABLE
:
963 case GLX_MAX_PBUFFER_WIDTH
:
964 case GLX_MAX_PBUFFER_HEIGHT
:
965 case GLX_MAX_PBUFFER_PIXELS
:
967 return NULL
; /* invalid config option */
968 parselist
+= 2; /* ignore the parameter */
971 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
972 parselist
++; /*skip*/
974 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
975 parselist
++; /*skip*/
977 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
978 parselist
++; /*skip*/
980 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
982 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
983 GLX_TEXTURE_2D_BIT_EXT
|
984 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
989 case GLX_Y_INVERTED_EXT
:
990 parselist
++; /*skip*/
998 /* undefined attribute */
999 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1007 if (num_samples
< 0) {
1008 _mesa_warning(NULL
, "GLX_SAMPLES_ARB: number of samples must not be negative");
1013 * Since we're only simulating the GLX extension this function will never
1014 * find any real GL visuals. Instead, all we can do is try to find an RGB
1015 * or CI visual of appropriate depth. Other requested attributes such as
1016 * double buffering, depth buffer, etc. will be associated with the X
1017 * visual and stored in the VisualTable[].
1019 if (desiredVisualID
!= -1) {
1020 /* try to get a specific visual, by visualID */
1023 temp
.visualid
= desiredVisualID
;
1024 temp
.screen
= screen
;
1025 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1027 /* give the visual some useful GLX attributes */
1028 double_flag
= GL_TRUE
;
1032 else if (level
==0) {
1033 /* normal color planes */
1034 /* Get an RGB visual */
1035 int min_rgb
= min_red
+ min_green
+ min_blue
;
1036 if (min_rgb
>1 && min_rgb
<8) {
1037 /* a special case to be sure we can get a monochrome visual */
1040 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
1043 _mesa_warning(NULL
, "overlay not supported");
1048 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1049 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1050 * largest depth buffer size, which is 32bits/value. Instead, we
1051 * return 16 to maintain performance with earlier versions of Mesa.
1053 if (stencil_size
> 0)
1054 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
1055 else if (depth_size
> 24)
1057 else if (depth_size
> 16)
1059 else if (depth_size
> 0) {
1060 depth_size
= default_depth_bits();
1064 alpha_flag
= default_alpha_bits() > 0;
1067 /* we only support one size of stencil and accum buffers. */
1068 if (stencil_size
> 0)
1071 if (accumRedSize
> 0 ||
1072 accumGreenSize
> 0 ||
1073 accumBlueSize
> 0 ||
1074 accumAlphaSize
> 0) {
1078 accumBlueSize
= default_accum_bits();
1080 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1083 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1084 stereo_flag
, depth_size
, stencil_size
,
1085 accumRedSize
, accumGreenSize
,
1086 accumBlueSize
, accumAlphaSize
, level
, numAux
,
1094 PUBLIC XVisualInfo
*
1095 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1099 /* register ourselves as an extension on this display */
1100 register_with_display(dpy
);
1102 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1104 /* create a new vishandle - the cached one may be stale */
1105 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1106 if (xmvis
->vishandle
) {
1107 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1109 return xmvis
->vishandle
;
1117 * Helper function used by other glXCreateContext functions.
1120 create_context(Display
*dpy
, XMesaVisual xmvis
,
1121 XMesaContext shareCtx
, Bool direct
,
1122 unsigned major
, unsigned minor
,
1123 unsigned profileMask
, unsigned contextFlags
)
1130 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1134 /* deallocate unused windows/buffers */
1136 XMesaGarbageCollect();
1139 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
, shareCtx
, major
, minor
,
1140 profileMask
, contextFlags
);
1141 if (!glxCtx
->xmesaContext
) {
1146 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1147 glxCtx
->currentDpy
= dpy
;
1148 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1155 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1156 GLXContext shareCtx
, Bool direct
)
1160 xmvis
= find_glx_visual( dpy
, visinfo
);
1162 /* This visual wasn't found with glXChooseVisual() */
1163 xmvis
= create_glx_visual( dpy
, visinfo
);
1165 /* unusable visual */
1170 return create_context(dpy
, xmvis
,
1171 shareCtx
? shareCtx
->xmesaContext
: NULL
,
1173 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
1177 /* GLX 1.3 and later */
1179 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1180 GLXDrawable read
, GLXContext ctx
)
1182 GLXContext glxCtx
= ctx
;
1183 GLXContext current
= GetCurrentContext();
1184 static boolean firsttime
= 1, no_rast
= 0;
1187 no_rast
= getenv("SP_NO_RAST") != NULL
;
1191 if (ctx
&& draw
&& read
) {
1192 XMesaBuffer drawBuffer
, readBuffer
;
1193 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1195 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1196 if (ctx
== current
) {
1197 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1200 /* drawable must be a new window! */
1201 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1203 /* Out of memory, or context/drawable depth mismatch */
1208 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1209 if (ctx
== current
) {
1210 readBuffer
= XMesaFindBuffer( dpy
, read
);
1213 /* drawable must be a new window! */
1214 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1216 /* Out of memory, or context/drawable depth mismatch */
1221 if (no_rast
&& current
== ctx
)
1224 /* Now make current! */
1225 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1226 ctx
->currentDpy
= dpy
;
1227 ctx
->currentDrawable
= draw
;
1228 ctx
->currentReadable
= read
;
1229 SetCurrentContext(ctx
);
1236 else if (!ctx
&& !draw
&& !read
) {
1237 /* release current context w/out assigning new one. */
1238 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1239 SetCurrentContext(NULL
);
1243 /* The args must either all be non-zero or all zero.
1252 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1254 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1259 glXGetCurrentContext(void)
1261 return GetCurrentContext();
1266 glXGetCurrentDisplay(void)
1268 GLXContext glxCtx
= glXGetCurrentContext();
1270 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1275 glXGetCurrentDisplayEXT(void)
1277 return glXGetCurrentDisplay();
1282 glXGetCurrentDrawable(void)
1284 GLXContext gc
= glXGetCurrentContext();
1285 return gc
? gc
->currentDrawable
: 0;
1290 glXGetCurrentReadDrawable(void)
1292 GLXContext gc
= glXGetCurrentContext();
1293 return gc
? gc
->currentReadable
: 0;
1298 glXGetCurrentReadDrawableSGI(void)
1300 return glXGetCurrentReadDrawable();
1305 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1310 v
= find_glx_visual( dpy
, visinfo
);
1312 v
= create_glx_visual( dpy
, visinfo
);
1314 /* unusable visual */
1319 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1323 return b
->ws
.drawable
;
1327 /*** GLX_MESA_pixmap_colormap ***/
1330 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1331 Pixmap pixmap
, Colormap cmap
)
1336 v
= find_glx_visual( dpy
, visinfo
);
1338 v
= create_glx_visual( dpy
, visinfo
);
1340 /* unusable visual */
1345 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1349 return b
->ws
.drawable
;
1354 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1356 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1358 XMesaDestroyBuffer(b
);
1360 else if (getenv("MESA_DEBUG")) {
1361 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1367 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1368 unsigned long mask
)
1370 XMesaContext xm_src
= src
->xmesaContext
;
1371 XMesaContext xm_dst
= dst
->xmesaContext
;
1373 if (GetCurrentContext() == src
) {
1376 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1381 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1384 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1385 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1391 return True
; /* we're faking GLX so always return success */
1396 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1399 GLXContext glxCtx
= ctx
;
1401 XMesaDestroyContext( glxCtx
->xmesaContext
);
1402 XMesaGarbageCollect();
1409 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1411 return ctx
? ctx
->isDirect
: False
;
1417 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1419 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1420 static boolean firsttime
= 1, no_rast
= 0;
1423 no_rast
= getenv("SP_NO_RAST") != NULL
;
1431 XMesaSwapBuffers(buffer
);
1433 else if (getenv("MESA_DEBUG")) {
1434 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1441 /*** GLX_MESA_copy_sub_buffer ***/
1444 glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
1445 int x
, int y
, int width
, int height
)
1447 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1449 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1451 else if (getenv("MESA_DEBUG")) {
1452 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1458 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1461 /* Return GLX version, not Mesa version */
1462 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1463 *maj
= CLIENT_MAJOR_VERSION
;
1464 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1470 * Query the GLX attributes of the given XVisualInfo.
1473 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1479 return GLX_BAD_ATTRIBUTE
;
1480 *value
= (int) True
;
1482 case GLX_BUFFER_SIZE
:
1483 *value
= xmvis
->visinfo
->depth
;
1486 *value
= xmvis
->mesa_visual
.level
;
1490 return GLX_BAD_ATTRIBUTE
;
1493 case GLX_DOUBLEBUFFER
:
1494 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1497 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1499 case GLX_AUX_BUFFERS
:
1500 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1503 *value
= xmvis
->mesa_visual
.redBits
;
1505 case GLX_GREEN_SIZE
:
1506 *value
= xmvis
->mesa_visual
.greenBits
;
1509 *value
= xmvis
->mesa_visual
.blueBits
;
1511 case GLX_ALPHA_SIZE
:
1512 *value
= xmvis
->mesa_visual
.alphaBits
;
1514 case GLX_DEPTH_SIZE
:
1515 *value
= xmvis
->mesa_visual
.depthBits
;
1517 case GLX_STENCIL_SIZE
:
1518 *value
= xmvis
->mesa_visual
.stencilBits
;
1520 case GLX_ACCUM_RED_SIZE
:
1521 *value
= xmvis
->mesa_visual
.accumRedBits
;
1523 case GLX_ACCUM_GREEN_SIZE
:
1524 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1526 case GLX_ACCUM_BLUE_SIZE
:
1527 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1529 case GLX_ACCUM_ALPHA_SIZE
:
1530 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1534 * GLX_EXT_visual_info extension
1536 case GLX_X_VISUAL_TYPE_EXT
:
1537 switch (xmvis
->visinfo
->CLASS
) {
1538 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1539 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1540 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1541 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1542 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1543 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1546 case GLX_TRANSPARENT_TYPE_EXT
:
1548 *value
= GLX_NONE_EXT
;
1550 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1553 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1556 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1559 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1562 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1567 * GLX_EXT_visual_info extension
1569 case GLX_VISUAL_CAVEAT_EXT
:
1570 /* test for zero, just in case */
1571 if (xmvis
->mesa_visual
.visualRating
> 0)
1572 *value
= xmvis
->mesa_visual
.visualRating
;
1574 *value
= GLX_NONE_EXT
;
1578 * GLX_ARB_multisample
1580 case GLX_SAMPLE_BUFFERS_ARB
:
1581 *value
= xmvis
->mesa_visual
.sampleBuffers
;
1583 case GLX_SAMPLES_ARB
:
1584 *value
= xmvis
->mesa_visual
.samples
;
1590 case GLX_SCREEN_EXT
:
1592 return GLX_BAD_ATTRIBUTE
;
1593 *value
= xmvis
->visinfo
->screen
;
1595 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1597 return GLX_BAD_ATTRIBUTE
;
1598 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1600 case GLX_RENDER_TYPE_SGIX
:
1602 return GLX_BAD_ATTRIBUTE
;
1603 *value
= GLX_RGBA_BIT
;
1605 case GLX_X_RENDERABLE_SGIX
:
1607 return GLX_BAD_ATTRIBUTE
;
1608 *value
= True
; /* XXX really? */
1610 case GLX_FBCONFIG_ID_SGIX
:
1612 return GLX_BAD_ATTRIBUTE
;
1613 *value
= xmvis
->visinfo
->visualid
;
1615 case GLX_MAX_PBUFFER_WIDTH
:
1617 return GLX_BAD_ATTRIBUTE
;
1618 /* XXX should be same as ctx->Const.MaxRenderbufferSize */
1619 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1621 case GLX_MAX_PBUFFER_HEIGHT
:
1623 return GLX_BAD_ATTRIBUTE
;
1624 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1626 case GLX_MAX_PBUFFER_PIXELS
:
1628 return GLX_BAD_ATTRIBUTE
;
1629 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1630 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1634 return GLX_BAD_ATTRIBUTE
;
1635 *value
= xmvis
->visinfo
->visualid
;
1638 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1639 *value
= True
; /*XXX*/
1641 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1643 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1645 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1646 *value
= True
; /*XXX*/
1648 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1649 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1650 GLX_TEXTURE_2D_BIT_EXT
|
1651 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1653 case GLX_Y_INVERTED_EXT
:
1654 *value
= True
; /*XXX*/
1658 return GLX_BAD_ATTRIBUTE
;
1665 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1666 int attrib
, int *value
)
1670 if (!dpy
|| !visinfo
)
1671 return GLX_BAD_ATTRIBUTE
;
1673 xmvis
= find_glx_visual( dpy
, visinfo
);
1675 /* this visual wasn't obtained with glXChooseVisual */
1676 xmvis
= create_glx_visual( dpy
, visinfo
);
1678 /* this visual can't be used for GL rendering */
1679 if (attrib
==GLX_USE_GL
) {
1680 *value
= (int) False
;
1684 return GLX_BAD_VISUAL
;
1689 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1697 XMesaContext xmesa
= XMesaGetCurrentContext();
1698 XMesaFlush( xmesa
);
1706 XMesaContext xmesa
= XMesaGetCurrentContext();
1707 XMesaFlush( xmesa
);
1712 get_extensions( void )
1719 /* GLX 1.1 and later */
1721 glXQueryExtensionsString( Display
*dpy
, int screen
)
1725 return get_extensions();
1730 /* GLX 1.1 and later */
1732 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1734 static char version
[1000];
1735 sprintf(version
, "%d.%d %s",
1736 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, xmesa_get_name());
1742 case GLX_EXTENSIONS
:
1743 return get_extensions();
1755 /* GLX 1.1 and later */
1757 glXGetClientString( Display
*dpy
, int name
)
1759 static char version
[1000];
1760 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1761 CLIENT_MINOR_VERSION
, xmesa_get_name());
1766 case GLX_EXTENSIONS
:
1767 return get_extensions();
1785 glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1786 int attribute
, int *value
)
1788 XMesaVisual v
= (XMesaVisual
) config
;
1792 if (!dpy
|| !config
|| !value
)
1795 return get_config(v
, attribute
, value
, GL_TRUE
);
1799 PUBLIC GLXFBConfig
*
1800 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1802 XVisualInfo
*visuals
, visTemplate
;
1803 const long visMask
= VisualScreenMask
;
1806 /* Get list of all X visuals */
1807 visTemplate
.screen
= screen
;
1808 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1809 if (*nelements
> 0) {
1810 XMesaVisual
*results
= malloc(*nelements
* sizeof(XMesaVisual
));
1815 for (i
= 0; i
< *nelements
; i
++) {
1816 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1822 return (GLXFBConfig
*) results
;
1828 PUBLIC GLXFBConfig
*
1829 glXChooseFBConfig(Display
*dpy
, int screen
,
1830 const int *attribList
, int *nitems
)
1834 /* register ourselves as an extension on this display */
1835 register_with_display(dpy
);
1837 if (!attribList
|| !attribList
[0]) {
1838 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1839 return glXGetFBConfigs(dpy
, screen
, nitems
);
1842 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1844 GLXFBConfig
*config
= malloc(sizeof(XMesaVisual
));
1850 config
[0] = (GLXFBConfig
) xmvis
;
1851 return (GLXFBConfig
*) config
;
1860 PUBLIC XVisualInfo
*
1861 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1863 if (dpy
&& config
) {
1864 XMesaVisual xmvis
= (XMesaVisual
) config
;
1866 return xmvis
->vishandle
;
1868 /* create a new vishandle - the cached one may be stale */
1869 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1870 if (xmvis
->vishandle
) {
1871 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1873 return xmvis
->vishandle
;
1883 glXCreateWindow(Display
*dpy
, GLXFBConfig config
, Window win
,
1884 const int *attribList
)
1886 XMesaVisual xmvis
= (XMesaVisual
) config
;
1891 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1896 (void) attribList
; /* Ignored in GLX 1.3 */
1898 return win
; /* A hack for now */
1903 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1905 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1907 XMesaDestroyBuffer(b
);
1908 /* don't destroy X window */
1914 glXCreatePixmap(Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1915 const int *attribList
)
1917 XMesaVisual v
= (XMesaVisual
) config
;
1920 int target
= 0, format
= 0, mipmap
= 0;
1923 if (!dpy
|| !config
|| !pixmap
)
1926 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1928 case GLX_TEXTURE_FORMAT_EXT
:
1931 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1932 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1933 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1941 case GLX_TEXTURE_TARGET_EXT
:
1944 case GLX_TEXTURE_1D_EXT
:
1945 case GLX_TEXTURE_2D_EXT
:
1946 case GLX_TEXTURE_RECTANGLE_EXT
:
1954 case GLX_MIPMAP_TEXTURE_EXT
:
1965 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1966 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1967 &value
, GL_TRUE
) != Success
1969 return 0; /* error! */
1972 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
1973 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
1974 &value
, GL_TRUE
) != Success
1976 return 0; /* error! */
1980 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
1981 &value
, GL_TRUE
) != Success
1983 return 0; /* error! */
1986 if (target
== GLX_TEXTURE_1D_EXT
) {
1987 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1988 &value
, GL_TRUE
) != Success
1989 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
1990 return 0; /* error! */
1993 else if (target
== GLX_TEXTURE_2D_EXT
) {
1994 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1995 &value
, GL_TRUE
) != Success
1996 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
1997 return 0; /* error! */
2000 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2001 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2002 &value
, GL_TRUE
) != Success
2003 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2004 return 0; /* error! */
2008 if (format
|| target
|| mipmap
) {
2009 /* texture from pixmap */
2010 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2013 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2024 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2026 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
2028 XMesaDestroyBuffer(b
);
2029 /* don't destroy X pixmap */
2034 glXCreatePbuffer(Display
*dpy
, GLXFBConfig config
, const int *attribList
)
2036 XMesaVisual xmvis
= (XMesaVisual
) config
;
2039 int width
= 0, height
= 0;
2040 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2044 for (attrib
= attribList
; *attrib
; attrib
++) {
2046 case GLX_PBUFFER_WIDTH
:
2050 case GLX_PBUFFER_HEIGHT
:
2054 case GLX_PRESERVED_CONTENTS
:
2056 preserveContents
= *attrib
;
2058 case GLX_LARGEST_PBUFFER
:
2060 useLargest
= *attrib
;
2067 if (width
== 0 || height
== 0)
2070 if (width
> PBUFFER_MAX_SIZE
|| height
> PBUFFER_MAX_SIZE
) {
2071 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2072 * allocate the largest possible buffer.
2075 width
= PBUFFER_MAX_SIZE
;
2076 height
= PBUFFER_MAX_SIZE
;
2080 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2081 /* A GLXPbuffer handle must be an X Drawable because that's what
2082 * glXMakeCurrent takes.
2085 xmbuf
->largestPbuffer
= useLargest
;
2086 xmbuf
->preservedContents
= preserveContents
;
2087 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2096 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2098 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2100 XMesaDestroyBuffer(b
);
2106 glXQueryDrawable(Display
*dpy
, GLXDrawable draw
, int attribute
,
2107 unsigned int *value
)
2109 GLuint width
, height
;
2110 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2112 generate_error(dpy
, GLXBadDrawable
, draw
, X_GLXGetDrawableAttributes
, False
);
2116 /* make sure buffer's dimensions are up to date */
2117 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2119 switch (attribute
) {
2126 case GLX_PRESERVED_CONTENTS
:
2127 *value
= xmbuf
->preservedContents
;
2129 case GLX_LARGEST_PBUFFER
:
2130 *value
= xmbuf
->largestPbuffer
;
2132 case GLX_FBCONFIG_ID
:
2133 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2135 case GLX_TEXTURE_FORMAT_EXT
:
2136 *value
= xmbuf
->TextureFormat
;
2138 case GLX_TEXTURE_TARGET_EXT
:
2139 *value
= xmbuf
->TextureTarget
;
2141 case GLX_MIPMAP_TEXTURE_EXT
:
2142 *value
= xmbuf
->TextureMipmap
;
2146 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, true);
2153 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2154 int renderType
, GLXContext shareCtx
, Bool direct
)
2156 XMesaVisual xmvis
= (XMesaVisual
) config
;
2158 if (!dpy
|| !config
||
2159 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2162 return create_context(dpy
, xmvis
,
2163 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2165 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2170 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2172 GLXContext glxCtx
= ctx
;
2173 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2178 switch (attribute
) {
2179 case GLX_FBCONFIG_ID
:
2180 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2182 case GLX_RENDER_TYPE
:
2183 *value
= GLX_RGBA_TYPE
;
2189 return GLX_BAD_ATTRIBUTE
;
2196 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2198 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2200 xmbuf
->selectedEvents
= mask
;
2205 glXGetSelectedEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2207 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2209 *mask
= xmbuf
->selectedEvents
;
2216 /*** GLX_SGI_swap_control ***/
2219 glXSwapIntervalSGI(int interval
)
2227 /*** GLX_SGI_video_sync ***/
2229 static unsigned int FrameCounter
= 0;
2232 glXGetVideoSyncSGI(unsigned int *count
)
2234 /* this is a bogus implementation */
2235 *count
= FrameCounter
++;
2240 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2242 if (divisor
<= 0 || remainder
< 0)
2243 return GLX_BAD_VALUE
;
2244 /* this is a bogus implementation */
2246 while (FrameCounter
% divisor
!= remainder
)
2248 *count
= FrameCounter
;
2254 /*** GLX_SGI_make_current_read ***/
2257 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
,
2260 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2265 glXGetCurrentReadDrawableSGI(void)
2272 /*** GLX_SGIX_video_source ***/
2275 PUBLIC GLXVideoSourceSGIX
2276 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
,
2277 VLPath path
, int nodeClass
, VLNode drainNode
)
2289 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2298 /*** GLX_EXT_import_context ***/
2301 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2308 glXGetContextIDEXT(const GLXContext context
)
2315 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2323 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
,
2335 /*** GLX_SGIX_fbconfig ***/
2338 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2339 int attribute
, int *value
)
2341 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2344 PUBLIC GLXFBConfigSGIX
*
2345 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
,
2348 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
,
2349 attrib_list
, nelements
);
2354 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2357 XMesaVisual xmvis
= (XMesaVisual
) config
;
2358 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2359 return xmbuf
->ws
.drawable
; /* need to return an X ID */
2364 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2365 int renderType
, GLXContext shareCtx
,
2368 XMesaVisual xmvis
= (XMesaVisual
) config
;
2370 if (!dpy
|| !config
||
2371 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2374 return create_context(dpy
, xmvis
,
2375 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2377 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2381 PUBLIC XVisualInfo
*
2382 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2384 return glXGetVisualFromFBConfig(dpy
, config
);
2388 PUBLIC GLXFBConfigSGIX
2389 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2391 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2393 /* This visual wasn't found with glXChooseVisual() */
2394 xmvis
= create_glx_visual(dpy
, vis
);
2397 return (GLXFBConfigSGIX
) xmvis
;
2402 /*** GLX_SGIX_pbuffer ***/
2404 PUBLIC GLXPbufferSGIX
2405 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2406 unsigned int width
, unsigned int height
,
2409 XMesaVisual xmvis
= (XMesaVisual
) config
;
2412 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2416 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2418 case GLX_PRESERVED_CONTENTS_SGIX
:
2420 preserveContents
= *attrib
; /* ignored */
2422 case GLX_LARGEST_PBUFFER_SGIX
:
2424 useLargest
= *attrib
; /* ignored */
2431 /* not used at this time */
2433 (void) preserveContents
;
2435 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2436 /* A GLXPbuffer handle must be an X Drawable because that's what
2437 * glXMakeCurrent takes.
2439 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2444 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2446 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2448 XMesaDestroyBuffer(xmbuf
);
2454 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
,
2455 unsigned int *value
)
2457 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2460 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2464 switch (attribute
) {
2465 case GLX_PRESERVED_CONTENTS_SGIX
:
2468 case GLX_LARGEST_PBUFFER_SGIX
:
2469 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2471 case GLX_WIDTH_SGIX
:
2472 *value
= xmesa_buffer_width(xmbuf
);
2474 case GLX_HEIGHT_SGIX
:
2475 *value
= xmesa_buffer_height(xmbuf
);
2477 case GLX_EVENT_MASK_SGIX
:
2478 *value
= 0; /* XXX might be wrong */
2487 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2489 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2491 /* Note: we'll never generate clobber events */
2492 xmbuf
->selectedEvents
= mask
;
2498 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
,
2499 unsigned long *mask
)
2501 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2503 *mask
= xmbuf
->selectedEvents
;
2512 /*** GLX_SGI_cushion ***/
2515 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2524 /*** GLX_SGIX_video_resize ***/
2527 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
,
2538 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2539 int x
, int y
, int w
, int h
)
2552 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2553 int *x
, int *y
, int *w
, int *h
)
2566 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
,
2567 int *dx
, int *dy
, int *dw
, int *dh
)
2580 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2591 /*** GLX_SGIX_dmbuffer **/
2593 #if defined(_DM_BUFFER_H_)
2595 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
,
2596 DMparams
*params
, DMbuffer dmbuffer
)
2607 /*** GLX_SUN_get_transparent_index ***/
2610 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
,
2611 unsigned long *pTransparent
)
2616 (void) pTransparent
;
2622 /*** GLX_MESA_release_buffers ***/
2625 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2626 * (a window or pixmap) prior to destroying the GLXDrawable.
2629 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2631 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2633 XMesaDestroyBuffer(b
);
2639 /*** GLX_EXT_texture_from_pixmap ***/
2642 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2643 const int *attrib_list
)
2645 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2647 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2651 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2653 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2655 XMesaReleaseTexImage(dpy
, b
, buffer
);
2660 /*** GLX_ARB_create_context ***/
2664 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
2665 GLXContext shareCtx
, Bool direct
,
2666 const int *attrib_list
)
2668 XMesaVisual xmvis
= (XMesaVisual
) config
;
2669 int majorVersion
= 1, minorVersion
= 0;
2670 int contextFlags
= 0x0;
2671 int profileMask
= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
;
2672 int renderType
= GLX_RGBA_TYPE
;
2675 const int contextFlagsAll
= (GLX_CONTEXT_DEBUG_BIT_ARB
|
2676 GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
);
2679 /* parse attrib_list */
2680 for (i
= 0; !done
&& attrib_list
&& attrib_list
[i
]; i
++) {
2681 switch (attrib_list
[i
]) {
2682 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2683 majorVersion
= attrib_list
[++i
];
2685 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2686 minorVersion
= attrib_list
[++i
];
2688 case GLX_CONTEXT_FLAGS_ARB
:
2689 contextFlags
= attrib_list
[++i
];
2691 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2692 profileMask
= attrib_list
[++i
];
2694 case GLX_RENDER_TYPE
:
2695 renderType
= attrib_list
[++i
];
2703 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2708 /* check contextFlags */
2709 if (contextFlags
& ~contextFlagsAll
) {
2710 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2714 /* check profileMask */
2715 if (profileMask
!= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
&&
2716 profileMask
!= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
&&
2717 profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
) {
2718 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAttribsARB
, False
);
2722 /* check renderType */
2723 if (renderType
!= GLX_RGBA_TYPE
&&
2724 renderType
!= GLX_COLOR_INDEX_TYPE
) {
2725 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
2730 if (majorVersion
<= 0 ||
2732 (profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2733 ((majorVersion
== 1 && minorVersion
> 5) ||
2734 (majorVersion
== 2 && minorVersion
> 1) ||
2735 (majorVersion
== 3 && minorVersion
> 3) ||
2736 (majorVersion
== 4 && minorVersion
> 5) ||
2737 majorVersion
> 4))) {
2738 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2741 if (profileMask
== GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2742 ((majorVersion
== 1 && minorVersion
> 1) ||
2743 (majorVersion
== 2 && minorVersion
> 0) ||
2744 (majorVersion
== 3 && minorVersion
> 1) ||
2745 majorVersion
> 3)) {
2746 /* GLX_EXT_create_context_es2_profile says nothing to justifying a
2747 * different error code for invalid ES versions, but this is what NVIDIA
2748 * does and piglit expects.
2750 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAttribsARB
, False
);
2754 if ((contextFlags
& GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
) &&
2756 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2760 if (renderType
== GLX_COLOR_INDEX_TYPE
&& majorVersion
>= 3) {
2761 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAttribsARB
, True
);
2765 ctx
= create_context(dpy
, xmvis
,
2766 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2768 majorVersion
, minorVersion
,
2769 profileMask
, contextFlags
);
2771 generate_error(dpy
, GLXBadFBConfig
, 0, X_GLXCreateContextAttribsARB
, False
);