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. |
| 28 | * |
| 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> |
| 38 | #include "glapi.h" |
| 39 | #include "glxextensions.h" |
| 40 | #include "glcontextmodes.h" |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 41 | #include "glheader.h" |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 42 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Change a drawable's attribute. |
| 46 | * |
| 47 | * This function is used to implement \c glXSelectEvent and |
| 48 | * \c glXSelectEventSGIX. |
| 49 | * |
| 50 | * \note |
| 51 | * This function dynamically determines whether to use the SGIX_pbuffer |
| 52 | * version of the protocol or the GLX 1.3 version of the protocol. |
| 53 | * |
| 54 | * \todo |
| 55 | * This function needs to be modified to work with direct-rendering drivers. |
| 56 | */ |
| 57 | static void |
| 58 | ChangeDrawableAttribute( Display * dpy, GLXDrawable drawable, |
| 59 | const CARD32 * attribs, size_t num_attribs ) |
| 60 | { |
| 61 | __GLXdisplayPrivate *priv = __glXInitialize(dpy); |
| 62 | CARD32 * output; |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 63 | CARD8 opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 64 | |
| 65 | if ( (dpy == NULL) || (drawable == 0) ) { |
| 66 | return; |
| 67 | } |
| 68 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 69 | opcode = __glXSetupForCommand(dpy); |
| 70 | if (!opcode) |
| 71 | return; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 72 | |
| 73 | LockDisplay(dpy); |
| 74 | |
| 75 | if ( (priv->majorVersion > 1) || (priv->minorVersion >= 3) ) { |
| 76 | xGLXChangeDrawableAttributesReq *req; |
| 77 | |
| 78 | GetReqExtra( GLXChangeDrawableAttributes, 8 + (8 * num_attribs), req ); |
| 79 | output = (CARD32 *) (req + 1); |
| 80 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 81 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 82 | req->glxCode = X_GLXChangeDrawableAttributes; |
| 83 | req->drawable = drawable; |
| 84 | req->numAttribs = (CARD32) num_attribs; |
| 85 | } |
| 86 | else { |
| 87 | xGLXVendorPrivateWithReplyReq *vpreq; |
| 88 | |
| 89 | GetReqExtra( GLXVendorPrivateWithReply, 4 + (8 * num_attribs), vpreq ); |
| 90 | output = (CARD32 *) (vpreq + 1); |
| 91 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 92 | vpreq->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 93 | vpreq->glxCode = X_GLXVendorPrivateWithReply; |
| 94 | vpreq->vendorCode = X_GLXvop_ChangeDrawableAttributesSGIX; |
| 95 | |
| 96 | output[0] = (CARD32) drawable; |
| 97 | output++; |
| 98 | } |
| 99 | |
| 100 | (void) memcpy( output, attribs, sizeof( CARD32 ) * 2 * num_attribs ); |
| 101 | |
| 102 | UnlockDisplay(dpy); |
| 103 | SyncHandle(); |
| 104 | |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | /** |
| 110 | * Destroy a pbuffer. |
| 111 | * |
| 112 | * This function is used to implement \c glXDestroyPbuffer and |
| 113 | * \c glXDestroyGLXPbufferSGIX. |
| 114 | * |
| 115 | * \note |
| 116 | * This function dynamically determines whether to use the SGIX_pbuffer |
| 117 | * version of the protocol or the GLX 1.3 version of the protocol. |
| 118 | * |
| 119 | * \todo |
| 120 | * This function needs to be modified to work with direct-rendering drivers. |
| 121 | */ |
| 122 | static void |
| 123 | DestroyPbuffer( Display * dpy, GLXDrawable drawable ) |
| 124 | { |
| 125 | __GLXdisplayPrivate *priv = __glXInitialize(dpy); |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 126 | CARD8 opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 127 | |
| 128 | if ( (dpy == NULL) || (drawable == 0) ) { |
| 129 | return; |
| 130 | } |
| 131 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 132 | opcode = __glXSetupForCommand(dpy); |
| 133 | if (!opcode) |
| 134 | return; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 135 | |
| 136 | LockDisplay(dpy); |
| 137 | |
| 138 | if ( (priv->majorVersion > 1) || (priv->minorVersion >= 3) ) { |
| 139 | xGLXDestroyPbufferReq * req; |
| 140 | |
Brian | 7fcf231 | 2007-05-17 15:25:26 -0600 | [diff] [blame] | 141 | GetReq( GLXDestroyPbuffer, req ); |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 142 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 143 | req->glxCode = X_GLXDestroyPbuffer; |
| 144 | req->pbuffer = (GLXPbuffer) drawable; |
| 145 | } |
| 146 | else { |
| 147 | xGLXVendorPrivateWithReplyReq *vpreq; |
| 148 | CARD32 * data; |
| 149 | |
| 150 | GetReqExtra( GLXVendorPrivateWithReply, 4, vpreq ); |
| 151 | data = (CARD32 *) (vpreq + 1); |
| 152 | |
| 153 | data[0] = (CARD32) drawable; |
| 154 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 155 | vpreq->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 156 | vpreq->glxCode = X_GLXVendorPrivateWithReply; |
| 157 | vpreq->vendorCode = X_GLXvop_DestroyGLXPbufferSGIX; |
| 158 | } |
| 159 | |
| 160 | UnlockDisplay(dpy); |
| 161 | SyncHandle(); |
| 162 | |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | |
| 167 | /** |
| 168 | * Get a drawable's attribute. |
| 169 | * |
| 170 | * This function is used to implement \c glXGetSelectedEvent and |
| 171 | * \c glXGetSelectedEventSGIX. |
| 172 | * |
| 173 | * \note |
| 174 | * This function dynamically determines whether to use the SGIX_pbuffer |
| 175 | * version of the protocol or the GLX 1.3 version of the protocol. |
| 176 | * |
| 177 | * \todo |
| 178 | * The number of attributes returned is likely to be small, probably less than |
| 179 | * 10. Given that, this routine should try to use an array on the stack to |
| 180 | * capture the reply rather than always calling Xmalloc. |
| 181 | * |
| 182 | * \todo |
| 183 | * This function needs to be modified to work with direct-rendering drivers. |
| 184 | */ |
| 185 | static int |
| 186 | GetDrawableAttribute( Display *dpy, GLXDrawable drawable, |
| 187 | int attribute, unsigned int *value ) |
| 188 | { |
Adam Jackson | d25ad50 | 2006-04-07 00:05:50 +0000 | [diff] [blame] | 189 | __GLXdisplayPrivate *priv; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 190 | xGLXGetDrawableAttributesReply reply; |
| 191 | CARD32 * data; |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 192 | CARD8 opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 193 | unsigned int length; |
| 194 | unsigned int i; |
| 195 | unsigned int num_attributes; |
Adam Jackson | d25ad50 | 2006-04-07 00:05:50 +0000 | [diff] [blame] | 196 | |
| 197 | if ( (dpy == NULL) || (drawable == 0) ) { |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | priv = __glXInitialize(dpy); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 202 | GLboolean use_glx_1_3 = ((priv->majorVersion > 1) |
| 203 | || (priv->minorVersion >= 3)); |
| 204 | |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 205 | *value = 0; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 206 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 207 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 208 | opcode = __glXSetupForCommand(dpy); |
| 209 | if (!opcode) |
| 210 | return 0; |
| 211 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 212 | LockDisplay(dpy); |
| 213 | |
| 214 | if ( use_glx_1_3 ) { |
| 215 | xGLXGetDrawableAttributesReq *req; |
| 216 | |
| 217 | GetReqExtra( GLXGetDrawableAttributes, 4, req ); |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 218 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 219 | req->glxCode = X_GLXGetDrawableAttributes; |
| 220 | req->drawable = drawable; |
| 221 | } |
| 222 | else { |
| 223 | xGLXVendorPrivateWithReplyReq *vpreq; |
| 224 | |
| 225 | GetReqExtra( GLXVendorPrivateWithReply, 4, vpreq ); |
| 226 | data = (CARD32 *) (vpreq + 1); |
| 227 | data[0] = (CARD32) drawable; |
| 228 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 229 | vpreq->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 230 | vpreq->glxCode = X_GLXVendorPrivateWithReply; |
| 231 | vpreq->vendorCode = X_GLXvop_GetDrawableAttributesSGIX; |
| 232 | } |
| 233 | |
| 234 | _XReply(dpy, (xReply*) &reply, 0, False); |
| 235 | |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 236 | if (reply.type == X_Error) |
| 237 | { |
| 238 | UnlockDisplay(dpy); |
| 239 | SyncHandle(); |
| 240 | return 0; |
| 241 | } |
| 242 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 243 | length = reply.length; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 244 | if (length) |
| 245 | { |
| 246 | num_attributes = (use_glx_1_3) ? reply.numAttribs : length / 2; |
| 247 | data = (CARD32 *) Xmalloc( length * sizeof(CARD32) ); |
| 248 | if ( data == NULL ) { |
| 249 | /* Throw data on the floor */ |
| 250 | _XEatData(dpy, length); |
| 251 | } else { |
| 252 | _XRead(dpy, (char *)data, length * sizeof(CARD32) ); |
| 253 | |
| 254 | /* Search the set of returned attributes for the attribute requested by |
| 255 | * the caller. |
| 256 | */ |
| 257 | for ( i = 0 ; i < num_attributes ; i++ ) { |
| 258 | if ( data[i*2] == attribute ) { |
| 259 | *value = data[ (i*2) + 1 ]; |
| 260 | break; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | Xfree( data ); |
| 265 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | UnlockDisplay(dpy); |
| 269 | SyncHandle(); |
| 270 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | |
| 275 | /** |
| 276 | * Create a non-pbuffer GLX drawable. |
| 277 | * |
| 278 | * \todo |
| 279 | * This function needs to be modified to work with direct-rendering drivers. |
| 280 | */ |
| 281 | static GLXDrawable |
| 282 | CreateDrawable( Display *dpy, const __GLcontextModes * fbconfig, |
| 283 | Drawable drawable, const int *attrib_list, |
| 284 | CARD8 glxCode ) |
| 285 | { |
| 286 | xGLXCreateWindowReq * req; |
| 287 | CARD32 * data; |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 288 | unsigned int i; |
David Reveman | 342d1de | 2006-04-11 12:07:41 +0000 | [diff] [blame] | 289 | CARD8 opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 290 | |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 291 | i = 0; |
| 292 | if (attrib_list) { |
| 293 | while (attrib_list[i * 2] != None) |
| 294 | i++; |
| 295 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 296 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 297 | opcode = __glXSetupForCommand(dpy); |
| 298 | if (!opcode) |
| 299 | return None; |
David Reveman | 342d1de | 2006-04-11 12:07:41 +0000 | [diff] [blame] | 300 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 301 | LockDisplay(dpy); |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 302 | GetReqExtra( GLXCreateWindow, 8 * i, req ); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 303 | data = (CARD32 *) (req + 1); |
| 304 | |
David Reveman | 342d1de | 2006-04-11 12:07:41 +0000 | [diff] [blame] | 305 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 306 | req->glxCode = glxCode; |
| 307 | req->screen = (CARD32) fbconfig->screen; |
| 308 | req->fbconfig = fbconfig->fbconfigID; |
| 309 | req->window = (GLXPbuffer) drawable; |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 310 | req->glxwindow = (GLXWindow) XAllocID(dpy); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 311 | req->numAttribs = (CARD32) i; |
| 312 | |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 313 | memcpy( data, attrib_list, 8 * i ); |
| 314 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 315 | UnlockDisplay(dpy); |
| 316 | SyncHandle(); |
| 317 | |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 318 | return (GLXDrawable)req->glxwindow; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | |
| 322 | /** |
| 323 | * Destroy a non-pbuffer GLX drawable. |
| 324 | * |
| 325 | * \todo |
| 326 | * This function needs to be modified to work with direct-rendering drivers. |
| 327 | */ |
| 328 | static void |
| 329 | DestroyDrawable( Display * dpy, GLXDrawable drawable, CARD32 glxCode ) |
| 330 | { |
| 331 | xGLXDestroyPbufferReq * req; |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 332 | CARD8 opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 333 | |
| 334 | if ( (dpy == NULL) || (drawable == 0) ) { |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 339 | opcode = __glXSetupForCommand(dpy); |
| 340 | if (!opcode) |
| 341 | return; |
| 342 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 343 | LockDisplay(dpy); |
| 344 | |
| 345 | GetReqExtra( GLXDestroyPbuffer, 4, req ); |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 346 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 347 | req->glxCode = glxCode; |
| 348 | req->pbuffer = (GLXPbuffer) drawable; |
| 349 | |
| 350 | UnlockDisplay(dpy); |
| 351 | SyncHandle(); |
| 352 | |
| 353 | return; |
| 354 | } |
| 355 | |
| 356 | |
| 357 | /** |
| 358 | * Create a pbuffer. |
| 359 | * |
| 360 | * This function is used to implement \c glXCreatePbuffer and |
| 361 | * \c glXCreateGLXPbufferSGIX. |
| 362 | * |
| 363 | * \note |
| 364 | * This function dynamically determines whether to use the SGIX_pbuffer |
| 365 | * version of the protocol or the GLX 1.3 version of the protocol. |
| 366 | * |
| 367 | * \todo |
| 368 | * This function needs to be modified to work with direct-rendering drivers. |
| 369 | */ |
| 370 | static GLXDrawable |
| 371 | CreatePbuffer( Display *dpy, const __GLcontextModes * fbconfig, |
| 372 | unsigned int width, unsigned int height, |
| 373 | const int *attrib_list, GLboolean size_in_attribs ) |
| 374 | { |
| 375 | __GLXdisplayPrivate *priv = __glXInitialize(dpy); |
| 376 | GLXDrawable id = 0; |
| 377 | CARD32 * data; |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 378 | CARD8 opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 379 | unsigned int i; |
| 380 | |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 381 | i = 0; |
| 382 | if (attrib_list) { |
| 383 | while (attrib_list[i * 2]) |
| 384 | i++; |
| 385 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 386 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 387 | opcode = __glXSetupForCommand(dpy); |
| 388 | if (!opcode) |
| 389 | return None; |
| 390 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 391 | LockDisplay(dpy); |
| 392 | id = XAllocID(dpy); |
| 393 | |
| 394 | if ( (priv->majorVersion > 1) || (priv->minorVersion >= 3) ) { |
| 395 | xGLXCreatePbufferReq * req; |
| 396 | unsigned int extra = (size_in_attribs) ? 0 : 2; |
| 397 | |
| 398 | GetReqExtra( GLXCreatePbuffer, (8 * (i + extra)), req ); |
| 399 | data = (CARD32 *) (req + 1); |
| 400 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 401 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 402 | req->glxCode = X_GLXCreatePbuffer; |
| 403 | req->screen = (CARD32) fbconfig->screen; |
| 404 | req->fbconfig = fbconfig->fbconfigID; |
| 405 | req->pbuffer = (GLXPbuffer) id; |
| 406 | req->numAttribs = (CARD32) (i + extra); |
| 407 | |
| 408 | if ( ! size_in_attribs ) { |
| 409 | data[(2 * i) + 0] = GLX_PBUFFER_WIDTH; |
| 410 | data[(2 * i) + 1] = width; |
| 411 | data[(2 * i) + 2] = GLX_PBUFFER_HEIGHT; |
| 412 | data[(2 * i) + 3] = height; |
| 413 | data += 4; |
| 414 | } |
| 415 | } |
| 416 | else { |
| 417 | xGLXVendorPrivateReq *vpreq; |
| 418 | |
| 419 | GetReqExtra( GLXVendorPrivate, 20 + (8 * i), vpreq ); |
| 420 | data = (CARD32 *) (vpreq + 1); |
| 421 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 422 | vpreq->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 423 | vpreq->glxCode = X_GLXVendorPrivate; |
| 424 | vpreq->vendorCode = X_GLXvop_CreateGLXPbufferSGIX; |
| 425 | |
| 426 | data[0] = (CARD32) fbconfig->screen; |
| 427 | data[1] = (CARD32) fbconfig->fbconfigID; |
| 428 | data[2] = (CARD32) id; |
| 429 | data[3] = (CARD32) width; |
| 430 | data[4] = (CARD32) height; |
| 431 | data += 5; |
| 432 | } |
| 433 | |
| 434 | (void) memcpy( data, attrib_list, sizeof(CARD32) * 2 * i ); |
| 435 | |
| 436 | UnlockDisplay(dpy); |
| 437 | SyncHandle(); |
| 438 | |
| 439 | return id; |
| 440 | } |
| 441 | |
| 442 | |
| 443 | /** |
| 444 | * Create a new pbuffer. |
| 445 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 446 | PUBLIC GLXPbufferSGIX |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 447 | glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config, |
| 448 | unsigned int width, unsigned int height, |
| 449 | int *attrib_list) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 450 | { |
| 451 | return (GLXPbufferSGIX) CreatePbuffer( dpy, (__GLcontextModes *) config, |
| 452 | width, height, |
| 453 | attrib_list, GL_FALSE ); |
| 454 | } |
| 455 | |
| 456 | |
| 457 | /** |
| 458 | * Create a new pbuffer. |
| 459 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 460 | PUBLIC GLXPbuffer |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 461 | glXCreatePbuffer(Display *dpy, GLXFBConfig config, const int *attrib_list) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 462 | { |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame^] | 463 | int i, width, height; |
| 464 | |
| 465 | width = 0; |
| 466 | height = 0; |
| 467 | |
| 468 | for (i = 0; attrib_list[i * 2]; i++) { |
| 469 | switch (attrib_list[i * 2]) { |
| 470 | case GLX_PBUFFER_WIDTH: |
| 471 | width = attrib_list[i * 2 + 1]; |
| 472 | break; |
| 473 | case GLX_PBUFFER_HEIGHT: |
| 474 | height = attrib_list[i * 2 + 1]; |
| 475 | break; |
| 476 | } |
| 477 | } |
| 478 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 479 | return (GLXPbuffer) CreatePbuffer( dpy, (__GLcontextModes *) config, |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame^] | 480 | width, height, |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 481 | attrib_list, GL_TRUE ); |
| 482 | } |
| 483 | |
| 484 | |
| 485 | /** |
| 486 | * Destroy an existing pbuffer. |
| 487 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 488 | PUBLIC void |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 489 | glXDestroyPbuffer(Display *dpy, GLXPbuffer pbuf) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 490 | { |
| 491 | DestroyPbuffer( dpy, pbuf ); |
| 492 | } |
| 493 | |
| 494 | |
| 495 | /** |
| 496 | * Query an attribute of a drawable. |
| 497 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 498 | PUBLIC void |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 499 | glXQueryDrawable(Display *dpy, GLXDrawable drawable, |
| 500 | int attribute, unsigned int *value) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 501 | { |
| 502 | GetDrawableAttribute( dpy, drawable, attribute, value ); |
| 503 | } |
| 504 | |
| 505 | |
| 506 | /** |
| 507 | * Query an attribute of a pbuffer. |
| 508 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 509 | PUBLIC int |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 510 | glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX drawable, |
| 511 | int attribute, unsigned int *value) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 512 | { |
| 513 | return GetDrawableAttribute( dpy, drawable, attribute, value ); |
| 514 | } |
| 515 | |
| 516 | |
| 517 | /** |
| 518 | * Select the event mask for a drawable. |
| 519 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 520 | PUBLIC void |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 521 | glXSelectEvent(Display *dpy, GLXDrawable drawable, unsigned long mask) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 522 | { |
| 523 | CARD32 attribs[2]; |
| 524 | |
| 525 | attribs[0] = (CARD32) GLX_EVENT_MASK; |
| 526 | attribs[1] = (CARD32) mask; |
| 527 | |
| 528 | ChangeDrawableAttribute( dpy, drawable, attribs, 1 ); |
| 529 | } |
| 530 | |
| 531 | |
| 532 | /** |
| 533 | * Get the selected event mask for a drawable. |
| 534 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 535 | PUBLIC void |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 536 | glXGetSelectedEvent(Display *dpy, GLXDrawable drawable, unsigned long *mask) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 537 | { |
| 538 | unsigned int value; |
| 539 | |
| 540 | |
| 541 | /* The non-sense with value is required because on LP64 platforms |
| 542 | * sizeof(unsigned int) != sizeof(unsigned long). On little-endian |
| 543 | * we could just type-cast the pointer, but why? |
| 544 | */ |
| 545 | |
| 546 | GetDrawableAttribute( dpy, drawable, GLX_EVENT_MASK_SGIX, & value ); |
| 547 | *mask = value; |
| 548 | } |
| 549 | |
| 550 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 551 | PUBLIC GLXPixmap |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 552 | glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap, |
| 553 | const int *attrib_list ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 554 | { |
| 555 | return CreateDrawable( dpy, (__GLcontextModes *) config, |
| 556 | (Drawable) pixmap, attrib_list, |
| 557 | X_GLXCreatePixmap ); |
| 558 | } |
| 559 | |
| 560 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 561 | PUBLIC GLXWindow |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 562 | glXCreateWindow( Display *dpy, GLXFBConfig config, Window win, |
| 563 | const int *attrib_list ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 564 | { |
| 565 | return CreateDrawable( dpy, (__GLcontextModes *) config, |
| 566 | (Drawable) win, attrib_list, |
| 567 | X_GLXCreateWindow ); |
| 568 | } |
| 569 | |
| 570 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 571 | PUBLIC void |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 572 | glXDestroyPixmap(Display *dpy, GLXPixmap pixmap) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 573 | { |
| 574 | DestroyDrawable( dpy, (GLXDrawable) pixmap, X_GLXDestroyPixmap ); |
| 575 | } |
| 576 | |
| 577 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 578 | PUBLIC void |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 579 | glXDestroyWindow(Display *dpy, GLXWindow win) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 580 | { |
| 581 | DestroyDrawable( dpy, (GLXDrawable) win, X_GLXDestroyWindow ); |
| 582 | } |
| 583 | |
| 584 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 585 | PUBLIC GLX_ALIAS_VOID(glXDestroyGLXPbufferSGIX, |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 586 | (Display *dpy, GLXPbufferSGIX pbuf), |
| 587 | (dpy, pbuf), |
| 588 | glXDestroyPbuffer) |
| 589 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 590 | PUBLIC GLX_ALIAS_VOID(glXSelectEventSGIX, |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 591 | (Display *dpy, GLXDrawable drawable, unsigned long mask), |
| 592 | (dpy, drawable, mask), |
| 593 | glXSelectEvent) |
| 594 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 595 | PUBLIC GLX_ALIAS_VOID(glXGetSelectedEventSGIX, |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 596 | (Display *dpy, GLXDrawable drawable, unsigned long *mask), |
| 597 | (dpy, drawable, mask), |
| 598 | glXGetSelectedEvent) |