~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to GL/glx/single2swap.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/GL/glx/single2swap.c,v 1.7 2002/01/14 22:47:08 tsi Exp $ */
 
2
/*
 
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:
 
10
** 
 
11
** http://oss.sgi.com/projects/FreeB
 
12
** 
 
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.
 
18
** 
 
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.
 
24
** 
 
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.
 
34
**
 
35
*/
 
36
 
 
37
#define NEED_REPLIES
 
38
#ifdef HAVE_DIX_CONFIG_H
 
39
#include <dix-config.h>
 
40
#endif
 
41
 
 
42
#include "glxserver.h"
 
43
#include "glxutil.h"
 
44
#include "glxext.h"
 
45
#include "indirect_dispatch.h"
 
46
#include "unpack.h"
 
47
#include "GL/glx_ansic.h"
 
48
#include "glapitable.h"
 
49
#include "glapi.h"
 
50
#include "glthread.h"
 
51
#include "dispatch.h"
 
52
 
 
53
int __glXDispSwap_FeedbackBuffer(__GLXclientState *cl, GLbyte *pc)
 
54
{
 
55
    GLsizei size;
 
56
    GLenum type;
 
57
    __GLX_DECLARE_SWAP_VARIABLES;
 
58
    __GLXcontext *cx;
 
59
    int error;
 
60
 
 
61
    __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
 
62
    cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
 
63
    if (!cx) {
 
64
        return error;
 
65
    }
 
66
 
 
67
    pc += __GLX_SINGLE_HDR_SIZE;
 
68
    __GLX_SWAP_INT(pc+0);
 
69
    __GLX_SWAP_INT(pc+4);
 
70
    size = *(GLsizei *)(pc+0);
 
71
    type = *(GLenum *)(pc+4);
 
72
    if (cx->feedbackBufSize < size) {
 
73
        cx->feedbackBuf = (GLfloat *) __glXRealloc(cx->feedbackBuf,
 
74
                                                   (size_t) size 
 
75
                                                   * __GLX_SIZE_FLOAT32);
 
76
        if (!cx->feedbackBuf) {
 
77
            cl->client->errorValue = size;
 
78
            return BadAlloc;
 
79
        }
 
80
        cx->feedbackBufSize = size;
 
81
    }
 
82
    CALL_FeedbackBuffer( GET_DISPATCH(), (size, type, cx->feedbackBuf) );
 
83
    __GLX_NOTE_UNFLUSHED_CMDS(cx);
 
84
    return Success;
 
85
}
 
86
 
 
87
int __glXDispSwap_SelectBuffer(__GLXclientState *cl, GLbyte *pc)
 
88
{
 
89
    __GLXcontext *cx;
 
90
    GLsizei size;
 
91
    __GLX_DECLARE_SWAP_VARIABLES;
 
92
    int error;
 
93
 
 
94
    __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
 
95
    cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
 
96
    if (!cx) {
 
97
        return error;
 
98
    }
 
99
 
 
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,
 
105
                                                (size_t) size 
 
106
                                                * __GLX_SIZE_CARD32);
 
107
        if (!cx->selectBuf) {
 
108
            cl->client->errorValue = size;
 
109
            return BadAlloc;
 
110
        }
 
111
        cx->selectBufSize = size;
 
112
    }
 
113
    CALL_SelectBuffer( GET_DISPATCH(), (size, cx->selectBuf) );
 
114
    __GLX_NOTE_UNFLUSHED_CMDS(cx);
 
115
    return Success;
 
116
}
 
117
 
 
118
int __glXDispSwap_RenderMode(__GLXclientState *cl, GLbyte *pc)
 
119
{
 
120
    ClientPtr client;
 
121
    __GLXcontext *cx;
 
122
    xGLXRenderModeReply reply;
 
123
    GLint nitems=0, retBytes=0, retval, newModeCheck;
 
124
    GLubyte *retBuffer = NULL;
 
125
    GLenum newMode;
 
126
    __GLX_DECLARE_SWAP_VARIABLES;
 
127
    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
128
    int error;
 
129
 
 
130
    __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
 
131
    cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
 
132
    if (!cx) {
 
133
        return error;
 
134
    }
 
135
 
 
136
    pc += __GLX_SINGLE_HDR_SIZE;
 
137
    __GLX_SWAP_INT(pc);
 
138
    newMode = *(GLenum*) pc;
 
139
    retval = CALL_RenderMode( GET_DISPATCH(), (newMode) );
 
140
 
 
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;
 
147
    }
 
148
 
 
149
    /*
 
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.
 
153
    */
 
154
 
 
155
    switch (cx->renderMode) {
 
156
      case GL_RENDER:
 
157
        cx->renderMode = newMode;
 
158
        break;
 
159
      case GL_FEEDBACK:
 
160
        if (retval < 0) {
 
161
            /* Overflow happened. Copy the entire buffer */
 
162
            nitems = cx->feedbackBufSize;
 
163
        } else {
 
164
            nitems = retval;
 
165
        }
 
166
        retBytes = nitems * __GLX_SIZE_FLOAT32;
 
167
        retBuffer = (GLubyte*) cx->feedbackBuf;
 
168
        __GLX_SWAP_FLOAT_ARRAY((GLbyte *)retBuffer, nitems);
 
169
        cx->renderMode = newMode;
 
170
        break;
 
171
      case GL_SELECT:
 
172
        if (retval < 0) {
 
173
            /* Overflow happened.  Copy the entire buffer */
 
174
            nitems = cx->selectBufSize;
 
175
        } else {
 
176
            GLuint *bp = cx->selectBuf;
 
177
            GLint i;
 
178
 
 
179
            /*
 
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.
 
184
            */
 
185
            nitems = 0;
 
186
            i = retval;
 
187
            while (--i >= 0) {
 
188
                GLuint n;
 
189
 
 
190
                /* Parse select data for this hit */
 
191
                n = *bp;
 
192
                bp += 3 + n;
 
193
            }
 
194
            nitems = bp - cx->selectBuf;
 
195
        }
 
196
        retBytes = nitems * __GLX_SIZE_CARD32;
 
197
        retBuffer = (GLubyte*) cx->selectBuf;
 
198
        __GLX_SWAP_INT_ARRAY((GLbyte *)retBuffer, nitems);
 
199
        cx->renderMode = newMode;
 
200
        break;
 
201
    }
 
202
 
 
203
    /*
 
204
    ** First reply is the number of elements returned in the feedback or
 
205
    ** selection array, as per the API for glRenderMode itself.
 
206
    */
 
207
  noChangeAllowed:;
 
208
    client = cl->client;
 
209
    reply.length = nitems;
 
210
    reply.type = X_Reply;
 
211
    reply.sequenceNumber = client->sequence;
 
212
    reply.retval = retval;
 
213
    reply.size = nitems;
 
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);
 
221
    if (retBytes) {
 
222
        WriteToClient(client, retBytes, (char *)retBuffer);
 
223
    }
 
224
    return Success;
 
225
}
 
226
 
 
227
int __glXDispSwap_Flush(__GLXclientState *cl, GLbyte *pc)
 
228
{
 
229
        __GLXcontext *cx;
 
230
        int error;
 
231
        __GLX_DECLARE_SWAP_VARIABLES;
 
232
 
 
233
        __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
 
234
        cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
 
235
        if (!cx) {
 
236
                return error;
 
237
        }
 
238
 
 
239
        CALL_Flush( GET_DISPATCH(), () );
 
240
        __GLX_NOTE_FLUSHED_CMDS(cx);
 
241
        return Success;
 
242
}
 
243
 
 
244
int __glXDispSwap_Finish(__GLXclientState *cl, GLbyte *pc)
 
245
{
 
246
    __GLXcontext *cx;
 
247
    ClientPtr client;
 
248
    int error;
 
249
    __GLX_DECLARE_SWAP_VARIABLES;
 
250
 
 
251
    __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
 
252
    cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
 
253
    if (!cx) {
 
254
        return error;
 
255
    }
 
256
 
 
257
    /* Do a local glFinish */
 
258
    CALL_Finish( GET_DISPATCH(), () );
 
259
    __GLX_NOTE_FLUSHED_CMDS(cx);
 
260
 
 
261
    /* Send empty reply packet to indicate finish is finished */
 
262
    client = cl->client;
 
263
    __GLX_BEGIN_REPLY(0);
 
264
    __GLX_PUT_RETVAL(0);
 
265
    __GLX_SWAP_REPLY_HEADER();
 
266
    __GLX_SEND_HEADER();
 
267
 
 
268
    return Success;
 
269
}
 
270
 
 
271
int __glXDispSwap_GetString(__GLXclientState *cl, GLbyte *pc)
 
272
{
 
273
    return DoGetString(cl, pc, GL_TRUE);
 
274
}