blob: 88a17df6f8d13748a0274089c9549d07ce7dd779 [file] [log] [blame]
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001/*
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óf08962682009-08-12 12:41:22 +020028 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +000029 * \author Ian Romanick <idr@us.ibm.com>
30 */
31
32#include <inttypes.h>
33#include "glxclient.h"
Brian Paul82dfd4b2005-08-11 14:18:53 +000034#include <X11/extensions/extutil.h>
35#include <X11/extensions/Xext.h>
Adam Jacksoncb3610e2004-10-25 21:09:16 +000036#include <assert.h>
37#include <string.h>
38#include "glapi.h"
39#include "glxextensions.h"
40#include "glcontextmodes.h"
41
Adam Jacksoncb3610e2004-10-25 21:09:16 +000042
43/**
44 * Change a drawable's attribute.
45 *
46 * This function is used to implement \c glXSelectEvent and
47 * \c glXSelectEventSGIX.
48 *
49 * \note
50 * This function dynamically determines whether to use the SGIX_pbuffer
51 * version of the protocol or the GLX 1.3 version of the protocol.
52 *
53 * \todo
54 * This function needs to be modified to work with direct-rendering drivers.
55 */
56static void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +020057ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable,
58 const CARD32 * attribs, size_t num_attribs)
Adam Jacksoncb3610e2004-10-25 21:09:16 +000059{
60 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +020061 CARD32 *output;
Kristian Høgsbergc25eb992006-06-13 01:41:18 +000062 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +000063
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +020064 if ((dpy == NULL) || (drawable == 0)) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +000065 return;
66 }
67
Kristian Høgsbergc25eb992006-06-13 01:41:18 +000068 opcode = __glXSetupForCommand(dpy);
69 if (!opcode)
70 return;
Adam Jacksoncb3610e2004-10-25 21:09:16 +000071
72 LockDisplay(dpy);
73
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +020074 if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +000075 xGLXChangeDrawableAttributesReq *req;
76
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +020077 GetReqExtra(GLXChangeDrawableAttributes, 8 + (8 * num_attribs), req);
Adam Jacksoncb3610e2004-10-25 21:09:16 +000078 output = (CARD32 *) (req + 1);
79
Kristian Høgsbergc25eb992006-06-13 01:41:18 +000080 req->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +000081 req->glxCode = X_GLXChangeDrawableAttributes;
82 req->drawable = drawable;
83 req->numAttribs = (CARD32) num_attribs;
84 }
85 else {
86 xGLXVendorPrivateWithReplyReq *vpreq;
87
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +020088 GetReqExtra(GLXVendorPrivateWithReply, 4 + (8 * num_attribs), vpreq);
Adam Jacksoncb3610e2004-10-25 21:09:16 +000089 output = (CARD32 *) (vpreq + 1);
90
Kristian Høgsbergc25eb992006-06-13 01:41:18 +000091 vpreq->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +000092 vpreq->glxCode = X_GLXVendorPrivateWithReply;
93 vpreq->vendorCode = X_GLXvop_ChangeDrawableAttributesSGIX;
94
95 output[0] = (CARD32) drawable;
96 output++;
97 }
98
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +020099 (void) memcpy(output, attribs, sizeof(CARD32) * 2 * num_attribs);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000100
101 UnlockDisplay(dpy);
102 SyncHandle();
103
104 return;
105}
106
107
108/**
109 * Destroy a pbuffer.
110 *
111 * This function is used to implement \c glXDestroyPbuffer and
112 * \c glXDestroyGLXPbufferSGIX.
113 *
114 * \note
115 * This function dynamically determines whether to use the SGIX_pbuffer
116 * version of the protocol or the GLX 1.3 version of the protocol.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200117 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000118 * \todo
119 * This function needs to be modified to work with direct-rendering drivers.
120 */
121static void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200122DestroyPbuffer(Display * dpy, GLXDrawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000123{
124 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000125 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000126
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200127 if ((dpy == NULL) || (drawable == 0)) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000128 return;
129 }
130
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000131 opcode = __glXSetupForCommand(dpy);
132 if (!opcode)
133 return;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000134
135 LockDisplay(dpy);
136
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200137 if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) {
138 xGLXDestroyPbufferReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000139
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200140 GetReq(GLXDestroyPbuffer, req);
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000141 req->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000142 req->glxCode = X_GLXDestroyPbuffer;
143 req->pbuffer = (GLXPbuffer) drawable;
144 }
145 else {
146 xGLXVendorPrivateWithReplyReq *vpreq;
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200147 CARD32 *data;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000148
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200149 GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000150 data = (CARD32 *) (vpreq + 1);
151
152 data[0] = (CARD32) drawable;
153
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000154 vpreq->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000155 vpreq->glxCode = X_GLXVendorPrivateWithReply;
156 vpreq->vendorCode = X_GLXvop_DestroyGLXPbufferSGIX;
157 }
158
159 UnlockDisplay(dpy);
160 SyncHandle();
161
162 return;
163}
164
165
Michel Dänzer236355102008-04-10 15:45:52 -0400166#ifdef GLX_DIRECT_RENDERING
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200167extern __GLXDRIdrawable *GetGLXDRIDrawable(Display * dpy,
168 GLXDrawable drawable,
169 int *const scrn_num);
Michel Dänzer236355102008-04-10 15:45:52 -0400170
171static GLenum
172determineTextureTarget(const int *attribs, int numAttribs)
173{
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200174 GLenum target = 0;
175 int i;
Michel Dänzer236355102008-04-10 15:45:52 -0400176
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200177 for (i = 0; i < numAttribs; i++) {
178 if (attribs[2 * i] == GLX_TEXTURE_TARGET_EXT) {
179 switch (attribs[2 * i + 1]) {
180 case GLX_TEXTURE_2D_EXT:
181 target = GL_TEXTURE_2D;
182 break;
183 case GLX_TEXTURE_RECTANGLE_EXT:
184 target = GL_TEXTURE_RECTANGLE_ARB;
185 break;
186 }
187 }
188 }
189
190 return target;
Michel Dänzer236355102008-04-10 15:45:52 -0400191}
Eric Anholt66175aa2009-03-18 12:07:09 -0700192
193
194static GLenum
195determineTextureFormat(const int *attribs, int numAttribs)
196{
Eric Anholt66175aa2009-03-18 12:07:09 -0700197 int i;
198
199 for (i = 0; i < numAttribs; i++) {
200 if (attribs[2 * i] == GLX_TEXTURE_FORMAT_EXT)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200201 return attribs[2 * i + 1];
Eric Anholt66175aa2009-03-18 12:07:09 -0700202 }
203
204 return 0;
205}
Michel Dänzer236355102008-04-10 15:45:52 -0400206#endif
207
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000208/**
209 * Get a drawable's attribute.
210 *
211 * This function is used to implement \c glXGetSelectedEvent and
212 * \c glXGetSelectedEventSGIX.
213 *
214 * \note
215 * This function dynamically determines whether to use the SGIX_pbuffer
216 * version of the protocol or the GLX 1.3 version of the protocol.
217 *
218 * \todo
219 * The number of attributes returned is likely to be small, probably less than
220 * 10. Given that, this routine should try to use an array on the stack to
221 * capture the reply rather than always calling Xmalloc.
222 *
223 * \todo
224 * This function needs to be modified to work with direct-rendering drivers.
225 */
226static int
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200227GetDrawableAttribute(Display * dpy, GLXDrawable drawable,
228 int attribute, unsigned int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000229{
Adam Jacksond25ad502006-04-07 00:05:50 +0000230 __GLXdisplayPrivate *priv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000231 xGLXGetDrawableAttributesReply reply;
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200232 CARD32 *data;
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000233 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000234 unsigned int length;
235 unsigned int i;
236 unsigned int num_attributes;
Owain G. Ainsworthb4866f82009-01-11 20:40:07 +0000237 GLboolean use_glx_1_3;
Adam Jacksond25ad502006-04-07 00:05:50 +0000238
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200239 if ((dpy == NULL) || (drawable == 0)) {
Adam Jacksond25ad502006-04-07 00:05:50 +0000240 return 0;
241 }
242
243 priv = __glXInitialize(dpy);
Owain G. Ainsworthb4866f82009-01-11 20:40:07 +0000244 use_glx_1_3 = ((priv->majorVersion > 1) || (priv->minorVersion >= 3));
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000245
Brian Paul42725d62006-02-07 00:39:56 +0000246 *value = 0;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000247
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000248
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000249 opcode = __glXSetupForCommand(dpy);
250 if (!opcode)
251 return 0;
252
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000253 LockDisplay(dpy);
254
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200255 if (use_glx_1_3) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000256 xGLXGetDrawableAttributesReq *req;
257
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200258 GetReqExtra(GLXGetDrawableAttributes, 4, req);
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000259 req->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000260 req->glxCode = X_GLXGetDrawableAttributes;
261 req->drawable = drawable;
262 }
263 else {
264 xGLXVendorPrivateWithReplyReq *vpreq;
265
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200266 GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000267 data = (CARD32 *) (vpreq + 1);
268 data[0] = (CARD32) drawable;
269
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000270 vpreq->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000271 vpreq->glxCode = X_GLXVendorPrivateWithReply;
272 vpreq->vendorCode = X_GLXvop_GetDrawableAttributesSGIX;
273 }
274
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200275 _XReply(dpy, (xReply *) & reply, 0, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000276
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200277 if (reply.type == X_Error) {
278 UnlockDisplay(dpy);
279 SyncHandle();
280 return 0;
Brian Paul42725d62006-02-07 00:39:56 +0000281 }
282
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000283 length = reply.length;
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200284 if (length) {
285 num_attributes = (use_glx_1_3) ? reply.numAttribs : length / 2;
286 data = (CARD32 *) Xmalloc(length * sizeof(CARD32));
287 if (data == NULL) {
288 /* Throw data on the floor */
289 _XEatData(dpy, length);
290 }
291 else {
292 _XRead(dpy, (char *) data, length * sizeof(CARD32));
Brian Paul42725d62006-02-07 00:39:56 +0000293
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200294 /* Search the set of returned attributes for the attribute requested by
295 * the caller.
296 */
297 for (i = 0; i < num_attributes; i++) {
298 if (data[i * 2] == attribute) {
299 *value = data[(i * 2) + 1];
300 break;
301 }
302 }
Brian Paul42725d62006-02-07 00:39:56 +0000303
Michel Dänzer236355102008-04-10 15:45:52 -0400304#ifdef GLX_DIRECT_RENDERING
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200305 {
306 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);
Michel Dänzer236355102008-04-10 15:45:52 -0400307
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200308 if (pdraw != NULL && !pdraw->textureTarget)
309 pdraw->textureTarget =
310 determineTextureTarget((const int *) data, num_attributes);
Eric Anholt66175aa2009-03-18 12:07:09 -0700311 if (pdraw != NULL && !pdraw->textureFormat)
312 pdraw->textureFormat =
313 determineTextureFormat((const int *) data, num_attributes);
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200314 }
Michel Dänzer236355102008-04-10 15:45:52 -0400315#endif
316
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200317 Xfree(data);
318 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000319 }
320
321 UnlockDisplay(dpy);
322 SyncHandle();
323
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000324 return 0;
325}
326
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000327/**
328 * Create a non-pbuffer GLX drawable.
329 *
330 * \todo
331 * This function needs to be modified to work with direct-rendering drivers.
332 */
333static GLXDrawable
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200334CreateDrawable(Display * dpy, const __GLcontextModes * fbconfig,
335 Drawable drawable, const int *attrib_list, CARD8 glxCode)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000336{
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200337 xGLXCreateWindowReq *req;
338 CARD32 *data;
Ian Romanickb47731f2005-03-04 17:53:24 +0000339 unsigned int i;
David Reveman342d1de2006-04-11 12:07:41 +0000340 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000341
Ian Romanickb47731f2005-03-04 17:53:24 +0000342 i = 0;
343 if (attrib_list) {
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200344 while (attrib_list[i * 2] != None)
345 i++;
Ian Romanickb47731f2005-03-04 17:53:24 +0000346 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000347
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000348 opcode = __glXSetupForCommand(dpy);
349 if (!opcode)
350 return None;
David Reveman342d1de2006-04-11 12:07:41 +0000351
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000352 LockDisplay(dpy);
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200353 GetReqExtra(GLXCreateWindow, 8 * i, req);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000354 data = (CARD32 *) (req + 1);
355
David Reveman342d1de2006-04-11 12:07:41 +0000356 req->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000357 req->glxCode = glxCode;
358 req->screen = (CARD32) fbconfig->screen;
359 req->fbconfig = fbconfig->fbconfigID;
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400360 req->window = (CARD32) drawable;
Ian Romanickb47731f2005-03-04 17:53:24 +0000361 req->glxwindow = (GLXWindow) XAllocID(dpy);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000362 req->numAttribs = (CARD32) i;
363
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200364 memcpy(data, attrib_list, 8 * i);
365
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000366 UnlockDisplay(dpy);
367 SyncHandle();
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200368
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400369#ifdef GLX_DIRECT_RENDERING
370 do {
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200371 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
372 * is actually bound to a context... */
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400373
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200374 __GLXdisplayPrivate *const priv = __glXInitialize(dpy);
375 __GLXDRIdrawable *pdraw;
376 __GLXscreenConfigs *psc;
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400377
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200378 psc = &priv->screenConfigs[fbconfig->screen];
379 if (psc->driScreen == NULL)
380 break;
381 pdraw = psc->driScreen->createDrawable(psc, drawable,
382 req->glxwindow, fbconfig);
383 if (pdraw == NULL) {
384 fprintf(stderr, "failed to create drawable\n");
385 break;
386 }
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400387
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200388 if (__glxHashInsert(psc->drawHash, req->glxwindow, pdraw)) {
389 (*pdraw->destroyDrawable) (pdraw);
390 return None; /* FIXME: Check what we're supposed to do here... */
391 }
392
393 pdraw->textureTarget = determineTextureTarget(attrib_list, i);
Eric Anholt66175aa2009-03-18 12:07:09 -0700394 pdraw->textureFormat = determineTextureFormat(attrib_list, i);
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400395 } while (0);
396#endif
397
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200398 return (GLXDrawable) req->glxwindow;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000399}
400
401
402/**
403 * Destroy a non-pbuffer GLX drawable.
404 *
405 * \todo
406 * This function needs to be modified to work with direct-rendering drivers.
407 */
408static void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200409DestroyDrawable(Display * dpy, GLXDrawable drawable, CARD32 glxCode)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000410{
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200411 xGLXDestroyPbufferReq *req;
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000412 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000413
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200414 if ((dpy == NULL) || (drawable == 0)) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000415 return;
416 }
417
418
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000419 opcode = __glXSetupForCommand(dpy);
420 if (!opcode)
421 return;
422
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000423 LockDisplay(dpy);
424
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200425 GetReqExtra(GLXDestroyPbuffer, 4, req);
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000426 req->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000427 req->glxCode = glxCode;
428 req->pbuffer = (GLXPbuffer) drawable;
429
430 UnlockDisplay(dpy);
431 SyncHandle();
432
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400433#ifdef GLX_DIRECT_RENDERING
434 {
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200435 int screen;
436 __GLXdisplayPrivate *const priv = __glXInitialize(dpy);
437 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
438 __GLXscreenConfigs *psc = &priv->screenConfigs[screen];
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400439
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200440 if (pdraw != NULL) {
441 (*pdraw->destroyDrawable) (pdraw);
442 __glxHashDelete(psc->drawHash, drawable);
443 }
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400444 }
445#endif
446
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000447 return;
448}
449
450
451/**
452 * Create a pbuffer.
453 *
454 * This function is used to implement \c glXCreatePbuffer and
455 * \c glXCreateGLXPbufferSGIX.
456 *
457 * \note
458 * This function dynamically determines whether to use the SGIX_pbuffer
459 * version of the protocol or the GLX 1.3 version of the protocol.
460 *
461 * \todo
462 * This function needs to be modified to work with direct-rendering drivers.
463 */
464static GLXDrawable
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200465CreatePbuffer(Display * dpy, const __GLcontextModes * fbconfig,
466 unsigned int width, unsigned int height,
467 const int *attrib_list, GLboolean size_in_attribs)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000468{
469 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
470 GLXDrawable id = 0;
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200471 CARD32 *data;
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000472 CARD8 opcode;
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200473 unsigned int i;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000474
Ian Romanickb47731f2005-03-04 17:53:24 +0000475 i = 0;
476 if (attrib_list) {
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200477 while (attrib_list[i * 2])
478 i++;
Ian Romanickb47731f2005-03-04 17:53:24 +0000479 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000480
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000481 opcode = __glXSetupForCommand(dpy);
482 if (!opcode)
483 return None;
484
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000485 LockDisplay(dpy);
486 id = XAllocID(dpy);
487
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200488 if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) {
489 xGLXCreatePbufferReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000490 unsigned int extra = (size_in_attribs) ? 0 : 2;
491
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200492 GetReqExtra(GLXCreatePbuffer, (8 * (i + extra)), req);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000493 data = (CARD32 *) (req + 1);
494
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000495 req->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000496 req->glxCode = X_GLXCreatePbuffer;
497 req->screen = (CARD32) fbconfig->screen;
498 req->fbconfig = fbconfig->fbconfigID;
499 req->pbuffer = (GLXPbuffer) id;
500 req->numAttribs = (CARD32) (i + extra);
501
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200502 if (!size_in_attribs) {
503 data[(2 * i) + 0] = GLX_PBUFFER_WIDTH;
504 data[(2 * i) + 1] = width;
505 data[(2 * i) + 2] = GLX_PBUFFER_HEIGHT;
506 data[(2 * i) + 3] = height;
507 data += 4;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000508 }
509 }
510 else {
511 xGLXVendorPrivateReq *vpreq;
512
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200513 GetReqExtra(GLXVendorPrivate, 20 + (8 * i), vpreq);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000514 data = (CARD32 *) (vpreq + 1);
515
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000516 vpreq->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000517 vpreq->glxCode = X_GLXVendorPrivate;
518 vpreq->vendorCode = X_GLXvop_CreateGLXPbufferSGIX;
519
520 data[0] = (CARD32) fbconfig->screen;
521 data[1] = (CARD32) fbconfig->fbconfigID;
522 data[2] = (CARD32) id;
523 data[3] = (CARD32) width;
524 data[4] = (CARD32) height;
525 data += 5;
526 }
527
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200528 (void) memcpy(data, attrib_list, sizeof(CARD32) * 2 * i);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000529
530 UnlockDisplay(dpy);
531 SyncHandle();
532
533 return id;
534}
535
536
537/**
538 * Create a new pbuffer.
539 */
Adam Jackson489ccef2004-12-15 17:18:06 +0000540PUBLIC GLXPbufferSGIX
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200541glXCreateGLXPbufferSGIX(Display * dpy, GLXFBConfigSGIX config,
542 unsigned int width, unsigned int height,
543 int *attrib_list)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000544{
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200545 return (GLXPbufferSGIX) CreatePbuffer(dpy, (__GLcontextModes *) config,
546 width, height,
547 attrib_list, GL_FALSE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000548}
549
550
551/**
552 * Create a new pbuffer.
553 */
Adam Jackson489ccef2004-12-15 17:18:06 +0000554PUBLIC GLXPbuffer
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200555glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int *attrib_list)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000556{
Kristian Høgsberg8b204112007-08-27 14:16:30 -0400557 int i, width, height;
558
559 width = 0;
560 height = 0;
561
562 for (i = 0; attrib_list[i * 2]; i++) {
563 switch (attrib_list[i * 2]) {
564 case GLX_PBUFFER_WIDTH:
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200565 width = attrib_list[i * 2 + 1];
566 break;
Kristian Høgsberg8b204112007-08-27 14:16:30 -0400567 case GLX_PBUFFER_HEIGHT:
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200568 height = attrib_list[i * 2 + 1];
569 break;
Kristian Høgsberg8b204112007-08-27 14:16:30 -0400570 }
571 }
572
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200573 return (GLXPbuffer) CreatePbuffer(dpy, (__GLcontextModes *) config,
574 width, height, attrib_list, GL_TRUE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000575}
576
577
578/**
579 * Destroy an existing pbuffer.
580 */
Adam Jackson489ccef2004-12-15 17:18:06 +0000581PUBLIC void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200582glXDestroyPbuffer(Display * dpy, GLXPbuffer pbuf)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000583{
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200584 DestroyPbuffer(dpy, pbuf);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000585}
586
587
588/**
589 * Query an attribute of a drawable.
590 */
Adam Jackson489ccef2004-12-15 17:18:06 +0000591PUBLIC void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200592glXQueryDrawable(Display * dpy, GLXDrawable drawable,
593 int attribute, unsigned int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000594{
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200595 GetDrawableAttribute(dpy, drawable, attribute, value);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000596}
597
598
599/**
600 * Query an attribute of a pbuffer.
601 */
Adam Jackson489ccef2004-12-15 17:18:06 +0000602PUBLIC int
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200603glXQueryGLXPbufferSGIX(Display * dpy, GLXPbufferSGIX drawable,
604 int attribute, unsigned int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000605{
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200606 return GetDrawableAttribute(dpy, drawable, attribute, value);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000607}
608
609
610/**
611 * Select the event mask for a drawable.
612 */
Adam Jackson489ccef2004-12-15 17:18:06 +0000613PUBLIC void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200614glXSelectEvent(Display * dpy, GLXDrawable drawable, unsigned long mask)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000615{
616 CARD32 attribs[2];
617
618 attribs[0] = (CARD32) GLX_EVENT_MASK;
619 attribs[1] = (CARD32) mask;
620
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200621 ChangeDrawableAttribute(dpy, drawable, attribs, 1);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000622}
623
624
625/**
626 * Get the selected event mask for a drawable.
627 */
Adam Jackson489ccef2004-12-15 17:18:06 +0000628PUBLIC void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200629glXGetSelectedEvent(Display * dpy, GLXDrawable drawable, unsigned long *mask)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000630{
631 unsigned int value;
632
633
634 /* The non-sense with value is required because on LP64 platforms
635 * sizeof(unsigned int) != sizeof(unsigned long). On little-endian
636 * we could just type-cast the pointer, but why?
637 */
638
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200639 GetDrawableAttribute(dpy, drawable, GLX_EVENT_MASK_SGIX, &value);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000640 *mask = value;
641}
642
643
Adam Jackson489ccef2004-12-15 17:18:06 +0000644PUBLIC GLXPixmap
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200645glXCreatePixmap(Display * dpy, GLXFBConfig config, Pixmap pixmap,
646 const int *attrib_list)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000647{
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200648 return CreateDrawable(dpy, (__GLcontextModes *) config,
649 (Drawable) pixmap, attrib_list, X_GLXCreatePixmap);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000650}
651
652
Adam Jackson489ccef2004-12-15 17:18:06 +0000653PUBLIC GLXWindow
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200654glXCreateWindow(Display * dpy, GLXFBConfig config, Window win,
655 const int *attrib_list)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000656{
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200657 return CreateDrawable(dpy, (__GLcontextModes *) config,
658 (Drawable) win, attrib_list, X_GLXCreateWindow);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000659}
660
661
Adam Jackson489ccef2004-12-15 17:18:06 +0000662PUBLIC void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200663glXDestroyPixmap(Display * dpy, GLXPixmap pixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000664{
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200665 DestroyDrawable(dpy, (GLXDrawable) pixmap, X_GLXDestroyPixmap);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000666}
667
668
Adam Jackson489ccef2004-12-15 17:18:06 +0000669PUBLIC void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200670glXDestroyWindow(Display * dpy, GLXWindow win)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000671{
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200672 DestroyDrawable(dpy, (GLXDrawable) win, X_GLXDestroyWindow);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000673}
674
675
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200676PUBLIC
677GLX_ALIAS_VOID(glXDestroyGLXPbufferSGIX,
678 (Display * dpy, GLXPbufferSGIX pbuf),
679 (dpy, pbuf), glXDestroyPbuffer)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000680
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200681PUBLIC
682GLX_ALIAS_VOID(glXSelectEventSGIX,
683 (Display * dpy, GLXDrawable drawable,
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200684 unsigned long mask), (dpy, drawable, mask), glXSelectEvent)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000685
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200686PUBLIC
687GLX_ALIAS_VOID(glXGetSelectedEventSGIX,
688 (Display * dpy, GLXDrawable drawable,
689 unsigned long *mask), (dpy, drawable, mask),
690 glXGetSelectedEvent)