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