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