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.
31 #ifdef HAVE_DIX_CONFIG_H
32 #include <dix-config.h>
35 #include "glxserver.h"
38 #include "indirect_dispatch.h"
40 #include "glapitable.h"
45 int __glXDispSwap_FeedbackBuffer(__GLXclientState *cl, GLbyte *pc)
49 __GLX_DECLARE_SWAP_VARIABLES;
53 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
54 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
59 pc += __GLX_SINGLE_HDR_SIZE;
62 size = *(GLsizei *)(pc+0);
63 type = *(GLenum *)(pc+4);
64 if (cx->feedbackBufSize < size) {
65 cx->feedbackBuf = (GLfloat *) realloc(cx->feedbackBuf,
67 * __GLX_SIZE_FLOAT32);
68 if (!cx->feedbackBuf) {
69 cl->client->errorValue = size;
72 cx->feedbackBufSize = size;
74 CALL_FeedbackBuffer( GET_DISPATCH(), (size, type, cx->feedbackBuf) );
75 __GLX_NOTE_UNFLUSHED_CMDS(cx);
79 int __glXDispSwap_SelectBuffer(__GLXclientState *cl, GLbyte *pc)
83 __GLX_DECLARE_SWAP_VARIABLES;
86 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
87 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
92 pc += __GLX_SINGLE_HDR_SIZE;
94 size = *(GLsizei *)(pc+0);
95 if (cx->selectBufSize < size) {
96 cx->selectBuf = (GLuint *) realloc(cx->selectBuf,
100 cl->client->errorValue = size;
103 cx->selectBufSize = size;
105 CALL_SelectBuffer( GET_DISPATCH(), (size, cx->selectBuf) );
106 __GLX_NOTE_UNFLUSHED_CMDS(cx);
110 int __glXDispSwap_RenderMode(__GLXclientState *cl, GLbyte *pc)
114 xGLXRenderModeReply reply;
115 GLint nitems=0, retBytes=0, retval, newModeCheck;
116 GLubyte *retBuffer = NULL;
118 __GLX_DECLARE_SWAP_VARIABLES;
119 __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
122 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
123 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
128 pc += __GLX_SINGLE_HDR_SIZE;
130 newMode = *(GLenum*) pc;
131 retval = CALL_RenderMode( GET_DISPATCH(), (newMode) );
133 /* Check that render mode worked */
134 CALL_GetIntegerv( GET_DISPATCH(), (GL_RENDER_MODE, &newModeCheck) );
135 if (newModeCheck != newMode) {
136 /* Render mode change failed. Bail */
137 newMode = newModeCheck;
138 goto noChangeAllowed;
142 ** Render mode might have still failed if we get here. But in this
143 ** case we can't really tell, nor does it matter. If it did fail, it
144 ** will return 0, and thus we won't send any data across the wire.
147 switch (cx->renderMode) {
149 cx->renderMode = newMode;
153 /* Overflow happened. Copy the entire buffer */
154 nitems = cx->feedbackBufSize;
158 retBytes = nitems * __GLX_SIZE_FLOAT32;
159 retBuffer = (GLubyte*) cx->feedbackBuf;
160 __GLX_SWAP_FLOAT_ARRAY((GLbyte *)retBuffer, nitems);
161 cx->renderMode = newMode;
165 /* Overflow happened. Copy the entire buffer */
166 nitems = cx->selectBufSize;
168 GLuint *bp = cx->selectBuf;
172 ** Figure out how many bytes of data need to be sent. Parse
173 ** the selection buffer to determine this fact as the
174 ** return value is the number of hits, not the number of
175 ** items in the buffer.
182 /* Parse select data for this hit */
186 nitems = bp - cx->selectBuf;
188 retBytes = nitems * __GLX_SIZE_CARD32;
189 retBuffer = (GLubyte*) cx->selectBuf;
190 __GLX_SWAP_INT_ARRAY((GLbyte *)retBuffer, nitems);
191 cx->renderMode = newMode;
196 ** First reply is the number of elements returned in the feedback or
197 ** selection array, as per the API for glRenderMode itself.
201 reply.length = nitems;
202 reply.type = X_Reply;
203 reply.sequenceNumber = client->sequence;
204 reply.retval = retval;
206 reply.newMode = newMode;
207 __GLX_SWAP_SHORT(&reply.sequenceNumber);
208 __GLX_SWAP_INT(&reply.length);
209 __GLX_SWAP_INT(&reply.retval);
210 __GLX_SWAP_INT(&reply.size);
211 __GLX_SWAP_INT(&reply.newMode);
212 WriteToClient(client, sz_xGLXRenderModeReply, (char *)&reply);
214 WriteToClient(client, retBytes, (char *)retBuffer);
219 int __glXDispSwap_Flush(__GLXclientState *cl, GLbyte *pc)
223 __GLX_DECLARE_SWAP_VARIABLES;
225 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
226 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
231 CALL_Flush( GET_DISPATCH(), () );
232 __GLX_NOTE_FLUSHED_CMDS(cx);
236 int __glXDispSwap_Finish(__GLXclientState *cl, GLbyte *pc)
241 __GLX_DECLARE_SWAP_VARIABLES;
243 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
244 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
249 /* Do a local glFinish */
250 CALL_Finish( GET_DISPATCH(), () );
251 __GLX_NOTE_FLUSHED_CMDS(cx);
253 /* Send empty reply packet to indicate finish is finished */
255 __GLX_BEGIN_REPLY(0);
257 __GLX_SWAP_REPLY_HEADER();
263 int __glXDispSwap_GetString(__GLXclientState *cl, GLbyte *pc)
265 return DoGetString(cl, pc, GL_TRUE);