First import
[xorg_rtime.git] / xorg-server-1.4 / GL / glx / single2swap.c
blob41a42bb0f320c7824b785279b61aad37c91289c8
1 /*
2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
9 **
10 ** http://oss.sgi.com/projects/FreeB
11 **
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
17 **
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
23 **
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
36 #define NEED_REPLIES
37 #ifdef HAVE_DIX_CONFIG_H
38 #include <dix-config.h>
39 #endif
41 #include "glxserver.h"
42 #include "glxutil.h"
43 #include "glxext.h"
44 #include "indirect_dispatch.h"
45 #include "unpack.h"
46 #include "glapitable.h"
47 #include "glapi.h"
48 #include "glthread.h"
49 #include "dispatch.h"
51 int __glXDispSwap_FeedbackBuffer(__GLXclientState *cl, GLbyte *pc)
53 GLsizei size;
54 GLenum type;
55 __GLX_DECLARE_SWAP_VARIABLES;
56 __GLXcontext *cx;
57 int error;
59 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
60 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
61 if (!cx) {
62 return error;
65 pc += __GLX_SINGLE_HDR_SIZE;
66 __GLX_SWAP_INT(pc+0);
67 __GLX_SWAP_INT(pc+4);
68 size = *(GLsizei *)(pc+0);
69 type = *(GLenum *)(pc+4);
70 if (cx->feedbackBufSize < size) {
71 cx->feedbackBuf = (GLfloat *) xrealloc(cx->feedbackBuf,
72 (size_t) size
73 * __GLX_SIZE_FLOAT32);
74 if (!cx->feedbackBuf) {
75 cl->client->errorValue = size;
76 return BadAlloc;
78 cx->feedbackBufSize = size;
80 CALL_FeedbackBuffer( GET_DISPATCH(), (size, type, cx->feedbackBuf) );
81 __GLX_NOTE_UNFLUSHED_CMDS(cx);
82 return Success;
85 int __glXDispSwap_SelectBuffer(__GLXclientState *cl, GLbyte *pc)
87 __GLXcontext *cx;
88 GLsizei size;
89 __GLX_DECLARE_SWAP_VARIABLES;
90 int error;
92 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
93 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
94 if (!cx) {
95 return error;
98 pc += __GLX_SINGLE_HDR_SIZE;
99 __GLX_SWAP_INT(pc+0);
100 size = *(GLsizei *)(pc+0);
101 if (cx->selectBufSize < size) {
102 cx->selectBuf = (GLuint *) xrealloc(cx->selectBuf,
103 (size_t) size
104 * __GLX_SIZE_CARD32);
105 if (!cx->selectBuf) {
106 cl->client->errorValue = size;
107 return BadAlloc;
109 cx->selectBufSize = size;
111 CALL_SelectBuffer( GET_DISPATCH(), (size, cx->selectBuf) );
112 __GLX_NOTE_UNFLUSHED_CMDS(cx);
113 return Success;
116 int __glXDispSwap_RenderMode(__GLXclientState *cl, GLbyte *pc)
118 ClientPtr client;
119 __GLXcontext *cx;
120 xGLXRenderModeReply reply;
121 GLint nitems=0, retBytes=0, retval, newModeCheck;
122 GLubyte *retBuffer = NULL;
123 GLenum newMode;
124 __GLX_DECLARE_SWAP_VARIABLES;
125 __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
126 int error;
128 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
129 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
130 if (!cx) {
131 return error;
134 pc += __GLX_SINGLE_HDR_SIZE;
135 __GLX_SWAP_INT(pc);
136 newMode = *(GLenum*) pc;
137 retval = CALL_RenderMode( GET_DISPATCH(), (newMode) );
139 /* Check that render mode worked */
140 CALL_GetIntegerv( GET_DISPATCH(), (GL_RENDER_MODE, &newModeCheck) );
141 if (newModeCheck != newMode) {
142 /* Render mode change failed. Bail */
143 newMode = newModeCheck;
144 goto noChangeAllowed;
148 ** Render mode might have still failed if we get here. But in this
149 ** case we can't really tell, nor does it matter. If it did fail, it
150 ** will return 0, and thus we won't send any data across the wire.
153 switch (cx->renderMode) {
154 case GL_RENDER:
155 cx->renderMode = newMode;
156 break;
157 case GL_FEEDBACK:
158 if (retval < 0) {
159 /* Overflow happened. Copy the entire buffer */
160 nitems = cx->feedbackBufSize;
161 } else {
162 nitems = retval;
164 retBytes = nitems * __GLX_SIZE_FLOAT32;
165 retBuffer = (GLubyte*) cx->feedbackBuf;
166 __GLX_SWAP_FLOAT_ARRAY((GLbyte *)retBuffer, nitems);
167 cx->renderMode = newMode;
168 break;
169 case GL_SELECT:
170 if (retval < 0) {
171 /* Overflow happened. Copy the entire buffer */
172 nitems = cx->selectBufSize;
173 } else {
174 GLuint *bp = cx->selectBuf;
175 GLint i;
178 ** Figure out how many bytes of data need to be sent. Parse
179 ** the selection buffer to determine this fact as the
180 ** return value is the number of hits, not the number of
181 ** items in the buffer.
183 nitems = 0;
184 i = retval;
185 while (--i >= 0) {
186 GLuint n;
188 /* Parse select data for this hit */
189 n = *bp;
190 bp += 3 + n;
192 nitems = bp - cx->selectBuf;
194 retBytes = nitems * __GLX_SIZE_CARD32;
195 retBuffer = (GLubyte*) cx->selectBuf;
196 __GLX_SWAP_INT_ARRAY((GLbyte *)retBuffer, nitems);
197 cx->renderMode = newMode;
198 break;
202 ** First reply is the number of elements returned in the feedback or
203 ** selection array, as per the API for glRenderMode itself.
205 noChangeAllowed:;
206 client = cl->client;
207 reply.length = nitems;
208 reply.type = X_Reply;
209 reply.sequenceNumber = client->sequence;
210 reply.retval = retval;
211 reply.size = nitems;
212 reply.newMode = newMode;
213 __GLX_SWAP_SHORT(&reply.sequenceNumber);
214 __GLX_SWAP_INT(&reply.length);
215 __GLX_SWAP_INT(&reply.retval);
216 __GLX_SWAP_INT(&reply.size);
217 __GLX_SWAP_INT(&reply.newMode);
218 WriteToClient(client, sz_xGLXRenderModeReply, (char *)&reply);
219 if (retBytes) {
220 WriteToClient(client, retBytes, (char *)retBuffer);
222 return Success;
225 int __glXDispSwap_Flush(__GLXclientState *cl, GLbyte *pc)
227 __GLXcontext *cx;
228 int error;
229 __GLX_DECLARE_SWAP_VARIABLES;
231 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
232 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
233 if (!cx) {
234 return error;
237 CALL_Flush( GET_DISPATCH(), () );
238 __GLX_NOTE_FLUSHED_CMDS(cx);
239 return Success;
242 int __glXDispSwap_Finish(__GLXclientState *cl, GLbyte *pc)
244 __GLXcontext *cx;
245 ClientPtr client;
246 int error;
247 __GLX_DECLARE_SWAP_VARIABLES;
249 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
250 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
251 if (!cx) {
252 return error;
255 /* Do a local glFinish */
256 CALL_Finish( GET_DISPATCH(), () );
257 __GLX_NOTE_FLUSHED_CMDS(cx);
259 /* Send empty reply packet to indicate finish is finished */
260 client = cl->client;
261 __GLX_BEGIN_REPLY(0);
262 __GLX_PUT_RETVAL(0);
263 __GLX_SWAP_REPLY_HEADER();
264 __GLX_SEND_HEADER();
266 return Success;
269 int __glXDispSwap_GetString(__GLXclientState *cl, GLbyte *pc)
271 return DoGetString(cl, pc, GL_TRUE);