1
/* $XFree86: xc/programs/Xserver/GL/glx/single2swap.c,v 1.7 2002/01/14 22:47:08 tsi Exp $ */
3
** License Applicability. Except to the extent portions of this file are
4
** made subject to an alternative license as permitted in the SGI Free
5
** Software License B, Version 1.1 (the "License"), the contents of this
6
** file are subject only to the provisions of the License. You may not use
7
** this file except in compliance with the License. You may obtain a copy
8
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
11
** http://oss.sgi.com/projects/FreeB
13
** Note that, as provided in the License, the Software is distributed on an
14
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
19
** Original Code. The Original Code is: OpenGL Sample Implementation,
20
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22
** Copyright in any portions created by third parties is as indicated
23
** elsewhere herein. All Rights Reserved.
25
** Additional Notice Provisions: The application programming interfaces
26
** established by SGI in conjunction with the Original Code are The
27
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30
** Window System(R) (Version 1.3), released October 19, 1998. This software
31
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32
** published by SGI, but has not been independently verified as being
33
** compliant with the OpenGL(R) version 1.2.1 Specification.
38
#ifdef HAVE_DIX_CONFIG_H
39
#include <dix-config.h>
42
#include "glxserver.h"
45
#include "indirect_dispatch.h"
47
#include "GL/glx_ansic.h"
48
#include "glapitable.h"
53
int __glXDispSwap_FeedbackBuffer(__GLXclientState *cl, GLbyte *pc)
57
__GLX_DECLARE_SWAP_VARIABLES;
61
__GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
62
cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
67
pc += __GLX_SINGLE_HDR_SIZE;
70
size = *(GLsizei *)(pc+0);
71
type = *(GLenum *)(pc+4);
72
if (cx->feedbackBufSize < size) {
73
cx->feedbackBuf = (GLfloat *) __glXRealloc(cx->feedbackBuf,
75
* __GLX_SIZE_FLOAT32);
76
if (!cx->feedbackBuf) {
77
cl->client->errorValue = size;
80
cx->feedbackBufSize = size;
82
CALL_FeedbackBuffer( GET_DISPATCH(), (size, type, cx->feedbackBuf) );
83
__GLX_NOTE_UNFLUSHED_CMDS(cx);
87
int __glXDispSwap_SelectBuffer(__GLXclientState *cl, GLbyte *pc)
91
__GLX_DECLARE_SWAP_VARIABLES;
94
__GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
95
cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
100
pc += __GLX_SINGLE_HDR_SIZE;
101
__GLX_SWAP_INT(pc+0);
102
size = *(GLsizei *)(pc+0);
103
if (cx->selectBufSize < size) {
104
cx->selectBuf = (GLuint *) __glXRealloc(cx->selectBuf,
106
* __GLX_SIZE_CARD32);
107
if (!cx->selectBuf) {
108
cl->client->errorValue = size;
111
cx->selectBufSize = size;
113
CALL_SelectBuffer( GET_DISPATCH(), (size, cx->selectBuf) );
114
__GLX_NOTE_UNFLUSHED_CMDS(cx);
118
int __glXDispSwap_RenderMode(__GLXclientState *cl, GLbyte *pc)
122
xGLXRenderModeReply reply;
123
GLint nitems=0, retBytes=0, retval, newModeCheck;
124
GLubyte *retBuffer = NULL;
126
__GLX_DECLARE_SWAP_VARIABLES;
127
__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
130
__GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
131
cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
136
pc += __GLX_SINGLE_HDR_SIZE;
138
newMode = *(GLenum*) pc;
139
retval = CALL_RenderMode( GET_DISPATCH(), (newMode) );
141
/* Check that render mode worked */
142
CALL_GetIntegerv( GET_DISPATCH(), (GL_RENDER_MODE, &newModeCheck) );
143
if (newModeCheck != newMode) {
144
/* Render mode change failed. Bail */
145
newMode = newModeCheck;
146
goto noChangeAllowed;
150
** Render mode might have still failed if we get here. But in this
151
** case we can't really tell, nor does it matter. If it did fail, it
152
** will return 0, and thus we won't send any data across the wire.
155
switch (cx->renderMode) {
157
cx->renderMode = newMode;
161
/* Overflow happened. Copy the entire buffer */
162
nitems = cx->feedbackBufSize;
166
retBytes = nitems * __GLX_SIZE_FLOAT32;
167
retBuffer = (GLubyte*) cx->feedbackBuf;
168
__GLX_SWAP_FLOAT_ARRAY((GLbyte *)retBuffer, nitems);
169
cx->renderMode = newMode;
173
/* Overflow happened. Copy the entire buffer */
174
nitems = cx->selectBufSize;
176
GLuint *bp = cx->selectBuf;
180
** Figure out how many bytes of data need to be sent. Parse
181
** the selection buffer to determine this fact as the
182
** return value is the number of hits, not the number of
183
** items in the buffer.
190
/* Parse select data for this hit */
194
nitems = bp - cx->selectBuf;
196
retBytes = nitems * __GLX_SIZE_CARD32;
197
retBuffer = (GLubyte*) cx->selectBuf;
198
__GLX_SWAP_INT_ARRAY((GLbyte *)retBuffer, nitems);
199
cx->renderMode = newMode;
204
** First reply is the number of elements returned in the feedback or
205
** selection array, as per the API for glRenderMode itself.
209
reply.length = nitems;
210
reply.type = X_Reply;
211
reply.sequenceNumber = client->sequence;
212
reply.retval = retval;
214
reply.newMode = newMode;
215
__GLX_SWAP_SHORT(&reply.sequenceNumber);
216
__GLX_SWAP_INT(&reply.length);
217
__GLX_SWAP_INT(&reply.retval);
218
__GLX_SWAP_INT(&reply.size);
219
__GLX_SWAP_INT(&reply.newMode);
220
WriteToClient(client, sz_xGLXRenderModeReply, (char *)&reply);
222
WriteToClient(client, retBytes, (char *)retBuffer);
227
int __glXDispSwap_Flush(__GLXclientState *cl, GLbyte *pc)
231
__GLX_DECLARE_SWAP_VARIABLES;
233
__GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
234
cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
239
CALL_Flush( GET_DISPATCH(), () );
240
__GLX_NOTE_FLUSHED_CMDS(cx);
244
int __glXDispSwap_Finish(__GLXclientState *cl, GLbyte *pc)
249
__GLX_DECLARE_SWAP_VARIABLES;
251
__GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
252
cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
257
/* Do a local glFinish */
258
CALL_Finish( GET_DISPATCH(), () );
259
__GLX_NOTE_FLUSHED_CMDS(cx);
261
/* Send empty reply packet to indicate finish is finished */
263
__GLX_BEGIN_REPLY(0);
265
__GLX_SWAP_REPLY_HEADER();
271
int __glXDispSwap_GetString(__GLXclientState *cl, GLbyte *pc)
273
return DoGetString(cl, pc, GL_TRUE);