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 | |
Kristian Høgsberg | eeaab20 | 2010-07-22 22:36:37 -0400 | [diff] [blame^] | 98 | pdraw = GetGLXDRIDrawable(dpy, drawable); |
Vinson Lee | 5c9e54f | 2010-07-15 00:20:41 -0700 | [diff] [blame] | 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 | { |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 217 | __GLXdisplayPrivate *const priv = __glXInitialize(dpy); |
Kristian Høgsberg | eeaab20 | 2010-07-22 22:36:37 -0400 | [diff] [blame^] | 218 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable); |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 219 | |
| 220 | if (pdraw != NULL) { |
| 221 | if (destroy_xdrawable) |
Kristian Høgsberg | eeaab20 | 2010-07-22 22:36:37 -0400 | [diff] [blame^] | 222 | XFreePixmap(pdraw->psc->dpy, pdraw->xDrawable); |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 223 | (*pdraw->destroyDrawable) (pdraw); |
Kristian Høgsberg | e3e8196 | 2010-07-19 21:15:50 -0400 | [diff] [blame] | 224 | __glxHashDelete(priv->drawHash, drawable); |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
| 228 | #else |
| 229 | |
| 230 | static void |
| 231 | CreateDRIDrawable(Display *dpy, const __GLcontextModes * fbconfig, |
| 232 | XID drawable, XID glxdrawable, |
| 233 | const int *attrib_list, size_t num_attribs) |
| 234 | { |
| 235 | } |
| 236 | |
| 237 | static void |
| 238 | DestroyDRIDrawable(Display *dpy, GLXDrawable drawable, int destroy_xdrawable) |
| 239 | { |
| 240 | } |
| 241 | |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 242 | #endif |
| 243 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 244 | /** |
| 245 | * Get a drawable's attribute. |
| 246 | * |
| 247 | * This function is used to implement \c glXGetSelectedEvent and |
| 248 | * \c glXGetSelectedEventSGIX. |
| 249 | * |
| 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. |
| 253 | * |
| 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. |
| 258 | * |
| 259 | * \todo |
| 260 | * This function needs to be modified to work with direct-rendering drivers. |
| 261 | */ |
| 262 | static int |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 263 | GetDrawableAttribute(Display * dpy, GLXDrawable drawable, |
| 264 | int attribute, unsigned int *value) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 265 | { |
Adam Jackson | d25ad50 | 2006-04-07 00:05:50 +0000 | [diff] [blame] | 266 | __GLXdisplayPrivate *priv; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 267 | xGLXGetDrawableAttributesReply reply; |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 268 | CARD32 *data; |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 269 | CARD8 opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 270 | unsigned int length; |
| 271 | unsigned int i; |
| 272 | unsigned int num_attributes; |
Owain G. Ainsworth | b4866f8 | 2009-01-11 20:40:07 +0000 | [diff] [blame] | 273 | GLboolean use_glx_1_3; |
Adam Jackson | d25ad50 | 2006-04-07 00:05:50 +0000 | [diff] [blame] | 274 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 275 | if ((dpy == NULL) || (drawable == 0)) { |
Adam Jackson | d25ad50 | 2006-04-07 00:05:50 +0000 | [diff] [blame] | 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | priv = __glXInitialize(dpy); |
Owain G. Ainsworth | b4866f8 | 2009-01-11 20:40:07 +0000 | [diff] [blame] | 280 | use_glx_1_3 = ((priv->majorVersion > 1) || (priv->minorVersion >= 3)); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 281 | |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 282 | *value = 0; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 283 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 284 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 285 | opcode = __glXSetupForCommand(dpy); |
| 286 | if (!opcode) |
| 287 | return 0; |
| 288 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 289 | LockDisplay(dpy); |
| 290 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 291 | if (use_glx_1_3) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 292 | xGLXGetDrawableAttributesReq *req; |
| 293 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 294 | GetReqExtra(GLXGetDrawableAttributes, 4, req); |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 295 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 296 | req->glxCode = X_GLXGetDrawableAttributes; |
| 297 | req->drawable = drawable; |
| 298 | } |
| 299 | else { |
| 300 | xGLXVendorPrivateWithReplyReq *vpreq; |
| 301 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 302 | GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 303 | data = (CARD32 *) (vpreq + 1); |
| 304 | data[0] = (CARD32) drawable; |
| 305 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 306 | vpreq->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 307 | vpreq->glxCode = X_GLXVendorPrivateWithReply; |
| 308 | vpreq->vendorCode = X_GLXvop_GetDrawableAttributesSGIX; |
| 309 | } |
| 310 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 311 | _XReply(dpy, (xReply *) & reply, 0, False); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 312 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 313 | if (reply.type == X_Error) { |
| 314 | UnlockDisplay(dpy); |
| 315 | SyncHandle(); |
| 316 | return 0; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 319 | length = reply.length; |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 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); |
| 326 | } |
| 327 | else { |
| 328 | _XRead(dpy, (char *) data, length * sizeof(CARD32)); |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 329 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 330 | /* Search the set of returned attributes for the attribute requested by |
| 331 | * the caller. |
| 332 | */ |
| 333 | for (i = 0; i < num_attributes; i++) { |
| 334 | if (data[i * 2] == attribute) { |
| 335 | *value = data[(i * 2) + 1]; |
| 336 | break; |
| 337 | } |
| 338 | } |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 339 | |
Jeremy Huddleston | 80b280d | 2010-04-02 01:35:19 -0700 | [diff] [blame] | 340 | #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 341 | { |
Kristian Høgsberg | eeaab20 | 2010-07-22 22:36:37 -0400 | [diff] [blame^] | 342 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable); |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 343 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 344 | if (pdraw != NULL && !pdraw->textureTarget) |
| 345 | pdraw->textureTarget = |
| 346 | determineTextureTarget((const int *) data, num_attributes); |
Eric Anholt | 66175aa | 2009-03-18 12:07:09 -0700 | [diff] [blame] | 347 | if (pdraw != NULL && !pdraw->textureFormat) |
| 348 | pdraw->textureFormat = |
| 349 | determineTextureFormat((const int *) data, num_attributes); |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 350 | } |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 351 | #endif |
| 352 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 353 | Xfree(data); |
| 354 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | UnlockDisplay(dpy); |
| 358 | SyncHandle(); |
| 359 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 360 | return 0; |
| 361 | } |
| 362 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 363 | /** |
| 364 | * Create a non-pbuffer GLX drawable. |
| 365 | * |
| 366 | * \todo |
| 367 | * This function needs to be modified to work with direct-rendering drivers. |
| 368 | */ |
| 369 | static GLXDrawable |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 370 | CreateDrawable(Display * dpy, const __GLcontextModes * fbconfig, |
| 371 | Drawable drawable, const int *attrib_list, CARD8 glxCode) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 372 | { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 373 | xGLXCreateWindowReq *req; |
| 374 | CARD32 *data; |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 375 | unsigned int i; |
David Reveman | 342d1de | 2006-04-11 12:07:41 +0000 | [diff] [blame] | 376 | CARD8 opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 377 | |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 378 | i = 0; |
| 379 | if (attrib_list) { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 380 | while (attrib_list[i * 2] != None) |
| 381 | i++; |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 382 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 383 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 384 | opcode = __glXSetupForCommand(dpy); |
| 385 | if (!opcode) |
| 386 | return None; |
David Reveman | 342d1de | 2006-04-11 12:07:41 +0000 | [diff] [blame] | 387 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 388 | LockDisplay(dpy); |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 389 | GetReqExtra(GLXCreateWindow, 8 * i, req); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 390 | data = (CARD32 *) (req + 1); |
| 391 | |
David Reveman | 342d1de | 2006-04-11 12:07:41 +0000 | [diff] [blame] | 392 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 393 | req->glxCode = glxCode; |
| 394 | req->screen = (CARD32) fbconfig->screen; |
| 395 | req->fbconfig = fbconfig->fbconfigID; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 396 | req->window = (CARD32) drawable; |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 397 | req->glxwindow = (GLXWindow) XAllocID(dpy); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 398 | req->numAttribs = (CARD32) i; |
| 399 | |
Brian Paul | 5f40a7a | 2010-03-02 07:34:29 -0700 | [diff] [blame] | 400 | if (attrib_list) |
| 401 | memcpy(data, attrib_list, 8 * i); |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 402 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 403 | UnlockDisplay(dpy); |
| 404 | SyncHandle(); |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 405 | |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 406 | CreateDRIDrawable(dpy, fbconfig, drawable, req->glxwindow, attrib_list, i); |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 407 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 408 | return (GLXDrawable) req->glxwindow; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | |
| 412 | /** |
| 413 | * Destroy a non-pbuffer GLX drawable. |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 414 | */ |
| 415 | static void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 416 | DestroyDrawable(Display * dpy, GLXDrawable drawable, CARD32 glxCode) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 417 | { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 418 | xGLXDestroyPbufferReq *req; |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 419 | CARD8 opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 420 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 421 | if ((dpy == NULL) || (drawable == 0)) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 422 | return; |
| 423 | } |
| 424 | |
| 425 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 426 | opcode = __glXSetupForCommand(dpy); |
| 427 | if (!opcode) |
| 428 | return; |
| 429 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 430 | LockDisplay(dpy); |
| 431 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 432 | GetReqExtra(GLXDestroyPbuffer, 4, req); |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 433 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 434 | req->glxCode = glxCode; |
| 435 | req->pbuffer = (GLXPbuffer) drawable; |
| 436 | |
| 437 | UnlockDisplay(dpy); |
| 438 | SyncHandle(); |
| 439 | |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 440 | DestroyDRIDrawable(dpy, drawable, GL_FALSE); |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 441 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 442 | return; |
| 443 | } |
| 444 | |
| 445 | |
| 446 | /** |
| 447 | * Create a pbuffer. |
| 448 | * |
| 449 | * This function is used to implement \c glXCreatePbuffer and |
| 450 | * \c glXCreateGLXPbufferSGIX. |
| 451 | * |
| 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. |
| 455 | * |
| 456 | * \todo |
| 457 | * This function needs to be modified to work with direct-rendering drivers. |
| 458 | */ |
| 459 | static GLXDrawable |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 460 | CreatePbuffer(Display * dpy, const __GLcontextModes * fbconfig, |
| 461 | unsigned int width, unsigned int height, |
| 462 | const int *attrib_list, GLboolean size_in_attribs) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 463 | { |
| 464 | __GLXdisplayPrivate *priv = __glXInitialize(dpy); |
| 465 | GLXDrawable id = 0; |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 466 | CARD32 *data; |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 467 | CARD8 opcode; |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 468 | unsigned int i; |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 469 | Pixmap pixmap; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 470 | |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 471 | i = 0; |
| 472 | if (attrib_list) { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 473 | while (attrib_list[i * 2]) |
| 474 | i++; |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 475 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 476 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 477 | opcode = __glXSetupForCommand(dpy); |
| 478 | if (!opcode) |
| 479 | return None; |
| 480 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 481 | LockDisplay(dpy); |
| 482 | id = XAllocID(dpy); |
| 483 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 484 | if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) { |
| 485 | xGLXCreatePbufferReq *req; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 486 | unsigned int extra = (size_in_attribs) ? 0 : 2; |
| 487 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 488 | GetReqExtra(GLXCreatePbuffer, (8 * (i + extra)), req); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 489 | data = (CARD32 *) (req + 1); |
| 490 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 491 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 492 | req->glxCode = X_GLXCreatePbuffer; |
| 493 | req->screen = (CARD32) fbconfig->screen; |
| 494 | req->fbconfig = fbconfig->fbconfigID; |
| 495 | req->pbuffer = (GLXPbuffer) id; |
| 496 | req->numAttribs = (CARD32) (i + extra); |
| 497 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 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; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | else { |
| 507 | xGLXVendorPrivateReq *vpreq; |
| 508 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 509 | GetReqExtra(GLXVendorPrivate, 20 + (8 * i), vpreq); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 510 | data = (CARD32 *) (vpreq + 1); |
| 511 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 512 | vpreq->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 513 | vpreq->glxCode = X_GLXVendorPrivate; |
| 514 | vpreq->vendorCode = X_GLXvop_CreateGLXPbufferSGIX; |
| 515 | |
| 516 | data[0] = (CARD32) fbconfig->screen; |
| 517 | data[1] = (CARD32) fbconfig->fbconfigID; |
| 518 | data[2] = (CARD32) id; |
| 519 | data[3] = (CARD32) width; |
| 520 | data[4] = (CARD32) height; |
| 521 | data += 5; |
| 522 | } |
| 523 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 524 | (void) memcpy(data, attrib_list, sizeof(CARD32) * 2 * i); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 525 | |
| 526 | UnlockDisplay(dpy); |
| 527 | SyncHandle(); |
| 528 | |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 529 | pixmap = XCreatePixmap(dpy, RootWindow(dpy, fbconfig->screen), |
| 530 | width, height, fbconfig->rgbBits); |
| 531 | |
| 532 | CreateDRIDrawable(dpy, fbconfig, pixmap, id, attrib_list, i); |
| 533 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 534 | return id; |
| 535 | } |
| 536 | |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 537 | /** |
| 538 | * Destroy a pbuffer. |
| 539 | * |
| 540 | * This function is used to implement \c glXDestroyPbuffer and |
| 541 | * \c glXDestroyGLXPbufferSGIX. |
| 542 | * |
| 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. |
| 546 | */ |
| 547 | static void |
| 548 | DestroyPbuffer(Display * dpy, GLXDrawable drawable) |
| 549 | { |
| 550 | __GLXdisplayPrivate *priv = __glXInitialize(dpy); |
| 551 | CARD8 opcode; |
| 552 | |
| 553 | if ((dpy == NULL) || (drawable == 0)) { |
| 554 | return; |
| 555 | } |
| 556 | |
| 557 | opcode = __glXSetupForCommand(dpy); |
| 558 | if (!opcode) |
| 559 | return; |
| 560 | |
| 561 | LockDisplay(dpy); |
| 562 | |
| 563 | if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) { |
| 564 | xGLXDestroyPbufferReq *req; |
| 565 | |
| 566 | GetReq(GLXDestroyPbuffer, req); |
| 567 | req->reqType = opcode; |
| 568 | req->glxCode = X_GLXDestroyPbuffer; |
| 569 | req->pbuffer = (GLXPbuffer) drawable; |
| 570 | } |
| 571 | else { |
| 572 | xGLXVendorPrivateWithReplyReq *vpreq; |
| 573 | CARD32 *data; |
| 574 | |
| 575 | GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq); |
| 576 | data = (CARD32 *) (vpreq + 1); |
| 577 | |
| 578 | data[0] = (CARD32) drawable; |
| 579 | |
| 580 | vpreq->reqType = opcode; |
| 581 | vpreq->glxCode = X_GLXVendorPrivateWithReply; |
| 582 | vpreq->vendorCode = X_GLXvop_DestroyGLXPbufferSGIX; |
| 583 | } |
| 584 | |
| 585 | UnlockDisplay(dpy); |
| 586 | SyncHandle(); |
| 587 | |
| 588 | DestroyDRIDrawable(dpy, drawable, GL_TRUE); |
| 589 | |
| 590 | return; |
| 591 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 592 | |
| 593 | /** |
| 594 | * Create a new pbuffer. |
| 595 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 596 | PUBLIC GLXPbufferSGIX |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 597 | glXCreateGLXPbufferSGIX(Display * dpy, GLXFBConfigSGIX config, |
| 598 | unsigned int width, unsigned int height, |
| 599 | int *attrib_list) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 600 | { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 601 | return (GLXPbufferSGIX) CreatePbuffer(dpy, (__GLcontextModes *) config, |
| 602 | width, height, |
| 603 | attrib_list, GL_FALSE); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 606 | #endif /* GLX_USE_APPLEGL */ |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 607 | |
| 608 | /** |
| 609 | * Create a new pbuffer. |
| 610 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 611 | PUBLIC GLXPbuffer |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 612 | glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int *attrib_list) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 613 | { |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame] | 614 | int i, width, height; |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 615 | #ifdef GLX_USE_APPLEGL |
| 616 | GLXPbuffer result; |
| 617 | int errorcode; |
| 618 | #endif |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame] | 619 | |
| 620 | width = 0; |
| 621 | height = 0; |
| 622 | |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 623 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 624 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 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; |
| 632 | |
| 633 | case GLX_PBUFFER_HEIGHT: |
| 634 | height = attrib_list[i + 1]; |
| 635 | ++i; |
| 636 | break; |
| 637 | |
| 638 | case GLX_LARGEST_PBUFFER: |
| 639 | /* This is a hint we should probably handle, but how? */ |
| 640 | ++i; |
| 641 | break; |
| 642 | |
| 643 | case GLX_PRESERVED_CONTENTS: |
| 644 | /* The contents are always preserved with AppleSGLX with CGL. */ |
| 645 | ++i; |
| 646 | break; |
| 647 | |
| 648 | default: |
| 649 | return None; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | if (apple_glx_pbuffer_create(dpy, config, width, height, &errorcode, |
| 654 | &result)) { |
| 655 | /* |
| 656 | * apple_glx_pbuffer_create only sets the errorcode to core X11 |
| 657 | * errors. |
| 658 | */ |
| 659 | __glXSendError(dpy, errorcode, 0, X_GLXCreatePbuffer, true); |
| 660 | |
| 661 | return None; |
| 662 | } |
| 663 | |
| 664 | return result; |
| 665 | #else |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame] | 666 | for (i = 0; attrib_list[i * 2]; i++) { |
| 667 | switch (attrib_list[i * 2]) { |
| 668 | case GLX_PBUFFER_WIDTH: |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 669 | width = attrib_list[i * 2 + 1]; |
| 670 | break; |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame] | 671 | case GLX_PBUFFER_HEIGHT: |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 672 | height = attrib_list[i * 2 + 1]; |
| 673 | break; |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 677 | return (GLXPbuffer) CreatePbuffer(dpy, (__GLcontextModes *) config, |
| 678 | width, height, attrib_list, GL_TRUE); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 679 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | |
| 683 | /** |
| 684 | * Destroy an existing pbuffer. |
| 685 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 686 | PUBLIC void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 687 | glXDestroyPbuffer(Display * dpy, GLXPbuffer pbuf) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 688 | { |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 689 | #ifdef GLX_USE_APPLEGL |
| 690 | if (apple_glx_pbuffer_destroy(dpy, pbuf)) { |
| 691 | __glXSendError(dpy, GLXBadPbuffer, pbuf, X_GLXDestroyPbuffer, false); |
| 692 | } |
| 693 | #else |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 694 | DestroyPbuffer(dpy, pbuf); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 695 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | |
| 699 | /** |
| 700 | * Query an attribute of a drawable. |
| 701 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 702 | PUBLIC void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 703 | glXQueryDrawable(Display * dpy, GLXDrawable drawable, |
| 704 | int attribute, unsigned int *value) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 705 | { |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 706 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 707 | #ifdef GLX_USE_APPLEGL |
| 708 | Window root; |
| 709 | int x, y; |
| 710 | unsigned int width, height, bd, depth; |
| 711 | |
| 712 | if (apple_glx_pixmap_query(drawable, attribute, value)) |
| 713 | return; /*done */ |
| 714 | |
| 715 | if (apple_glx_pbuffer_query(drawable, attribute, value)) |
| 716 | return; /*done */ |
| 717 | |
| 718 | /* |
| 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. |
| 728 | */ |
| 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; |
| 735 | |
| 736 | case GLX_HEIGHT: |
| 737 | *value = height; |
| 738 | break; |
| 739 | } |
| 740 | } |
| 741 | #else |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 742 | GetDrawableAttribute(dpy, drawable, attribute, value); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 743 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 747 | #ifndef GLX_USE_APPLEGL |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 748 | /** |
| 749 | * Query an attribute of a pbuffer. |
| 750 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 751 | PUBLIC int |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 752 | glXQueryGLXPbufferSGIX(Display * dpy, GLXPbufferSGIX drawable, |
| 753 | int attribute, unsigned int *value) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 754 | { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 755 | return GetDrawableAttribute(dpy, drawable, attribute, value); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 756 | } |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 757 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 758 | |
| 759 | /** |
| 760 | * Select the event mask for a drawable. |
| 761 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 762 | PUBLIC void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 763 | glXSelectEvent(Display * dpy, GLXDrawable drawable, unsigned long mask) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 764 | { |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 765 | #ifdef GLX_USE_APPLEGL |
| 766 | XWindowAttributes xwattr; |
| 767 | |
| 768 | if (apple_glx_pbuffer_set_event_mask(drawable, mask)) |
| 769 | return; /*done */ |
| 770 | |
| 771 | /* |
| 772 | * The spec allows a window, but currently there are no valid |
| 773 | * events for a window, so do nothing. |
| 774 | */ |
| 775 | if (XGetWindowAttributes(dpy, drawable, &xwattr)) |
| 776 | return; /*done */ |
| 777 | /* The drawable seems to be invalid. Report an error. */ |
| 778 | |
| 779 | __glXSendError(dpy, GLXBadDrawable, drawable, |
| 780 | X_GLXChangeDrawableAttributes, false); |
| 781 | #else |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 782 | CARD32 attribs[2]; |
| 783 | |
| 784 | attribs[0] = (CARD32) GLX_EVENT_MASK; |
| 785 | attribs[1] = (CARD32) mask; |
| 786 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 787 | ChangeDrawableAttribute(dpy, drawable, attribs, 1); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 788 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | |
| 792 | /** |
| 793 | * Get the selected event mask for a drawable. |
| 794 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 795 | PUBLIC void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 796 | glXGetSelectedEvent(Display * dpy, GLXDrawable drawable, unsigned long *mask) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 797 | { |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 798 | #ifdef GLX_USE_APPLEGL |
| 799 | XWindowAttributes xwattr; |
| 800 | |
| 801 | if (apple_glx_pbuffer_get_event_mask(drawable, mask)) |
| 802 | return; /*done */ |
| 803 | |
| 804 | /* |
| 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. |
| 807 | */ |
| 808 | if (XGetWindowAttributes(dpy, drawable, &xwattr)) { |
| 809 | /* The window is valid, so set the mask to 0. */ |
| 810 | *mask = 0; |
| 811 | return; /*done */ |
| 812 | } |
| 813 | /* The drawable seems to be invalid. Report an error. */ |
| 814 | |
| 815 | __glXSendError(dpy, GLXBadDrawable, drawable, X_GLXGetDrawableAttributes, |
| 816 | true); |
| 817 | #else |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 818 | unsigned int value; |
| 819 | |
| 820 | |
| 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? |
| 824 | */ |
| 825 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 826 | GetDrawableAttribute(dpy, drawable, GLX_EVENT_MASK_SGIX, &value); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 827 | *mask = value; |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 828 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 832 | PUBLIC GLXPixmap |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 833 | glXCreatePixmap(Display * dpy, GLXFBConfig config, Pixmap pixmap, |
| 834 | const int *attrib_list) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 835 | { |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 836 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 837 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 838 | #ifdef GLX_USE_APPLEGL |
| 839 | const __GLcontextModes *modes = (const __GLcontextModes *) config; |
| 840 | |
| 841 | if (apple_glx_pixmap_create(dpy, modes->screen, pixmap, modes)) |
| 842 | return None; |
| 843 | |
| 844 | return pixmap; |
| 845 | #else |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 846 | return CreateDrawable(dpy, (__GLcontextModes *) config, |
| 847 | (Drawable) pixmap, attrib_list, X_GLXCreatePixmap); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 848 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 852 | PUBLIC GLXWindow |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 853 | glXCreateWindow(Display * dpy, GLXFBConfig config, Window win, |
| 854 | const int *attrib_list) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 855 | { |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 856 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 857 | #ifdef GLX_USE_APPLEGL |
| 858 | XWindowAttributes xwattr; |
| 859 | XVisualInfo *visinfo; |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 860 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 861 | (void) attrib_list; /*unused according to GLX 1.4 */ |
| 862 | |
| 863 | XGetWindowAttributes(dpy, win, &xwattr); |
| 864 | |
| 865 | visinfo = glXGetVisualFromFBConfig(dpy, config); |
| 866 | |
| 867 | if (NULL == visinfo) { |
| 868 | __glXSendError(dpy, GLXBadFBConfig, 0, X_GLXCreateWindow, false); |
| 869 | return None; |
| 870 | } |
| 871 | |
| 872 | if (visinfo->visualid != XVisualIDFromVisual(xwattr.visual)) { |
| 873 | __glXSendError(dpy, BadMatch, 0, X_GLXCreateWindow, true); |
| 874 | return None; |
| 875 | } |
| 876 | |
| 877 | XFree(visinfo); |
| 878 | |
| 879 | return win; |
| 880 | #else |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 881 | return CreateDrawable(dpy, (__GLcontextModes *) config, |
| 882 | (Drawable) win, attrib_list, X_GLXCreateWindow); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 883 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 887 | PUBLIC void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 888 | glXDestroyPixmap(Display * dpy, GLXPixmap pixmap) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 889 | { |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 890 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 891 | #ifdef GLX_USE_APPLEGL |
| 892 | if (apple_glx_pixmap_destroy(dpy, pixmap)) |
| 893 | __glXSendError(dpy, GLXBadPixmap, pixmap, X_GLXDestroyPixmap, false); |
| 894 | #else |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 895 | DestroyDrawable(dpy, (GLXDrawable) pixmap, X_GLXDestroyPixmap); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 896 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 900 | PUBLIC void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 901 | glXDestroyWindow(Display * dpy, GLXWindow win) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 902 | { |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 903 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 904 | #ifndef GLX_USE_APPLEGL |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 905 | DestroyDrawable(dpy, (GLXDrawable) win, X_GLXDestroyWindow); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 906 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 907 | } |
| 908 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 909 | #ifndef GLX_USE_APPLEGL |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 910 | PUBLIC |
| 911 | GLX_ALIAS_VOID(glXDestroyGLXPbufferSGIX, |
| 912 | (Display * dpy, GLXPbufferSGIX pbuf), |
| 913 | (dpy, pbuf), glXDestroyPbuffer) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 914 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 915 | PUBLIC |
| 916 | GLX_ALIAS_VOID(glXSelectEventSGIX, |
| 917 | (Display * dpy, GLXDrawable drawable, |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 918 | unsigned long mask), (dpy, drawable, mask), glXSelectEvent) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 919 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 920 | PUBLIC |
| 921 | GLX_ALIAS_VOID(glXGetSelectedEventSGIX, |
| 922 | (Display * dpy, GLXDrawable drawable, |
| 923 | unsigned long *mask), (dpy, drawable, mask), |
| 924 | glXGetSelectedEvent) |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 925 | #endif |