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