ir_validate: Validate loop control fields in ir_loop
[mesa/nouveau-pmpeg.git] / src / glx / glx_pbuffer.c
blob15bfb1591916e1cd0c51a7cd65027e190fb0c3f7
1 /*
2 * (C) Copyright IBM Corporation 2004
3 * All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 /**
26 * \file glx_pbuffer.c
27 * Implementation of pbuffer related functions.
29 * \author Ian Romanick <idr@us.ibm.com>
32 #include <inttypes.h>
33 #include "glxclient.h"
34 #include <X11/extensions/extutil.h>
35 #include <X11/extensions/Xext.h>
36 #include <assert.h>
37 #include <string.h>
38 #include "glxextensions.h"
40 #ifdef GLX_USE_APPLEGL
41 #include <pthread.h>
42 #include "apple_glx_drawable.h"
43 #include "glx_error.h"
44 #endif
46 #define WARN_ONCE_GLX_1_3(a, b) { \
47 static int warned=1; \
48 if(warned) { \
49 warn_GLX_1_3((a), b ); \
50 warned=0; \
51 } \
54 /**
55 * Emit a warning when clients use GLX 1.3 functions on pre-1.3 systems.
57 static void
58 warn_GLX_1_3(Display * dpy, const char *function_name)
60 struct glx_display *priv = __glXInitialize(dpy);
62 if (priv->minorVersion < 3) {
63 fprintf(stderr,
64 "WARNING: Application calling GLX 1.3 function \"%s\" "
65 "when GLX 1.3 is not supported! This is an application bug!\n",
66 function_name);
70 #ifndef GLX_USE_APPLEGL
71 /**
72 * Change a drawable's attribute.
74 * This function is used to implement \c glXSelectEvent and
75 * \c glXSelectEventSGIX.
77 * \note
78 * This function dynamically determines whether to use the SGIX_pbuffer
79 * version of the protocol or the GLX 1.3 version of the protocol.
81 * \todo
82 * This function needs to be modified to work with direct-rendering drivers.
84 static void
85 ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable,
86 const CARD32 * attribs, size_t num_attribs)
88 struct glx_display *priv = __glXInitialize(dpy);
89 __GLXDRIdrawable *pdraw;
90 CARD32 *output;
91 CARD8 opcode;
92 int i;
94 if ((dpy == NULL) || (drawable == 0)) {
95 return;
98 pdraw = GetGLXDRIDrawable(dpy, drawable);
100 opcode = __glXSetupForCommand(dpy);
101 if (!opcode)
102 return;
104 LockDisplay(dpy);
106 if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) {
107 xGLXChangeDrawableAttributesReq *req;
109 GetReqExtra(GLXChangeDrawableAttributes, 8 + (8 * num_attribs), req);
110 output = (CARD32 *) (req + 1);
112 req->reqType = opcode;
113 req->glxCode = X_GLXChangeDrawableAttributes;
114 req->drawable = drawable;
115 req->numAttribs = (CARD32) num_attribs;
117 else {
118 xGLXVendorPrivateWithReplyReq *vpreq;
120 GetReqExtra(GLXVendorPrivateWithReply, 4 + (8 * num_attribs), vpreq);
121 output = (CARD32 *) (vpreq + 1);
123 vpreq->reqType = opcode;
124 vpreq->glxCode = X_GLXVendorPrivateWithReply;
125 vpreq->vendorCode = X_GLXvop_ChangeDrawableAttributesSGIX;
127 output[0] = (CARD32) drawable;
128 output++;
131 (void) memcpy(output, attribs, sizeof(CARD32) * 2 * num_attribs);
133 UnlockDisplay(dpy);
134 SyncHandle();
136 for (i = 0; i < num_attribs; i++) {
137 switch(attribs[i * 2]) {
138 case GLX_EVENT_MASK:
139 /* Keep a local copy for masking out DRI2 proto events as needed */
140 pdraw->eventMask = attribs[i * 2 + 1];
141 break;
145 return;
149 #ifdef GLX_DIRECT_RENDERING
150 static GLenum
151 determineTextureTarget(const int *attribs, int numAttribs)
153 GLenum target = 0;
154 int i;
156 for (i = 0; i < numAttribs; i++) {
157 if (attribs[2 * i] == GLX_TEXTURE_TARGET_EXT) {
158 switch (attribs[2 * i + 1]) {
159 case GLX_TEXTURE_2D_EXT:
160 target = GL_TEXTURE_2D;
161 break;
162 case GLX_TEXTURE_RECTANGLE_EXT:
163 target = GL_TEXTURE_RECTANGLE_ARB;
164 break;
169 return target;
172 static GLenum
173 determineTextureFormat(const int *attribs, int numAttribs)
175 int i;
177 for (i = 0; i < numAttribs; i++) {
178 if (attribs[2 * i] == GLX_TEXTURE_FORMAT_EXT)
179 return attribs[2 * i + 1];
182 return 0;
185 static void
186 CreateDRIDrawable(Display *dpy, struct glx_config *config,
187 XID drawable, XID glxdrawable,
188 const int *attrib_list, size_t num_attribs)
190 struct glx_display *const priv = __glXInitialize(dpy);
191 __GLXDRIdrawable *pdraw;
192 struct glx_screen *psc;
194 psc = priv->screens[config->screen];
195 if (psc->driScreen == NULL)
196 return;
198 pdraw = psc->driScreen->createDrawable(psc, drawable,
199 glxdrawable, config);
200 if (pdraw == NULL) {
201 fprintf(stderr, "failed to create drawable\n");
202 return;
205 if (__glxHashInsert(priv->drawHash, glxdrawable, pdraw)) {
206 (*pdraw->destroyDrawable) (pdraw);
207 return; /* FIXME: Check what we're supposed to do here... */
210 pdraw->textureTarget = determineTextureTarget(attrib_list, num_attribs);
211 pdraw->textureFormat = determineTextureFormat(attrib_list, num_attribs);
214 static void
215 DestroyDRIDrawable(Display *dpy, GLXDrawable drawable, int destroy_xdrawable)
217 struct glx_display *const priv = __glXInitialize(dpy);
218 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
220 if (pdraw != NULL) {
221 if (destroy_xdrawable)
222 XFreePixmap(pdraw->psc->dpy, pdraw->xDrawable);
223 (*pdraw->destroyDrawable) (pdraw);
224 __glxHashDelete(priv->drawHash, drawable);
228 #else
230 static void
231 CreateDRIDrawable(Display *dpy, const struct glx_config * fbconfig,
232 XID drawable, XID glxdrawable,
233 const int *attrib_list, size_t num_attribs)
237 static void
238 DestroyDRIDrawable(Display *dpy, GLXDrawable drawable, int destroy_xdrawable)
242 #endif
245 * Get a drawable's attribute.
247 * This function is used to implement \c glXGetSelectedEvent and
248 * \c glXGetSelectedEventSGIX.
250 * \note
251 * This function dynamically determines whether to use the SGIX_pbuffer
252 * version of the protocol or the GLX 1.3 version of the protocol.
254 * \todo
255 * The number of attributes returned is likely to be small, probably less than
256 * 10. Given that, this routine should try to use an array on the stack to
257 * capture the reply rather than always calling Xmalloc.
259 * \todo
260 * This function needs to be modified to work with direct-rendering drivers.
262 static int
263 GetDrawableAttribute(Display * dpy, GLXDrawable drawable,
264 int attribute, unsigned int *value)
266 struct glx_display *priv;
267 xGLXGetDrawableAttributesReply reply;
268 CARD32 *data;
269 CARD8 opcode;
270 unsigned int length;
271 unsigned int i;
272 unsigned int num_attributes;
273 GLboolean use_glx_1_3;
275 if ((dpy == NULL) || (drawable == 0)) {
276 return 0;
279 priv = __glXInitialize(dpy);
280 use_glx_1_3 = ((priv->majorVersion > 1) || (priv->minorVersion >= 3));
282 *value = 0;
285 opcode = __glXSetupForCommand(dpy);
286 if (!opcode)
287 return 0;
289 LockDisplay(dpy);
291 if (use_glx_1_3) {
292 xGLXGetDrawableAttributesReq *req;
294 GetReqExtra(GLXGetDrawableAttributes, 4, req);
295 req->reqType = opcode;
296 req->glxCode = X_GLXGetDrawableAttributes;
297 req->drawable = drawable;
299 else {
300 xGLXVendorPrivateWithReplyReq *vpreq;
302 GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq);
303 data = (CARD32 *) (vpreq + 1);
304 data[0] = (CARD32) drawable;
306 vpreq->reqType = opcode;
307 vpreq->glxCode = X_GLXVendorPrivateWithReply;
308 vpreq->vendorCode = X_GLXvop_GetDrawableAttributesSGIX;
311 _XReply(dpy, (xReply *) & reply, 0, False);
313 if (reply.type == X_Error) {
314 UnlockDisplay(dpy);
315 SyncHandle();
316 return 0;
319 length = reply.length;
320 if (length) {
321 num_attributes = (use_glx_1_3) ? reply.numAttribs : length / 2;
322 data = (CARD32 *) Xmalloc(length * sizeof(CARD32));
323 if (data == NULL) {
324 /* Throw data on the floor */
325 _XEatData(dpy, length);
327 else {
328 _XRead(dpy, (char *) data, length * sizeof(CARD32));
330 /* Search the set of returned attributes for the attribute requested by
331 * the caller.
333 for (i = 0; i < num_attributes; i++) {
334 if (data[i * 2] == attribute) {
335 *value = data[(i * 2) + 1];
336 break;
340 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
342 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
344 if (pdraw != NULL && !pdraw->textureTarget)
345 pdraw->textureTarget =
346 determineTextureTarget((const int *) data, num_attributes);
347 if (pdraw != NULL && !pdraw->textureFormat)
348 pdraw->textureFormat =
349 determineTextureFormat((const int *) data, num_attributes);
351 #endif
353 Xfree(data);
357 UnlockDisplay(dpy);
358 SyncHandle();
360 return 0;
364 * Create a non-pbuffer GLX drawable.
366 * \todo
367 * This function needs to be modified to work with direct-rendering drivers.
369 static GLXDrawable
370 CreateDrawable(Display *dpy, struct glx_config *config,
371 Drawable drawable, const int *attrib_list, CARD8 glxCode)
373 xGLXCreateWindowReq *req;
374 CARD32 *data;
375 unsigned int i;
376 CARD8 opcode;
378 i = 0;
379 if (attrib_list) {
380 while (attrib_list[i * 2] != None)
381 i++;
384 opcode = __glXSetupForCommand(dpy);
385 if (!opcode)
386 return None;
388 LockDisplay(dpy);
389 GetReqExtra(GLXCreateWindow, 8 * i, req);
390 data = (CARD32 *) (req + 1);
392 req->reqType = opcode;
393 req->glxCode = glxCode;
394 req->screen = config->screen;
395 req->fbconfig = config->fbconfigID;
396 req->window = drawable;
397 req->glxwindow = XAllocID(dpy);
398 req->numAttribs = i;
400 if (attrib_list)
401 memcpy(data, attrib_list, 8 * i);
403 UnlockDisplay(dpy);
404 SyncHandle();
406 CreateDRIDrawable(dpy, config, drawable, req->glxwindow, attrib_list, i);
408 return req->glxwindow;
413 * Destroy a non-pbuffer GLX drawable.
415 static void
416 DestroyDrawable(Display * dpy, GLXDrawable drawable, CARD32 glxCode)
418 xGLXDestroyPbufferReq *req;
419 CARD8 opcode;
421 if ((dpy == NULL) || (drawable == 0)) {
422 return;
426 opcode = __glXSetupForCommand(dpy);
427 if (!opcode)
428 return;
430 LockDisplay(dpy);
432 GetReqExtra(GLXDestroyPbuffer, 4, req);
433 req->reqType = opcode;
434 req->glxCode = glxCode;
435 req->pbuffer = (GLXPbuffer) drawable;
437 UnlockDisplay(dpy);
438 SyncHandle();
440 DestroyDRIDrawable(dpy, drawable, GL_FALSE);
442 return;
447 * Create a pbuffer.
449 * This function is used to implement \c glXCreatePbuffer and
450 * \c glXCreateGLXPbufferSGIX.
452 * \note
453 * This function dynamically determines whether to use the SGIX_pbuffer
454 * version of the protocol or the GLX 1.3 version of the protocol.
456 * \todo
457 * This function needs to be modified to work with direct-rendering drivers.
459 static GLXDrawable
460 CreatePbuffer(Display * dpy, struct glx_config *config,
461 unsigned int width, unsigned int height,
462 const int *attrib_list, GLboolean size_in_attribs)
464 struct glx_display *priv = __glXInitialize(dpy);
465 GLXDrawable id = 0;
466 CARD32 *data;
467 CARD8 opcode;
468 unsigned int i;
469 Pixmap pixmap;
471 i = 0;
472 if (attrib_list) {
473 while (attrib_list[i * 2])
474 i++;
477 opcode = __glXSetupForCommand(dpy);
478 if (!opcode)
479 return None;
481 LockDisplay(dpy);
482 id = XAllocID(dpy);
484 if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) {
485 xGLXCreatePbufferReq *req;
486 unsigned int extra = (size_in_attribs) ? 0 : 2;
488 GetReqExtra(GLXCreatePbuffer, (8 * (i + extra)), req);
489 data = (CARD32 *) (req + 1);
491 req->reqType = opcode;
492 req->glxCode = X_GLXCreatePbuffer;
493 req->screen = config->screen;
494 req->fbconfig = config->fbconfigID;
495 req->pbuffer = id;
496 req->numAttribs = i + extra;
498 if (!size_in_attribs) {
499 data[(2 * i) + 0] = GLX_PBUFFER_WIDTH;
500 data[(2 * i) + 1] = width;
501 data[(2 * i) + 2] = GLX_PBUFFER_HEIGHT;
502 data[(2 * i) + 3] = height;
503 data += 4;
506 else {
507 xGLXVendorPrivateReq *vpreq;
509 GetReqExtra(GLXVendorPrivate, 20 + (8 * i), vpreq);
510 data = (CARD32 *) (vpreq + 1);
512 vpreq->reqType = opcode;
513 vpreq->glxCode = X_GLXVendorPrivate;
514 vpreq->vendorCode = X_GLXvop_CreateGLXPbufferSGIX;
516 data[0] = config->screen;
517 data[1] = config->fbconfigID;
518 data[2] = id;
519 data[3] = width;
520 data[4] = height;
521 data += 5;
524 (void) memcpy(data, attrib_list, sizeof(CARD32) * 2 * i);
526 UnlockDisplay(dpy);
527 SyncHandle();
529 pixmap = XCreatePixmap(dpy, RootWindow(dpy, config->screen),
530 width, height, config->rgbBits);
532 CreateDRIDrawable(dpy, config, pixmap, id, attrib_list, i);
534 return id;
538 * Destroy a pbuffer.
540 * This function is used to implement \c glXDestroyPbuffer and
541 * \c glXDestroyGLXPbufferSGIX.
543 * \note
544 * This function dynamically determines whether to use the SGIX_pbuffer
545 * version of the protocol or the GLX 1.3 version of the protocol.
547 static void
548 DestroyPbuffer(Display * dpy, GLXDrawable drawable)
550 struct glx_display *priv = __glXInitialize(dpy);
551 CARD8 opcode;
553 if ((dpy == NULL) || (drawable == 0)) {
554 return;
557 opcode = __glXSetupForCommand(dpy);
558 if (!opcode)
559 return;
561 LockDisplay(dpy);
563 if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) {
564 xGLXDestroyPbufferReq *req;
566 GetReq(GLXDestroyPbuffer, req);
567 req->reqType = opcode;
568 req->glxCode = X_GLXDestroyPbuffer;
569 req->pbuffer = (GLXPbuffer) drawable;
571 else {
572 xGLXVendorPrivateWithReplyReq *vpreq;
573 CARD32 *data;
575 GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq);
576 data = (CARD32 *) (vpreq + 1);
578 data[0] = (CARD32) drawable;
580 vpreq->reqType = opcode;
581 vpreq->glxCode = X_GLXVendorPrivateWithReply;
582 vpreq->vendorCode = X_GLXvop_DestroyGLXPbufferSGIX;
585 UnlockDisplay(dpy);
586 SyncHandle();
588 DestroyDRIDrawable(dpy, drawable, GL_TRUE);
590 return;
594 * Create a new pbuffer.
596 _X_EXPORT GLXPbufferSGIX
597 glXCreateGLXPbufferSGIX(Display * dpy, GLXFBConfigSGIX config,
598 unsigned int width, unsigned int height,
599 int *attrib_list)
601 return (GLXPbufferSGIX) CreatePbuffer(dpy, (struct glx_config *) config,
602 width, height,
603 attrib_list, GL_FALSE);
606 #endif /* GLX_USE_APPLEGL */
609 * Create a new pbuffer.
611 _X_EXPORT GLXPbuffer
612 glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int *attrib_list)
614 int i, width, height;
615 #ifdef GLX_USE_APPLEGL
616 GLXPbuffer result;
617 int errorcode;
618 #endif
620 width = 0;
621 height = 0;
623 WARN_ONCE_GLX_1_3(dpy, __func__);
625 #ifdef GLX_USE_APPLEGL
626 for (i = 0; attrib_list[i]; ++i) {
627 switch (attrib_list[i]) {
628 case GLX_PBUFFER_WIDTH:
629 width = attrib_list[i + 1];
630 ++i;
631 break;
633 case GLX_PBUFFER_HEIGHT:
634 height = attrib_list[i + 1];
635 ++i;
636 break;
638 case GLX_LARGEST_PBUFFER:
639 /* This is a hint we should probably handle, but how? */
640 ++i;
641 break;
643 case GLX_PRESERVED_CONTENTS:
644 /* The contents are always preserved with AppleSGLX with CGL. */
645 ++i;
646 break;
648 default:
649 return None;
653 if (apple_glx_pbuffer_create(dpy, config, width, height, &errorcode,
654 &result)) {
656 * apple_glx_pbuffer_create only sets the errorcode to core X11
657 * errors.
659 __glXSendError(dpy, errorcode, 0, X_GLXCreatePbuffer, true);
661 return None;
664 return result;
665 #else
666 for (i = 0; attrib_list[i * 2]; i++) {
667 switch (attrib_list[i * 2]) {
668 case GLX_PBUFFER_WIDTH:
669 width = attrib_list[i * 2 + 1];
670 break;
671 case GLX_PBUFFER_HEIGHT:
672 height = attrib_list[i * 2 + 1];
673 break;
677 return (GLXPbuffer) CreatePbuffer(dpy, (struct glx_config *) config,
678 width, height, attrib_list, GL_TRUE);
679 #endif
684 * Destroy an existing pbuffer.
686 _X_EXPORT void
687 glXDestroyPbuffer(Display * dpy, GLXPbuffer pbuf)
689 #ifdef GLX_USE_APPLEGL
690 if (apple_glx_pbuffer_destroy(dpy, pbuf)) {
691 __glXSendError(dpy, GLXBadPbuffer, pbuf, X_GLXDestroyPbuffer, false);
693 #else
694 DestroyPbuffer(dpy, pbuf);
695 #endif
700 * Query an attribute of a drawable.
702 _X_EXPORT void
703 glXQueryDrawable(Display * dpy, GLXDrawable drawable,
704 int attribute, unsigned int *value)
706 WARN_ONCE_GLX_1_3(dpy, __func__);
707 #ifdef GLX_USE_APPLEGL
708 Window root;
709 int x, y;
710 unsigned int width, height, bd, depth;
712 if (apple_glx_pixmap_query(drawable, attribute, value))
713 return; /*done */
715 if (apple_glx_pbuffer_query(drawable, attribute, value))
716 return; /*done */
719 * The OpenGL spec states that we should report GLXBadDrawable if
720 * the drawable is invalid, however doing so would require that we
721 * use XSetErrorHandler(), which is known to not be thread safe.
722 * If we use a round-trip call to validate the drawable, there could
723 * be a race, so instead we just opt in favor of letting the
724 * XGetGeometry request fail with a GetGeometry request X error
725 * rather than GLXBadDrawable, in what is hoped to be a rare
726 * case of an invalid drawable. In practice most and possibly all
727 * X11 apps using GLX shouldn't notice a difference.
729 if (XGetGeometry
730 (dpy, drawable, &root, &x, &y, &width, &height, &bd, &depth)) {
731 switch (attribute) {
732 case GLX_WIDTH:
733 *value = width;
734 break;
736 case GLX_HEIGHT:
737 *value = height;
738 break;
741 #else
742 GetDrawableAttribute(dpy, drawable, attribute, value);
743 #endif
747 #ifndef GLX_USE_APPLEGL
749 * Query an attribute of a pbuffer.
751 _X_EXPORT int
752 glXQueryGLXPbufferSGIX(Display * dpy, GLXPbufferSGIX drawable,
753 int attribute, unsigned int *value)
755 return GetDrawableAttribute(dpy, drawable, attribute, value);
757 #endif
760 * Select the event mask for a drawable.
762 _X_EXPORT void
763 glXSelectEvent(Display * dpy, GLXDrawable drawable, unsigned long mask)
765 #ifdef GLX_USE_APPLEGL
766 XWindowAttributes xwattr;
768 if (apple_glx_pbuffer_set_event_mask(drawable, mask))
769 return; /*done */
772 * The spec allows a window, but currently there are no valid
773 * events for a window, so do nothing.
775 if (XGetWindowAttributes(dpy, drawable, &xwattr))
776 return; /*done */
777 /* The drawable seems to be invalid. Report an error. */
779 __glXSendError(dpy, GLXBadDrawable, drawable,
780 X_GLXChangeDrawableAttributes, false);
781 #else
782 CARD32 attribs[2];
784 attribs[0] = (CARD32) GLX_EVENT_MASK;
785 attribs[1] = (CARD32) mask;
787 ChangeDrawableAttribute(dpy, drawable, attribs, 1);
788 #endif
793 * Get the selected event mask for a drawable.
795 _X_EXPORT void
796 glXGetSelectedEvent(Display * dpy, GLXDrawable drawable, unsigned long *mask)
798 #ifdef GLX_USE_APPLEGL
799 XWindowAttributes xwattr;
801 if (apple_glx_pbuffer_get_event_mask(drawable, mask))
802 return; /*done */
805 * The spec allows a window, but currently there are no valid
806 * events for a window, so do nothing, but set the mask to 0.
808 if (XGetWindowAttributes(dpy, drawable, &xwattr)) {
809 /* The window is valid, so set the mask to 0. */
810 *mask = 0;
811 return; /*done */
813 /* The drawable seems to be invalid. Report an error. */
815 __glXSendError(dpy, GLXBadDrawable, drawable, X_GLXGetDrawableAttributes,
816 true);
817 #else
818 unsigned int value;
821 /* The non-sense with value is required because on LP64 platforms
822 * sizeof(unsigned int) != sizeof(unsigned long). On little-endian
823 * we could just type-cast the pointer, but why?
826 GetDrawableAttribute(dpy, drawable, GLX_EVENT_MASK_SGIX, &value);
827 *mask = value;
828 #endif
832 _X_EXPORT GLXPixmap
833 glXCreatePixmap(Display * dpy, GLXFBConfig config, Pixmap pixmap,
834 const int *attrib_list)
836 WARN_ONCE_GLX_1_3(dpy, __func__);
838 #ifdef GLX_USE_APPLEGL
839 const struct glx_config *modes = (const __GLcontextModes *) config;
841 if (apple_glx_pixmap_create(dpy, modes->screen, pixmap, modes))
842 return None;
844 return pixmap;
845 #else
846 return CreateDrawable(dpy, (struct glx_config *) config,
847 (Drawable) pixmap, attrib_list, X_GLXCreatePixmap);
848 #endif
852 _X_EXPORT GLXWindow
853 glXCreateWindow(Display * dpy, GLXFBConfig config, Window win,
854 const int *attrib_list)
856 WARN_ONCE_GLX_1_3(dpy, __func__);
857 #ifdef GLX_USE_APPLEGL
858 XWindowAttributes xwattr;
859 XVisualInfo *visinfo;
861 (void) attrib_list; /*unused according to GLX 1.4 */
863 XGetWindowAttributes(dpy, win, &xwattr);
865 visinfo = glXGetVisualFromFBConfig(dpy, config);
867 if (NULL == visinfo) {
868 __glXSendError(dpy, GLXBadFBConfig, 0, X_GLXCreateWindow, false);
869 return None;
872 if (visinfo->visualid != XVisualIDFromVisual(xwattr.visual)) {
873 __glXSendError(dpy, BadMatch, 0, X_GLXCreateWindow, true);
874 return None;
877 XFree(visinfo);
879 return win;
880 #else
881 return CreateDrawable(dpy, (struct glx_config *) config,
882 (Drawable) win, attrib_list, X_GLXCreateWindow);
883 #endif
887 _X_EXPORT void
888 glXDestroyPixmap(Display * dpy, GLXPixmap pixmap)
890 WARN_ONCE_GLX_1_3(dpy, __func__);
891 #ifdef GLX_USE_APPLEGL
892 if (apple_glx_pixmap_destroy(dpy, pixmap))
893 __glXSendError(dpy, GLXBadPixmap, pixmap, X_GLXDestroyPixmap, false);
894 #else
895 DestroyDrawable(dpy, (GLXDrawable) pixmap, X_GLXDestroyPixmap);
896 #endif
900 _X_EXPORT void
901 glXDestroyWindow(Display * dpy, GLXWindow win)
903 WARN_ONCE_GLX_1_3(dpy, __func__);
904 #ifndef GLX_USE_APPLEGL
905 DestroyDrawable(dpy, (GLXDrawable) win, X_GLXDestroyWindow);
906 #endif
909 #ifndef GLX_USE_APPLEGL
910 _X_EXPORT
911 GLX_ALIAS_VOID(glXDestroyGLXPbufferSGIX,
912 (Display * dpy, GLXPbufferSGIX pbuf),
913 (dpy, pbuf), glXDestroyPbuffer)
915 _X_EXPORT
916 GLX_ALIAS_VOID(glXSelectEventSGIX,
917 (Display * dpy, GLXDrawable drawable,
918 unsigned long mask), (dpy, drawable, mask), glXSelectEvent)
920 _X_EXPORT
921 GLX_ALIAS_VOID(glXGetSelectedEventSGIX,
922 (Display * dpy, GLXDrawable drawable,
923 unsigned long *mask), (dpy, drawable, mask),
924 glXGetSelectedEvent)
925 #endif