Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright IBM Corporation 2004 |
| 3 | * All Rights Reserved. |
| 4 | * |
| 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: |
| 11 | * |
| 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. |
| 15 | * |
| 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. |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | * \file glx_pbuffer.c |
| 27 | * Implementation of pbuffer related functions. |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 28 | * |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 29 | * \author Ian Romanick <idr@us.ibm.com> |
| 30 | */ |
| 31 | |
| 32 | #include <inttypes.h> |
| 33 | #include "glxclient.h" |
Brian Paul | 82dfd4b | 2005-08-11 14:18:53 +0000 | [diff] [blame] | 34 | #include <X11/extensions/extutil.h> |
| 35 | #include <X11/extensions/Xext.h> |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 36 | #include <assert.h> |
| 37 | #include <string.h> |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 38 | #include "glxextensions.h" |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 39 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 40 | #ifdef GLX_USE_APPLEGL |
| 41 | #include <pthread.h> |
| 42 | #include "apple_glx_drawable.h" |
| 43 | #include "glx_error.h" |
| 44 | #endif |
| 45 | |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 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 | } \ |
| 52 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 53 | |
| 54 | /** |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 55 | * Emit a warning when clients use GLX 1.3 functions on pre-1.3 systems. |
| 56 | */ |
| 57 | static void |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 58 | warn_GLX_1_3(Display * dpy, const char *function_name) |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 59 | { |
| 60 | __GLXdisplayPrivate *priv = __glXInitialize(dpy); |
| 61 | |
| 62 | if (priv->minorVersion < 3) { |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 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); |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 70 | #ifndef GLX_USE_APPLEGL |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 71 | /** |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 72 | * Change a drawable's attribute. |
| 73 | * |
| 74 | * This function is used to implement \c glXSelectEvent and |
| 75 | * \c glXSelectEventSGIX. |
| 76 | * |
| 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. |
| 80 | * |
| 81 | * \todo |
| 82 | * This function needs to be modified to work with direct-rendering drivers. |
| 83 | */ |
| 84 | static void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 85 | ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable, |
| 86 | const CARD32 * attribs, size_t num_attribs) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 87 | { |
| 88 | __GLXdisplayPrivate *priv = __glXInitialize(dpy); |
Vinson Lee | 5c9e54f | 2010-07-15 00:20:41 -0700 | [diff] [blame] | 89 | __GLXDRIdrawable *pdraw; |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 90 | CARD32 *output; |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 91 | CARD8 opcode; |
Nick Bowler | f8d81c3 | 2010-07-14 12:01:49 -0400 | [diff] [blame] | 92 | int i; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 93 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 94 | if ((dpy == NULL) || (drawable == 0)) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 95 | return; |
| 96 | } |
| 97 | |
Vinson Lee | 5c9e54f | 2010-07-15 00:20:41 -0700 | [diff] [blame] | 98 | pdraw = GetGLXDRIDrawable(dpy, drawable, NULL); |
| 99 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 100 | opcode = __glXSetupForCommand(dpy); |
| 101 | if (!opcode) |
| 102 | return; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 103 | |
| 104 | LockDisplay(dpy); |
| 105 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 106 | if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 107 | xGLXChangeDrawableAttributesReq *req; |
| 108 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 109 | GetReqExtra(GLXChangeDrawableAttributes, 8 + (8 * num_attribs), req); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 110 | output = (CARD32 *) (req + 1); |
| 111 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 112 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 113 | req->glxCode = X_GLXChangeDrawableAttributes; |
| 114 | req->drawable = drawable; |
| 115 | req->numAttribs = (CARD32) num_attribs; |
| 116 | } |
| 117 | else { |
| 118 | xGLXVendorPrivateWithReplyReq *vpreq; |
| 119 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 120 | GetReqExtra(GLXVendorPrivateWithReply, 4 + (8 * num_attribs), vpreq); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 121 | output = (CARD32 *) (vpreq + 1); |
| 122 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 123 | vpreq->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 124 | vpreq->glxCode = X_GLXVendorPrivateWithReply; |
| 125 | vpreq->vendorCode = X_GLXvop_ChangeDrawableAttributesSGIX; |
| 126 | |
| 127 | output[0] = (CARD32) drawable; |
| 128 | output++; |
| 129 | } |
| 130 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 131 | (void) memcpy(output, attribs, sizeof(CARD32) * 2 * num_attribs); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 132 | |
| 133 | UnlockDisplay(dpy); |
| 134 | SyncHandle(); |
| 135 | |
Nick Bowler | f8d81c3 | 2010-07-14 12:01:49 -0400 | [diff] [blame] | 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; |
| 142 | } |
| 143 | } |
| 144 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 145 | return; |
| 146 | } |
| 147 | |
| 148 | |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 149 | #ifdef GLX_DIRECT_RENDERING |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 150 | static GLenum |
| 151 | determineTextureTarget(const int *attribs, int numAttribs) |
| 152 | { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 153 | GLenum target = 0; |
| 154 | int i; |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 155 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 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; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | return target; |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 170 | } |
Eric Anholt | 66175aa | 2009-03-18 12:07:09 -0700 | [diff] [blame] | 171 | |
Eric Anholt | 66175aa | 2009-03-18 12:07:09 -0700 | [diff] [blame] | 172 | static GLenum |
| 173 | determineTextureFormat(const int *attribs, int numAttribs) |
| 174 | { |
Eric Anholt | 66175aa | 2009-03-18 12:07:09 -0700 | [diff] [blame] | 175 | int i; |
| 176 | |
| 177 | for (i = 0; i < numAttribs; i++) { |
| 178 | if (attribs[2 * i] == GLX_TEXTURE_FORMAT_EXT) |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 179 | return attribs[2 * i + 1]; |
Eric Anholt | 66175aa | 2009-03-18 12:07:09 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | return 0; |
| 183 | } |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 184 | |
| 185 | static void |
| 186 | CreateDRIDrawable(Display *dpy, const __GLcontextModes *fbconfig, |
| 187 | XID drawable, XID glxdrawable, |
| 188 | const int *attrib_list, size_t num_attribs) |
| 189 | { |
| 190 | __GLXdisplayPrivate *const priv = __glXInitialize(dpy); |
| 191 | __GLXDRIdrawable *pdraw; |
| 192 | __GLXscreenConfigs *psc; |
| 193 | |
Kristian Høgsberg | f972115 | 2010-07-19 14:57:59 -0400 | [diff] [blame] | 194 | psc = priv->screenConfigs[fbconfig->screen]; |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 195 | if (psc->driScreen == NULL) |
| 196 | return; |
| 197 | |
| 198 | pdraw = psc->driScreen->createDrawable(psc, drawable, |
| 199 | glxdrawable, fbconfig); |
| 200 | if (pdraw == NULL) { |
| 201 | fprintf(stderr, "failed to create drawable\n"); |
| 202 | return; |
| 203 | } |
| 204 | |
Kristian Høgsberg | e3e8196 | 2010-07-19 21:15:50 -0400 | [diff] [blame^] | 205 | if (__glxHashInsert(priv->drawHash, glxdrawable, pdraw)) { |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 206 | (*pdraw->destroyDrawable) (pdraw); |
| 207 | return; /* FIXME: Check what we're supposed to do here... */ |
| 208 | } |
| 209 | |
| 210 | pdraw->textureTarget = determineTextureTarget(attrib_list, num_attribs); |
| 211 | pdraw->textureFormat = determineTextureFormat(attrib_list, num_attribs); |
| 212 | } |
| 213 | |
| 214 | static void |
| 215 | DestroyDRIDrawable(Display *dpy, GLXDrawable drawable, int destroy_xdrawable) |
| 216 | { |
| 217 | int screen; |
| 218 | __GLXdisplayPrivate *const priv = __glXInitialize(dpy); |
| 219 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); |
Kristian Høgsberg | f972115 | 2010-07-19 14:57:59 -0400 | [diff] [blame] | 220 | __GLXscreenConfigs *psc = priv->screenConfigs[screen]; |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 221 | |
| 222 | if (pdraw != NULL) { |
| 223 | if (destroy_xdrawable) |
| 224 | XFreePixmap(psc->dpy, pdraw->xDrawable); |
| 225 | (*pdraw->destroyDrawable) (pdraw); |
Kristian Høgsberg | e3e8196 | 2010-07-19 21:15:50 -0400 | [diff] [blame^] | 226 | __glxHashDelete(priv->drawHash, drawable); |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
| 230 | #else |
| 231 | |
| 232 | static void |
| 233 | CreateDRIDrawable(Display *dpy, const __GLcontextModes * fbconfig, |
| 234 | XID drawable, XID glxdrawable, |
| 235 | const int *attrib_list, size_t num_attribs) |
| 236 | { |
| 237 | } |
| 238 | |
| 239 | static void |
| 240 | DestroyDRIDrawable(Display *dpy, GLXDrawable drawable, int destroy_xdrawable) |
| 241 | { |
| 242 | } |
| 243 | |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 244 | #endif |
| 245 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 246 | /** |
| 247 | * Get a drawable's attribute. |
| 248 | * |
| 249 | * This function is used to implement \c glXGetSelectedEvent and |
| 250 | * \c glXGetSelectedEventSGIX. |
| 251 | * |
| 252 | * \note |
| 253 | * This function dynamically determines whether to use the SGIX_pbuffer |
| 254 | * version of the protocol or the GLX 1.3 version of the protocol. |
| 255 | * |
| 256 | * \todo |
| 257 | * The number of attributes returned is likely to be small, probably less than |
| 258 | * 10. Given that, this routine should try to use an array on the stack to |
| 259 | * capture the reply rather than always calling Xmalloc. |
| 260 | * |
| 261 | * \todo |
| 262 | * This function needs to be modified to work with direct-rendering drivers. |
| 263 | */ |
| 264 | static int |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 265 | GetDrawableAttribute(Display * dpy, GLXDrawable drawable, |
| 266 | int attribute, unsigned int *value) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 267 | { |
Adam Jackson | d25ad50 | 2006-04-07 00:05:50 +0000 | [diff] [blame] | 268 | __GLXdisplayPrivate *priv; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 269 | xGLXGetDrawableAttributesReply reply; |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 270 | CARD32 *data; |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 271 | CARD8 opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 272 | unsigned int length; |
| 273 | unsigned int i; |
| 274 | unsigned int num_attributes; |
Owain G. Ainsworth | b4866f8 | 2009-01-11 20:40:07 +0000 | [diff] [blame] | 275 | GLboolean use_glx_1_3; |
Adam Jackson | d25ad50 | 2006-04-07 00:05:50 +0000 | [diff] [blame] | 276 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 277 | if ((dpy == NULL) || (drawable == 0)) { |
Adam Jackson | d25ad50 | 2006-04-07 00:05:50 +0000 | [diff] [blame] | 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | priv = __glXInitialize(dpy); |
Owain G. Ainsworth | b4866f8 | 2009-01-11 20:40:07 +0000 | [diff] [blame] | 282 | use_glx_1_3 = ((priv->majorVersion > 1) || (priv->minorVersion >= 3)); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 283 | |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 284 | *value = 0; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 285 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 286 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 287 | opcode = __glXSetupForCommand(dpy); |
| 288 | if (!opcode) |
| 289 | return 0; |
| 290 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 291 | LockDisplay(dpy); |
| 292 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 293 | if (use_glx_1_3) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 294 | xGLXGetDrawableAttributesReq *req; |
| 295 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 296 | GetReqExtra(GLXGetDrawableAttributes, 4, req); |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 297 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 298 | req->glxCode = X_GLXGetDrawableAttributes; |
| 299 | req->drawable = drawable; |
| 300 | } |
| 301 | else { |
| 302 | xGLXVendorPrivateWithReplyReq *vpreq; |
| 303 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 304 | GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 305 | data = (CARD32 *) (vpreq + 1); |
| 306 | data[0] = (CARD32) drawable; |
| 307 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 308 | vpreq->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 309 | vpreq->glxCode = X_GLXVendorPrivateWithReply; |
| 310 | vpreq->vendorCode = X_GLXvop_GetDrawableAttributesSGIX; |
| 311 | } |
| 312 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 313 | _XReply(dpy, (xReply *) & reply, 0, False); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 314 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 315 | if (reply.type == X_Error) { |
| 316 | UnlockDisplay(dpy); |
| 317 | SyncHandle(); |
| 318 | return 0; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 321 | length = reply.length; |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 322 | if (length) { |
| 323 | num_attributes = (use_glx_1_3) ? reply.numAttribs : length / 2; |
| 324 | data = (CARD32 *) Xmalloc(length * sizeof(CARD32)); |
| 325 | if (data == NULL) { |
| 326 | /* Throw data on the floor */ |
| 327 | _XEatData(dpy, length); |
| 328 | } |
| 329 | else { |
| 330 | _XRead(dpy, (char *) data, length * sizeof(CARD32)); |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 331 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 332 | /* Search the set of returned attributes for the attribute requested by |
| 333 | * the caller. |
| 334 | */ |
| 335 | for (i = 0; i < num_attributes; i++) { |
| 336 | if (data[i * 2] == attribute) { |
| 337 | *value = data[(i * 2) + 1]; |
| 338 | break; |
| 339 | } |
| 340 | } |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 341 | |
Jeremy Huddleston | 80b280d | 2010-04-02 01:35:19 -0700 | [diff] [blame] | 342 | #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 343 | { |
| 344 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL); |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 345 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 346 | if (pdraw != NULL && !pdraw->textureTarget) |
| 347 | pdraw->textureTarget = |
| 348 | determineTextureTarget((const int *) data, num_attributes); |
Eric Anholt | 66175aa | 2009-03-18 12:07:09 -0700 | [diff] [blame] | 349 | if (pdraw != NULL && !pdraw->textureFormat) |
| 350 | pdraw->textureFormat = |
| 351 | determineTextureFormat((const int *) data, num_attributes); |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 352 | } |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 353 | #endif |
| 354 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 355 | Xfree(data); |
| 356 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | UnlockDisplay(dpy); |
| 360 | SyncHandle(); |
| 361 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 362 | return 0; |
| 363 | } |
| 364 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 365 | /** |
| 366 | * Create a non-pbuffer GLX drawable. |
| 367 | * |
| 368 | * \todo |
| 369 | * This function needs to be modified to work with direct-rendering drivers. |
| 370 | */ |
| 371 | static GLXDrawable |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 372 | CreateDrawable(Display * dpy, const __GLcontextModes * fbconfig, |
| 373 | Drawable drawable, const int *attrib_list, CARD8 glxCode) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 374 | { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 375 | xGLXCreateWindowReq *req; |
| 376 | CARD32 *data; |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 377 | unsigned int i; |
David Reveman | 342d1de | 2006-04-11 12:07:41 +0000 | [diff] [blame] | 378 | CARD8 opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 379 | |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 380 | i = 0; |
| 381 | if (attrib_list) { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 382 | while (attrib_list[i * 2] != None) |
| 383 | i++; |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 384 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 385 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 386 | opcode = __glXSetupForCommand(dpy); |
| 387 | if (!opcode) |
| 388 | return None; |
David Reveman | 342d1de | 2006-04-11 12:07:41 +0000 | [diff] [blame] | 389 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 390 | LockDisplay(dpy); |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 391 | GetReqExtra(GLXCreateWindow, 8 * i, req); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 392 | data = (CARD32 *) (req + 1); |
| 393 | |
David Reveman | 342d1de | 2006-04-11 12:07:41 +0000 | [diff] [blame] | 394 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 395 | req->glxCode = glxCode; |
| 396 | req->screen = (CARD32) fbconfig->screen; |
| 397 | req->fbconfig = fbconfig->fbconfigID; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 398 | req->window = (CARD32) drawable; |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 399 | req->glxwindow = (GLXWindow) XAllocID(dpy); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 400 | req->numAttribs = (CARD32) i; |
| 401 | |
Brian Paul | 5f40a7a | 2010-03-02 07:34:29 -0700 | [diff] [blame] | 402 | if (attrib_list) |
| 403 | memcpy(data, attrib_list, 8 * i); |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 404 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 405 | UnlockDisplay(dpy); |
| 406 | SyncHandle(); |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 407 | |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 408 | CreateDRIDrawable(dpy, fbconfig, drawable, req->glxwindow, attrib_list, i); |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 409 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 410 | return (GLXDrawable) req->glxwindow; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | |
| 414 | /** |
| 415 | * Destroy a non-pbuffer GLX drawable. |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 416 | */ |
| 417 | static void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 418 | DestroyDrawable(Display * dpy, GLXDrawable drawable, CARD32 glxCode) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 419 | { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 420 | xGLXDestroyPbufferReq *req; |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 421 | CARD8 opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 422 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 423 | if ((dpy == NULL) || (drawable == 0)) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 424 | return; |
| 425 | } |
| 426 | |
| 427 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 428 | opcode = __glXSetupForCommand(dpy); |
| 429 | if (!opcode) |
| 430 | return; |
| 431 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 432 | LockDisplay(dpy); |
| 433 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 434 | GetReqExtra(GLXDestroyPbuffer, 4, req); |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 435 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 436 | req->glxCode = glxCode; |
| 437 | req->pbuffer = (GLXPbuffer) drawable; |
| 438 | |
| 439 | UnlockDisplay(dpy); |
| 440 | SyncHandle(); |
| 441 | |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 442 | DestroyDRIDrawable(dpy, drawable, GL_FALSE); |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 443 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 444 | return; |
| 445 | } |
| 446 | |
| 447 | |
| 448 | /** |
| 449 | * Create a pbuffer. |
| 450 | * |
| 451 | * This function is used to implement \c glXCreatePbuffer and |
| 452 | * \c glXCreateGLXPbufferSGIX. |
| 453 | * |
| 454 | * \note |
| 455 | * This function dynamically determines whether to use the SGIX_pbuffer |
| 456 | * version of the protocol or the GLX 1.3 version of the protocol. |
| 457 | * |
| 458 | * \todo |
| 459 | * This function needs to be modified to work with direct-rendering drivers. |
| 460 | */ |
| 461 | static GLXDrawable |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 462 | CreatePbuffer(Display * dpy, const __GLcontextModes * fbconfig, |
| 463 | unsigned int width, unsigned int height, |
| 464 | const int *attrib_list, GLboolean size_in_attribs) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 465 | { |
| 466 | __GLXdisplayPrivate *priv = __glXInitialize(dpy); |
| 467 | GLXDrawable id = 0; |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 468 | CARD32 *data; |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 469 | CARD8 opcode; |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 470 | unsigned int i; |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 471 | Pixmap pixmap; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 472 | |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 473 | i = 0; |
| 474 | if (attrib_list) { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 475 | while (attrib_list[i * 2]) |
| 476 | i++; |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 477 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 478 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 479 | opcode = __glXSetupForCommand(dpy); |
| 480 | if (!opcode) |
| 481 | return None; |
| 482 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 483 | LockDisplay(dpy); |
| 484 | id = XAllocID(dpy); |
| 485 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 486 | if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) { |
| 487 | xGLXCreatePbufferReq *req; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 488 | unsigned int extra = (size_in_attribs) ? 0 : 2; |
| 489 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 490 | GetReqExtra(GLXCreatePbuffer, (8 * (i + extra)), req); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 491 | data = (CARD32 *) (req + 1); |
| 492 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 493 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 494 | req->glxCode = X_GLXCreatePbuffer; |
| 495 | req->screen = (CARD32) fbconfig->screen; |
| 496 | req->fbconfig = fbconfig->fbconfigID; |
| 497 | req->pbuffer = (GLXPbuffer) id; |
| 498 | req->numAttribs = (CARD32) (i + extra); |
| 499 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 500 | if (!size_in_attribs) { |
| 501 | data[(2 * i) + 0] = GLX_PBUFFER_WIDTH; |
| 502 | data[(2 * i) + 1] = width; |
| 503 | data[(2 * i) + 2] = GLX_PBUFFER_HEIGHT; |
| 504 | data[(2 * i) + 3] = height; |
| 505 | data += 4; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | else { |
| 509 | xGLXVendorPrivateReq *vpreq; |
| 510 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 511 | GetReqExtra(GLXVendorPrivate, 20 + (8 * i), vpreq); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 512 | data = (CARD32 *) (vpreq + 1); |
| 513 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 514 | vpreq->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 515 | vpreq->glxCode = X_GLXVendorPrivate; |
| 516 | vpreq->vendorCode = X_GLXvop_CreateGLXPbufferSGIX; |
| 517 | |
| 518 | data[0] = (CARD32) fbconfig->screen; |
| 519 | data[1] = (CARD32) fbconfig->fbconfigID; |
| 520 | data[2] = (CARD32) id; |
| 521 | data[3] = (CARD32) width; |
| 522 | data[4] = (CARD32) height; |
| 523 | data += 5; |
| 524 | } |
| 525 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 526 | (void) memcpy(data, attrib_list, sizeof(CARD32) * 2 * i); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 527 | |
| 528 | UnlockDisplay(dpy); |
| 529 | SyncHandle(); |
| 530 | |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 531 | pixmap = XCreatePixmap(dpy, RootWindow(dpy, fbconfig->screen), |
| 532 | width, height, fbconfig->rgbBits); |
| 533 | |
| 534 | CreateDRIDrawable(dpy, fbconfig, pixmap, id, attrib_list, i); |
| 535 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 536 | return id; |
| 537 | } |
| 538 | |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 539 | /** |
| 540 | * Destroy a pbuffer. |
| 541 | * |
| 542 | * This function is used to implement \c glXDestroyPbuffer and |
| 543 | * \c glXDestroyGLXPbufferSGIX. |
| 544 | * |
| 545 | * \note |
| 546 | * This function dynamically determines whether to use the SGIX_pbuffer |
| 547 | * version of the protocol or the GLX 1.3 version of the protocol. |
| 548 | */ |
| 549 | static void |
| 550 | DestroyPbuffer(Display * dpy, GLXDrawable drawable) |
| 551 | { |
| 552 | __GLXdisplayPrivate *priv = __glXInitialize(dpy); |
| 553 | CARD8 opcode; |
| 554 | |
| 555 | if ((dpy == NULL) || (drawable == 0)) { |
| 556 | return; |
| 557 | } |
| 558 | |
| 559 | opcode = __glXSetupForCommand(dpy); |
| 560 | if (!opcode) |
| 561 | return; |
| 562 | |
| 563 | LockDisplay(dpy); |
| 564 | |
| 565 | if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) { |
| 566 | xGLXDestroyPbufferReq *req; |
| 567 | |
| 568 | GetReq(GLXDestroyPbuffer, req); |
| 569 | req->reqType = opcode; |
| 570 | req->glxCode = X_GLXDestroyPbuffer; |
| 571 | req->pbuffer = (GLXPbuffer) drawable; |
| 572 | } |
| 573 | else { |
| 574 | xGLXVendorPrivateWithReplyReq *vpreq; |
| 575 | CARD32 *data; |
| 576 | |
| 577 | GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq); |
| 578 | data = (CARD32 *) (vpreq + 1); |
| 579 | |
| 580 | data[0] = (CARD32) drawable; |
| 581 | |
| 582 | vpreq->reqType = opcode; |
| 583 | vpreq->glxCode = X_GLXVendorPrivateWithReply; |
| 584 | vpreq->vendorCode = X_GLXvop_DestroyGLXPbufferSGIX; |
| 585 | } |
| 586 | |
| 587 | UnlockDisplay(dpy); |
| 588 | SyncHandle(); |
| 589 | |
| 590 | DestroyDRIDrawable(dpy, drawable, GL_TRUE); |
| 591 | |
| 592 | return; |
| 593 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 594 | |
| 595 | /** |
| 596 | * Create a new pbuffer. |
| 597 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 598 | PUBLIC GLXPbufferSGIX |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 599 | glXCreateGLXPbufferSGIX(Display * dpy, GLXFBConfigSGIX config, |
| 600 | unsigned int width, unsigned int height, |
| 601 | int *attrib_list) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 602 | { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 603 | return (GLXPbufferSGIX) CreatePbuffer(dpy, (__GLcontextModes *) config, |
| 604 | width, height, |
| 605 | attrib_list, GL_FALSE); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 608 | #endif /* GLX_USE_APPLEGL */ |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 609 | |
| 610 | /** |
| 611 | * Create a new pbuffer. |
| 612 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 613 | PUBLIC GLXPbuffer |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 614 | glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int *attrib_list) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 615 | { |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame] | 616 | int i, width, height; |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 617 | #ifdef GLX_USE_APPLEGL |
| 618 | GLXPbuffer result; |
| 619 | int errorcode; |
| 620 | #endif |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame] | 621 | |
| 622 | width = 0; |
| 623 | height = 0; |
| 624 | |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 625 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 626 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 627 | #ifdef GLX_USE_APPLEGL |
| 628 | for (i = 0; attrib_list[i]; ++i) { |
| 629 | switch (attrib_list[i]) { |
| 630 | case GLX_PBUFFER_WIDTH: |
| 631 | width = attrib_list[i + 1]; |
| 632 | ++i; |
| 633 | break; |
| 634 | |
| 635 | case GLX_PBUFFER_HEIGHT: |
| 636 | height = attrib_list[i + 1]; |
| 637 | ++i; |
| 638 | break; |
| 639 | |
| 640 | case GLX_LARGEST_PBUFFER: |
| 641 | /* This is a hint we should probably handle, but how? */ |
| 642 | ++i; |
| 643 | break; |
| 644 | |
| 645 | case GLX_PRESERVED_CONTENTS: |
| 646 | /* The contents are always preserved with AppleSGLX with CGL. */ |
| 647 | ++i; |
| 648 | break; |
| 649 | |
| 650 | default: |
| 651 | return None; |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | if (apple_glx_pbuffer_create(dpy, config, width, height, &errorcode, |
| 656 | &result)) { |
| 657 | /* |
| 658 | * apple_glx_pbuffer_create only sets the errorcode to core X11 |
| 659 | * errors. |
| 660 | */ |
| 661 | __glXSendError(dpy, errorcode, 0, X_GLXCreatePbuffer, true); |
| 662 | |
| 663 | return None; |
| 664 | } |
| 665 | |
| 666 | return result; |
| 667 | #else |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame] | 668 | for (i = 0; attrib_list[i * 2]; i++) { |
| 669 | switch (attrib_list[i * 2]) { |
| 670 | case GLX_PBUFFER_WIDTH: |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 671 | width = attrib_list[i * 2 + 1]; |
| 672 | break; |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame] | 673 | case GLX_PBUFFER_HEIGHT: |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 674 | height = attrib_list[i * 2 + 1]; |
| 675 | break; |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 679 | return (GLXPbuffer) CreatePbuffer(dpy, (__GLcontextModes *) config, |
| 680 | width, height, attrib_list, GL_TRUE); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 681 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | |
| 685 | /** |
| 686 | * Destroy an existing pbuffer. |
| 687 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 688 | PUBLIC void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 689 | glXDestroyPbuffer(Display * dpy, GLXPbuffer pbuf) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 690 | { |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 691 | #ifdef GLX_USE_APPLEGL |
| 692 | if (apple_glx_pbuffer_destroy(dpy, pbuf)) { |
| 693 | __glXSendError(dpy, GLXBadPbuffer, pbuf, X_GLXDestroyPbuffer, false); |
| 694 | } |
| 695 | #else |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 696 | DestroyPbuffer(dpy, pbuf); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 697 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | |
| 701 | /** |
| 702 | * Query an attribute of a drawable. |
| 703 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 704 | PUBLIC void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 705 | glXQueryDrawable(Display * dpy, GLXDrawable drawable, |
| 706 | int attribute, unsigned int *value) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 707 | { |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 708 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 709 | #ifdef GLX_USE_APPLEGL |
| 710 | Window root; |
| 711 | int x, y; |
| 712 | unsigned int width, height, bd, depth; |
| 713 | |
| 714 | if (apple_glx_pixmap_query(drawable, attribute, value)) |
| 715 | return; /*done */ |
| 716 | |
| 717 | if (apple_glx_pbuffer_query(drawable, attribute, value)) |
| 718 | return; /*done */ |
| 719 | |
| 720 | /* |
| 721 | * The OpenGL spec states that we should report GLXBadDrawable if |
| 722 | * the drawable is invalid, however doing so would require that we |
| 723 | * use XSetErrorHandler(), which is known to not be thread safe. |
| 724 | * If we use a round-trip call to validate the drawable, there could |
| 725 | * be a race, so instead we just opt in favor of letting the |
| 726 | * XGetGeometry request fail with a GetGeometry request X error |
| 727 | * rather than GLXBadDrawable, in what is hoped to be a rare |
| 728 | * case of an invalid drawable. In practice most and possibly all |
| 729 | * X11 apps using GLX shouldn't notice a difference. |
| 730 | */ |
| 731 | if (XGetGeometry |
| 732 | (dpy, drawable, &root, &x, &y, &width, &height, &bd, &depth)) { |
| 733 | switch (attribute) { |
| 734 | case GLX_WIDTH: |
| 735 | *value = width; |
| 736 | break; |
| 737 | |
| 738 | case GLX_HEIGHT: |
| 739 | *value = height; |
| 740 | break; |
| 741 | } |
| 742 | } |
| 743 | #else |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 744 | GetDrawableAttribute(dpy, drawable, attribute, value); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 745 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 749 | #ifndef GLX_USE_APPLEGL |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 750 | /** |
| 751 | * Query an attribute of a pbuffer. |
| 752 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 753 | PUBLIC int |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 754 | glXQueryGLXPbufferSGIX(Display * dpy, GLXPbufferSGIX drawable, |
| 755 | int attribute, unsigned int *value) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 756 | { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 757 | return GetDrawableAttribute(dpy, drawable, attribute, value); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 758 | } |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 759 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 760 | |
| 761 | /** |
| 762 | * Select the event mask for a drawable. |
| 763 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 764 | PUBLIC void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 765 | glXSelectEvent(Display * dpy, GLXDrawable drawable, unsigned long mask) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 766 | { |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 767 | #ifdef GLX_USE_APPLEGL |
| 768 | XWindowAttributes xwattr; |
| 769 | |
| 770 | if (apple_glx_pbuffer_set_event_mask(drawable, mask)) |
| 771 | return; /*done */ |
| 772 | |
| 773 | /* |
| 774 | * The spec allows a window, but currently there are no valid |
| 775 | * events for a window, so do nothing. |
| 776 | */ |
| 777 | if (XGetWindowAttributes(dpy, drawable, &xwattr)) |
| 778 | return; /*done */ |
| 779 | /* The drawable seems to be invalid. Report an error. */ |
| 780 | |
| 781 | __glXSendError(dpy, GLXBadDrawable, drawable, |
| 782 | X_GLXChangeDrawableAttributes, false); |
| 783 | #else |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 784 | CARD32 attribs[2]; |
| 785 | |
| 786 | attribs[0] = (CARD32) GLX_EVENT_MASK; |
| 787 | attribs[1] = (CARD32) mask; |
| 788 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 789 | ChangeDrawableAttribute(dpy, drawable, attribs, 1); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 790 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | |
| 794 | /** |
| 795 | * Get the selected event mask for a drawable. |
| 796 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 797 | PUBLIC void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 798 | glXGetSelectedEvent(Display * dpy, GLXDrawable drawable, unsigned long *mask) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 799 | { |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 800 | #ifdef GLX_USE_APPLEGL |
| 801 | XWindowAttributes xwattr; |
| 802 | |
| 803 | if (apple_glx_pbuffer_get_event_mask(drawable, mask)) |
| 804 | return; /*done */ |
| 805 | |
| 806 | /* |
| 807 | * The spec allows a window, but currently there are no valid |
| 808 | * events for a window, so do nothing, but set the mask to 0. |
| 809 | */ |
| 810 | if (XGetWindowAttributes(dpy, drawable, &xwattr)) { |
| 811 | /* The window is valid, so set the mask to 0. */ |
| 812 | *mask = 0; |
| 813 | return; /*done */ |
| 814 | } |
| 815 | /* The drawable seems to be invalid. Report an error. */ |
| 816 | |
| 817 | __glXSendError(dpy, GLXBadDrawable, drawable, X_GLXGetDrawableAttributes, |
| 818 | true); |
| 819 | #else |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 820 | unsigned int value; |
| 821 | |
| 822 | |
| 823 | /* The non-sense with value is required because on LP64 platforms |
| 824 | * sizeof(unsigned int) != sizeof(unsigned long). On little-endian |
| 825 | * we could just type-cast the pointer, but why? |
| 826 | */ |
| 827 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 828 | GetDrawableAttribute(dpy, drawable, GLX_EVENT_MASK_SGIX, &value); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 829 | *mask = value; |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 830 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 834 | PUBLIC GLXPixmap |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 835 | glXCreatePixmap(Display * dpy, GLXFBConfig config, Pixmap pixmap, |
| 836 | const int *attrib_list) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 837 | { |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 838 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 839 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 840 | #ifdef GLX_USE_APPLEGL |
| 841 | const __GLcontextModes *modes = (const __GLcontextModes *) config; |
| 842 | |
| 843 | if (apple_glx_pixmap_create(dpy, modes->screen, pixmap, modes)) |
| 844 | return None; |
| 845 | |
| 846 | return pixmap; |
| 847 | #else |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 848 | return CreateDrawable(dpy, (__GLcontextModes *) config, |
| 849 | (Drawable) pixmap, attrib_list, X_GLXCreatePixmap); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 850 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 854 | PUBLIC GLXWindow |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 855 | glXCreateWindow(Display * dpy, GLXFBConfig config, Window win, |
| 856 | const int *attrib_list) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 857 | { |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 858 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 859 | #ifdef GLX_USE_APPLEGL |
| 860 | XWindowAttributes xwattr; |
| 861 | XVisualInfo *visinfo; |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 862 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 863 | (void) attrib_list; /*unused according to GLX 1.4 */ |
| 864 | |
| 865 | XGetWindowAttributes(dpy, win, &xwattr); |
| 866 | |
| 867 | visinfo = glXGetVisualFromFBConfig(dpy, config); |
| 868 | |
| 869 | if (NULL == visinfo) { |
| 870 | __glXSendError(dpy, GLXBadFBConfig, 0, X_GLXCreateWindow, false); |
| 871 | return None; |
| 872 | } |
| 873 | |
| 874 | if (visinfo->visualid != XVisualIDFromVisual(xwattr.visual)) { |
| 875 | __glXSendError(dpy, BadMatch, 0, X_GLXCreateWindow, true); |
| 876 | return None; |
| 877 | } |
| 878 | |
| 879 | XFree(visinfo); |
| 880 | |
| 881 | return win; |
| 882 | #else |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 883 | return CreateDrawable(dpy, (__GLcontextModes *) config, |
| 884 | (Drawable) win, attrib_list, X_GLXCreateWindow); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 885 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 889 | PUBLIC void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 890 | glXDestroyPixmap(Display * dpy, GLXPixmap pixmap) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 891 | { |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 892 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 893 | #ifdef GLX_USE_APPLEGL |
| 894 | if (apple_glx_pixmap_destroy(dpy, pixmap)) |
| 895 | __glXSendError(dpy, GLXBadPixmap, pixmap, X_GLXDestroyPixmap, false); |
| 896 | #else |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 897 | DestroyDrawable(dpy, (GLXDrawable) pixmap, X_GLXDestroyPixmap); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 898 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 902 | PUBLIC void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 903 | glXDestroyWindow(Display * dpy, GLXWindow win) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 904 | { |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 905 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 906 | #ifndef GLX_USE_APPLEGL |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 907 | DestroyDrawable(dpy, (GLXDrawable) win, X_GLXDestroyWindow); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 908 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 909 | } |
| 910 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 911 | #ifndef GLX_USE_APPLEGL |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 912 | PUBLIC |
| 913 | GLX_ALIAS_VOID(glXDestroyGLXPbufferSGIX, |
| 914 | (Display * dpy, GLXPbufferSGIX pbuf), |
| 915 | (dpy, pbuf), glXDestroyPbuffer) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 916 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 917 | PUBLIC |
| 918 | GLX_ALIAS_VOID(glXSelectEventSGIX, |
| 919 | (Display * dpy, GLXDrawable drawable, |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 920 | unsigned long mask), (dpy, drawable, mask), glXSelectEvent) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 921 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 922 | PUBLIC |
| 923 | GLX_ALIAS_VOID(glXGetSelectedEventSGIX, |
| 924 | (Display * dpy, GLXDrawable drawable, |
| 925 | unsigned long *mask), (dpy, drawable, mask), |
| 926 | glXGetSelectedEvent) |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 927 | #endif |