All elements of pre-DRI_NEW_INTERFACE_ONLY are removed. This allows
[mesa.git] / src / glx / x11 / glxcmds.c
1 /* $XFree86: xc/lib/GL/glx/glxcmds.c,v 1.30 2004/01/30 20:33:06 alanh Exp $ */
2 /*
3 ** License Applicability. Except to the extent portions of this file are
4 ** made subject to an alternative license as permitted in the SGI Free
5 ** Software License B, Version 1.1 (the "License"), the contents of this
6 ** file are subject only to the provisions of the License. You may not use
7 ** this file except in compliance with the License. You may obtain a copy
8 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 **
11 ** http://oss.sgi.com/projects/FreeB
12 **
13 ** Note that, as provided in the License, the Software is distributed on an
14 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 **
19 ** Original Code. The Original Code is: OpenGL Sample Implementation,
20 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22 ** Copyright in any portions created by third parties is as indicated
23 ** elsewhere herein. All Rights Reserved.
24 **
25 ** Additional Notice Provisions: The application programming interfaces
26 ** established by SGI in conjunction with the Original Code are The
27 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30 ** Window System(R) (Version 1.3), released October 19, 1998. This software
31 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32 ** published by SGI, but has not been independently verified as being
33 ** compliant with the OpenGL(R) version 1.2.1 Specification.
34 **
35 */
36
37 /**
38 * \file glxcmds.c
39 * Client-side GLX interface.
40 */
41
42 #include <inttypes.h>
43 #include "glxclient.h"
44 #include <extutil.h>
45 #include <Xext.h>
46 #include <assert.h>
47 #include <string.h>
48 #include "glapi.h"
49 #ifdef GLX_DIRECT_RENDERING
50 #include "indirect_init.h"
51 #include "xf86vmode.h"
52 #endif
53 #include "glxextensions.h"
54 #include "glcontextmodes.h"
55 #include "glheader.h"
56 #include <sys/time.h>
57
58 #ifdef IN_DOXYGEN
59 #define GLX_PREFIX(x) x
60 #endif /* IN_DOXYGEN */
61
62 static const char __glXGLXClientVendorName[] = "SGI";
63 static const char __glXGLXClientVersion[] = "1.4";
64
65
66 #if defined(GLX_DIRECT_RENDERING)
67 #include "xf86dri.h"
68
69 static Bool __glXWindowExists(Display *dpy, GLXDrawable draw);
70 #endif
71
72
73 /****************************************************************************/
74 /**
75 * Get the __DRIdrawable for the drawable associated with a GLXContext
76 *
77 * \param dpy The display associated with \c drawable.
78 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
79 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
80 * the drawable is not associated with a direct-rendering context.
81 */
82
83 #ifdef GLX_DIRECT_RENDERING
84 static __DRIdrawable *
85 GetDRIDrawable( Display *dpy, GLXDrawable drawable, int * const scrn_num )
86 {
87 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
88
89 if ( (priv != NULL) && (priv->driDisplay.private != NULL) ) {
90 const unsigned screen_count = ScreenCount(dpy);
91 unsigned i;
92
93 for ( i = 0 ; i < screen_count ; i++ ) {
94 __DRIscreen * const psc = &priv->screenConfigs[i].driScreen;
95 __DRIdrawable * const pdraw = (psc->private != NULL)
96 ? (*psc->getDrawable)(dpy, drawable, psc->private) : NULL;
97
98 if ( pdraw != NULL ) {
99 if ( scrn_num != NULL ) {
100 *scrn_num = i;
101 }
102 return pdraw;
103 }
104 }
105 }
106
107 return NULL;
108 }
109 #endif
110
111
112 /**
113 * Get the GLX per-screen data structure associated with a GLX context.
114 *
115 * \param dpy Display for which the GLX per-screen information is to be
116 * retrieved.
117 * \param scrn Screen on \c dpy for which the GLX per-screen information is
118 * to be retrieved.
119 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
120 * specify a valid GLX screen, or NULL otherwise.
121 *
122 * \todo Should this function validate that \c scrn is within the screen
123 * number range for \c dpy?
124 */
125
126 static __GLXscreenConfigs *
127 GetGLXScreenConfigs(Display *dpy, int scrn)
128 {
129 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
130
131 return (priv->screenConfigs != NULL) ? &priv->screenConfigs[scrn] : NULL;
132 }
133
134
135 static int
136 GetGLXPrivScreenConfig( Display *dpy, int scrn, __GLXdisplayPrivate ** ppriv,
137 __GLXscreenConfigs ** ppsc )
138 {
139 /* Initialize the extension, if needed . This has the added value
140 * of initializing/allocating the display private
141 */
142
143 if ( dpy == NULL ) {
144 return GLX_NO_EXTENSION;
145 }
146
147 *ppriv = __glXInitialize(dpy);
148 if ( *ppriv == NULL ) {
149 return GLX_NO_EXTENSION;
150 }
151
152 /* Check screen number to see if its valid */
153 if ((scrn < 0) || (scrn >= ScreenCount(dpy))) {
154 return GLX_BAD_SCREEN;
155 }
156
157 /* Check to see if the GL is supported on this screen */
158 *ppsc = &((*ppriv)->screenConfigs[scrn]);
159 if ( (*ppsc)->configs == NULL ) {
160 /* No support for GL on this screen regardless of visual */
161 return GLX_BAD_VISUAL;
162 }
163
164 return Success;
165 }
166
167
168 /**
169 * Determine if a \c GLXFBConfig supplied by the application is valid.
170 *
171 * \param dpy Application supplied \c Display pointer.
172 * \param config Application supplied \c GLXFBConfig.
173 *
174 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
175 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
176 * is returned.
177 */
178 static __GLcontextModes *
179 ValidateGLXFBConfig( Display * dpy, GLXFBConfig config )
180 {
181 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
182 const unsigned num_screens = ScreenCount(dpy);
183 unsigned i;
184 const __GLcontextModes * modes;
185
186
187 if ( priv != NULL ) {
188 for ( i = 0 ; i < num_screens ; i++ ) {
189 for ( modes = priv->screenConfigs[i].configs
190 ; modes != NULL
191 ; modes = modes->next ) {
192 if ( modes == (__GLcontextModes *) config ) {
193 return (__GLcontextModes *) config;
194 }
195 }
196 }
197 }
198
199 return NULL;
200 }
201
202
203 /**
204 * \todo It should be possible to move the allocate of \c client_state_private
205 * later in the function for direct-rendering contexts. Direct-rendering
206 * contexts don't need to track client state, so they don't need that memory
207 * at all.
208 *
209 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
210 * function called \c __glXAllocateClientState that allocates the memory and
211 * does all the initialization (including the pixel pack / unpack).
212 */
213 static
214 GLXContext AllocateGLXContext( Display *dpy )
215 {
216 GLXContext gc;
217 int bufSize;
218 CARD8 opcode;
219 __GLXattribute *state;
220
221 if (!dpy)
222 return NULL;
223
224 opcode = __glXSetupForCommand(dpy);
225 if (!opcode) {
226 return NULL;
227 }
228
229 /* Allocate our context record */
230 gc = (GLXContext) Xmalloc(sizeof(struct __GLXcontextRec));
231 if (!gc) {
232 /* Out of memory */
233 return NULL;
234 }
235 memset(gc, 0, sizeof(struct __GLXcontextRec));
236
237 state = Xmalloc(sizeof(struct __GLXattributeRec));
238 if (state == NULL) {
239 /* Out of memory */
240 Xfree(gc);
241 return NULL;
242 }
243 gc->client_state_private = state;
244 memset(gc->client_state_private, 0, sizeof(struct __GLXattributeRec));
245 state->NoDrawArraysProtocol = (getenv("LIBGL_NO_DRAWARRAYS") != NULL);
246
247 /*
248 ** Create a temporary buffer to hold GLX rendering commands. The size
249 ** of the buffer is selected so that the maximum number of GLX rendering
250 ** commands can fit in a single X packet and still have room in the X
251 ** packet for the GLXRenderReq header.
252 */
253
254 bufSize = (XMaxRequestSize(dpy) * 4) - sz_xGLXRenderReq;
255 gc->buf = (GLubyte *) Xmalloc(bufSize);
256 if (!gc->buf) {
257 Xfree(gc->client_state_private);
258 Xfree(gc);
259 return NULL;
260 }
261 gc->bufSize = bufSize;
262
263 /* Fill in the new context */
264 gc->renderMode = GL_RENDER;
265
266 state->storePack.alignment = 4;
267 state->storeUnpack.alignment = 4;
268
269 gc->attributes.stackPointer = &gc->attributes.stack[0];
270
271 /*
272 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
273 ** Other code uses the fastImageUnpack bit, but it is never set
274 ** to GL_TRUE.
275 */
276 gc->fastImageUnpack = GL_FALSE;
277 gc->fillImage = __glFillImage;
278 gc->isDirect = GL_FALSE;
279 gc->pc = gc->buf;
280 gc->bufEnd = gc->buf + bufSize;
281 if (__glXDebug) {
282 /*
283 ** Set limit register so that there will be one command per packet
284 */
285 gc->limit = gc->buf;
286 } else {
287 gc->limit = gc->buf + bufSize - __GLX_BUFFER_LIMIT_SIZE;
288 }
289 gc->createDpy = dpy;
290 gc->majorOpcode = opcode;
291
292 /*
293 ** Constrain the maximum drawing command size allowed to be
294 ** transfered using the X_GLXRender protocol request. First
295 ** constrain by a software limit, then constrain by the protocl
296 ** limit.
297 */
298 if (bufSize > __GLX_RENDER_CMD_SIZE_LIMIT) {
299 bufSize = __GLX_RENDER_CMD_SIZE_LIMIT;
300 }
301 if (bufSize > __GLX_MAX_RENDER_CMD_SIZE) {
302 bufSize = __GLX_MAX_RENDER_CMD_SIZE;
303 }
304 gc->maxSmallRenderCommandSize = bufSize;
305 return gc;
306 }
307
308
309 /**
310 * Create a new context. Exactly one of \c vis and \c fbconfig should be
311 * non-NULL.
312 *
313 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
314 * SGIX_fbconfig protocol be used?
315 * \param renderType For FBConfigs, what is the rendering type?
316 */
317
318 static GLXContext
319 CreateContext(Display *dpy, XVisualInfo *vis,
320 const __GLcontextModes * const fbconfig,
321 GLXContext shareList,
322 Bool allowDirect, GLXContextID contextID,
323 Bool use_glx_1_3, int renderType)
324 {
325 GLXContext gc;
326
327 if ( dpy == NULL )
328 return NULL;
329
330 gc = AllocateGLXContext(dpy);
331 if (!gc)
332 return NULL;
333
334 if (None == contextID) {
335 if ( (vis == NULL) && (fbconfig == NULL) )
336 return NULL;
337
338 #ifdef GLX_DIRECT_RENDERING
339 if (allowDirect) {
340 int screen = (fbconfig == NULL) ? vis->screen : fbconfig->screen;
341 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
342 const __GLcontextModes * mode;
343
344 /* The value of fbconfig cannot change because it is tested
345 * later in the function.
346 */
347 if ( fbconfig == NULL ) {
348 /* FIXME: Is it possible for the __GLcontextModes structure
349 * FIXME: to not be found?
350 */
351 mode = _gl_context_modes_find_visual( psc->configs,
352 vis->visualid );
353 assert( mode != NULL );
354 assert( mode->screen == screen );
355 }
356 else {
357 mode = fbconfig;
358 }
359
360 if (psc && psc->driScreen.private) {
361 void * const shared = (shareList != NULL)
362 ? shareList->driContext.private : NULL;
363 gc->driContext.private =
364 (*psc->driScreen.createNewContext)( dpy, mode, renderType,
365 shared,
366 &gc->driContext );
367 if (gc->driContext.private) {
368 gc->isDirect = GL_TRUE;
369 gc->screen = mode->screen;
370 gc->vid = mode->visualID;
371 gc->fbconfigID = mode->fbconfigID;
372 gc->driContext.mode = mode;
373 }
374 }
375 }
376 #endif
377
378 LockDisplay(dpy);
379 if ( fbconfig == NULL ) {
380 xGLXCreateContextReq *req;
381
382 /* Send the glXCreateContext request */
383 GetReq(GLXCreateContext,req);
384 req->reqType = gc->majorOpcode;
385 req->glxCode = X_GLXCreateContext;
386 req->context = gc->xid = XAllocID(dpy);
387 req->visual = vis->visualid;
388 req->screen = vis->screen;
389 req->shareList = shareList ? shareList->xid : None;
390 req->isDirect = gc->isDirect;
391 }
392 else if ( use_glx_1_3 ) {
393 xGLXCreateNewContextReq *req;
394
395 /* Send the glXCreateNewContext request */
396 GetReq(GLXCreateNewContext,req);
397 req->reqType = gc->majorOpcode;
398 req->glxCode = X_GLXCreateNewContext;
399 req->context = gc->xid = XAllocID(dpy);
400 req->fbconfig = fbconfig->fbconfigID;
401 req->screen = fbconfig->screen;
402 req->renderType = renderType;
403 req->shareList = shareList ? shareList->xid : None;
404 req->isDirect = gc->isDirect;
405 }
406 else {
407 xGLXVendorPrivateWithReplyReq *vpreq;
408 xGLXCreateContextWithConfigSGIXReq *req;
409
410 /* Send the glXCreateNewContext request */
411 GetReqExtra(GLXVendorPrivateWithReply,
412 sz_xGLXCreateContextWithConfigSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq);
413 req = (xGLXCreateContextWithConfigSGIXReq *)vpreq;
414 req->reqType = gc->majorOpcode;
415 req->glxCode = X_GLXVendorPrivateWithReply;
416 req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
417 req->context = gc->xid = XAllocID(dpy);
418 req->fbconfig = fbconfig->fbconfigID;
419 req->screen = fbconfig->screen;
420 req->renderType = renderType;
421 req->shareList = shareList ? shareList->xid : None;
422 req->isDirect = gc->isDirect;
423 }
424
425 UnlockDisplay(dpy);
426 SyncHandle();
427 gc->imported = GL_FALSE;
428 }
429 else {
430 gc->xid = contextID;
431 gc->imported = GL_TRUE;
432 }
433
434 return gc;
435 }
436
437 PUBLIC GLXContext GLX_PREFIX(glXCreateContext)(Display *dpy, XVisualInfo *vis,
438 GLXContext shareList,
439 Bool allowDirect)
440 {
441 return CreateContext(dpy, vis, NULL, shareList, allowDirect, None,
442 False, 0);
443 }
444
445 void __glXFreeContext(__GLXcontext *gc)
446 {
447 if (gc->vendor) XFree((char *) gc->vendor);
448 if (gc->renderer) XFree((char *) gc->renderer);
449 if (gc->version) XFree((char *) gc->version);
450 if (gc->extensions) XFree((char *) gc->extensions);
451 __glFreeAttributeState(gc);
452 XFree((char *) gc->buf);
453 Xfree((char *) gc->client_state_private);
454 XFree((char *) gc);
455
456 }
457
458 /*
459 ** Destroy the named context
460 */
461 static void
462 DestroyContext(Display *dpy, GLXContext gc)
463 {
464 xGLXDestroyContextReq *req;
465 GLXContextID xid;
466 CARD8 opcode;
467 GLboolean imported;
468
469 opcode = __glXSetupForCommand(dpy);
470 if (!opcode || !gc) {
471 return;
472 }
473
474 __glXLock();
475 xid = gc->xid;
476 imported = gc->imported;
477 gc->xid = None;
478
479 #ifdef GLX_DIRECT_RENDERING
480 /* Destroy the direct rendering context */
481 if (gc->isDirect) {
482 if (gc->driContext.private) {
483 (*gc->driContext.destroyContext)(dpy, gc->screen,
484 gc->driContext.private);
485 gc->driContext.private = NULL;
486 }
487 }
488 #endif
489
490 if (gc->currentDpy) {
491 /* Have to free later cuz it's in use now */
492 __glXUnlock();
493 } else {
494 /* Destroy the handle if not current to anybody */
495 __glXUnlock();
496 __glXFreeContext(gc);
497 }
498
499 if (!imported) {
500 /*
501 ** This dpy also created the server side part of the context.
502 ** Send the glXDestroyContext request.
503 */
504 LockDisplay(dpy);
505 GetReq(GLXDestroyContext,req);
506 req->reqType = opcode;
507 req->glxCode = X_GLXDestroyContext;
508 req->context = xid;
509 UnlockDisplay(dpy);
510 SyncHandle();
511 }
512 }
513
514 PUBLIC void GLX_PREFIX(glXDestroyContext)(Display *dpy, GLXContext gc)
515 {
516 DestroyContext(dpy, gc);
517 }
518
519 /*
520 ** Return the major and minor version #s for the GLX extension
521 */
522 PUBLIC Bool GLX_PREFIX(glXQueryVersion)(Display *dpy, int *major, int *minor)
523 {
524 __GLXdisplayPrivate *priv;
525
526 /* Init the extension. This fetches the major and minor version. */
527 priv = __glXInitialize(dpy);
528 if (!priv) return GL_FALSE;
529
530 if (major) *major = priv->majorVersion;
531 if (minor) *minor = priv->minorVersion;
532 return GL_TRUE;
533 }
534
535 /*
536 ** Query the existance of the GLX extension
537 */
538 PUBLIC Bool GLX_PREFIX(glXQueryExtension)(Display *dpy, int *errorBase,
539 int *eventBase)
540 {
541 int major_op, erb, evb;
542 Bool rv;
543
544 rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb);
545 if (rv) {
546 if (errorBase) *errorBase = erb;
547 if (eventBase) *eventBase = evb;
548 }
549 return rv;
550 }
551
552 /*
553 ** Put a barrier in the token stream that forces the GL to finish its
554 ** work before X can proceed.
555 */
556 PUBLIC void GLX_PREFIX(glXWaitGL)(void)
557 {
558 xGLXWaitGLReq *req;
559 GLXContext gc = __glXGetCurrentContext();
560 Display *dpy = gc->currentDpy;
561
562 if (!dpy) return;
563
564 /* Flush any pending commands out */
565 __glXFlushRenderBuffer(gc, gc->pc);
566
567 #ifdef GLX_DIRECT_RENDERING
568 if (gc->isDirect) {
569 /* This bit of ugliness unwraps the glFinish function */
570 #ifdef glFinish
571 #undef glFinish
572 #endif
573 glFinish();
574 return;
575 }
576 #endif
577
578 /* Send the glXWaitGL request */
579 LockDisplay(dpy);
580 GetReq(GLXWaitGL,req);
581 req->reqType = gc->majorOpcode;
582 req->glxCode = X_GLXWaitGL;
583 req->contextTag = gc->currentContextTag;
584 UnlockDisplay(dpy);
585 SyncHandle();
586 }
587
588 /*
589 ** Put a barrier in the token stream that forces X to finish its
590 ** work before GL can proceed.
591 */
592 PUBLIC void GLX_PREFIX(glXWaitX)(void)
593 {
594 xGLXWaitXReq *req;
595 GLXContext gc = __glXGetCurrentContext();
596 Display *dpy = gc->currentDpy;
597
598 if (!dpy) return;
599
600 /* Flush any pending commands out */
601 __glXFlushRenderBuffer(gc, gc->pc);
602
603 #ifdef GLX_DIRECT_RENDERING
604 if (gc->isDirect) {
605 XSync(dpy, False);
606 return;
607 }
608 #endif
609
610 /*
611 ** Send the glXWaitX request.
612 */
613 LockDisplay(dpy);
614 GetReq(GLXWaitX,req);
615 req->reqType = gc->majorOpcode;
616 req->glxCode = X_GLXWaitX;
617 req->contextTag = gc->currentContextTag;
618 UnlockDisplay(dpy);
619 SyncHandle();
620 }
621
622 PUBLIC void GLX_PREFIX(glXUseXFont)(Font font, int first, int count,
623 int listBase)
624 {
625 xGLXUseXFontReq *req;
626 GLXContext gc = __glXGetCurrentContext();
627 Display *dpy = gc->currentDpy;
628
629 if (!dpy) return;
630
631 /* Flush any pending commands out */
632 (void) __glXFlushRenderBuffer(gc, gc->pc);
633
634 #ifdef GLX_DIRECT_RENDERING
635 if (gc->isDirect) {
636 DRI_glXUseXFont(font, first, count, listBase);
637 return;
638 }
639 #endif
640
641 /* Send the glXUseFont request */
642 LockDisplay(dpy);
643 GetReq(GLXUseXFont,req);
644 req->reqType = gc->majorOpcode;
645 req->glxCode = X_GLXUseXFont;
646 req->contextTag = gc->currentContextTag;
647 req->font = font;
648 req->first = first;
649 req->count = count;
650 req->listBase = listBase;
651 UnlockDisplay(dpy);
652 SyncHandle();
653 }
654
655 /************************************************************************/
656
657 /*
658 ** Copy the source context to the destination context using the
659 ** attribute "mask".
660 */
661 PUBLIC void GLX_PREFIX(glXCopyContext)(Display *dpy, GLXContext source,
662 GLXContext dest, unsigned long mask)
663 {
664 xGLXCopyContextReq *req;
665 GLXContext gc = __glXGetCurrentContext();
666 GLXContextTag tag;
667 CARD8 opcode;
668
669 opcode = __glXSetupForCommand(dpy);
670 if (!opcode) {
671 return;
672 }
673
674 #ifdef GLX_DIRECT_RENDERING
675 if (gc->isDirect) {
676 /* NOT_DONE: This does not work yet */
677 }
678 #endif
679
680 /*
681 ** If the source is the current context, send its tag so that the context
682 ** can be flushed before the copy.
683 */
684 if (source == gc && dpy == gc->currentDpy) {
685 tag = gc->currentContextTag;
686 } else {
687 tag = 0;
688 }
689
690 /* Send the glXCopyContext request */
691 LockDisplay(dpy);
692 GetReq(GLXCopyContext,req);
693 req->reqType = opcode;
694 req->glxCode = X_GLXCopyContext;
695 req->source = source ? source->xid : None;
696 req->dest = dest ? dest->xid : None;
697 req->mask = mask;
698 req->contextTag = tag;
699 UnlockDisplay(dpy);
700 SyncHandle();
701 }
702
703
704 /**
705 * Determine if a context uses direct rendering.
706 *
707 * \param dpy Display where the context was created.
708 * \param contextID ID of the context to be tested.
709 *
710 * \returns \c GL_TRUE if the context is direct rendering or not.
711 */
712 static Bool __glXIsDirect(Display *dpy, GLXContextID contextID)
713 {
714 xGLXIsDirectReq *req;
715 xGLXIsDirectReply reply;
716 CARD8 opcode;
717
718 opcode = __glXSetupForCommand(dpy);
719 if (!opcode) {
720 return GL_FALSE;
721 }
722
723 /* Send the glXIsDirect request */
724 LockDisplay(dpy);
725 GetReq(GLXIsDirect,req);
726 req->reqType = opcode;
727 req->glxCode = X_GLXIsDirect;
728 req->context = contextID;
729 _XReply(dpy, (xReply*) &reply, 0, False);
730 UnlockDisplay(dpy);
731 SyncHandle();
732
733 return reply.isDirect;
734 }
735
736 /**
737 * \todo
738 * Shouldn't this function \b always return \c GL_FALSE when
739 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
740 * the GLX protocol here at all?
741 */
742 PUBLIC Bool GLX_PREFIX(glXIsDirect)(Display *dpy, GLXContext gc)
743 {
744 if (!gc) {
745 return GL_FALSE;
746 #ifdef GLX_DIRECT_RENDERING
747 } else if (gc->isDirect) {
748 return GL_TRUE;
749 #endif
750 }
751 return __glXIsDirect(dpy, gc->xid);
752 }
753
754 PUBLIC GLXPixmap GLX_PREFIX(glXCreateGLXPixmap)(Display *dpy, XVisualInfo *vis,
755 Pixmap pixmap)
756 {
757 xGLXCreateGLXPixmapReq *req;
758 GLXPixmap xid;
759 CARD8 opcode;
760
761 opcode = __glXSetupForCommand(dpy);
762 if (!opcode) {
763 return None;
764 }
765
766 /* Send the glXCreateGLXPixmap request */
767 LockDisplay(dpy);
768 GetReq(GLXCreateGLXPixmap,req);
769 req->reqType = opcode;
770 req->glxCode = X_GLXCreateGLXPixmap;
771 req->screen = vis->screen;
772 req->visual = vis->visualid;
773 req->pixmap = pixmap;
774 req->glxpixmap = xid = XAllocID(dpy);
775 UnlockDisplay(dpy);
776 SyncHandle();
777 return xid;
778 }
779
780 /*
781 ** Destroy the named pixmap
782 */
783 PUBLIC void GLX_PREFIX(glXDestroyGLXPixmap)(Display *dpy, GLXPixmap glxpixmap)
784 {
785 xGLXDestroyGLXPixmapReq *req;
786 CARD8 opcode;
787
788 opcode = __glXSetupForCommand(dpy);
789 if (!opcode) {
790 return;
791 }
792
793 /* Send the glXDestroyGLXPixmap request */
794 LockDisplay(dpy);
795 GetReq(GLXDestroyGLXPixmap,req);
796 req->reqType = opcode;
797 req->glxCode = X_GLXDestroyGLXPixmap;
798 req->glxpixmap = glxpixmap;
799 UnlockDisplay(dpy);
800 SyncHandle();
801 }
802
803 PUBLIC void GLX_PREFIX(glXSwapBuffers)(Display *dpy, GLXDrawable drawable)
804 {
805 xGLXSwapBuffersReq *req;
806 GLXContext gc;
807 GLXContextTag tag;
808 CARD8 opcode;
809 #ifdef GLX_DIRECT_RENDERING
810 __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, NULL );
811
812 if ( pdraw != NULL ) {
813 (*pdraw->swapBuffers)(dpy, pdraw->private);
814 return;
815 }
816 #endif
817
818 opcode = __glXSetupForCommand(dpy);
819 if (!opcode) {
820 return;
821 }
822
823 /*
824 ** The calling thread may or may not have a current context. If it
825 ** does, send the context tag so the server can do a flush.
826 */
827 gc = __glXGetCurrentContext();
828 if ((gc != NULL) && (dpy == gc->currentDpy) &&
829 ((drawable == gc->currentDrawable) || (drawable == gc->currentReadable)) ) {
830 tag = gc->currentContextTag;
831 } else {
832 tag = 0;
833 }
834
835 /* Send the glXSwapBuffers request */
836 LockDisplay(dpy);
837 GetReq(GLXSwapBuffers,req);
838 req->reqType = opcode;
839 req->glxCode = X_GLXSwapBuffers;
840 req->drawable = drawable;
841 req->contextTag = tag;
842 UnlockDisplay(dpy);
843 SyncHandle();
844 XFlush(dpy);
845 }
846
847
848 /*
849 ** Return configuration information for the given display, screen and
850 ** visual combination.
851 */
852 PUBLIC int GLX_PREFIX(glXGetConfig)(Display *dpy, XVisualInfo *vis,
853 int attribute, int *value_return)
854 {
855 __GLXdisplayPrivate *priv;
856 __GLXscreenConfigs *psc;
857 int status;
858
859 status = GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc );
860 if ( status == Success ) {
861 const __GLcontextModes * const modes = _gl_context_modes_find_visual(
862 psc->configs, vis->visualid );
863
864 /* Lookup attribute after first finding a match on the visual */
865 if ( modes != NULL ) {
866 return _gl_get_context_mode_data( modes, attribute, value_return );
867 }
868
869 status = GLX_BAD_VISUAL;
870 }
871
872 /*
873 ** If we can't find the config for this visual, this visual is not
874 ** supported by the OpenGL implementation on the server.
875 */
876 if ( (status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL) ) {
877 *value_return = GL_FALSE;
878 status = Success;
879 }
880
881 return status;
882 }
883
884 /************************************************************************/
885
886 static void
887 init_fbconfig_for_chooser( __GLcontextModes * config,
888 GLboolean fbconfig_style_tags )
889 {
890 memset( config, 0, sizeof( __GLcontextModes ) );
891 config->visualID = (XID) GLX_DONT_CARE;
892 config->visualType = GLX_DONT_CARE;
893
894 /* glXChooseFBConfig specifies different defaults for these two than
895 * glXChooseVisual.
896 */
897 if ( fbconfig_style_tags ) {
898 config->rgbMode = GL_TRUE;
899 config->doubleBufferMode = GLX_DONT_CARE;
900 }
901
902 config->visualRating = GLX_DONT_CARE;
903 config->transparentPixel = GLX_NONE;
904 config->transparentRed = GLX_DONT_CARE;
905 config->transparentGreen = GLX_DONT_CARE;
906 config->transparentBlue = GLX_DONT_CARE;
907 config->transparentAlpha = GLX_DONT_CARE;
908 config->transparentIndex = GLX_DONT_CARE;
909
910 config->drawableType = GLX_WINDOW_BIT;
911 config->renderType = (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
912 config->xRenderable = GLX_DONT_CARE;
913 config->fbconfigID = (GLXFBConfigID)(GLX_DONT_CARE);
914
915 config->swapMethod = GLX_DONT_CARE;
916 }
917
918 #define MATCH_DONT_CARE( param ) \
919 do { \
920 if ( (a-> param != GLX_DONT_CARE) \
921 && (a-> param != b-> param) ) { \
922 return False; \
923 } \
924 } while ( 0 )
925
926 #define MATCH_MINIMUM( param ) \
927 do { \
928 if ( (a-> param != GLX_DONT_CARE) \
929 && (a-> param > b-> param) ) { \
930 return False; \
931 } \
932 } while ( 0 )
933
934 #define MATCH_EXACT( param ) \
935 do { \
936 if ( a-> param != b-> param) { \
937 return False; \
938 } \
939 } while ( 0 )
940
941 /**
942 * Determine if two GLXFBConfigs are compatible.
943 *
944 * \param a Application specified config to test.
945 * \param b Server specified config to test against \c a.
946 */
947 static Bool
948 fbconfigs_compatible( const __GLcontextModes * const a,
949 const __GLcontextModes * const b )
950 {
951 MATCH_DONT_CARE( doubleBufferMode );
952 MATCH_DONT_CARE( visualType );
953 MATCH_DONT_CARE( visualRating );
954 MATCH_DONT_CARE( xRenderable );
955 MATCH_DONT_CARE( fbconfigID );
956 MATCH_DONT_CARE( swapMethod );
957
958 MATCH_MINIMUM( rgbBits );
959 MATCH_MINIMUM( numAuxBuffers );
960 MATCH_MINIMUM( redBits );
961 MATCH_MINIMUM( greenBits );
962 MATCH_MINIMUM( blueBits );
963 MATCH_MINIMUM( alphaBits );
964 MATCH_MINIMUM( depthBits );
965 MATCH_MINIMUM( stencilBits );
966 MATCH_MINIMUM( accumRedBits );
967 MATCH_MINIMUM( accumGreenBits );
968 MATCH_MINIMUM( accumBlueBits );
969 MATCH_MINIMUM( accumAlphaBits );
970 MATCH_MINIMUM( sampleBuffers );
971 MATCH_MINIMUM( maxPbufferWidth );
972 MATCH_MINIMUM( maxPbufferHeight );
973 MATCH_MINIMUM( maxPbufferPixels );
974 MATCH_MINIMUM( samples );
975
976 MATCH_DONT_CARE( stereoMode );
977 MATCH_EXACT( level );
978
979 if ( ((a->drawableType & b->drawableType) == 0)
980 || ((a->renderType & b->renderType) == 0) ) {
981 return False;
982 }
983
984
985 /* There is a bug in a few of the XFree86 DDX drivers. They contain
986 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
987 * Technically speaking, it is a bug in the DDX driver, but there is
988 * enough of an installed base to work around the problem here. In any
989 * case, 0 is not a valid value of the transparent type, so we'll treat 0
990 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
991 * 0 from the server to be a match to maintain backward compatibility with
992 * the (broken) drivers.
993 */
994
995 if ( a->transparentPixel != GLX_DONT_CARE
996 && a->transparentPixel != 0 ) {
997 if ( a->transparentPixel == GLX_NONE ) {
998 if ( b->transparentPixel != GLX_NONE && b->transparentPixel != 0 )
999 return False;
1000 } else {
1001 MATCH_EXACT( transparentPixel );
1002 }
1003
1004 switch ( a->transparentPixel ) {
1005 case GLX_TRANSPARENT_RGB:
1006 MATCH_DONT_CARE( transparentRed );
1007 MATCH_DONT_CARE( transparentGreen );
1008 MATCH_DONT_CARE( transparentBlue );
1009 MATCH_DONT_CARE( transparentAlpha );
1010 break;
1011
1012 case GLX_TRANSPARENT_INDEX:
1013 MATCH_DONT_CARE( transparentIndex );
1014 break;
1015
1016 default:
1017 break;
1018 }
1019 }
1020
1021 return True;
1022 }
1023
1024
1025 /* There's some trickly language in the GLX spec about how this is supposed
1026 * to work. Basically, if a given component size is either not specified
1027 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1028 * Well, that's really hard to do with the code as-is. This behavior is
1029 * closer to correct, but still not technically right.
1030 */
1031 #define PREFER_LARGER_OR_ZERO(comp) \
1032 do { \
1033 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1034 if ( ((*a)-> comp) == 0 ) { \
1035 return -1; \
1036 } \
1037 else if ( ((*b)-> comp) == 0 ) { \
1038 return 1; \
1039 } \
1040 else { \
1041 return ((*b)-> comp) - ((*a)-> comp) ; \
1042 } \
1043 } \
1044 } while( 0 )
1045
1046 #define PREFER_LARGER(comp) \
1047 do { \
1048 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1049 return ((*b)-> comp) - ((*a)-> comp) ; \
1050 } \
1051 } while( 0 )
1052
1053 #define PREFER_SMALLER(comp) \
1054 do { \
1055 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1056 return ((*a)-> comp) - ((*b)-> comp) ; \
1057 } \
1058 } while( 0 )
1059
1060 /**
1061 * Compare two GLXFBConfigs. This function is intended to be used as the
1062 * compare function passed in to qsort.
1063 *
1064 * \returns If \c a is a "better" config, according to the specification of
1065 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1066 * better, then a number greater than zero is return. If both are
1067 * equal, zero is returned.
1068 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1069 */
1070 static int
1071 fbconfig_compare( const __GLcontextModes * const * const a,
1072 const __GLcontextModes * const * const b )
1073 {
1074 /* The order of these comparisons must NOT change. It is defined by
1075 * the GLX 1.3 spec and ARB_multisample.
1076 */
1077
1078 PREFER_SMALLER( visualSelectGroup );
1079
1080 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1081 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1082 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1083 */
1084 PREFER_SMALLER( visualRating );
1085
1086 /* This isn't quite right. It is supposed to compare the sum of the
1087 * components the user specifically set minimums for.
1088 */
1089 PREFER_LARGER_OR_ZERO( redBits );
1090 PREFER_LARGER_OR_ZERO( greenBits );
1091 PREFER_LARGER_OR_ZERO( blueBits );
1092 PREFER_LARGER_OR_ZERO( alphaBits );
1093
1094 PREFER_SMALLER( rgbBits );
1095
1096 if ( ((*a)->doubleBufferMode != (*b)->doubleBufferMode) ) {
1097 /* Prefer single-buffer.
1098 */
1099 return ( !(*a)->doubleBufferMode ) ? -1 : 1;
1100 }
1101
1102 PREFER_SMALLER( numAuxBuffers );
1103
1104 PREFER_LARGER_OR_ZERO( depthBits );
1105 PREFER_SMALLER( stencilBits );
1106
1107 /* This isn't quite right. It is supposed to compare the sum of the
1108 * components the user specifically set minimums for.
1109 */
1110 PREFER_LARGER_OR_ZERO( accumRedBits );
1111 PREFER_LARGER_OR_ZERO( accumGreenBits );
1112 PREFER_LARGER_OR_ZERO( accumBlueBits );
1113 PREFER_LARGER_OR_ZERO( accumAlphaBits );
1114
1115 PREFER_SMALLER( visualType );
1116
1117 /* None of the multisample specs say where this comparison should happen,
1118 * so I put it near the end.
1119 */
1120 PREFER_SMALLER( sampleBuffers );
1121 PREFER_SMALLER( samples );
1122
1123 /* None of the pbuffer or fbconfig specs say that this comparison needs
1124 * to happen at all, but it seems like it should.
1125 */
1126 PREFER_LARGER( maxPbufferWidth );
1127 PREFER_LARGER( maxPbufferHeight );
1128 PREFER_LARGER( maxPbufferPixels );
1129
1130 return 0;
1131 }
1132
1133
1134 /**
1135 * Selects and sorts a subset of the supplied configs based on the attributes.
1136 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1137 * and \c glXChooseFBConfigSGIX.
1138 *
1139 * \param configs Array of pointers to possible configs. The elements of
1140 * this array that do not meet the criteria will be set to
1141 * NULL. The remaining elements will be sorted according to
1142 * the various visual / FBConfig selection rules.
1143 * \param num_configs Number of elements in the \c configs array.
1144 * \param attribList Attributes used select from \c configs. This array is
1145 * terminated by a \c None tag. The array can either take
1146 * the form expected by \c glXChooseVisual (where boolean
1147 * tags do not have a value) or by \c glXChooseFBConfig
1148 * (where every tag has a value).
1149 * \param fbconfig_style_tags Selects whether \c attribList is in
1150 * \c glXChooseVisual style or
1151 * \c glXChooseFBConfig style.
1152 * \returns The number of valid elements left in \c configs.
1153 *
1154 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1155 */
1156 static int
1157 choose_visual( __GLcontextModes ** configs, int num_configs,
1158 const int *attribList, GLboolean fbconfig_style_tags )
1159 {
1160 __GLcontextModes test_config;
1161 int base;
1162 int i;
1163
1164 /* This is a fairly direct implementation of the selection method
1165 * described by GLX_SGIX_fbconfig. Start by culling out all the
1166 * configs that are not compatible with the selected parameter
1167 * list.
1168 */
1169
1170 init_fbconfig_for_chooser( & test_config, fbconfig_style_tags );
1171 __glXInitializeVisualConfigFromTags( & test_config, 512,
1172 (const INT32 *) attribList,
1173 GL_TRUE, fbconfig_style_tags );
1174
1175 base = 0;
1176 for ( i = 0 ; i < num_configs ; i++ ) {
1177 if ( fbconfigs_compatible( & test_config, configs[i] ) ) {
1178 configs[ base ] = configs[ i ];
1179 base++;
1180 }
1181 }
1182
1183 if ( base == 0 ) {
1184 return 0;
1185 }
1186
1187 if ( base < num_configs ) {
1188 (void) memset( & configs[ base ], 0,
1189 sizeof( void * ) * (num_configs - base) );
1190 }
1191
1192 /* After the incompatible configs are removed, the resulting
1193 * list is sorted according to the rules set out in the various
1194 * specifications.
1195 */
1196
1197 qsort( configs, base, sizeof( __GLcontextModes * ),
1198 (int (*)(const void*, const void*)) fbconfig_compare );
1199 return base;
1200 }
1201
1202
1203
1204
1205 /*
1206 ** Return the visual that best matches the template. Return None if no
1207 ** visual matches the template.
1208 */
1209 PUBLIC XVisualInfo *GLX_PREFIX(glXChooseVisual)(Display *dpy, int screen,
1210 int *attribList)
1211 {
1212 XVisualInfo *visualList = NULL;
1213 __GLXdisplayPrivate *priv;
1214 __GLXscreenConfigs *psc;
1215 __GLcontextModes test_config;
1216 __GLcontextModes *modes;
1217 const __GLcontextModes *best_config = NULL;
1218
1219 /*
1220 ** Get a list of all visuals, return if list is empty
1221 */
1222 if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) {
1223 return None;
1224 }
1225
1226
1227 /*
1228 ** Build a template from the defaults and the attribute list
1229 ** Free visual list and return if an unexpected token is encountered
1230 */
1231 init_fbconfig_for_chooser( & test_config, GL_FALSE );
1232 __glXInitializeVisualConfigFromTags( & test_config, 512,
1233 (const INT32 *) attribList,
1234 GL_TRUE, GL_FALSE );
1235
1236 /*
1237 ** Eliminate visuals that don't meet minimum requirements
1238 ** Compute a score for those that do
1239 ** Remember which visual, if any, got the highest score
1240 */
1241 for ( modes = psc->configs ; modes != NULL ; modes = modes->next ) {
1242 if ( fbconfigs_compatible( & test_config, modes )
1243 && ((best_config == NULL)
1244 || (fbconfig_compare( (const __GLcontextModes * const * const)&modes, &best_config ) < 0)) ) {
1245 best_config = modes;
1246 }
1247 }
1248
1249 /*
1250 ** If no visual is acceptable, return None
1251 ** Otherwise, create an XVisualInfo list with just the selected X visual
1252 ** and return this.
1253 */
1254 if (best_config != NULL) {
1255 XVisualInfo visualTemplate;
1256 int i;
1257
1258 visualTemplate.screen = screen;
1259 visualTemplate.visualid = best_config->visualID;
1260 visualList = XGetVisualInfo( dpy, VisualScreenMask|VisualIDMask,
1261 &visualTemplate, &i );
1262 }
1263
1264 return visualList;
1265 }
1266
1267
1268 PUBLIC const char *GLX_PREFIX(glXQueryExtensionsString)( Display *dpy,
1269 int screen )
1270 {
1271 __GLXscreenConfigs *psc;
1272 __GLXdisplayPrivate *priv;
1273
1274 if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) {
1275 return NULL;
1276 }
1277
1278 if (!psc->effectiveGLXexts) {
1279 if (!psc->serverGLXexts) {
1280 psc->serverGLXexts = __glXGetStringFromServer(dpy, priv->majorOpcode,
1281 X_GLXQueryServerString,
1282 screen, GLX_EXTENSIONS);
1283 }
1284
1285 __glXCalculateUsableExtensions(psc,
1286 #ifdef GLX_DIRECT_RENDERING
1287 (priv->driDisplay.private != NULL),
1288 #else
1289 GL_FALSE,
1290 #endif
1291 priv->minorVersion);
1292 }
1293
1294 return psc->effectiveGLXexts;
1295 }
1296
1297 PUBLIC const char *GLX_PREFIX(glXGetClientString)( Display *dpy, int name )
1298 {
1299 switch(name) {
1300 case GLX_VENDOR:
1301 return (__glXGLXClientVendorName);
1302 case GLX_VERSION:
1303 return (__glXGLXClientVersion);
1304 case GLX_EXTENSIONS:
1305 return (__glXGetClientExtensions());
1306 default:
1307 return NULL;
1308 }
1309 }
1310
1311 PUBLIC const char *GLX_PREFIX(glXQueryServerString)( Display *dpy, int screen,
1312 int name )
1313 {
1314 __GLXscreenConfigs *psc;
1315 __GLXdisplayPrivate *priv;
1316 const char ** str;
1317
1318
1319 if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) {
1320 return NULL;
1321 }
1322
1323 switch(name) {
1324 case GLX_VENDOR:
1325 str = & priv->serverGLXvendor;
1326 break;
1327 case GLX_VERSION:
1328 str = & priv->serverGLXversion;
1329 break;
1330 case GLX_EXTENSIONS:
1331 str = & psc->serverGLXexts;
1332 break;
1333 default:
1334 return NULL;
1335 }
1336
1337 if ( *str == NULL ) {
1338 *str = __glXGetStringFromServer(dpy, priv->majorOpcode,
1339 X_GLXQueryServerString, screen, name);
1340 }
1341
1342 return *str;
1343 }
1344
1345 void __glXClientInfo ( Display *dpy, int opcode )
1346 {
1347 xGLXClientInfoReq *req;
1348 int size;
1349 char * ext_str = __glXGetClientGLExtensionString();
1350
1351 /* Send the glXClientInfo request */
1352 LockDisplay(dpy);
1353 GetReq(GLXClientInfo,req);
1354 req->reqType = opcode;
1355 req->glxCode = X_GLXClientInfo;
1356 req->major = GLX_MAJOR_VERSION;
1357 req->minor = GLX_MINOR_VERSION;
1358
1359 size = strlen( ext_str ) + 1;
1360 req->length += (size + 3) >> 2;
1361 req->numbytes = size;
1362 Data(dpy, ext_str, size);
1363
1364 UnlockDisplay(dpy);
1365 SyncHandle();
1366
1367 Xfree( ext_str );
1368 }
1369
1370
1371 /*
1372 ** EXT_import_context
1373 */
1374
1375 PUBLIC Display *glXGetCurrentDisplay(void)
1376 {
1377 GLXContext gc = __glXGetCurrentContext();
1378 if (NULL == gc) return NULL;
1379 return gc->currentDpy;
1380 }
1381
1382 PUBLIC GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
1383 glXGetCurrentDisplay)
1384
1385 /**
1386 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1387 * to the X-server.
1388 *
1389 * \param dpy Display where \c ctx was created.
1390 * \param ctx Context to query.
1391 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1392 * or zero if the request failed due to internal problems (i.e.,
1393 * unable to allocate temporary memory, etc.)
1394 *
1395 * \note
1396 * This function dynamically determines whether to use the EXT_import_context
1397 * version of the protocol or the GLX 1.3 version of the protocol.
1398 */
1399 static int __glXQueryContextInfo(Display *dpy, GLXContext ctx)
1400 {
1401 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
1402 xGLXQueryContextReply reply;
1403 CARD8 opcode;
1404 GLuint numValues;
1405 int retval;
1406
1407 if (ctx == NULL) {
1408 return GLX_BAD_CONTEXT;
1409 }
1410 opcode = __glXSetupForCommand(dpy);
1411 if (!opcode) {
1412 return 0;
1413 }
1414
1415 /* Send the glXQueryContextInfoEXT request */
1416 LockDisplay(dpy);
1417
1418 if ( (priv->majorVersion > 1) || (priv->minorVersion >= 3) ) {
1419 xGLXQueryContextReq *req;
1420
1421 GetReq(GLXQueryContext, req);
1422
1423 req->reqType = opcode;
1424 req->glxCode = X_GLXQueryContext;
1425 req->context = (unsigned int)(ctx->xid);
1426 }
1427 else {
1428 xGLXVendorPrivateReq *vpreq;
1429 xGLXQueryContextInfoEXTReq *req;
1430
1431 GetReqExtra( GLXVendorPrivate,
1432 sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq,
1433 vpreq );
1434 req = (xGLXQueryContextInfoEXTReq *)vpreq;
1435 req->reqType = opcode;
1436 req->glxCode = X_GLXVendorPrivateWithReply;
1437 req->vendorCode = X_GLXvop_QueryContextInfoEXT;
1438 req->context = (unsigned int)(ctx->xid);
1439 }
1440
1441 _XReply(dpy, (xReply*) &reply, 0, False);
1442
1443 numValues = reply.n;
1444 if (numValues == 0)
1445 retval = Success;
1446 else if (numValues > __GLX_MAX_CONTEXT_PROPS)
1447 retval = 0;
1448 else
1449 {
1450 int *propList, *pProp;
1451 int nPropListBytes;
1452 int i;
1453
1454 nPropListBytes = numValues << 3;
1455 propList = (int *) Xmalloc(nPropListBytes);
1456 if (NULL == propList) {
1457 retval = 0;
1458 } else {
1459 _XRead(dpy, (char *)propList, nPropListBytes);
1460 pProp = propList;
1461 for (i=0; i < numValues; i++) {
1462 switch (*pProp++) {
1463 case GLX_SHARE_CONTEXT_EXT:
1464 ctx->share_xid = *pProp++;
1465 break;
1466 case GLX_VISUAL_ID_EXT:
1467 ctx->vid = *pProp++;
1468 break;
1469 case GLX_SCREEN:
1470 ctx->screen = *pProp++;
1471 break;
1472 case GLX_FBCONFIG_ID:
1473 ctx->fbconfigID = *pProp++;
1474 break;
1475 case GLX_RENDER_TYPE:
1476 ctx->renderType = *pProp++;
1477 break;
1478 default:
1479 pProp++;
1480 continue;
1481 }
1482 }
1483 Xfree((char *)propList);
1484 retval = Success;
1485 }
1486 }
1487 UnlockDisplay(dpy);
1488 SyncHandle();
1489 return retval;
1490 }
1491
1492 PUBLIC int
1493 GLX_PREFIX(glXQueryContext)(Display *dpy, GLXContext ctx,
1494 int attribute, int *value)
1495 {
1496 int retVal;
1497
1498 /* get the information from the server if we don't have it already */
1499 if (!ctx->isDirect && (ctx->vid == None)) {
1500 retVal = __glXQueryContextInfo(dpy, ctx);
1501 if (Success != retVal) return retVal;
1502 }
1503 switch (attribute) {
1504 case GLX_SHARE_CONTEXT_EXT:
1505 *value = (int)(ctx->share_xid);
1506 break;
1507 case GLX_VISUAL_ID_EXT:
1508 *value = (int)(ctx->vid);
1509 break;
1510 case GLX_SCREEN:
1511 *value = (int)(ctx->screen);
1512 break;
1513 case GLX_FBCONFIG_ID:
1514 *value = (int)(ctx->fbconfigID);
1515 break;
1516 case GLX_RENDER_TYPE:
1517 *value = (int)(ctx->renderType);
1518 break;
1519 default:
1520 return GLX_BAD_ATTRIBUTE;
1521 }
1522 return Success;
1523 }
1524
1525 PUBLIC GLX_ALIAS( int, glXQueryContextInfoEXT,
1526 (Display *dpy, GLXContext ctx, int attribute, int *value),
1527 (dpy, ctx, attribute, value),
1528 glXQueryContext )
1529
1530 PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx)
1531 {
1532 return ctx->xid;
1533 }
1534
1535 PUBLIC GLXContext GLX_PREFIX(glXImportContextEXT)(Display *dpy,
1536 GLXContextID contextID)
1537 {
1538 GLXContext ctx;
1539
1540 if (contextID == None) {
1541 return NULL;
1542 }
1543 if (__glXIsDirect(dpy, contextID)) {
1544 return NULL;
1545 }
1546
1547 ctx = CreateContext(dpy, NULL, NULL, NULL, False, contextID, False, 0);
1548 if (NULL != ctx) {
1549 if (Success != __glXQueryContextInfo(dpy, ctx)) {
1550 return NULL;
1551 }
1552 }
1553 return ctx;
1554 }
1555
1556 PUBLIC void GLX_PREFIX(glXFreeContextEXT)(Display *dpy, GLXContext ctx)
1557 {
1558 DestroyContext(dpy, ctx);
1559 }
1560
1561
1562
1563 /*
1564 * GLX 1.3 functions - these are just stubs for now!
1565 */
1566
1567 PUBLIC GLXFBConfig *GLX_PREFIX(glXChooseFBConfig)(Display *dpy, int screen,
1568 const int *attribList,
1569 int *nitems)
1570 {
1571 __GLcontextModes ** config_list;
1572 int list_size;
1573
1574
1575 config_list = (__GLcontextModes **)
1576 GLX_PREFIX(glXGetFBConfigs)( dpy, screen, & list_size );
1577
1578 if ( (config_list != NULL) && (list_size > 0) && (attribList != NULL) ) {
1579 list_size = choose_visual( config_list, list_size, attribList,
1580 GL_TRUE );
1581 if ( list_size == 0 ) {
1582 XFree( config_list );
1583 config_list = NULL;
1584 }
1585 }
1586
1587 *nitems = list_size;
1588 return (GLXFBConfig *) config_list;
1589 }
1590
1591
1592 PUBLIC GLXContext GLX_PREFIX(glXCreateNewContext)(Display *dpy,
1593 GLXFBConfig config,
1594 int renderType,
1595 GLXContext shareList,
1596 Bool allowDirect)
1597 {
1598 return CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList,
1599 allowDirect, None, True, renderType );
1600 }
1601
1602
1603 PUBLIC GLXDrawable GLX_PREFIX(glXGetCurrentReadDrawable)(void)
1604 {
1605 GLXContext gc = __glXGetCurrentContext();
1606 return gc->currentReadable;
1607 }
1608
1609
1610 PUBLIC GLXFBConfig *GLX_PREFIX(glXGetFBConfigs)(Display *dpy, int screen,
1611 int *nelements)
1612 {
1613 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
1614 __GLcontextModes ** config = NULL;
1615 int i;
1616
1617 if ( (priv->screenConfigs != NULL)
1618 && (screen >= 0) && (screen <= ScreenCount(dpy))
1619 && (priv->screenConfigs[screen].configs != NULL)
1620 && (priv->screenConfigs[screen].configs->fbconfigID != GLX_DONT_CARE) ) {
1621 unsigned num_configs = 0;
1622 __GLcontextModes * modes;
1623
1624
1625 for ( modes = priv->screenConfigs[screen].configs
1626 ; modes != NULL
1627 ; modes = modes->next ) {
1628 if ( modes->fbconfigID != GLX_DONT_CARE ) {
1629 num_configs++;
1630 }
1631 }
1632
1633 config = (__GLcontextModes **) Xmalloc( sizeof(__GLcontextModes *)
1634 * num_configs );
1635 if ( config != NULL ) {
1636 *nelements = num_configs;
1637 i = 0;
1638 for ( modes = priv->screenConfigs[screen].configs
1639 ; modes != NULL
1640 ; modes = modes->next ) {
1641 config[i] = modes;
1642 i++;
1643 }
1644 }
1645 }
1646 return (GLXFBConfig *) config;
1647 }
1648
1649
1650 PUBLIC int GLX_PREFIX(glXGetFBConfigAttrib)(Display *dpy, GLXFBConfig config,
1651 int attribute, int *value)
1652 {
1653 __GLcontextModes * const modes = ValidateGLXFBConfig( dpy, config );
1654
1655 return (modes != NULL)
1656 ? _gl_get_context_mode_data( modes, attribute, value )
1657 : GLXBadFBConfig;
1658 }
1659
1660
1661 PUBLIC XVisualInfo *GLX_PREFIX(glXGetVisualFromFBConfig)(Display *dpy,
1662 GLXFBConfig config)
1663 {
1664 XVisualInfo visualTemplate;
1665 __GLcontextModes * fbconfig = (__GLcontextModes *) config;
1666 int count;
1667
1668 /*
1669 ** Get a list of all visuals, return if list is empty
1670 */
1671 visualTemplate.visualid = fbconfig->visualID;
1672 return XGetVisualInfo(dpy,VisualIDMask,&visualTemplate,&count);
1673 }
1674
1675
1676 /*
1677 ** GLX_SGI_make_current_read
1678 */
1679
1680 PUBLIC GLX_ALIAS(GLXDrawable, glXGetCurrentReadDrawableSGI, (void), (),
1681 glXGetCurrentReadDrawable)
1682
1683
1684 /*
1685 ** GLX_SGI_swap_control
1686 */
1687 PUBLIC int GLX_PREFIX(glXSwapIntervalSGI)(int interval)
1688 {
1689 xGLXVendorPrivateReq *req;
1690 GLXContext gc = __glXGetCurrentContext();
1691 Display * dpy;
1692 CARD32 * interval_ptr;
1693 CARD8 opcode;
1694
1695 if ( gc == NULL ) {
1696 return GLX_BAD_CONTEXT;
1697 }
1698
1699 if ( interval <= 0 ) {
1700 return GLX_BAD_VALUE;
1701 }
1702
1703 #ifdef GLX_DIRECT_RENDERING
1704 if ( gc->isDirect ) {
1705 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1706 gc->screen );
1707 __DRIdrawable * const pdraw = GetDRIDrawable( gc->currentDpy,
1708 gc->currentDrawable,
1709 NULL );
1710 if ( __glXExtensionBitIsEnabled( psc, SGI_swap_control_bit )
1711 && (pdraw != NULL) ) {
1712 pdraw->swap_interval = interval;
1713 return 0;
1714 }
1715 else {
1716 return GLX_BAD_CONTEXT;
1717 }
1718 }
1719 #endif
1720 dpy = gc->currentDpy;
1721 opcode = __glXSetupForCommand(dpy);
1722 if (!opcode) {
1723 return 0;
1724 }
1725
1726 /* Send the glXSwapIntervalSGI request */
1727 LockDisplay(dpy);
1728 GetReqExtra(GLXVendorPrivate,sizeof(CARD32),req);
1729 req->reqType = opcode;
1730 req->glxCode = X_GLXVendorPrivate;
1731 req->vendorCode = X_GLXvop_SwapIntervalSGI;
1732 req->contextTag = gc->currentContextTag;
1733
1734 interval_ptr = (CARD32 *) req + 1;
1735 *interval_ptr = interval;
1736
1737 UnlockDisplay(dpy);
1738 SyncHandle();
1739 XFlush(dpy);
1740
1741 return 0;
1742 }
1743
1744
1745 /*
1746 ** GLX_MESA_swap_control
1747 */
1748 PUBLIC GLint GLX_PREFIX(glXSwapIntervalMESA)(unsigned interval)
1749 {
1750 #ifdef GLX_DIRECT_RENDERING
1751 GLXContext gc = __glXGetCurrentContext();
1752
1753 if ( interval < 0 ) {
1754 return GLX_BAD_VALUE;
1755 }
1756
1757 if ( (gc != NULL) && gc->isDirect ) {
1758 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1759 gc->screen );
1760
1761 if ( (psc != NULL) && (psc->driScreen.private != NULL)
1762 && __glXExtensionBitIsEnabled( psc, MESA_swap_control_bit ) ) {
1763 __DRIdrawable * const pdraw =
1764 (*psc->driScreen.getDrawable)(gc->currentDpy,
1765 gc->currentDrawable,
1766 psc->driScreen.private);
1767 if ( pdraw != NULL ) {
1768 pdraw->swap_interval = interval;
1769 return 0;
1770 }
1771 }
1772 }
1773 #else
1774 (void) interval;
1775 #endif
1776
1777 return GLX_BAD_CONTEXT;
1778 }
1779
1780 PUBLIC GLint GLX_PREFIX(glXGetSwapIntervalMESA)( void )
1781 {
1782 #ifdef GLX_DIRECT_RENDERING
1783 GLXContext gc = __glXGetCurrentContext();
1784
1785 if ( (gc != NULL) && gc->isDirect ) {
1786 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1787 gc->screen );
1788
1789 if ( (psc != NULL) && (psc->driScreen.private != NULL)
1790 && __glXExtensionBitIsEnabled( psc, MESA_swap_control_bit ) ) {
1791 __DRIdrawable * const pdraw =
1792 (*psc->driScreen.getDrawable)(gc->currentDpy,
1793 gc->currentDrawable,
1794 psc->driScreen.private);
1795 if ( pdraw != NULL ) {
1796 return pdraw->swap_interval;
1797 }
1798 }
1799 }
1800 #endif
1801
1802 return 0;
1803 }
1804
1805
1806 /*
1807 ** GLX_MESA_swap_frame_usage
1808 */
1809
1810 PUBLIC GLint GLX_PREFIX(glXBeginFrameTrackingMESA)(Display *dpy,
1811 GLXDrawable drawable)
1812 {
1813 int status = GLX_BAD_CONTEXT;
1814 #ifdef GLX_DIRECT_RENDERING
1815 int screen;
1816 __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
1817 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
1818
1819 if ( (pdraw != NULL) && (pdraw->frameTracking != NULL)
1820 && __glXExtensionBitIsEnabled( psc, MESA_swap_frame_usage_bit ) ) {
1821 status = pdraw->frameTracking( dpy, pdraw->private, GL_TRUE );
1822 }
1823 #else
1824 (void) dpy;
1825 (void) drawable;
1826 #endif
1827 return status;
1828 }
1829
1830
1831 PUBLIC GLint GLX_PREFIX(glXEndFrameTrackingMESA)(Display *dpy,
1832 GLXDrawable drawable)
1833 {
1834 int status = GLX_BAD_CONTEXT;
1835 #ifdef GLX_DIRECT_RENDERING
1836 int screen;
1837 __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
1838 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
1839
1840 if ( (pdraw != NULL) && (pdraw->frameTracking != NULL)
1841 && __glXExtensionBitIsEnabled( psc, MESA_swap_frame_usage_bit ) ) {
1842 status = pdraw->frameTracking( dpy, pdraw->private, GL_FALSE );
1843 }
1844 #else
1845 (void) dpy;
1846 (void) drawable;
1847 #endif
1848 return status;
1849 }
1850
1851
1852 PUBLIC GLint GLX_PREFIX(glXGetFrameUsageMESA)(Display *dpy,
1853 GLXDrawable drawable,
1854 GLfloat *usage)
1855 {
1856 int status = GLX_BAD_CONTEXT;
1857 #ifdef GLX_DIRECT_RENDERING
1858 int screen;
1859 __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
1860 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
1861
1862 if ( (pdraw != NULL ) && (pdraw->queryFrameTracking != NULL)
1863 && __glXExtensionBitIsEnabled( psc, MESA_swap_frame_usage_bit ) ) {
1864 int64_t sbc, missedFrames;
1865 float lastMissedUsage;
1866
1867 status = pdraw->queryFrameTracking( dpy, pdraw->private, &sbc,
1868 &missedFrames, &lastMissedUsage,
1869 usage );
1870 }
1871 #else
1872 (void) dpy;
1873 (void) drawable;
1874 (void) usage;
1875 #endif
1876 return status;
1877 }
1878
1879
1880 PUBLIC GLint GLX_PREFIX(glXQueryFrameTrackingMESA)(Display *dpy,
1881 GLXDrawable drawable,
1882 int64_t *sbc,
1883 int64_t *missedFrames,
1884 GLfloat *lastMissedUsage)
1885 {
1886 int status = GLX_BAD_CONTEXT;
1887 #ifdef GLX_DIRECT_RENDERING
1888 int screen;
1889 __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
1890 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
1891
1892 if ( (pdraw != NULL ) && (pdraw->queryFrameTracking != NULL)
1893 && __glXExtensionBitIsEnabled( psc, MESA_swap_frame_usage_bit ) ) {
1894 float usage;
1895
1896 status = pdraw->queryFrameTracking( dpy, pdraw->private, sbc,
1897 missedFrames, lastMissedUsage,
1898 & usage );
1899 }
1900 #else
1901 (void) dpy;
1902 (void) drawable;
1903 (void) sbc;
1904 (void) missedFrames;
1905 (void) lastMissedUsage;
1906 #endif
1907 return status;
1908 }
1909
1910
1911 /*
1912 ** GLX_SGI_video_sync
1913 */
1914 PUBLIC int GLX_PREFIX(glXGetVideoSyncSGI)(unsigned int *count)
1915 {
1916 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1917 * FIXME: there should be a GLX encoding for this call. I can find no
1918 * FIXME: documentation for the GLX encoding.
1919 */
1920 #ifdef GLX_DIRECT_RENDERING
1921 GLXContext gc = __glXGetCurrentContext();
1922
1923
1924 if ( (gc != NULL) && gc->isDirect ) {
1925 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1926 gc->screen );
1927 if ( __glXExtensionBitIsEnabled( psc, SGI_video_sync_bit )
1928 && psc->driScreen.private && psc->driScreen.getMSC) {
1929 int ret;
1930 int64_t temp;
1931
1932 ret = psc->driScreen.getMSC( psc->driScreen.private, & temp );
1933 *count = (unsigned) temp;
1934 return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
1935 }
1936 }
1937 #else
1938 (void) count;
1939 #endif
1940 return GLX_BAD_CONTEXT;
1941 }
1942
1943 PUBLIC int GLX_PREFIX(glXWaitVideoSyncSGI)(int divisor, int remainder,
1944 unsigned int *count)
1945 {
1946 #ifdef GLX_DIRECT_RENDERING
1947 GLXContext gc = __glXGetCurrentContext();
1948
1949 if ( divisor <= 0 || remainder < 0 )
1950 return GLX_BAD_VALUE;
1951
1952 if ( (gc != NULL) && gc->isDirect ) {
1953 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1954 gc->screen );
1955 if ( __glXExtensionBitIsEnabled( psc, SGI_video_sync_bit )
1956 && psc->driScreen.private ) {
1957 __DRIdrawable * const pdraw =
1958 (*psc->driScreen.getDrawable)(gc->currentDpy,
1959 gc->currentDrawable,
1960 psc->driScreen.private);
1961 if ( (pdraw != NULL) && (pdraw->waitForMSC != NULL) ) {
1962 int ret;
1963 int64_t msc;
1964 int64_t sbc;
1965
1966 ret = (*pdraw->waitForMSC)( gc->currentDpy, pdraw->private,
1967 0, divisor, remainder,
1968 & msc, & sbc );
1969 *count = (unsigned) msc;
1970 return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
1971 }
1972 }
1973 }
1974 #else
1975 (void) count;
1976 #endif
1977 return GLX_BAD_CONTEXT;
1978 }
1979
1980
1981 /*
1982 ** GLX_SGIS_video_source
1983 */
1984 #if defined(_VL_H)
1985
1986 PUBLIC GLXVideoSourceSGIX GLX_PREFIX(glXCreateGLXVideoSourceSGIX)(Display *dpy,
1987 int screen, VLServer server, VLPath path,
1988 int nodeClass, VLNode drainNode)
1989 {
1990 (void) dpy;
1991 (void) screen;
1992 (void) server;
1993 (void) path;
1994 (void) nodeClass;
1995 (void) drainNode;
1996 return 0;
1997 }
1998
1999 PUBLIC void GLX_PREFIX(glXDestroyGLXVideoSourceSGIX)(Display *dpy,
2000 GLXVideoSourceSGIX src)
2001 {
2002 (void) dpy;
2003 (void) src;
2004 }
2005
2006 #endif
2007
2008
2009 /*
2010 ** GLX_SGIX_fbconfig
2011 ** Many of these functions are aliased to GLX 1.3 entry points in the
2012 ** GLX_functions table.
2013 */
2014
2015 PUBLIC GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
2016 (Display *dpy, GLXFBConfigSGIX config, int attribute, int *value),
2017 (dpy, config, attribute, value),
2018 glXGetFBConfigAttrib)
2019
2020 PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
2021 (Display *dpy, int screen, int *attrib_list, int *nelements),
2022 (dpy, screen, attrib_list, nelements),
2023 glXChooseFBConfig)
2024
2025 PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
2026 (Display * dpy, GLXFBConfigSGIX config),
2027 (dpy, config),
2028 glXGetVisualFromFBConfig)
2029
2030 PUBLIC GLXPixmap GLX_PREFIX(glXCreateGLXPixmapWithConfigSGIX)(Display *dpy,
2031 GLXFBConfigSGIX config, Pixmap pixmap)
2032 {
2033 xGLXVendorPrivateWithReplyReq *vpreq;
2034 xGLXCreateGLXPixmapWithConfigSGIXReq *req;
2035 GLXPixmap xid = None;
2036 CARD8 opcode;
2037 const __GLcontextModes * const fbconfig = (__GLcontextModes *) config;
2038 __GLXscreenConfigs * psc;
2039
2040
2041 if ( (dpy == NULL) || (config == NULL) ) {
2042 return None;
2043 }
2044
2045 psc = GetGLXScreenConfigs( dpy, fbconfig->screen );
2046 if ( (psc != NULL)
2047 && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) {
2048 opcode = __glXSetupForCommand(dpy);
2049 if (!opcode) {
2050 return None;
2051 }
2052
2053 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2054 LockDisplay(dpy);
2055 GetReqExtra(GLXVendorPrivateWithReply,
2056 sz_xGLXCreateGLXPixmapWithConfigSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq);
2057 req = (xGLXCreateGLXPixmapWithConfigSGIXReq *)vpreq;
2058 req->reqType = opcode;
2059 req->glxCode = X_GLXVendorPrivateWithReply;
2060 req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
2061 req->screen = fbconfig->screen;
2062 req->fbconfig = fbconfig->fbconfigID;
2063 req->pixmap = pixmap;
2064 req->glxpixmap = xid = XAllocID(dpy);
2065 UnlockDisplay(dpy);
2066 SyncHandle();
2067 }
2068
2069 return xid;
2070 }
2071
2072 PUBLIC GLXContext GLX_PREFIX(glXCreateContextWithConfigSGIX)(Display *dpy,
2073 GLXFBConfigSGIX config, int renderType,
2074 GLXContext shareList, Bool allowDirect)
2075 {
2076 GLXContext gc = NULL;
2077 const __GLcontextModes * const fbconfig = (__GLcontextModes *) config;
2078 __GLXscreenConfigs * psc;
2079
2080
2081 if ( (dpy == NULL) || (config == NULL) ) {
2082 return None;
2083 }
2084
2085 psc = GetGLXScreenConfigs( dpy, fbconfig->screen );
2086 if ( (psc != NULL)
2087 && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) {
2088 gc = CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList,
2089 allowDirect, None, False, renderType );
2090 }
2091
2092 return gc;
2093 }
2094
2095
2096 PUBLIC GLXFBConfigSGIX GLX_PREFIX(glXGetFBConfigFromVisualSGIX)(Display *dpy,
2097 XVisualInfo *vis)
2098 {
2099 __GLXdisplayPrivate *priv;
2100 __GLXscreenConfigs *psc;
2101
2102 if ( (GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc ) != Success)
2103 && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit )
2104 && (psc->configs->fbconfigID != GLX_DONT_CARE) ) {
2105 return (GLXFBConfigSGIX) _gl_context_modes_find_visual( psc->configs,
2106 vis->visualid );
2107 }
2108
2109 return NULL;
2110 }
2111
2112
2113 /*
2114 ** GLX_SGI_cushion
2115 */
2116 PUBLIC void GLX_PREFIX(glXCushionSGI)(Display *dpy, Window win, float cushion)
2117 {
2118 (void) dpy;
2119 (void) win;
2120 (void) cushion;
2121 }
2122
2123
2124 /*
2125 ** GLX_SGIX_video_resize
2126 */
2127 PUBLIC int GLX_PREFIX(glXBindChannelToWindowSGIX)(Display *dpy, int screen,
2128 int channel , Window window)
2129 {
2130 (void) dpy;
2131 (void) screen;
2132 (void) channel;
2133 (void) window;
2134 return 0;
2135 }
2136
2137 PUBLIC int GLX_PREFIX(glXChannelRectSGIX)(Display *dpy, int screen, int channel,
2138 int x, int y, int w, int h)
2139 {
2140 (void) dpy;
2141 (void) screen;
2142 (void) channel;
2143 (void) x;
2144 (void) y;
2145 (void) w;
2146 (void) h;
2147 return 0;
2148 }
2149
2150 PUBLIC int GLX_PREFIX(glXQueryChannelRectSGIX)(Display *dpy, int screen,
2151 int channel, int *x, int *y,
2152 int *w, int *h)
2153 {
2154 (void) dpy;
2155 (void) screen;
2156 (void) channel;
2157 (void) x;
2158 (void) y;
2159 (void) w;
2160 (void) h;
2161 return 0;
2162 }
2163
2164 int GLX_PREFIX(glXQueryChannelDeltasSGIX)(Display *dpy, int screen, int channel,
2165 int *dx, int *dy, int *dw, int *dh)
2166 {
2167 (void) dpy;
2168 (void) screen;
2169 (void) channel;
2170 (void) dx;
2171 (void) dy;
2172 (void) dw;
2173 (void) dh;
2174 return 0;
2175 }
2176
2177 PUBLIC int GLX_PREFIX(glXChannelRectSyncSGIX)(Display *dpy, int screen,
2178 int channel, GLenum synctype)
2179 {
2180 (void) dpy;
2181 (void) screen;
2182 (void) channel;
2183 (void) synctype;
2184 return 0;
2185 }
2186
2187
2188 #if defined(_DM_BUFFER_H_)
2189
2190 PUBLIC Bool GLX_PREFIX(glXAssociateDMPbufferSGIX)(Display *dpy,
2191 GLXPbufferSGIX pbuffer,
2192 DMparams *params,
2193 DMbuffer dmbuffer)
2194 {
2195 (void) dpy;
2196 (void) pbuffer;
2197 (void) params;
2198 (void) dmbuffer;
2199 return False;
2200 }
2201
2202 #endif
2203
2204
2205 /*
2206 ** GLX_SGIX_swap_group
2207 */
2208 PUBLIC void GLX_PREFIX(glXJoinSwapGroupSGIX)(Display *dpy, GLXDrawable drawable,
2209 GLXDrawable member)
2210 {
2211 (void) dpy;
2212 (void) drawable;
2213 (void) member;
2214 }
2215
2216
2217 /*
2218 ** GLX_SGIX_swap_barrier
2219 */
2220 PUBLIC void GLX_PREFIX(glXBindSwapBarrierSGIX)(Display *dpy,
2221 GLXDrawable drawable,
2222 int barrier)
2223 {
2224 (void) dpy;
2225 (void) drawable;
2226 (void) barrier;
2227 }
2228
2229 PUBLIC Bool GLX_PREFIX(glXQueryMaxSwapBarriersSGIX)(Display *dpy, int screen,
2230 int *max)
2231 {
2232 (void) dpy;
2233 (void) screen;
2234 (void) max;
2235 return False;
2236 }
2237
2238
2239 /*
2240 ** GLX_SUN_get_transparent_index
2241 */
2242 PUBLIC Status GLX_PREFIX(glXGetTransparentIndexSUN)(Display *dpy,
2243 Window overlay,
2244 Window underlay,
2245 long *pTransparent)
2246 {
2247 (void) dpy;
2248 (void) overlay;
2249 (void) underlay;
2250 (void) pTransparent;
2251 return 0;
2252 }
2253
2254
2255 /*
2256 ** GLX_OML_sync_control
2257 */
2258 PUBLIC Bool GLX_PREFIX(glXGetSyncValuesOML)(Display *dpy, GLXDrawable drawable,
2259 int64_t *ust, int64_t *msc, int64_t *sbc)
2260 {
2261 #ifdef GLX_DIRECT_RENDERING
2262 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
2263
2264 if ( priv != NULL ) {
2265 int i;
2266 __DRIdrawable * const pdraw = GetDRIDrawable( dpy, drawable, & i );
2267 __GLXscreenConfigs * const psc = &priv->screenConfigs[i];
2268
2269 assert( (pdraw == NULL) || (i != -1) );
2270 return ( (pdraw && pdraw->getSBC && psc->driScreen.getMSC)
2271 && __glXExtensionBitIsEnabled( psc, OML_sync_control_bit )
2272 && ((*psc->driScreen.getMSC)( psc->driScreen.private, msc ) == 0)
2273 && ((*pdraw->getSBC)( dpy, psc->driScreen.private, sbc ) == 0)
2274 && (__glXGetUST( ust ) == 0) );
2275 }
2276 #else
2277 (void) dpy;
2278 (void) drawable;
2279 (void) ust;
2280 (void) msc;
2281 (void) sbc;
2282 #endif
2283 return False;
2284 }
2285
2286
2287 /**
2288 * Determine the refresh rate of the specified drawable and display.
2289 *
2290 * \param dpy Display whose refresh rate is to be determined.
2291 * \param drawable Drawable whose refresh rate is to be determined.
2292 * \param numerator Numerator of the refresh rate.
2293 * \param demoninator Denominator of the refresh rate.
2294 * \return If the refresh rate for the specified display and drawable could
2295 * be calculated, True is returned. Otherwise False is returned.
2296 *
2297 * \note This function is implemented entirely client-side. A lot of other
2298 * functionality is required to export GLX_OML_sync_control, so on
2299 * XFree86 this function can be called for direct-rendering contexts
2300 * when GLX_OML_sync_control appears in the client extension string.
2301 */
2302
2303 PUBLIC Bool GLX_PREFIX(glXGetMscRateOML)(Display * dpy, GLXDrawable drawable,
2304 int32_t * numerator, int32_t * denominator)
2305 {
2306 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2307 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
2308
2309
2310 if ( priv != NULL ) {
2311 XF86VidModeModeLine mode_line;
2312 int dot_clock;
2313 int screen_num;
2314 int i;
2315
2316
2317 GetDRIDrawable( dpy, drawable, & screen_num );
2318 if ( (screen_num != -1)
2319 && XF86VidModeQueryVersion( dpy, & i, & i )
2320 && XF86VidModeGetModeLine( dpy, screen_num, & dot_clock,
2321 & mode_line ) ) {
2322 unsigned n = dot_clock * 1000;
2323 unsigned d = mode_line.vtotal * mode_line.htotal;
2324
2325 # define V_INTERLACE 0x010
2326 # define V_DBLSCAN 0x020
2327
2328 if ( (mode_line.flags & V_INTERLACE) ) {
2329 n *= 2;
2330 }
2331 else if ( (mode_line.flags & V_DBLSCAN) ) {
2332 d *= 2;
2333 }
2334
2335 /* The OML_sync_control spec requires that if the refresh rate is a
2336 * whole number, that the returned numerator be equal to the refresh
2337 * rate and the denominator be 1.
2338 */
2339
2340 if ( (n % d) == 0 ) {
2341 n /= d;
2342 d = 1;
2343 }
2344 else {
2345 static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 };
2346
2347
2348 /* This is a poor man's way to reduce a fraction. It's far from
2349 * perfect, but it will work well enough for this situation.
2350 */
2351
2352 for ( i = 0 ; f[i] != 0 ; i++ ) {
2353 while ( ((n % f[i]) == 0) && ((d % f[i]) == 0) ) {
2354 d /= f[i];
2355 n /= f[i];
2356 }
2357 }
2358 }
2359
2360 *numerator = n;
2361 *denominator = d;
2362
2363 (void) drawable;
2364 return True;
2365 }
2366 }
2367 #else
2368 (void) dpy;
2369 (void) drawable;
2370 (void) numerator;
2371 (void) denominator;
2372 #endif
2373 return False;
2374 }
2375
2376
2377 PUBLIC int64_t GLX_PREFIX(glXSwapBuffersMscOML)(Display *dpy,
2378 GLXDrawable drawable,
2379 int64_t target_msc,
2380 int64_t divisor,
2381 int64_t remainder)
2382 {
2383 #ifdef GLX_DIRECT_RENDERING
2384 int screen;
2385 __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
2386 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
2387
2388 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2389 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2390 * of -1 if the function failed because of errors detected in the input
2391 * parameters"
2392 */
2393 if ( divisor < 0 || remainder < 0 || target_msc < 0 )
2394 return -1;
2395 if ( divisor > 0 && remainder >= divisor )
2396 return -1;
2397
2398 if ( (pdraw != NULL) && (pdraw->swapBuffersMSC != NULL)
2399 && __glXExtensionBitIsEnabled( psc, OML_sync_control_bit ) ) {
2400 return (*pdraw->swapBuffersMSC)(dpy, pdraw->private, target_msc,
2401 divisor, remainder);
2402 }
2403 #else
2404 (void) dpy;
2405 (void) drawable;
2406 (void) target_msc;
2407 (void) divisor;
2408 (void) remainder;
2409 #endif
2410 return 0;
2411 }
2412
2413
2414 PUBLIC Bool GLX_PREFIX(glXWaitForMscOML)(Display * dpy, GLXDrawable drawable,
2415 int64_t target_msc, int64_t divisor,
2416 int64_t remainder, int64_t *ust,
2417 int64_t *msc, int64_t *sbc)
2418 {
2419 #ifdef GLX_DIRECT_RENDERING
2420 int screen;
2421 __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
2422 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
2423 int ret;
2424
2425 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2426 * error", but the return type in the spec is Bool.
2427 */
2428 if ( divisor < 0 || remainder < 0 || target_msc < 0 )
2429 return False;
2430 if ( divisor > 0 && remainder >= divisor )
2431 return False;
2432
2433 if ( (pdraw != NULL) && (pdraw->waitForMSC != NULL)
2434 && __glXExtensionBitIsEnabled( psc, OML_sync_control_bit ) ) {
2435 ret = (*pdraw->waitForMSC)( dpy, pdraw->private, target_msc,
2436 divisor, remainder, msc, sbc );
2437
2438 /* __glXGetUST returns zero on success and non-zero on failure.
2439 * This function returns True on success and False on failure.
2440 */
2441 return ( (ret == 0) && (__glXGetUST( ust ) == 0) );
2442 }
2443 #else
2444 (void) dpy;
2445 (void) drawable;
2446 (void) target_msc;
2447 (void) divisor;
2448 (void) remainder;
2449 (void) ust;
2450 (void) msc;
2451 (void) sbc;
2452 #endif
2453 return False;
2454 }
2455
2456
2457 PUBLIC Bool GLX_PREFIX(glXWaitForSbcOML)(Display * dpy, GLXDrawable drawable,
2458 int64_t target_sbc, int64_t *ust,
2459 int64_t *msc, int64_t *sbc )
2460 {
2461 #ifdef GLX_DIRECT_RENDERING
2462 int screen;
2463 __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
2464 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
2465 int ret;
2466
2467 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2468 * error", but the return type in the spec is Bool.
2469 */
2470 if ( target_sbc < 0 )
2471 return False;
2472
2473 if ( (pdraw != NULL) && (pdraw->waitForSBC != NULL)
2474 && __glXExtensionBitIsEnabled( psc, OML_sync_control_bit )) {
2475 ret = (*pdraw->waitForSBC)( dpy, pdraw->private, target_sbc, msc, sbc );
2476
2477 /* __glXGetUST returns zero on success and non-zero on failure.
2478 * This function returns True on success and False on failure.
2479 */
2480 return( (ret == 0) && (__glXGetUST( ust ) == 0) );
2481 }
2482 #else
2483 (void) dpy;
2484 (void) drawable;
2485 (void) target_sbc;
2486 (void) ust;
2487 (void) msc;
2488 (void) sbc;
2489 #endif
2490 return False;
2491 }
2492
2493
2494 /**
2495 * GLX_MESA_allocate_memory
2496 */
2497 /*@{*/
2498
2499 PUBLIC void *GLX_PREFIX(glXAllocateMemoryMESA)(Display *dpy, int scrn,
2500 size_t size, float readFreq,
2501 float writeFreq, float priority)
2502 {
2503 #ifdef GLX_DIRECT_RENDERING
2504 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
2505
2506 if ( __glXExtensionBitIsEnabled( psc, MESA_allocate_memory_bit ) ) {
2507 if (psc && psc->driScreen.private && psc->driScreen.allocateMemory) {
2508 return (*psc->driScreen.allocateMemory)( dpy, scrn, size,
2509 readFreq, writeFreq,
2510 priority );
2511 }
2512 }
2513 #else
2514 (void) dpy;
2515 (void) scrn;
2516 (void) size;
2517 (void) readFreq;
2518 (void) writeFreq;
2519 (void) priority;
2520 #endif /* GLX_DIRECT_RENDERING */
2521
2522 return NULL;
2523 }
2524
2525
2526 PUBLIC void GLX_PREFIX(glXFreeMemoryMESA)(Display *dpy, int scrn, void *pointer)
2527 {
2528 #ifdef GLX_DIRECT_RENDERING
2529 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
2530
2531 if ( __glXExtensionBitIsEnabled( psc, MESA_allocate_memory_bit ) ) {
2532 if (psc && psc->driScreen.private && psc->driScreen.freeMemory) {
2533 (*psc->driScreen.freeMemory)( dpy, scrn, pointer );
2534 }
2535 }
2536 #else
2537 (void) dpy;
2538 (void) scrn;
2539 (void) pointer;
2540 #endif /* GLX_DIRECT_RENDERING */
2541 }
2542
2543
2544 PUBLIC GLuint GLX_PREFIX(glXGetMemoryOffsetMESA)( Display *dpy, int scrn,
2545 const void *pointer )
2546 {
2547 #ifdef GLX_DIRECT_RENDERING
2548 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
2549
2550 if ( __glXExtensionBitIsEnabled( psc, MESA_allocate_memory_bit ) ) {
2551 if (psc && psc->driScreen.private && psc->driScreen.memoryOffset) {
2552 return (*psc->driScreen.memoryOffset)( dpy, scrn, pointer );
2553 }
2554 }
2555 #else
2556 (void) dpy;
2557 (void) scrn;
2558 (void) pointer;
2559 #endif /* GLX_DIRECT_RENDERING */
2560
2561 return ~0L;
2562 }
2563 /*@}*/
2564
2565
2566 /**
2567 * Mesa extension stubs. These will help reduce portability problems.
2568 */
2569 /*@{*/
2570
2571 /**
2572 * Release all buffers associated with the specified GLX drawable.
2573 *
2574 * \todo
2575 * This function was intended for stand-alone Mesa. The issue there is that
2576 * the library doesn't get any notification when a window is closed. In
2577 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2578 * supported, there are 3 different functions to destroy a drawable. It
2579 * should be possible to create GLX protocol (or have it determine which
2580 * protocol to use based on the type of the drawable) to have one function
2581 * do the work of 3. For the direct-rendering case, this function could
2582 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2583 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2584 * would need to be used. This really should be done as part of the new DRI
2585 * interface work.
2586 *
2587 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2588 * __driGarbageCollectDrawables
2589 * glXDestroyGLXPixmap
2590 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2591 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2592 */
2593 PUBLIC Bool GLX_PREFIX(glXReleaseBuffersMESA)( Display *dpy, GLXDrawable d )
2594 {
2595 (void) dpy;
2596 (void) d;
2597 return False;
2598 }
2599
2600
2601 PUBLIC GLXPixmap GLX_PREFIX(glXCreateGLXPixmapMESA)( Display *dpy,
2602 XVisualInfo *visual,
2603 Pixmap pixmap,
2604 Colormap cmap )
2605 {
2606 (void) dpy;
2607 (void) visual;
2608 (void) pixmap;
2609 (void) cmap;
2610 return 0;
2611 }
2612
2613
2614 PUBLIC void GLX_PREFIX(glXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable,
2615 int x, int y,
2616 int width, int height)
2617 {
2618 (void) dpy;
2619 (void) drawable;
2620 (void) x;
2621 (void) y;
2622 (void) width;
2623 (void) height;
2624 }
2625
2626
2627 PUBLIC Bool GLX_PREFIX(glXSet3DfxModeMESA)( int mode )
2628 {
2629 (void) mode;
2630 return GL_FALSE;
2631 }
2632 /*@}*/
2633
2634
2635
2636 /**
2637 * \c strdup is actually not a standard ANSI C or POSIX routine.
2638 * Irix will not define it if ANSI mode is in effect.
2639 *
2640 * \sa strdup
2641 */
2642 char *
2643 __glXstrdup(const char *str)
2644 {
2645 char *copy;
2646 copy = (char *) Xmalloc(strlen(str) + 1);
2647 if (!copy)
2648 return NULL;
2649 strcpy(copy, str);
2650 return copy;
2651 }
2652
2653 /*
2654 ** glXGetProcAddress support
2655 */
2656
2657 struct name_address_pair {
2658 const char *Name;
2659 GLvoid *Address;
2660 };
2661
2662 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2663 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2664
2665 static const struct name_address_pair GLX_functions[] = {
2666 /*** GLX_VERSION_1_0 ***/
2667 GLX_FUNCTION( glXChooseVisual ),
2668 GLX_FUNCTION( glXCopyContext ),
2669 GLX_FUNCTION( glXCreateContext ),
2670 GLX_FUNCTION( glXCreateGLXPixmap ),
2671 GLX_FUNCTION( glXDestroyContext ),
2672 GLX_FUNCTION( glXDestroyGLXPixmap ),
2673 GLX_FUNCTION( glXGetConfig ),
2674 GLX_FUNCTION( glXGetCurrentContext ),
2675 GLX_FUNCTION( glXGetCurrentDrawable ),
2676 GLX_FUNCTION( glXIsDirect ),
2677 GLX_FUNCTION( glXMakeCurrent ),
2678 GLX_FUNCTION( glXQueryExtension ),
2679 GLX_FUNCTION( glXQueryVersion ),
2680 GLX_FUNCTION( glXSwapBuffers ),
2681 GLX_FUNCTION( glXUseXFont ),
2682 GLX_FUNCTION( glXWaitGL ),
2683 GLX_FUNCTION( glXWaitX ),
2684
2685 /*** GLX_VERSION_1_1 ***/
2686 GLX_FUNCTION( glXGetClientString ),
2687 GLX_FUNCTION( glXQueryExtensionsString ),
2688 GLX_FUNCTION( glXQueryServerString ),
2689
2690 /*** GLX_VERSION_1_2 ***/
2691 GLX_FUNCTION( glXGetCurrentDisplay ),
2692
2693 /*** GLX_VERSION_1_3 ***/
2694 GLX_FUNCTION( glXChooseFBConfig ),
2695 GLX_FUNCTION( glXCreateNewContext ),
2696 GLX_FUNCTION( glXCreatePbuffer ),
2697 GLX_FUNCTION( glXCreatePixmap ),
2698 GLX_FUNCTION( glXCreateWindow ),
2699 GLX_FUNCTION( glXDestroyPbuffer ),
2700 GLX_FUNCTION( glXDestroyPixmap ),
2701 GLX_FUNCTION( glXDestroyWindow ),
2702 GLX_FUNCTION( glXGetCurrentReadDrawable ),
2703 GLX_FUNCTION( glXGetFBConfigAttrib ),
2704 GLX_FUNCTION( glXGetFBConfigs ),
2705 GLX_FUNCTION( glXGetSelectedEvent ),
2706 GLX_FUNCTION( glXGetVisualFromFBConfig ),
2707 GLX_FUNCTION( glXMakeContextCurrent ),
2708 GLX_FUNCTION( glXQueryContext ),
2709 GLX_FUNCTION( glXQueryDrawable ),
2710 GLX_FUNCTION( glXSelectEvent ),
2711
2712 /*** GLX_SGI_swap_control ***/
2713 GLX_FUNCTION( glXSwapIntervalSGI ),
2714
2715 /*** GLX_SGI_video_sync ***/
2716 GLX_FUNCTION( glXGetVideoSyncSGI ),
2717 GLX_FUNCTION( glXWaitVideoSyncSGI ),
2718
2719 /*** GLX_SGI_make_current_read ***/
2720 GLX_FUNCTION2( glXMakeCurrentReadSGI, glXMakeContextCurrent ),
2721 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable ),
2722
2723 /*** GLX_SGIX_video_source ***/
2724 #if defined(_VL_H)
2725 GLX_FUNCTION( glXCreateGLXVideoSourceSGIX ),
2726 GLX_FUNCTION( glXDestroyGLXVideoSourceSGIX ),
2727 #endif
2728
2729 /*** GLX_EXT_import_context ***/
2730 GLX_FUNCTION( glXFreeContextEXT ),
2731 GLX_FUNCTION( glXGetContextIDEXT ),
2732 GLX_FUNCTION2( glXGetCurrentDisplayEXT, glXGetCurrentDisplay ),
2733 GLX_FUNCTION( glXImportContextEXT ),
2734 GLX_FUNCTION2( glXQueryContextInfoEXT, glXQueryContext ),
2735
2736 /*** GLX_SGIX_fbconfig ***/
2737 GLX_FUNCTION2( glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib ),
2738 GLX_FUNCTION2( glXChooseFBConfigSGIX, glXChooseFBConfig ),
2739 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX ),
2740 GLX_FUNCTION( glXCreateContextWithConfigSGIX ),
2741 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig ),
2742 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX ),
2743
2744 /*** GLX_SGIX_pbuffer ***/
2745 GLX_FUNCTION( glXCreateGLXPbufferSGIX ),
2746 GLX_FUNCTION( glXDestroyGLXPbufferSGIX ),
2747 GLX_FUNCTION( glXQueryGLXPbufferSGIX ),
2748 GLX_FUNCTION( glXSelectEventSGIX ),
2749 GLX_FUNCTION( glXGetSelectedEventSGIX ),
2750
2751 /*** GLX_SGI_cushion ***/
2752 GLX_FUNCTION( glXCushionSGI ),
2753
2754 /*** GLX_SGIX_video_resize ***/
2755 GLX_FUNCTION( glXBindChannelToWindowSGIX ),
2756 GLX_FUNCTION( glXChannelRectSGIX ),
2757 GLX_FUNCTION( glXQueryChannelRectSGIX ),
2758 GLX_FUNCTION( glXQueryChannelDeltasSGIX ),
2759 GLX_FUNCTION( glXChannelRectSyncSGIX ),
2760
2761 /*** GLX_SGIX_dmbuffer **/
2762 #if defined(_DM_BUFFER_H_)
2763 GLX_FUNCTION( glXAssociateDMPbufferSGIX ),
2764 #endif
2765
2766 /*** GLX_SGIX_swap_group ***/
2767 GLX_FUNCTION( glXJoinSwapGroupSGIX ),
2768
2769 /*** GLX_SGIX_swap_barrier ***/
2770 GLX_FUNCTION( glXBindSwapBarrierSGIX ),
2771 GLX_FUNCTION( glXQueryMaxSwapBarriersSGIX ),
2772
2773 /*** GLX_SUN_get_transparent_index ***/
2774 GLX_FUNCTION( glXGetTransparentIndexSUN ),
2775
2776 /*** GLX_MESA_allocate_memory ***/
2777 GLX_FUNCTION( glXAllocateMemoryMESA ),
2778 GLX_FUNCTION( glXFreeMemoryMESA ),
2779 GLX_FUNCTION( glXGetMemoryOffsetMESA ),
2780
2781 /*** GLX_MESA_copy_sub_buffer ***/
2782 GLX_FUNCTION( glXCopySubBufferMESA ),
2783
2784 /*** GLX_MESA_pixmap_colormap ***/
2785 GLX_FUNCTION( glXCreateGLXPixmapMESA ),
2786
2787 /*** GLX_MESA_release_buffers ***/
2788 GLX_FUNCTION( glXReleaseBuffersMESA ),
2789
2790 /*** GLX_MESA_set_3dfx_mode ***/
2791 GLX_FUNCTION( glXSet3DfxModeMESA ),
2792
2793 /*** GLX_MESA_swap_control ***/
2794 GLX_FUNCTION( glXSwapIntervalMESA ),
2795 GLX_FUNCTION( glXGetSwapIntervalMESA ),
2796
2797 /*** GLX_MESA_swap_frame_usage ***/
2798 GLX_FUNCTION( glXBeginFrameTrackingMESA ),
2799 GLX_FUNCTION( glXEndFrameTrackingMESA ),
2800 GLX_FUNCTION( glXGetFrameUsageMESA ),
2801 GLX_FUNCTION( glXQueryFrameTrackingMESA ),
2802
2803 /*** GLX_ARB_get_proc_address ***/
2804 GLX_FUNCTION( glXGetProcAddressARB ),
2805
2806 /*** GLX 1.4 ***/
2807 GLX_FUNCTION2( glXGetProcAddress, glXGetProcAddressARB ),
2808
2809 /*** GLX_OML_sync_control ***/
2810 GLX_FUNCTION( glXWaitForSbcOML ),
2811 GLX_FUNCTION( glXWaitForMscOML ),
2812 GLX_FUNCTION( glXSwapBuffersMscOML ),
2813 GLX_FUNCTION( glXGetMscRateOML ),
2814 GLX_FUNCTION( glXGetSyncValuesOML ),
2815
2816 #ifdef GLX_DIRECT_RENDERING
2817 /***
2818 *** Internal functions useful to DRI drivers
2819 *** With this, the DRI drivers shouldn't need dlopen()/dlsym() to
2820 *** access internal libGL functions which may or may not exist.
2821 ***/
2822 GLX_FUNCTION( __glXInitialize ),
2823 GLX_FUNCTION( __glXFindDRIScreen ),
2824 GLX_FUNCTION( __glXGetInternalVersion ),
2825 GLX_FUNCTION( __glXWindowExists ),
2826 GLX_FUNCTION2( __glXCreateContextWithConfig, XF86DRICreateContextWithConfig ),
2827 GLX_FUNCTION2( __glXGetDrawableInfo, XF86DRIGetDrawableInfo ),
2828
2829 /*** DRI configuration ***/
2830 GLX_FUNCTION( glXGetScreenDriver ),
2831 GLX_FUNCTION( glXGetDriverConfig ),
2832
2833 GLX_FUNCTION( __glXScrEnableExtension ),
2834
2835 GLX_FUNCTION( __glXGetUST ),
2836
2837 GLX_FUNCTION2( __glXCreateContextModes, _gl_context_modes_create ),
2838 GLX_FUNCTION2( __glXDestroyContextModes, _gl_context_modes_destroy ),
2839 #endif
2840
2841 { NULL, NULL } /* end of list */
2842 };
2843
2844
2845 static const GLvoid *
2846 get_glx_proc_address(const char *funcName)
2847 {
2848 GLuint i;
2849
2850 /* try static functions */
2851 for (i = 0; GLX_functions[i].Name; i++) {
2852 if (strcmp(GLX_functions[i].Name, funcName) == 0)
2853 return GLX_functions[i].Address;
2854 }
2855
2856 return NULL;
2857 }
2858
2859
2860 #ifndef GLX_BUILT_IN_XMESA
2861 /**
2862 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2863 * \c glXGetProcAddress.
2864 *
2865 * \param procName Name of a GL or GLX function.
2866 * \returns A pointer to the named function
2867 *
2868 * \sa glXGetProcAddress
2869 */
2870 PUBLIC void (*glXGetProcAddressARB(const GLubyte *procName))( void )
2871 {
2872 typedef void (*gl_function)( void );
2873 gl_function f;
2874
2875
2876 /* Search the table of GLX and internal functions first. If that
2877 * fails and the supplied name could be a valid core GL name, try
2878 * searching the core GL function table. This check is done to prevent
2879 * DRI based drivers from searching the core GL function table for
2880 * internal API functions.
2881 */
2882
2883 f = (gl_function) get_glx_proc_address((const char *) procName);
2884 if ( (f == NULL) && (procName[0] == 'g') && (procName[1] == 'l')
2885 && (procName[2] != 'X') ) {
2886 f = (gl_function) _glapi_get_proc_address((const char *) procName);
2887 }
2888
2889 return f;
2890 }
2891
2892 /**
2893 * Get the address of a named GL function. This is the GLX 1.4 name for
2894 * \c glXGetProcAddressARB.
2895 *
2896 * \param procName Name of a GL or GLX function.
2897 * \returns A pointer to the named function
2898 *
2899 * \sa glXGetProcAddressARB
2900 */
2901 PUBLIC void (*glXGetProcAddress(const GLubyte *procName))( void )
2902 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2903 __attribute__ ((alias ("glXGetProcAddressARB")));
2904 #else
2905 {
2906 return glXGetProcAddressARB(procName);
2907 }
2908 #endif /* __GNUC__ */
2909 #endif /* GLX_BUILT_IN_XMESA */
2910
2911
2912 #ifdef GLX_DIRECT_RENDERING
2913 /**
2914 * Retrieves the verion of the internal libGL API in YYYYMMDD format. This
2915 * might be used by the DRI drivers to determine how new libGL is at runtime.
2916 * Drivers should not call this function directly. They should instead use
2917 * \c glXGetProcAddress to obtain a pointer to the function.
2918 *
2919 * \returns An 8-digit decimal number representing the internal libGL API in
2920 * YYYYMMDD format.
2921 *
2922 * \sa glXGetProcAddress, PFNGLXGETINTERNALVERSIONPROC
2923 *
2924 * \since Internal API version 20021121.
2925 */
2926 int __glXGetInternalVersion(void)
2927 {
2928 /* History:
2929 * 20021121 - Initial version
2930 * 20021128 - Added __glXWindowExists() function
2931 * 20021207 - Added support for dynamic GLX extensions,
2932 * GLX_SGI_swap_control, GLX_SGI_video_sync,
2933 * GLX_OML_sync_control, and GLX_MESA_swap_control.
2934 * Never officially released. Do NOT test against
2935 * this version. Use 20030317 instead.
2936 * 20030317 - Added support GLX_SGIX_fbconfig,
2937 * GLX_MESA_swap_frame_usage, GLX_OML_swap_method,
2938 * GLX_{ARB,SGIS}_multisample, and
2939 * GLX_SGIX_visual_select_group.
2940 * 20030606 - Added support for GLX_SGI_make_current_read.
2941 * 20030813 - Made support for dynamic extensions multi-head aware.
2942 * 20030818 - Added support for GLX_MESA_allocate_memory in place of the
2943 * deprecated GLX_NV_vertex_array_range & GLX_MESA_agp_offset
2944 * interfaces.
2945 * 20031201 - Added support for the first round of DRI interface changes.
2946 * Do NOT test against this version! It has binary
2947 * compatibility bugs, use 20040317 instead.
2948 * 20040317 - Added the 'mode' field to __DRIcontextRec.
2949 * 20040415 - Added support for bindContext3 and unbindContext3.
2950 * 20040602 - Add __glXGetDrawableInfo. I though that was there
2951 * months ago. :(
2952 * 20050722 - Gut all the old interfaces. This breaks compatability with
2953 * any DRI driver built to any previous version.
2954 */
2955 return 20050722;
2956 }
2957
2958
2959
2960 static Bool windowExistsFlag;
2961
2962 static int windowExistsErrorHandler(Display *dpy, XErrorEvent *xerr)
2963 {
2964 if (xerr->error_code == BadWindow) {
2965 windowExistsFlag = GL_FALSE;
2966 }
2967 return 0;
2968 }
2969
2970 /**
2971 * Determine if a window associated with a \c GLXDrawable exists on the
2972 * X-server. This function is not used internally by libGL. It is provided
2973 * as a utility function for DRI drivers.
2974 * Drivers should not call this function directly. They should instead use
2975 * \c glXGetProcAddress to obtain a pointer to the function.
2976 *
2977 * \param dpy Display associated with the drawable to be queried.
2978 * \param draw \c GLXDrawable to test.
2979 *
2980 * \returns \c GL_TRUE if a window exists that is associated with \c draw,
2981 * otherwise \c GL_FALSE is returned.
2982 *
2983 * \warning This function is not currently thread-safe.
2984 *
2985 * \sa glXGetProcAddress
2986 *
2987 * \since Internal API version 20021128.
2988 */
2989 static Bool __glXWindowExists(Display *dpy, GLXDrawable draw)
2990 {
2991 XWindowAttributes xwa;
2992 int (*oldXErrorHandler)(Display *, XErrorEvent *);
2993
2994 XSync(dpy, GL_FALSE);
2995 windowExistsFlag = GL_TRUE;
2996 oldXErrorHandler = XSetErrorHandler(windowExistsErrorHandler);
2997 XGetWindowAttributes(dpy, draw, &xwa); /* dummy request */
2998 XSetErrorHandler(oldXErrorHandler);
2999 return windowExistsFlag;
3000 }
3001
3002
3003 /**
3004 * Get the unadjusted system time (UST). Currently, the UST is measured in
3005 * microseconds since Epoc. The actual resolution of the UST may vary from
3006 * system to system, and the units may vary from release to release.
3007 * Drivers should not call this function directly. They should instead use
3008 * \c glXGetProcAddress to obtain a pointer to the function.
3009 *
3010 * \param ust Location to store the 64-bit UST
3011 * \returns Zero on success or a negative errno value on failure.
3012 *
3013 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3014 *
3015 * \since Internal API version 20030317.
3016 */
3017 int __glXGetUST( int64_t * ust )
3018 {
3019 struct timeval tv;
3020
3021 if ( ust == NULL ) {
3022 return -EFAULT;
3023 }
3024
3025 if ( gettimeofday( & tv, NULL ) == 0 ) {
3026 ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
3027 return 0;
3028 } else {
3029 return -errno;
3030 }
3031 }
3032 #endif /* GLX_DIRECT_RENDERING */