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

« back to all changes in this revision

Viewing changes to GL/glx/glxbuf.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/glxbuf.c,v 1.6 2001/03/25 05:32:01 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
#ifdef HAVE_DIX_CONFIG_H
 
38
#include <dix-config.h>
 
39
#endif
 
40
 
 
41
#include "glxserver.h"
 
42
#include "glxutil.h"
 
43
#include "glxbuf.h"
 
44
#include "glxfb.h"
 
45
#include "glxmem.h"
 
46
#include "glxpix.h"
 
47
 
 
48
void
 
49
__glXFBInitDrawable(__GLXdrawablePrivate *glxPriv, __GLcontextModes *modes)
 
50
{
 
51
    __GLdrawablePrivate *glPriv;
 
52
    GLint rgbBits;
 
53
    GLint accumBits;
 
54
 
 
55
    glPriv = &glxPriv->glPriv;
 
56
    rgbBits = modes->rgbBits;
 
57
    accumBits = modes->accumRedBits + modes->accumGreenBits +
 
58
        modes->accumBlueBits + modes->accumAlphaBits;
 
59
 
 
60
#if defined(__GL_ALIGNED_BUFFERS)
 
61
    /* initialize pixel alignments (for more details see context.h) */
 
62
    glPriv->xAlignment = 1;
 
63
    glPriv->yAlignment = 1;
 
64
#endif
 
65
 
 
66
    glxPriv->swapBuffers = __glXFBMemSwapBuffers;
 
67
 
 
68
    glPriv->yInverted = GL_TRUE;        /* Y is upside-down */
 
69
 
 
70
    if (modes->doubleBufferMode) {
 
71
        if (modes->colorIndexMode) {
 
72
            __glXInitFB(&glPriv->frontBuffer, glPriv, modes->indexBits);
 
73
            __glXInitMem(&glPriv->backBuffer, glPriv, modes->indexBits);
 
74
        } else {
 
75
            __glXInitFB(&glPriv->frontBuffer, glPriv, rgbBits);
 
76
            __glXInitMem(&glPriv->backBuffer, glPriv, rgbBits);
 
77
        }
 
78
    } else {
 
79
        if (modes->colorIndexMode) {
 
80
            __glXInitFB(&glPriv->frontBuffer, glPriv, modes->indexBits);
 
81
        } else {
 
82
            __glXInitFB(&glPriv->frontBuffer, glPriv, rgbBits);
 
83
        }
 
84
    }
 
85
 
 
86
#if defined(__GL_MAX_AUXBUFFERS) && (__GL_MAX_AUXBUFFERS > 0)
 
87
    if (modes->maxAuxBuffers > 0) {
 
88
        GLint i;
 
89
 
 
90
        for (i=0; i < modes->maxAuxBuffers; i++) {
 
91
            if (modes->colorIndexMode) {
 
92
                __glXInitMem(&glPriv->auxBuffer[i], glPriv, modes->indexBits);
 
93
            } else {
 
94
                __glXInitMem(&glPriv->auxBuffer[i], glPriv, rgbBits);
 
95
            }
 
96
        }
 
97
    }
 
98
#endif
 
99
 
 
100
    if (modes->haveAccumBuffer) {
 
101
        __glXInitMem(&glPriv->accumBuffer, glPriv, accumBits);
 
102
    }
 
103
    if (modes->haveDepthBuffer) {
 
104
        __glXInitMem(&glPriv->depthBuffer, glPriv, modes->depthBits);
 
105
    }
 
106
    if (modes->haveStencilBuffer) {
 
107
        __glXInitMem(&glPriv->stencilBuffer, glPriv, modes->stencilBits);
 
108
    }
 
109
}
 
110
 
 
111
void
 
112
__glXPixInitDrawable(__GLXdrawablePrivate *glxPriv, __GLcontextModes *modes)
 
113
{
 
114
    __GLdrawablePrivate *glPriv;
 
115
    GLint rgbBits;
 
116
    GLint accumBits;
 
117
 
 
118
    assert(glxPriv->pGlxPixmap);
 
119
 
 
120
    glPriv = &glxPriv->glPriv;
 
121
    rgbBits = modes->rgbBits;
 
122
    accumBits = modes->accumRedBits + modes->accumGreenBits +
 
123
        modes->accumBlueBits + modes->accumAlphaBits;
 
124
 
 
125
#if defined(__GL_ALIGNED_BUFFERS)
 
126
    /* initialize pixel alignments (for more details see context.h) */
 
127
    glPriv->xAlignment = 1;
 
128
    glPriv->yAlignment = 1;
 
129
#endif
 
130
 
 
131
    glxPriv->swapBuffers = (GLboolean (*)(__GLXdrawablePrivate *))__glXNop;
 
132
 
 
133
    glPriv->yInverted = GL_FALSE;
 
134
 
 
135
    if (modes->doubleBufferMode) {
 
136
        if (modes->colorIndexMode) {
 
137
            __glXInitPix(&glPriv->frontBuffer, glPriv, rgbBits,
 
138
                         glxPriv->drawId, glxPriv->pGlxPixmap);
 
139
            __glXInitMem(&glPriv->backBuffer, glPriv, modes->indexBits);
 
140
        } else {
 
141
            __glXInitPix(&glPriv->frontBuffer, glPriv, rgbBits,
 
142
                         glxPriv->drawId, glxPriv->pGlxPixmap);
 
143
            __glXInitMem(&glPriv->backBuffer, glPriv, rgbBits);
 
144
        }
 
145
    } else {
 
146
        if (modes->colorIndexMode) {
 
147
            __glXInitPix(&glPriv->frontBuffer, glPriv, rgbBits, 
 
148
                         glxPriv->drawId, glxPriv->pGlxPixmap);
 
149
        } else {
 
150
            __glXInitPix(&glPriv->frontBuffer, glPriv, rgbBits,
 
151
                         glxPriv->drawId, glxPriv->pGlxPixmap);
 
152
        }
 
153
    }
 
154
 
 
155
#if defined(__GL_MAX_AUXBUFFERS) && (__GL_MAX_AUXBUFFERS > 0)
 
156
    if (modes->maxAuxBuffers > 0) {
 
157
        GLint i;
 
158
 
 
159
        for (i=0; i < modes->maxAuxBuffers; i++) {
 
160
            if (modes->colorIndexMode) {
 
161
                __glXInitMem(&glPriv->auxBuffer[i], glPriv, modes->indexBits);
 
162
            } else {
 
163
                __glXInitMem(&glPriv->auxBuffer[i], glPriv, rgbBits);
 
164
            }
 
165
        }
 
166
    }
 
167
#endif
 
168
 
 
169
    if (modes->haveAccumBuffer) {
 
170
        __glXInitMem(&glPriv->accumBuffer, glPriv, accumBits);
 
171
    }
 
172
    if (modes->haveDepthBuffer) {
 
173
        __glXInitMem(&glPriv->depthBuffer, glPriv, modes->depthBits);
 
174
    }
 
175
    if (modes->haveStencilBuffer) {
 
176
        __glXInitMem(&glPriv->stencilBuffer, glPriv, modes->stencilBits);
 
177
    }
 
178
}
 
179
 
 
180
 
 
181
#define __GLX_SET_ACCEL_BUFFER_MASK(bm) \
 
182
    if (status == GL_FALSE) return GL_FALSE; \
 
183
    if (status == GL_TRUE) accelBufferMask |= bm; \
 
184
    /* for __GL_BUFFER_FALLBACK don't do anything */
 
185
 
 
186
GLboolean
 
187
__glXResizeBuffers(__GLdrawablePrivate *glPriv,
 
188
                   GLint x, GLint y, GLuint width, GLuint height)
 
189
{
 
190
    __GLcontextModes *modes;
 
191
    __GLdrawableRegion *glRegion;
 
192
    GLboolean status;
 
193
    GLuint accelBufferMask;
 
194
 
 
195
    modes = glPriv->modes;
 
196
    accelBufferMask = 0;
 
197
 
 
198
    status = (*glPriv->frontBuffer.resize)(&glPriv->frontBuffer,
 
199
                                           x, y, width, height, glPriv,
 
200
                                           __GL_FRONT_BUFFER_MASK);
 
201
    __GLX_SET_ACCEL_BUFFER_MASK(__GL_FRONT_BUFFER_MASK);
 
202
 
 
203
    if (modes->doubleBufferMode) {
 
204
        status = (*glPriv->backBuffer.resize)(&glPriv->backBuffer,
 
205
                                              x, y, width, height, glPriv,
 
206
                                              __GL_BACK_BUFFER_MASK);
 
207
        __GLX_SET_ACCEL_BUFFER_MASK(__GL_BACK_BUFFER_MASK);
 
208
    }
 
209
 
 
210
#if defined(__GL_MAX_AUXBUFFERS) && (__GL_MAX_AUXBUFFERS > 0)
 
211
    if (modes->maxAuxBuffers > 0) {
 
212
        GLint i;
 
213
 
 
214
        for (i=0; i < modes->maxAuxBuffers; i++) {
 
215
            status = (*glPriv->auxBuffers[i].resize)(&glPriv->auxBuffer[i],
 
216
                                                     x, y, width, height, 
 
217
                                                     glPriv,
 
218
                                                     __GL_AUX_BUFFER_MASK(i));
 
219
            __GLX_SET_ACCEL_BUFFER_MASK(__GL_AUX_BUFFER_MASK(i));
 
220
        }
 
221
    }
 
222
#endif
 
223
 
 
224
    if (modes->haveAccumBuffer) {
 
225
        status = (*glPriv->accumBuffer.resize)(&glPriv->accumBuffer,
 
226
                                               x, y, width, height, glPriv,
 
227
                                               __GL_ACCUM_BUFFER_MASK);
 
228
        __GLX_SET_ACCEL_BUFFER_MASK(__GL_ACCUM_BUFFER_MASK);
 
229
    }
 
230
 
 
231
    if (modes->haveDepthBuffer) {
 
232
        status = (*glPriv->depthBuffer.resize)(&glPriv->depthBuffer,
 
233
                                               x, y, width, height, glPriv,
 
234
                                               __GL_DEPTH_BUFFER_MASK);
 
235
        __GLX_SET_ACCEL_BUFFER_MASK(__GL_DEPTH_BUFFER_MASK);
 
236
    }
 
237
 
 
238
    if (modes->haveStencilBuffer) {
 
239
        status = (*glPriv->stencilBuffer.resize)(&glPriv->stencilBuffer,
 
240
                                                 x, y, width, height, glPriv,
 
241
                                                 __GL_STENCIL_BUFFER_MASK);
 
242
        __GLX_SET_ACCEL_BUFFER_MASK(__GL_STENCIL_BUFFER_MASK);
 
243
    }
 
244
 
 
245
    glPriv->accelBufferMask = accelBufferMask;
 
246
 
 
247
    /* finally, update the ownership region */
 
248
    glRegion = &glPriv->ownershipRegion;
 
249
    glRegion->numRects = 1;
 
250
    glRegion->rects[0].x0 = 0;
 
251
    glRegion->rects[0].y0 = 0;
 
252
    glRegion->rects[0].x1 = width;
 
253
    glRegion->rects[0].y1 = height;
 
254
 
 
255
    return GL_TRUE;
 
256
}
 
257
 
 
258
void
 
259
__glXFreeBuffers(__GLXdrawablePrivate *glxPriv)
 
260
{
 
261
    __GLdrawablePrivate *glPriv = &glxPriv->glPriv;
 
262
#if defined(__GL_MAX_AUXBUFFERS) && (__GL_MAX_AUXBUFFERS > 0)
 
263
    __GLcontextModes *modes = glPriv->modes;
 
264
#endif
 
265
 
 
266
    if (glPriv->frontBuffer.free) {
 
267
        (*glPriv->frontBuffer.free)(&glPriv->frontBuffer, glPriv);
 
268
    }
 
269
    if (glPriv->backBuffer.free) {
 
270
        (*glPriv->backBuffer.free)(&glPriv->backBuffer, glPriv);
 
271
    }
 
272
 
 
273
#if defined(__GL_MAX_AUXBUFFERS) && (__GL_MAX_AUXBUFFERS > 0)
 
274
    if (modes->maxAuxBuffers > 0) {
 
275
        GLint i;
 
276
 
 
277
        for (i=0; i < modes->maxAuxBuffers; i++) {
 
278
            if (glPriv->auxBuffer[i].free) {
 
279
                (*glPriv->auxBuffer[i].free)(&glPriv->auxBuffer[i], glPriv);
 
280
            }
 
281
        }
 
282
    }
 
283
#endif
 
284
 
 
285
    if (glPriv->accumBuffer.free) {
 
286
        (*glPriv->accumBuffer.free)(&glPriv->accumBuffer, glPriv);
 
287
    }
 
288
 
 
289
    if (glPriv->depthBuffer.free) {
 
290
        (*glPriv->depthBuffer.free)(&glPriv->depthBuffer, glPriv);
 
291
    }
 
292
 
 
293
    if (glPriv->stencilBuffer.free) {
 
294
        (*glPriv->stencilBuffer.free)(&glPriv->stencilBuffer, glPriv);
 
295
    }
 
296
}