remove stray 'foo' line
[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 GLint glXSwapIntervalMESA(unsigned 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 PUBLIC GLint glXGetSwapIntervalMESA( void )
1758 {
1759 #ifdef GLX_DIRECT_RENDERING
1760 GLXContext gc = __glXGetCurrentContext();
1761
1762 if ( (gc != NULL) && gc->isDirect ) {
1763 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1764 gc->screen );
1765
1766 if ( (psc != NULL) && (psc->driScreen.private != NULL)
1767 && __glXExtensionBitIsEnabled( psc, MESA_swap_control_bit ) ) {
1768 __DRIdrawable * const pdraw =
1769 (*psc->driScreen.getDrawable)(gc->currentDpy,
1770 gc->currentDrawable,
1771 psc->driScreen.private);
1772 if ( pdraw != NULL ) {
1773 return pdraw->swap_interval;
1774 }
1775 }
1776 }
1777 #endif
1778
1779 return 0;
1780 }
1781
1782
1783 /*
1784 ** GLX_MESA_swap_frame_usage
1785 */
1786
1787 PUBLIC GLint glXBeginFrameTrackingMESA(Display *dpy, GLXDrawable drawable)
1788 {
1789 int status = GLX_BAD_CONTEXT;
1790 #ifdef GLX_DIRECT_RENDERING
1791 int screen;
1792 __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
1793 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
1794
1795 if ( (pdraw != NULL) && (pdraw->frameTracking != NULL)
1796 && __glXExtensionBitIsEnabled( psc, MESA_swap_frame_usage_bit ) ) {
1797 status = pdraw->frameTracking( dpy, pdraw->private, GL_TRUE );
1798 }
1799 #else
1800 (void) dpy;
1801 (void) drawable;
1802 #endif
1803 return status;
1804 }
1805
1806
1807 PUBLIC GLint glXEndFrameTrackingMESA(Display *dpy, GLXDrawable drawable)
1808 {
1809 int status = GLX_BAD_CONTEXT;
1810 #ifdef GLX_DIRECT_RENDERING
1811 int screen;
1812 __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
1813 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
1814
1815 if ( (pdraw != NULL) && (pdraw->frameTracking != NULL)
1816 && __glXExtensionBitIsEnabled( psc, MESA_swap_frame_usage_bit ) ) {
1817 status = pdraw->frameTracking( dpy, pdraw->private, GL_FALSE );
1818 }
1819 #else
1820 (void) dpy;
1821 (void) drawable;
1822 #endif
1823 return status;
1824 }
1825
1826
1827 PUBLIC GLint glXGetFrameUsageMESA(Display *dpy, GLXDrawable drawable,
1828 GLfloat *usage)
1829 {
1830 int status = GLX_BAD_CONTEXT;
1831 #ifdef GLX_DIRECT_RENDERING
1832 int screen;
1833 __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
1834 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
1835
1836 if ( (pdraw != NULL ) && (pdraw->queryFrameTracking != NULL)
1837 && __glXExtensionBitIsEnabled( psc, MESA_swap_frame_usage_bit ) ) {
1838 int64_t sbc, missedFrames;
1839 float lastMissedUsage;
1840
1841 status = pdraw->queryFrameTracking( dpy, pdraw->private, &sbc,
1842 &missedFrames, &lastMissedUsage,
1843 usage );
1844 }
1845 #else
1846 (void) dpy;
1847 (void) drawable;
1848 (void) usage;
1849 #endif
1850 return status;
1851 }
1852
1853
1854 PUBLIC GLint glXQueryFrameTrackingMESA(Display *dpy, GLXDrawable drawable,
1855 int64_t *sbc, int64_t *missedFrames,
1856 GLfloat *lastMissedUsage)
1857 {
1858 int status = GLX_BAD_CONTEXT;
1859 #ifdef GLX_DIRECT_RENDERING
1860 int screen;
1861 __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
1862 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
1863
1864 if ( (pdraw != NULL ) && (pdraw->queryFrameTracking != NULL)
1865 && __glXExtensionBitIsEnabled( psc, MESA_swap_frame_usage_bit ) ) {
1866 float usage;
1867
1868 status = pdraw->queryFrameTracking( dpy, pdraw->private, sbc,
1869 missedFrames, lastMissedUsage,
1870 & usage );
1871 }
1872 #else
1873 (void) dpy;
1874 (void) drawable;
1875 (void) sbc;
1876 (void) missedFrames;
1877 (void) lastMissedUsage;
1878 #endif
1879 return status;
1880 }
1881
1882
1883 /*
1884 ** GLX_SGI_video_sync
1885 */
1886 PUBLIC int glXGetVideoSyncSGI(unsigned int *count)
1887 {
1888 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1889 * FIXME: there should be a GLX encoding for this call. I can find no
1890 * FIXME: documentation for the GLX encoding.
1891 */
1892 #ifdef GLX_DIRECT_RENDERING
1893 GLXContext gc = __glXGetCurrentContext();
1894
1895
1896 if ( (gc != NULL) && gc->isDirect ) {
1897 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1898 gc->screen );
1899 if ( __glXExtensionBitIsEnabled( psc, SGI_video_sync_bit )
1900 && psc->driScreen.private && psc->driScreen.getMSC) {
1901 int ret;
1902 int64_t temp;
1903
1904 ret = psc->driScreen.getMSC( psc->driScreen.private, & temp );
1905 *count = (unsigned) temp;
1906 return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
1907 }
1908 }
1909 #else
1910 (void) count;
1911 #endif
1912 return GLX_BAD_CONTEXT;
1913 }
1914
1915 PUBLIC int glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
1916 {
1917 #ifdef GLX_DIRECT_RENDERING
1918 GLXContext gc = __glXGetCurrentContext();
1919
1920 if ( divisor <= 0 || remainder < 0 )
1921 return GLX_BAD_VALUE;
1922
1923 if ( (gc != NULL) && gc->isDirect ) {
1924 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1925 gc->screen );
1926 if ( __glXExtensionBitIsEnabled( psc, SGI_video_sync_bit )
1927 && psc->driScreen.private ) {
1928 __DRIdrawable * const pdraw =
1929 (*psc->driScreen.getDrawable)(gc->currentDpy,
1930 gc->currentDrawable,
1931 psc->driScreen.private);
1932 if ( (pdraw != NULL) && (pdraw->waitForMSC != NULL) ) {
1933 int ret;
1934 int64_t msc;
1935 int64_t sbc;
1936
1937 ret = (*pdraw->waitForMSC)( gc->currentDpy, pdraw->private,
1938 0, divisor, remainder,
1939 & msc, & sbc );
1940 *count = (unsigned) msc;
1941 return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
1942 }
1943 }
1944 }
1945 #else
1946 (void) count;
1947 #endif
1948 return GLX_BAD_CONTEXT;
1949 }
1950
1951
1952 /*
1953 ** GLX_SGIS_video_source
1954 */
1955 #if defined(_VL_H)
1956
1957 PUBLIC GLXVideoSourceSGIX glXCreateGLXVideoSourceSGIX(Display *dpy,
1958 int screen, VLServer server, VLPath path,
1959 int nodeClass, VLNode drainNode)
1960 {
1961 (void) dpy;
1962 (void) screen;
1963 (void) server;
1964 (void) path;
1965 (void) nodeClass;
1966 (void) drainNode;
1967 return 0;
1968 }
1969
1970 PUBLIC void glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src)
1971 {
1972 (void) dpy;
1973 (void) src;
1974 }
1975
1976 #endif
1977
1978
1979 /*
1980 ** GLX_SGIX_fbconfig
1981 ** Many of these functions are aliased to GLX 1.3 entry points in the
1982 ** GLX_functions table.
1983 */
1984
1985 PUBLIC GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
1986 (Display *dpy, GLXFBConfigSGIX config, int attribute, int *value),
1987 (dpy, config, attribute, value),
1988 glXGetFBConfigAttrib)
1989
1990 PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
1991 (Display *dpy, int screen, int *attrib_list, int *nelements),
1992 (dpy, screen, attrib_list, nelements),
1993 glXChooseFBConfig)
1994
1995 PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
1996 (Display * dpy, GLXFBConfigSGIX config),
1997 (dpy, config),
1998 glXGetVisualFromFBConfig)
1999
2000 PUBLIC GLXPixmap glXCreateGLXPixmapWithConfigSGIX(Display *dpy,
2001 GLXFBConfigSGIX config, Pixmap pixmap)
2002 {
2003 xGLXVendorPrivateWithReplyReq *vpreq;
2004 xGLXCreateGLXPixmapWithConfigSGIXReq *req;
2005 GLXPixmap xid = None;
2006 CARD8 opcode;
2007 const __GLcontextModes * const fbconfig = (__GLcontextModes *) config;
2008 __GLXscreenConfigs * psc;
2009
2010
2011 if ( (dpy == NULL) || (config == NULL) ) {
2012 return None;
2013 }
2014
2015 psc = GetGLXScreenConfigs( dpy, fbconfig->screen );
2016 if ( (psc != NULL)
2017 && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) {
2018 opcode = __glXSetupForCommand(dpy);
2019 if (!opcode) {
2020 return None;
2021 }
2022
2023 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2024 LockDisplay(dpy);
2025 GetReqExtra(GLXVendorPrivateWithReply,
2026 sz_xGLXCreateGLXPixmapWithConfigSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq);
2027 req = (xGLXCreateGLXPixmapWithConfigSGIXReq *)vpreq;
2028 req->reqType = opcode;
2029 req->glxCode = X_GLXVendorPrivateWithReply;
2030 req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
2031 req->screen = fbconfig->screen;
2032 req->fbconfig = fbconfig->fbconfigID;
2033 req->pixmap = pixmap;
2034 req->glxpixmap = xid = XAllocID(dpy);
2035 UnlockDisplay(dpy);
2036 SyncHandle();
2037 }
2038
2039 return xid;
2040 }
2041
2042 PUBLIC GLXContext glXCreateContextWithConfigSGIX(Display *dpy,
2043 GLXFBConfigSGIX config, int renderType,
2044 GLXContext shareList, Bool allowDirect)
2045 {
2046 GLXContext gc = NULL;
2047 const __GLcontextModes * const fbconfig = (__GLcontextModes *) config;
2048 __GLXscreenConfigs * psc;
2049
2050
2051 if ( (dpy == NULL) || (config == NULL) ) {
2052 return None;
2053 }
2054
2055 psc = GetGLXScreenConfigs( dpy, fbconfig->screen );
2056 if ( (psc != NULL)
2057 && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) {
2058 gc = CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList,
2059 allowDirect, None, False, renderType );
2060 }
2061
2062 return gc;
2063 }
2064
2065
2066 PUBLIC GLXFBConfigSGIX glXGetFBConfigFromVisualSGIX(Display *dpy,
2067 XVisualInfo *vis)
2068 {
2069 __GLXdisplayPrivate *priv;
2070 __GLXscreenConfigs *psc;
2071
2072 if ( (GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc ) != Success)
2073 && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit )
2074 && (psc->configs->fbconfigID != GLX_DONT_CARE) ) {
2075 return (GLXFBConfigSGIX) _gl_context_modes_find_visual( psc->configs,
2076 vis->visualid );
2077 }
2078
2079 return NULL;
2080 }
2081
2082
2083 /*
2084 ** GLX_SGI_cushion
2085 */
2086 PUBLIC void glXCushionSGI(Display *dpy, Window win, float cushion)
2087 {
2088 (void) dpy;
2089 (void) win;
2090 (void) cushion;
2091 }
2092
2093
2094 /*
2095 ** GLX_SGIX_video_resize
2096 */
2097 PUBLIC int glXBindChannelToWindowSGIX(Display *dpy, int screen,
2098 int channel , Window window)
2099 {
2100 (void) dpy;
2101 (void) screen;
2102 (void) channel;
2103 (void) window;
2104 return 0;
2105 }
2106
2107 PUBLIC int glXChannelRectSGIX(Display *dpy, int screen, int channel,
2108 int x, int y, int w, int h)
2109 {
2110 (void) dpy;
2111 (void) screen;
2112 (void) channel;
2113 (void) x;
2114 (void) y;
2115 (void) w;
2116 (void) h;
2117 return 0;
2118 }
2119
2120 PUBLIC int glXQueryChannelRectSGIX(Display *dpy, int screen, int channel,
2121 int *x, int *y, int *w, int *h)
2122 {
2123 (void) dpy;
2124 (void) screen;
2125 (void) channel;
2126 (void) x;
2127 (void) y;
2128 (void) w;
2129 (void) h;
2130 return 0;
2131 }
2132
2133 int glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel,
2134 int *dx, int *dy, int *dw, int *dh)
2135 {
2136 (void) dpy;
2137 (void) screen;
2138 (void) channel;
2139 (void) dx;
2140 (void) dy;
2141 (void) dw;
2142 (void) dh;
2143 return 0;
2144 }
2145
2146 PUBLIC int glXChannelRectSyncSGIX(Display *dpy, int screen,
2147 int channel, GLenum synctype)
2148 {
2149 (void) dpy;
2150 (void) screen;
2151 (void) channel;
2152 (void) synctype;
2153 return 0;
2154 }
2155
2156
2157 #if defined(_DM_BUFFER_H_)
2158
2159 PUBLIC Bool glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer,
2160 DMparams *params, DMbuffer dmbuffer)
2161 {
2162 (void) dpy;
2163 (void) pbuffer;
2164 (void) params;
2165 (void) dmbuffer;
2166 return False;
2167 }
2168
2169 #endif
2170
2171
2172 /*
2173 ** GLX_SGIX_swap_group
2174 */
2175 PUBLIC void glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable,
2176 GLXDrawable member)
2177 {
2178 (void) dpy;
2179 (void) drawable;
2180 (void) member;
2181 }
2182
2183
2184 /*
2185 ** GLX_SGIX_swap_barrier
2186 */
2187 PUBLIC void glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable,
2188 int barrier)
2189 {
2190 (void) dpy;
2191 (void) drawable;
2192 (void) barrier;
2193 }
2194
2195 PUBLIC Bool glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
2196 {
2197 (void) dpy;
2198 (void) screen;
2199 (void) max;
2200 return False;
2201 }
2202
2203
2204 /*
2205 ** GLX_SUN_get_transparent_index
2206 */
2207 PUBLIC Status glXGetTransparentIndexSUN(Display *dpy, Window overlay,
2208 Window underlay, long *pTransparent)
2209 {
2210 (void) dpy;
2211 (void) overlay;
2212 (void) underlay;
2213 (void) pTransparent;
2214 return 0;
2215 }
2216
2217
2218 /*
2219 ** GLX_OML_sync_control
2220 */
2221 PUBLIC Bool glXGetSyncValuesOML(Display *dpy, GLXDrawable drawable,
2222 int64_t *ust, int64_t *msc, int64_t *sbc)
2223 {
2224 #ifdef GLX_DIRECT_RENDERING
2225 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
2226
2227 if ( priv != NULL ) {
2228 int i;
2229 __DRIdrawable * const pdraw = GetDRIDrawable( dpy, drawable, & i );
2230 __GLXscreenConfigs * const psc = &priv->screenConfigs[i];
2231
2232 assert( (pdraw == NULL) || (i != -1) );
2233 return ( (pdraw && pdraw->getSBC && psc->driScreen.getMSC)
2234 && __glXExtensionBitIsEnabled( psc, OML_sync_control_bit )
2235 && ((*psc->driScreen.getMSC)( psc->driScreen.private, msc ) == 0)
2236 && ((*pdraw->getSBC)( dpy, psc->driScreen.private, sbc ) == 0)
2237 && (__glXGetUST( ust ) == 0) );
2238 }
2239 #else
2240 (void) dpy;
2241 (void) drawable;
2242 (void) ust;
2243 (void) msc;
2244 (void) sbc;
2245 #endif
2246 return False;
2247 }
2248
2249
2250 /**
2251 * Determine the refresh rate of the specified drawable and display.
2252 *
2253 * \param dpy Display whose refresh rate is to be determined.
2254 * \param drawable Drawable whose refresh rate is to be determined.
2255 * \param numerator Numerator of the refresh rate.
2256 * \param demoninator Denominator of the refresh rate.
2257 * \return If the refresh rate for the specified display and drawable could
2258 * be calculated, True is returned. Otherwise False is returned.
2259 *
2260 * \note This function is implemented entirely client-side. A lot of other
2261 * functionality is required to export GLX_OML_sync_control, so on
2262 * XFree86 this function can be called for direct-rendering contexts
2263 * when GLX_OML_sync_control appears in the client extension string.
2264 */
2265
2266 PUBLIC Bool glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
2267 int32_t * numerator, int32_t * denominator)
2268 {
2269 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2270 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
2271
2272
2273 if ( priv != NULL ) {
2274 XF86VidModeModeLine mode_line;
2275 int dot_clock;
2276 int screen_num;
2277 int i;
2278
2279
2280 GetDRIDrawable( dpy, drawable, & screen_num );
2281 if ( (screen_num != -1)
2282 && XF86VidModeQueryVersion( dpy, & i, & i )
2283 && XF86VidModeGetModeLine( dpy, screen_num, & dot_clock,
2284 & mode_line ) ) {
2285 unsigned n = dot_clock * 1000;
2286 unsigned d = mode_line.vtotal * mode_line.htotal;
2287
2288 # define V_INTERLACE 0x010
2289 # define V_DBLSCAN 0x020
2290
2291 if ( (mode_line.flags & V_INTERLACE) ) {
2292 n *= 2;
2293 }
2294 else if ( (mode_line.flags & V_DBLSCAN) ) {
2295 d *= 2;
2296 }
2297
2298 /* The OML_sync_control spec requires that if the refresh rate is a
2299 * whole number, that the returned numerator be equal to the refresh
2300 * rate and the denominator be 1.
2301 */
2302
2303 if ( (n % d) == 0 ) {
2304 n /= d;
2305 d = 1;
2306 }
2307 else {
2308 static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 };
2309
2310
2311 /* This is a poor man's way to reduce a fraction. It's far from
2312 * perfect, but it will work well enough for this situation.
2313 */
2314
2315 for ( i = 0 ; f[i] != 0 ; i++ ) {
2316 while ( ((n % f[i]) == 0) && ((d % f[i]) == 0) ) {
2317 d /= f[i];
2318 n /= f[i];
2319 }
2320 }
2321 }
2322
2323 *numerator = n;
2324 *denominator = d;
2325
2326 (void) drawable;
2327 return True;
2328 }
2329 }
2330 #else
2331 (void) dpy;
2332 (void) drawable;
2333 (void) numerator;
2334 (void) denominator;
2335 #endif
2336 return False;
2337 }
2338
2339
2340 PUBLIC int64_t glXSwapBuffersMscOML(Display *dpy, GLXDrawable drawable,
2341 int64_t target_msc, int64_t divisor,
2342 int64_t remainder)
2343 {
2344 #ifdef GLX_DIRECT_RENDERING
2345 int screen;
2346 __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
2347 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
2348
2349 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2350 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2351 * of -1 if the function failed because of errors detected in the input
2352 * parameters"
2353 */
2354 if ( divisor < 0 || remainder < 0 || target_msc < 0 )
2355 return -1;
2356 if ( divisor > 0 && remainder >= divisor )
2357 return -1;
2358
2359 if ( (pdraw != NULL) && (pdraw->swapBuffersMSC != NULL)
2360 && __glXExtensionBitIsEnabled( psc, OML_sync_control_bit ) ) {
2361 return (*pdraw->swapBuffersMSC)(dpy, pdraw->private, target_msc,
2362 divisor, remainder);
2363 }
2364 #else
2365 (void) dpy;
2366 (void) drawable;
2367 (void) target_msc;
2368 (void) divisor;
2369 (void) remainder;
2370 #endif
2371 return 0;
2372 }
2373
2374
2375 PUBLIC Bool glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
2376 int64_t target_msc, int64_t divisor,
2377 int64_t remainder, int64_t *ust,
2378 int64_t *msc, int64_t *sbc)
2379 {
2380 #ifdef GLX_DIRECT_RENDERING
2381 int screen;
2382 __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
2383 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
2384 int ret;
2385
2386 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2387 * error", but the return type in the spec is Bool.
2388 */
2389 if ( divisor < 0 || remainder < 0 || target_msc < 0 )
2390 return False;
2391 if ( divisor > 0 && remainder >= divisor )
2392 return False;
2393
2394 if ( (pdraw != NULL) && (pdraw->waitForMSC != NULL)
2395 && __glXExtensionBitIsEnabled( psc, OML_sync_control_bit ) ) {
2396 ret = (*pdraw->waitForMSC)( dpy, pdraw->private, target_msc,
2397 divisor, remainder, msc, sbc );
2398
2399 /* __glXGetUST returns zero on success and non-zero on failure.
2400 * This function returns True on success and False on failure.
2401 */
2402 return ( (ret == 0) && (__glXGetUST( ust ) == 0) );
2403 }
2404 #else
2405 (void) dpy;
2406 (void) drawable;
2407 (void) target_msc;
2408 (void) divisor;
2409 (void) remainder;
2410 (void) ust;
2411 (void) msc;
2412 (void) sbc;
2413 #endif
2414 return False;
2415 }
2416
2417
2418 PUBLIC Bool glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
2419 int64_t target_sbc, int64_t *ust,
2420 int64_t *msc, int64_t *sbc )
2421 {
2422 #ifdef GLX_DIRECT_RENDERING
2423 int screen;
2424 __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
2425 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
2426 int ret;
2427
2428 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2429 * error", but the return type in the spec is Bool.
2430 */
2431 if ( target_sbc < 0 )
2432 return False;
2433
2434 if ( (pdraw != NULL) && (pdraw->waitForSBC != NULL)
2435 && __glXExtensionBitIsEnabled( psc, OML_sync_control_bit )) {
2436 ret = (*pdraw->waitForSBC)( dpy, pdraw->private, target_sbc, msc, sbc );
2437
2438 /* __glXGetUST returns zero on success and non-zero on failure.
2439 * This function returns True on success and False on failure.
2440 */
2441 return( (ret == 0) && (__glXGetUST( ust ) == 0) );
2442 }
2443 #else
2444 (void) dpy;
2445 (void) drawable;
2446 (void) target_sbc;
2447 (void) ust;
2448 (void) msc;
2449 (void) sbc;
2450 #endif
2451 return False;
2452 }
2453
2454
2455 /**
2456 * GLX_MESA_allocate_memory
2457 */
2458 /*@{*/
2459
2460 PUBLIC void *glXAllocateMemoryMESA(Display *dpy, int scrn,
2461 size_t size, float readFreq,
2462 float writeFreq, float priority)
2463 {
2464 #ifdef GLX_DIRECT_RENDERING
2465 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
2466
2467 if ( __glXExtensionBitIsEnabled( psc, MESA_allocate_memory_bit ) ) {
2468 if (psc && psc->driScreen.private && psc->driScreen.allocateMemory) {
2469 return (*psc->driScreen.allocateMemory)( dpy, scrn, size,
2470 readFreq, writeFreq,
2471 priority );
2472 }
2473 }
2474 #else
2475 (void) dpy;
2476 (void) scrn;
2477 (void) size;
2478 (void) readFreq;
2479 (void) writeFreq;
2480 (void) priority;
2481 #endif /* GLX_DIRECT_RENDERING */
2482
2483 return NULL;
2484 }
2485
2486
2487 PUBLIC void glXFreeMemoryMESA(Display *dpy, int scrn, void *pointer)
2488 {
2489 #ifdef GLX_DIRECT_RENDERING
2490 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
2491
2492 if ( __glXExtensionBitIsEnabled( psc, MESA_allocate_memory_bit ) ) {
2493 if (psc && psc->driScreen.private && psc->driScreen.freeMemory) {
2494 (*psc->driScreen.freeMemory)( dpy, scrn, pointer );
2495 }
2496 }
2497 #else
2498 (void) dpy;
2499 (void) scrn;
2500 (void) pointer;
2501 #endif /* GLX_DIRECT_RENDERING */
2502 }
2503
2504
2505 PUBLIC GLuint glXGetMemoryOffsetMESA( Display *dpy, int scrn,
2506 const void *pointer )
2507 {
2508 #ifdef GLX_DIRECT_RENDERING
2509 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
2510
2511 if ( __glXExtensionBitIsEnabled( psc, MESA_allocate_memory_bit ) ) {
2512 if (psc && psc->driScreen.private && psc->driScreen.memoryOffset) {
2513 return (*psc->driScreen.memoryOffset)( dpy, scrn, pointer );
2514 }
2515 }
2516 #else
2517 (void) dpy;
2518 (void) scrn;
2519 (void) pointer;
2520 #endif /* GLX_DIRECT_RENDERING */
2521
2522 return ~0L;
2523 }
2524 /*@}*/
2525
2526
2527 /**
2528 * Mesa extension stubs. These will help reduce portability problems.
2529 */
2530 /*@{*/
2531
2532 /**
2533 * Release all buffers associated with the specified GLX drawable.
2534 *
2535 * \todo
2536 * This function was intended for stand-alone Mesa. The issue there is that
2537 * the library doesn't get any notification when a window is closed. In
2538 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2539 * supported, there are 3 different functions to destroy a drawable. It
2540 * should be possible to create GLX protocol (or have it determine which
2541 * protocol to use based on the type of the drawable) to have one function
2542 * do the work of 3. For the direct-rendering case, this function could
2543 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2544 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2545 * would need to be used. This really should be done as part of the new DRI
2546 * interface work.
2547 *
2548 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2549 * __driGarbageCollectDrawables
2550 * glXDestroyGLXPixmap
2551 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2552 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2553 */
2554 PUBLIC Bool glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
2555 {
2556 (void) dpy;
2557 (void) d;
2558 return False;
2559 }
2560
2561
2562 PUBLIC GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual,
2563 Pixmap pixmap, Colormap cmap )
2564 {
2565 (void) dpy;
2566 (void) visual;
2567 (void) pixmap;
2568 (void) cmap;
2569 return 0;
2570 }
2571
2572
2573 PUBLIC void glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable,
2574 int x, int y, int width, int height)
2575 {
2576 (void) dpy;
2577 (void) drawable;
2578 (void) x;
2579 (void) y;
2580 (void) width;
2581 (void) height;
2582 }
2583
2584
2585 PUBLIC Bool glXSet3DfxModeMESA( int mode )
2586 {
2587 (void) mode;
2588 return GL_FALSE;
2589 }
2590 /*@}*/
2591
2592 PUBLIC Bool glXBindTexImageEXT(Display *dpy,
2593 GLXDrawable drawable,
2594 int buffer)
2595 {
2596 xGLXVendorPrivateReq *req;
2597 GLXContext gc = __glXGetCurrentContext();
2598 CARD32 *drawable_ptr;
2599 INT32 *buffer_ptr;
2600 CARD8 opcode;
2601
2602 if (gc == NULL)
2603 return False;
2604
2605 #ifdef GLX_DIRECT_RENDERING
2606 if (gc->isDirect)
2607 return False;
2608 #endif
2609
2610 opcode = __glXSetupForCommand(dpy);
2611 if (!opcode)
2612 return False;
2613
2614 LockDisplay(dpy);
2615 GetReqExtra(GLXVendorPrivate, sizeof(CARD32)+sizeof(INT32),req);
2616 req->reqType = opcode;
2617 req->glxCode = X_GLXVendorPrivate;
2618 req->vendorCode = X_GLXvop_BindTexImageEXT;
2619 req->contextTag = gc->currentContextTag;
2620
2621 drawable_ptr = (CARD32 *) (req + 1);
2622 buffer_ptr = (INT32 *) (drawable_ptr + 1);
2623
2624 *drawable_ptr = drawable;
2625 *buffer_ptr = buffer;
2626
2627 UnlockDisplay(dpy);
2628 SyncHandle();
2629
2630 return True;
2631 }
2632
2633 PUBLIC Bool glXReleaseTexImageEXT(Display *dpy,
2634 GLXDrawable drawable,
2635 int buffer)
2636 {
2637 xGLXVendorPrivateReq *req;
2638 GLXContext gc = __glXGetCurrentContext();
2639 CARD32 *drawable_ptr;
2640 INT32 *buffer_ptr;
2641 CARD8 opcode;
2642
2643 if (gc == NULL)
2644 return False;
2645
2646 #ifdef GLX_DIRECT_RENDERING
2647 if (gc->isDirect)
2648 return False;
2649 #endif
2650
2651 opcode = __glXSetupForCommand(dpy);
2652 if (!opcode)
2653 return False;
2654
2655 LockDisplay(dpy);
2656 GetReqExtra(GLXVendorPrivate, sizeof(CARD32)+sizeof(INT32),req);
2657 req->reqType = opcode;
2658 req->glxCode = X_GLXVendorPrivate;
2659 req->vendorCode = X_GLXvop_ReleaseTexImageEXT;
2660 req->contextTag = gc->currentContextTag;
2661
2662 drawable_ptr = (CARD32 *) (req + 1);
2663 buffer_ptr = (INT32 *) (drawable_ptr + 1);
2664
2665 *drawable_ptr = drawable;
2666 *buffer_ptr = buffer;
2667
2668 UnlockDisplay(dpy);
2669 SyncHandle();
2670
2671 return True;
2672 }
2673
2674 /**
2675 * \c strdup is actually not a standard ANSI C or POSIX routine.
2676 * Irix will not define it if ANSI mode is in effect.
2677 *
2678 * \sa strdup
2679 */
2680 char *
2681 __glXstrdup(const char *str)
2682 {
2683 char *copy;
2684 copy = (char *) Xmalloc(strlen(str) + 1);
2685 if (!copy)
2686 return NULL;
2687 strcpy(copy, str);
2688 return copy;
2689 }
2690
2691 /*
2692 ** glXGetProcAddress support
2693 */
2694
2695 struct name_address_pair {
2696 const char *Name;
2697 GLvoid *Address;
2698 };
2699
2700 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2701 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2702
2703 static const struct name_address_pair GLX_functions[] = {
2704 /*** GLX_VERSION_1_0 ***/
2705 GLX_FUNCTION( glXChooseVisual ),
2706 GLX_FUNCTION( glXCopyContext ),
2707 GLX_FUNCTION( glXCreateContext ),
2708 GLX_FUNCTION( glXCreateGLXPixmap ),
2709 GLX_FUNCTION( glXDestroyContext ),
2710 GLX_FUNCTION( glXDestroyGLXPixmap ),
2711 GLX_FUNCTION( glXGetConfig ),
2712 GLX_FUNCTION( glXGetCurrentContext ),
2713 GLX_FUNCTION( glXGetCurrentDrawable ),
2714 GLX_FUNCTION( glXIsDirect ),
2715 GLX_FUNCTION( glXMakeCurrent ),
2716 GLX_FUNCTION( glXQueryExtension ),
2717 GLX_FUNCTION( glXQueryVersion ),
2718 GLX_FUNCTION( glXSwapBuffers ),
2719 GLX_FUNCTION( glXUseXFont ),
2720 GLX_FUNCTION( glXWaitGL ),
2721 GLX_FUNCTION( glXWaitX ),
2722
2723 /*** GLX_VERSION_1_1 ***/
2724 GLX_FUNCTION( glXGetClientString ),
2725 GLX_FUNCTION( glXQueryExtensionsString ),
2726 GLX_FUNCTION( glXQueryServerString ),
2727
2728 /*** GLX_VERSION_1_2 ***/
2729 GLX_FUNCTION( glXGetCurrentDisplay ),
2730
2731 /*** GLX_VERSION_1_3 ***/
2732 GLX_FUNCTION( glXChooseFBConfig ),
2733 GLX_FUNCTION( glXCreateNewContext ),
2734 GLX_FUNCTION( glXCreatePbuffer ),
2735 GLX_FUNCTION( glXCreatePixmap ),
2736 GLX_FUNCTION( glXCreateWindow ),
2737 GLX_FUNCTION( glXDestroyPbuffer ),
2738 GLX_FUNCTION( glXDestroyPixmap ),
2739 GLX_FUNCTION( glXDestroyWindow ),
2740 GLX_FUNCTION( glXGetCurrentReadDrawable ),
2741 GLX_FUNCTION( glXGetFBConfigAttrib ),
2742 GLX_FUNCTION( glXGetFBConfigs ),
2743 GLX_FUNCTION( glXGetSelectedEvent ),
2744 GLX_FUNCTION( glXGetVisualFromFBConfig ),
2745 GLX_FUNCTION( glXMakeContextCurrent ),
2746 GLX_FUNCTION( glXQueryContext ),
2747 GLX_FUNCTION( glXQueryDrawable ),
2748 GLX_FUNCTION( glXSelectEvent ),
2749
2750 /*** GLX_SGI_swap_control ***/
2751 GLX_FUNCTION( glXSwapIntervalSGI ),
2752
2753 /*** GLX_SGI_video_sync ***/
2754 GLX_FUNCTION( glXGetVideoSyncSGI ),
2755 GLX_FUNCTION( glXWaitVideoSyncSGI ),
2756
2757 /*** GLX_SGI_make_current_read ***/
2758 GLX_FUNCTION2( glXMakeCurrentReadSGI, glXMakeContextCurrent ),
2759 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable ),
2760
2761 /*** GLX_SGIX_video_source ***/
2762 #if defined(_VL_H)
2763 GLX_FUNCTION( glXCreateGLXVideoSourceSGIX ),
2764 GLX_FUNCTION( glXDestroyGLXVideoSourceSGIX ),
2765 #endif
2766
2767 /*** GLX_EXT_import_context ***/
2768 GLX_FUNCTION( glXFreeContextEXT ),
2769 GLX_FUNCTION( glXGetContextIDEXT ),
2770 GLX_FUNCTION2( glXGetCurrentDisplayEXT, glXGetCurrentDisplay ),
2771 GLX_FUNCTION( glXImportContextEXT ),
2772 GLX_FUNCTION2( glXQueryContextInfoEXT, glXQueryContext ),
2773
2774 /*** GLX_SGIX_fbconfig ***/
2775 GLX_FUNCTION2( glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib ),
2776 GLX_FUNCTION2( glXChooseFBConfigSGIX, glXChooseFBConfig ),
2777 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX ),
2778 GLX_FUNCTION( glXCreateContextWithConfigSGIX ),
2779 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig ),
2780 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX ),
2781
2782 /*** GLX_SGIX_pbuffer ***/
2783 GLX_FUNCTION( glXCreateGLXPbufferSGIX ),
2784 GLX_FUNCTION( glXDestroyGLXPbufferSGIX ),
2785 GLX_FUNCTION( glXQueryGLXPbufferSGIX ),
2786 GLX_FUNCTION( glXSelectEventSGIX ),
2787 GLX_FUNCTION( glXGetSelectedEventSGIX ),
2788
2789 /*** GLX_SGI_cushion ***/
2790 GLX_FUNCTION( glXCushionSGI ),
2791
2792 /*** GLX_SGIX_video_resize ***/
2793 GLX_FUNCTION( glXBindChannelToWindowSGIX ),
2794 GLX_FUNCTION( glXChannelRectSGIX ),
2795 GLX_FUNCTION( glXQueryChannelRectSGIX ),
2796 GLX_FUNCTION( glXQueryChannelDeltasSGIX ),
2797 GLX_FUNCTION( glXChannelRectSyncSGIX ),
2798
2799 /*** GLX_SGIX_dmbuffer **/
2800 #if defined(_DM_BUFFER_H_)
2801 GLX_FUNCTION( glXAssociateDMPbufferSGIX ),
2802 #endif
2803
2804 /*** GLX_SGIX_swap_group ***/
2805 GLX_FUNCTION( glXJoinSwapGroupSGIX ),
2806
2807 /*** GLX_SGIX_swap_barrier ***/
2808 GLX_FUNCTION( glXBindSwapBarrierSGIX ),
2809 GLX_FUNCTION( glXQueryMaxSwapBarriersSGIX ),
2810
2811 /*** GLX_SUN_get_transparent_index ***/
2812 GLX_FUNCTION( glXGetTransparentIndexSUN ),
2813
2814 /*** GLX_MESA_allocate_memory ***/
2815 GLX_FUNCTION( glXAllocateMemoryMESA ),
2816 GLX_FUNCTION( glXFreeMemoryMESA ),
2817 GLX_FUNCTION( glXGetMemoryOffsetMESA ),
2818
2819 /*** GLX_MESA_copy_sub_buffer ***/
2820 GLX_FUNCTION( glXCopySubBufferMESA ),
2821
2822 /*** GLX_MESA_pixmap_colormap ***/
2823 GLX_FUNCTION( glXCreateGLXPixmapMESA ),
2824
2825 /*** GLX_MESA_release_buffers ***/
2826 GLX_FUNCTION( glXReleaseBuffersMESA ),
2827
2828 /*** GLX_MESA_set_3dfx_mode ***/
2829 GLX_FUNCTION( glXSet3DfxModeMESA ),
2830
2831 /*** GLX_MESA_swap_control ***/
2832 GLX_FUNCTION( glXSwapIntervalMESA ),
2833 GLX_FUNCTION( glXGetSwapIntervalMESA ),
2834
2835 /*** GLX_MESA_swap_frame_usage ***/
2836 GLX_FUNCTION( glXBeginFrameTrackingMESA ),
2837 GLX_FUNCTION( glXEndFrameTrackingMESA ),
2838 GLX_FUNCTION( glXGetFrameUsageMESA ),
2839 GLX_FUNCTION( glXQueryFrameTrackingMESA ),
2840
2841 /*** GLX_ARB_get_proc_address ***/
2842 GLX_FUNCTION( glXGetProcAddressARB ),
2843
2844 /*** GLX 1.4 ***/
2845 GLX_FUNCTION2( glXGetProcAddress, glXGetProcAddressARB ),
2846
2847 /*** GLX_OML_sync_control ***/
2848 GLX_FUNCTION( glXWaitForSbcOML ),
2849 GLX_FUNCTION( glXWaitForMscOML ),
2850 GLX_FUNCTION( glXSwapBuffersMscOML ),
2851 GLX_FUNCTION( glXGetMscRateOML ),
2852 GLX_FUNCTION( glXGetSyncValuesOML ),
2853
2854 /*** GLX_EXT_texture_from_pixmap ***/
2855 GLX_FUNCTION( glXBindTexImageEXT ),
2856 GLX_FUNCTION( glXReleaseTexImageEXT ),
2857
2858 #ifdef GLX_DIRECT_RENDERING
2859 /*** DRI configuration ***/
2860 GLX_FUNCTION( glXGetScreenDriver ),
2861 GLX_FUNCTION( glXGetDriverConfig ),
2862 #endif
2863
2864 { NULL, NULL } /* end of list */
2865 };
2866
2867
2868 static const GLvoid *
2869 get_glx_proc_address(const char *funcName)
2870 {
2871 GLuint i;
2872
2873 /* try static functions */
2874 for (i = 0; GLX_functions[i].Name; i++) {
2875 if (strcmp(GLX_functions[i].Name, funcName) == 0)
2876 return GLX_functions[i].Address;
2877 }
2878
2879 return NULL;
2880 }
2881
2882
2883 /**
2884 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2885 * \c glXGetProcAddress.
2886 *
2887 * \param procName Name of a GL or GLX function.
2888 * \returns A pointer to the named function
2889 *
2890 * \sa glXGetProcAddress
2891 */
2892 PUBLIC void (*glXGetProcAddressARB(const GLubyte *procName))( void )
2893 {
2894 typedef void (*gl_function)( void );
2895 gl_function f;
2896
2897
2898 /* Search the table of GLX and internal functions first. If that
2899 * fails and the supplied name could be a valid core GL name, try
2900 * searching the core GL function table. This check is done to prevent
2901 * DRI based drivers from searching the core GL function table for
2902 * internal API functions.
2903 */
2904
2905 f = (gl_function) get_glx_proc_address((const char *) procName);
2906 if ( (f == NULL) && (procName[0] == 'g') && (procName[1] == 'l')
2907 && (procName[2] != 'X') ) {
2908 f = (gl_function) _glapi_get_proc_address((const char *) procName);
2909 }
2910
2911 return f;
2912 }
2913
2914 /**
2915 * Get the address of a named GL function. This is the GLX 1.4 name for
2916 * \c glXGetProcAddressARB.
2917 *
2918 * \param procName Name of a GL or GLX function.
2919 * \returns A pointer to the named function
2920 *
2921 * \sa glXGetProcAddressARB
2922 */
2923 PUBLIC void (*glXGetProcAddress(const GLubyte *procName))( void )
2924 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2925 __attribute__ ((alias ("glXGetProcAddressARB")));
2926 #else
2927 {
2928 return glXGetProcAddressARB(procName);
2929 }
2930 #endif /* __GNUC__ */
2931
2932
2933 #ifdef GLX_DIRECT_RENDERING
2934 /**
2935 * Retrieves the verion of the internal libGL API in YYYYMMDD format. This
2936 * might be used by the DRI drivers to determine how new libGL is at runtime.
2937 * Drivers should not call this function directly. They should instead use
2938 * \c glXGetProcAddress to obtain a pointer to the function.
2939 *
2940 * \returns An 8-digit decimal number representing the internal libGL API in
2941 * YYYYMMDD format.
2942 *
2943 * \sa glXGetProcAddress, PFNGLXGETINTERNALVERSIONPROC
2944 *
2945 * \since Internal API version 20021121.
2946 */
2947 int __glXGetInternalVersion(void)
2948 {
2949 /* History:
2950 * 20021121 - Initial version
2951 * 20021128 - Added __glXWindowExists() function
2952 * 20021207 - Added support for dynamic GLX extensions,
2953 * GLX_SGI_swap_control, GLX_SGI_video_sync,
2954 * GLX_OML_sync_control, and GLX_MESA_swap_control.
2955 * Never officially released. Do NOT test against
2956 * this version. Use 20030317 instead.
2957 * 20030317 - Added support GLX_SGIX_fbconfig,
2958 * GLX_MESA_swap_frame_usage, GLX_OML_swap_method,
2959 * GLX_{ARB,SGIS}_multisample, and
2960 * GLX_SGIX_visual_select_group.
2961 * 20030606 - Added support for GLX_SGI_make_current_read.
2962 * 20030813 - Made support for dynamic extensions multi-head aware.
2963 * 20030818 - Added support for GLX_MESA_allocate_memory in place of the
2964 * deprecated GLX_NV_vertex_array_range & GLX_MESA_agp_offset
2965 * interfaces.
2966 * 20031201 - Added support for the first round of DRI interface changes.
2967 * Do NOT test against this version! It has binary
2968 * compatibility bugs, use 20040317 instead.
2969 * 20040317 - Added the 'mode' field to __DRIcontextRec.
2970 * 20040415 - Added support for bindContext3 and unbindContext3.
2971 * 20040602 - Add __glXGetDrawableInfo. I though that was there
2972 * months ago. :(
2973 * 20050727 - Gut all the old interfaces. This breaks compatability with
2974 * any DRI driver built to any previous version.
2975 */
2976 return 20050727;
2977 }
2978
2979
2980
2981 static Bool windowExistsFlag;
2982
2983 static int windowExistsErrorHandler(Display *dpy, XErrorEvent *xerr)
2984 {
2985 if (xerr->error_code == BadWindow) {
2986 windowExistsFlag = GL_FALSE;
2987 }
2988 return 0;
2989 }
2990
2991 /**
2992 * Determine if a window associated with a \c GLXDrawable exists on the
2993 * X-server. This function is not used internally by libGL. It is provided
2994 * as a utility function for DRI drivers.
2995 * Drivers should not call this function directly. They should instead use
2996 * \c glXGetProcAddress to obtain a pointer to the function.
2997 *
2998 * \param dpy Display associated with the drawable to be queried.
2999 * \param draw \c GLXDrawable to test.
3000 *
3001 * \returns \c GL_TRUE if a window exists that is associated with \c draw,
3002 * otherwise \c GL_FALSE is returned.
3003 *
3004 * \warning This function is not currently thread-safe.
3005 *
3006 * \sa glXGetProcAddress
3007 *
3008 * \since Internal API version 20021128.
3009 */
3010 Bool __glXWindowExists(Display *dpy, GLXDrawable draw)
3011 {
3012 XWindowAttributes xwa;
3013 int (*oldXErrorHandler)(Display *, XErrorEvent *);
3014
3015 XSync(dpy, GL_FALSE);
3016 windowExistsFlag = GL_TRUE;
3017 oldXErrorHandler = XSetErrorHandler(windowExistsErrorHandler);
3018 XGetWindowAttributes(dpy, draw, &xwa); /* dummy request */
3019 XSetErrorHandler(oldXErrorHandler);
3020 return windowExistsFlag;
3021 }
3022
3023
3024 /**
3025 * Get the unadjusted system time (UST). Currently, the UST is measured in
3026 * microseconds since Epoc. The actual resolution of the UST may vary from
3027 * system to system, and the units may vary from release to release.
3028 * Drivers should not call this function directly. They should instead use
3029 * \c glXGetProcAddress to obtain a pointer to the function.
3030 *
3031 * \param ust Location to store the 64-bit UST
3032 * \returns Zero on success or a negative errno value on failure.
3033 *
3034 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3035 *
3036 * \since Internal API version 20030317.
3037 */
3038 int __glXGetUST( int64_t * ust )
3039 {
3040 struct timeval tv;
3041
3042 if ( ust == NULL ) {
3043 return -EFAULT;
3044 }
3045
3046 if ( gettimeofday( & tv, NULL ) == 0 ) {
3047 ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
3048 return 0;
3049 } else {
3050 return -errno;
3051 }
3052 }
3053 #endif /* GLX_DIRECT_RENDERING */