2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
33 * GLX protocol interface boot-strap code.
35 * Direct rendering support added by Precision Insight, Inc.
37 * \author Kevin E. Martin <kevin@precisioninsight.com>
41 #include "glxclient.h"
42 #include <X11/extensions/Xext.h>
43 #include <X11/extensions/extutil.h>
45 #include "glxextensions.h"
46 #include "glcontextmodes.h"
49 #include <X11/Xlib-xcb.h>
56 void __glXDumpDrawBuffer(__GLXcontext
* ctx
);
60 ** You can set this cell to 1 to force the gl drawing stuff to be
61 ** one command per packet
63 _X_HIDDEN
int __glXDebug
= 0;
65 /* Extension required boiler plate */
67 static char *__glXExtensionName
= GLX_EXTENSION_NAME
;
68 XExtensionInfo
*__glXExtensionInfo
= NULL
;
70 static /* const */ char *error_list
[] = {
76 "GLXBadCurrentWindow",
77 "GLXBadRenderRequest",
79 "GLXUnsupportedPrivateRequest",
82 "GLXBadCurrentDrawable",
87 __glXCloseDisplay(Display
* dpy
, XExtCodes
* codes
)
91 gc
= __glXGetCurrentContext();
92 if (dpy
== gc
->currentDpy
) {
93 __glXSetCurrentContextNull();
97 return XextRemoveDisplay(__glXExtensionInfo
, dpy
);
102 XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
103 __GLX_NUMBER_ERRORS
, error_list
)
105 static /* const */ XExtensionHooks __glXExtensionHooks
= {
106 NULL
, /* create_gc */
110 NULL
, /* create_font */
111 NULL
, /* free_font */
112 __glXCloseDisplay
, /* close_display */
113 NULL
, /* wire_to_event */
114 NULL
, /* event_to_wire */
116 __glXErrorString
, /* error_string */
120 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay
, __glXExtensionInfo
,
121 __glXExtensionName
, &__glXExtensionHooks
,
122 __GLX_NUMBER_EVENTS
, NULL
)
124 /************************************************************************/
126 ** Free the per screen configs data as well as the array of
127 ** __glXScreenConfigs.
130 FreeScreenConfigs(__GLXdisplayPrivate
* priv
)
132 __GLXscreenConfigs
*psc
;
135 /* Free screen configuration information */
136 psc
= priv
->screenConfigs
;
137 screens
= ScreenCount(priv
->dpy
);
138 for (i
= 0; i
< screens
; i
++, psc
++) {
140 _gl_context_modes_destroy(psc
->configs
);
141 if (psc
->effectiveGLXexts
)
142 Xfree(psc
->effectiveGLXexts
);
143 psc
->configs
= NULL
; /* NOTE: just for paranoia */
146 _gl_context_modes_destroy(psc
->visuals
);
147 psc
->visuals
= NULL
; /* NOTE: just for paranoia */
149 Xfree((char *) psc
->serverGLXexts
);
151 #ifdef GLX_DIRECT_RENDERING
152 if (psc
->driver_configs
) {
153 for(unsigned int i
= 0; psc
->driver_configs
[i
]; i
++)
154 free((__DRIconfig
*)psc
->driver_configs
[i
]);
155 free(psc
->driver_configs
);
156 psc
->driver_configs
= NULL
;
158 if (psc
->driScreen
) {
159 psc
->driScreen
->destroyScreen(psc
);
160 __glxHashDestroy(psc
->drawHash
);
161 XFree(psc
->driScreen
);
162 psc
->driScreen
= NULL
;
166 XFree((char *) priv
->screenConfigs
);
167 priv
->screenConfigs
= NULL
;
171 ** Release the private memory referred to in a display private
172 ** structure. The caller will free the extension structure.
175 __glXFreeDisplayPrivate(XExtData
* extension
)
177 __GLXdisplayPrivate
*priv
;
179 priv
= (__GLXdisplayPrivate
*) extension
->private_data
;
180 FreeScreenConfigs(priv
);
181 if (priv
->serverGLXvendor
) {
182 Xfree((char *) priv
->serverGLXvendor
);
183 priv
->serverGLXvendor
= 0x0; /* to protect against double free's */
185 if (priv
->serverGLXversion
) {
186 Xfree((char *) priv
->serverGLXversion
);
187 priv
->serverGLXversion
= 0x0; /* to protect against double free's */
190 #ifdef GLX_DIRECT_RENDERING
191 /* Free the direct rendering per display data */
192 if (priv
->driswDisplay
)
193 (*priv
->driswDisplay
->destroyDisplay
) (priv
->driswDisplay
);
194 priv
->driswDisplay
= NULL
;
196 if (priv
->driDisplay
)
197 (*priv
->driDisplay
->destroyDisplay
) (priv
->driDisplay
);
198 priv
->driDisplay
= NULL
;
200 if (priv
->dri2Display
)
201 (*priv
->dri2Display
->destroyDisplay
) (priv
->dri2Display
);
202 priv
->dri2Display
= NULL
;
205 Xfree((char *) priv
);
209 /************************************************************************/
212 ** Query the version of the GLX extension. This procedure works even if
213 ** the client extension is not completely set up.
216 QueryVersion(Display
* dpy
, int opcode
, int *major
, int *minor
)
219 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
220 xcb_glx_query_version_reply_t
* reply
=
221 xcb_glx_query_version_reply(c
,
222 xcb_glx_query_version(c
,
227 if(reply
->major_version
!= GLX_MAJOR_VERSION
)
232 *major
= reply
->major_version
;
233 *minor
= min(reply
->minor_version
, GLX_MINOR_VERSION
);
237 xGLXQueryVersionReq
*req
;
238 xGLXQueryVersionReply reply
;
240 /* Send the glXQueryVersion request */
242 GetReq(GLXQueryVersion
, req
);
243 req
->reqType
= opcode
;
244 req
->glxCode
= X_GLXQueryVersion
;
245 req
->majorVersion
= GLX_MAJOR_VERSION
;
246 req
->minorVersion
= GLX_MINOR_VERSION
;
247 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
251 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
253 ** The server does not support the same major release as this
258 *major
= reply
.majorVersion
;
259 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
266 __glXInitializeVisualConfigFromTags(__GLcontextModes
* config
, int count
,
267 const INT32
* bp
, Bool tagged_only
,
268 Bool fbconfig_style_tags
)
273 /* Copy in the first set of properties */
274 config
->visualID
= *bp
++;
276 config
->visualType
= _gl_convert_from_x_visual_type(*bp
++);
278 config
->rgbMode
= *bp
++;
280 config
->redBits
= *bp
++;
281 config
->greenBits
= *bp
++;
282 config
->blueBits
= *bp
++;
283 config
->alphaBits
= *bp
++;
284 config
->accumRedBits
= *bp
++;
285 config
->accumGreenBits
= *bp
++;
286 config
->accumBlueBits
= *bp
++;
287 config
->accumAlphaBits
= *bp
++;
289 config
->doubleBufferMode
= *bp
++;
290 config
->stereoMode
= *bp
++;
292 config
->rgbBits
= *bp
++;
293 config
->depthBits
= *bp
++;
294 config
->stencilBits
= *bp
++;
295 config
->numAuxBuffers
= *bp
++;
296 config
->level
= *bp
++;
298 count
-= __GLX_MIN_CONFIG_PROPS
;
302 ** Additional properties may be in a list at the end
303 ** of the reply. They are in pairs of property type
304 ** and property value.
307 #define FETCH_OR_SET(tag) \
308 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
310 for (i
= 0; i
< count
; i
+= 2) {
313 FETCH_OR_SET(rgbMode
);
315 case GLX_BUFFER_SIZE
:
316 config
->rgbBits
= *bp
++;
319 config
->level
= *bp
++;
321 case GLX_DOUBLEBUFFER
:
322 FETCH_OR_SET(doubleBufferMode
);
325 FETCH_OR_SET(stereoMode
);
327 case GLX_AUX_BUFFERS
:
328 config
->numAuxBuffers
= *bp
++;
331 config
->redBits
= *bp
++;
334 config
->greenBits
= *bp
++;
337 config
->blueBits
= *bp
++;
340 config
->alphaBits
= *bp
++;
343 config
->depthBits
= *bp
++;
345 case GLX_STENCIL_SIZE
:
346 config
->stencilBits
= *bp
++;
348 case GLX_ACCUM_RED_SIZE
:
349 config
->accumRedBits
= *bp
++;
351 case GLX_ACCUM_GREEN_SIZE
:
352 config
->accumGreenBits
= *bp
++;
354 case GLX_ACCUM_BLUE_SIZE
:
355 config
->accumBlueBits
= *bp
++;
357 case GLX_ACCUM_ALPHA_SIZE
:
358 config
->accumAlphaBits
= *bp
++;
360 case GLX_VISUAL_CAVEAT_EXT
:
361 config
->visualRating
= *bp
++;
363 case GLX_X_VISUAL_TYPE
:
364 config
->visualType
= *bp
++;
366 case GLX_TRANSPARENT_TYPE
:
367 config
->transparentPixel
= *bp
++;
369 case GLX_TRANSPARENT_INDEX_VALUE
:
370 config
->transparentIndex
= *bp
++;
372 case GLX_TRANSPARENT_RED_VALUE
:
373 config
->transparentRed
= *bp
++;
375 case GLX_TRANSPARENT_GREEN_VALUE
:
376 config
->transparentGreen
= *bp
++;
378 case GLX_TRANSPARENT_BLUE_VALUE
:
379 config
->transparentBlue
= *bp
++;
381 case GLX_TRANSPARENT_ALPHA_VALUE
:
382 config
->transparentAlpha
= *bp
++;
385 config
->visualID
= *bp
++;
387 case GLX_DRAWABLE_TYPE
:
388 config
->drawableType
= *bp
++;
390 case GLX_RENDER_TYPE
:
391 config
->renderType
= *bp
++;
393 case GLX_X_RENDERABLE
:
394 config
->xRenderable
= *bp
++;
396 case GLX_FBCONFIG_ID
:
397 config
->fbconfigID
= *bp
++;
399 case GLX_MAX_PBUFFER_WIDTH
:
400 config
->maxPbufferWidth
= *bp
++;
402 case GLX_MAX_PBUFFER_HEIGHT
:
403 config
->maxPbufferHeight
= *bp
++;
405 case GLX_MAX_PBUFFER_PIXELS
:
406 config
->maxPbufferPixels
= *bp
++;
408 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
409 config
->optimalPbufferWidth
= *bp
++;
411 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
412 config
->optimalPbufferHeight
= *bp
++;
414 case GLX_VISUAL_SELECT_GROUP_SGIX
:
415 config
->visualSelectGroup
= *bp
++;
417 case GLX_SWAP_METHOD_OML
:
418 config
->swapMethod
= *bp
++;
420 case GLX_SAMPLE_BUFFERS_SGIS
:
421 config
->sampleBuffers
= *bp
++;
423 case GLX_SAMPLES_SGIS
:
424 config
->samples
= *bp
++;
426 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
427 config
->bindToTextureRgb
= *bp
++;
429 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
430 config
->bindToTextureRgba
= *bp
++;
432 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
433 config
->bindToMipmapTexture
= *bp
++;
435 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
436 config
->bindToTextureTargets
= *bp
++;
438 case GLX_Y_INVERTED_EXT
:
439 config
->yInverted
= *bp
++;
450 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
452 config
->haveAccumBuffer
= ((config
->accumRedBits
+
453 config
->accumGreenBits
+
454 config
->accumBlueBits
+
455 config
->accumAlphaBits
) > 0);
456 config
->haveDepthBuffer
= (config
->depthBits
> 0);
457 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
460 static __GLcontextModes
*
461 createConfigsFromProperties(Display
* dpy
, int nvisuals
, int nprops
,
462 int screen
, GLboolean tagged_only
)
464 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
466 __GLcontextModes
*modes
, *m
;
472 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
474 /* Check number of properties */
475 if (nprops
< __GLX_MIN_CONFIG_PROPS
|| nprops
> __GLX_MAX_CONFIG_PROPS
)
478 /* Allocate memory for our config structure */
479 modes
= _gl_context_modes_create(nvisuals
, sizeof(__GLcontextModes
));
483 prop_size
= nprops
* __GLX_SIZE_INT32
;
484 if (prop_size
<= sizeof(buf
))
487 props
= Xmalloc(prop_size
);
489 /* Read each config structure and convert it into our format */
491 for (i
= 0; i
< nvisuals
; i
++) {
492 _XRead(dpy
, (char *) props
, prop_size
);
493 /* Older X servers don't send this so we default it here. */
494 m
->drawableType
= GLX_WINDOW_BIT
;
495 __glXInitializeVisualConfigFromTags(m
, nprops
, props
,
496 tagged_only
, GL_TRUE
);
508 getVisualConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
510 xGLXGetVisualConfigsReq
*req
;
511 __GLXscreenConfigs
*psc
;
512 xGLXGetVisualConfigsReply reply
;
516 psc
= priv
->screenConfigs
+ screen
;
518 GetReq(GLXGetVisualConfigs
, req
);
519 req
->reqType
= priv
->majorOpcode
;
520 req
->glxCode
= X_GLXGetVisualConfigs
;
521 req
->screen
= screen
;
523 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
526 psc
->visuals
= createConfigsFromProperties(dpy
,
533 return psc
->visuals
!= NULL
;
537 getFBConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
539 xGLXGetFBConfigsReq
*fb_req
;
540 xGLXGetFBConfigsSGIXReq
*sgi_req
;
541 xGLXVendorPrivateWithReplyReq
*vpreq
;
542 xGLXGetFBConfigsReply reply
;
543 __GLXscreenConfigs
*psc
;
545 psc
= priv
->screenConfigs
+ screen
;
546 psc
->serverGLXexts
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, GLX_EXTENSIONS
);
551 if (atof(priv
->serverGLXversion
) >= 1.3) {
552 GetReq(GLXGetFBConfigs
, fb_req
);
553 fb_req
->reqType
= priv
->majorOpcode
;
554 fb_req
->glxCode
= X_GLXGetFBConfigs
;
555 fb_req
->screen
= screen
;
557 else if (strstr(psc
->serverGLXexts
, "GLX_SGIX_fbconfig") != NULL
) {
558 GetReqExtra(GLXVendorPrivateWithReply
,
559 sz_xGLXGetFBConfigsSGIXReq
+
560 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
561 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
562 sgi_req
->reqType
= priv
->majorOpcode
;
563 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
564 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
565 sgi_req
->screen
= screen
;
570 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
573 psc
->configs
= createConfigsFromProperties(dpy
,
575 reply
.numAttribs
* 2,
580 return psc
->configs
!= NULL
;
584 ** Allocate the memory for the per screen configs for each screen.
585 ** If that works then fetch the per screen configs data.
588 AllocAndFetchScreenConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
)
590 __GLXscreenConfigs
*psc
;
594 ** First allocate memory for the array of per screen configs.
596 screens
= ScreenCount(dpy
);
597 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
601 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
602 priv
->screenConfigs
= psc
;
604 priv
->serverGLXversion
= __glXQueryServerString(dpy
, priv
->majorOpcode
, 0, GLX_VERSION
);
605 if (priv
->serverGLXversion
== NULL
) {
606 FreeScreenConfigs(priv
);
610 for (i
= 0; i
< screens
; i
++, psc
++) {
611 getVisualConfigs(dpy
, priv
, i
);
612 getFBConfigs(dpy
, priv
, i
);
614 #ifdef GLX_DIRECT_RENDERING
617 psc
->drawHash
= __glxHashCreate();
618 if (psc
->drawHash
== NULL
)
621 if (priv
->dri2Display
)
622 psc
->driScreen
= (*priv
->dri2Display
->createScreen
) (psc
, i
, priv
);
624 if (psc
->driScreen
== NULL
&& priv
->driDisplay
)
625 psc
->driScreen
= (*priv
->driDisplay
->createScreen
) (psc
, i
, priv
);
627 if (psc
->driScreen
== NULL
&& priv
->driswDisplay
)
628 psc
->driScreen
= (*priv
->driswDisplay
->createScreen
) (psc
, i
, priv
);
630 if (psc
->driScreen
== NULL
) {
631 __glxHashDestroy(psc
->drawHash
);
632 psc
->drawHash
= NULL
;
641 ** Initialize the client side extension code.
643 _X_HIDDEN __GLXdisplayPrivate
*
644 __glXInitialize(Display
* dpy
)
646 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
647 XExtData
**privList
, *private, *found
;
648 __GLXdisplayPrivate
*dpyPriv
;
649 XEDataObject dataObj
;
651 #ifdef GLX_DIRECT_RENDERING
652 Bool glx_direct
, glx_accel
;
655 #if defined(USE_XTHREADS)
657 static int firstCall
= 1;
659 /* initialize the GLX mutexes */
660 xmutex_init(&__glXmutex
);
666 /* The one and only long long lock */
669 if (!XextHasExtension(info
)) {
670 /* No GLX extension supported by this server. Oh well. */
672 XMissingExtension(dpy
, __glXExtensionName
);
676 /* See if a display private already exists. If so, return it */
677 dataObj
.display
= dpy
;
678 privList
= XEHeadOfExtensionList(dataObj
);
679 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
682 return (__GLXdisplayPrivate
*) found
->private_data
;
685 /* See if the versions are compatible */
686 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
687 /* The client and server do not agree on versions. Punt. */
693 ** Allocate memory for all the pieces needed for this buffer.
695 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
700 dpyPriv
= (__GLXdisplayPrivate
*) Xcalloc(1, sizeof(__GLXdisplayPrivate
));
703 Xfree((char *) private);
708 ** Init the display private and then read in the screen config
709 ** structures from the server.
711 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
712 dpyPriv
->majorVersion
= major
;
713 dpyPriv
->minorVersion
= minor
;
716 dpyPriv
->serverGLXvendor
= 0x0;
717 dpyPriv
->serverGLXversion
= 0x0;
719 #ifdef GLX_DIRECT_RENDERING
720 glx_direct
= (getenv("LIBGL_ALWAYS_INDIRECT") == NULL
);
721 glx_accel
= (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL
);
724 ** Initialize the direct rendering per display data and functions.
725 ** Note: This _must_ be done before calling any other DRI routines
726 ** (e.g., those called in AllocAndFetchScreenConfigs).
728 if (glx_direct
&& glx_accel
) {
729 dpyPriv
->dri2Display
= dri2CreateDisplay(dpy
);
730 dpyPriv
->driDisplay
= driCreateDisplay(dpy
);
733 dpyPriv
->driswDisplay
= driswCreateDisplay(dpy
);
736 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
738 Xfree((char *) dpyPriv
);
739 Xfree((char *) private);
744 ** Fill in the private structure. This is the actual structure that
745 ** hangs off of the Display structure. Our private structure is
746 ** referred to by this structure. Got that?
748 private->number
= info
->codes
->extension
;
750 private->free_private
= __glXFreeDisplayPrivate
;
751 private->private_data
= (char *) dpyPriv
;
752 XAddToExtensionList(privList
, private);
754 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
755 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
763 ** Setup for sending a GLX command on dpy. Make sure the extension is
764 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
767 __glXSetupForCommand(Display
* dpy
)
770 __GLXdisplayPrivate
*priv
;
772 /* If this thread has a current context, flush its rendering commands */
773 gc
= __glXGetCurrentContext();
774 if (gc
->currentDpy
) {
775 /* Flush rendering buffer of the current context, if any */
776 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
778 if (gc
->currentDpy
== dpy
) {
779 /* Use opcode from gc because its right */
780 return gc
->majorOpcode
;
784 ** Have to get info about argument dpy because it might be to
785 ** a different server
790 /* Forced to lookup extension via the slow initialize route */
791 priv
= __glXInitialize(dpy
);
795 return priv
->majorOpcode
;
799 * Flush the drawing command transport buffer.
801 * \param ctx Context whose transport buffer is to be flushed.
802 * \param pc Pointer to first unused buffer location.
805 * Modify this function to use \c ctx->pc instead of the explicit
809 __glXFlushRenderBuffer(__GLXcontext
* ctx
, GLubyte
* pc
)
811 Display
*const dpy
= ctx
->currentDpy
;
813 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
817 const GLint size
= pc
- ctx
->buf
;
819 if ((dpy
!= NULL
) && (size
> 0)) {
821 xcb_glx_render(c
, ctx
->currentContextTag
, size
,
822 (const uint8_t *) ctx
->buf
);
824 /* Send the entire buffer as an X request */
826 GetReq(GLXRender
, req
);
827 req
->reqType
= ctx
->majorOpcode
;
828 req
->glxCode
= X_GLXRender
;
829 req
->contextTag
= ctx
->currentContextTag
;
830 req
->length
+= (size
+ 3) >> 2;
831 _XSend(dpy
, (char *) ctx
->buf
, size
);
837 /* Reset pointer and return it */
844 * Send a portion of a GLXRenderLarge command to the server. The advantage of
845 * this function over \c __glXSendLargeCommand is that callers can use the
846 * data buffer in the GLX context and may be able to avoid allocating an
847 * extra buffer. The disadvantage is the clients will have to do more
848 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
850 * \sa __glXSendLargeCommand
852 * \param gc GLX context
853 * \param requestNumber Which part of the whole command is this? The first
855 * \param totalRequests How many requests will there be?
856 * \param data Command data.
857 * \param dataLen Size, in bytes, of the command data.
860 __glXSendLargeChunk(__GLXcontext
* gc
, GLint requestNumber
,
861 GLint totalRequests
, const GLvoid
* data
, GLint dataLen
)
863 Display
*dpy
= gc
->currentDpy
;
865 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
866 xcb_glx_render_large(c
, gc
->currentContextTag
, requestNumber
,
867 totalRequests
, dataLen
, data
);
869 xGLXRenderLargeReq
*req
;
871 if (requestNumber
== 1) {
875 GetReq(GLXRenderLarge
, req
);
876 req
->reqType
= gc
->majorOpcode
;
877 req
->glxCode
= X_GLXRenderLarge
;
878 req
->contextTag
= gc
->currentContextTag
;
879 req
->length
+= (dataLen
+ 3) >> 2;
880 req
->requestNumber
= requestNumber
;
881 req
->requestTotal
= totalRequests
;
882 req
->dataBytes
= dataLen
;
883 Data(dpy
, data
, dataLen
);
885 if (requestNumber
== totalRequests
) {
894 * Send a command that is too large for the GLXRender protocol request.
896 * Send a large command, one that is too large for some reason to
897 * send using the GLXRender protocol request. One reason to send
898 * a large command is to avoid copying the data.
900 * \param ctx GLX context
901 * \param header Header data.
902 * \param headerLen Size, in bytes, of the header data. It is assumed that
903 * the header data will always be small enough to fit in
904 * a single X protocol packet.
905 * \param data Command data.
906 * \param dataLen Size, in bytes, of the command data.
909 __glXSendLargeCommand(__GLXcontext
* ctx
,
910 const GLvoid
* header
, GLint headerLen
,
911 const GLvoid
* data
, GLint dataLen
)
914 GLint totalRequests
, requestNumber
;
917 ** Calculate the maximum amount of data can be stuffed into a single
918 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
919 ** packet size minus sz_xGLXRenderReq.
921 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
922 totalRequests
= 1 + (dataLen
/ maxSize
);
923 if (dataLen
% maxSize
)
927 ** Send all of the command, except the large array, as one request.
929 assert(headerLen
<= maxSize
);
930 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
933 ** Send enough requests until the whole array is sent.
935 for (requestNumber
= 2; requestNumber
<= (totalRequests
- 1);
937 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
938 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
943 assert(dataLen
<= maxSize
);
944 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
947 /************************************************************************/
951 __glXDumpDrawBuffer(__GLXcontext
* ctx
)
953 GLubyte
*p
= ctx
->buf
;
954 GLubyte
*end
= ctx
->pc
;
955 GLushort opcode
, length
;
959 opcode
= *((GLushort
*) p
);
960 length
= *((GLushort
*) (p
+ 2));
961 printf("%2x: %5d: ", opcode
, length
);
965 printf("%08x ", *((unsigned *) p
));