1
/* $XFree86: xc/programs/Xserver/GL/glx/glxbuf.c,v 1.6 2001/03/25 05:32:01 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.
37
#ifdef HAVE_DIX_CONFIG_H
38
#include <dix-config.h>
41
#include "glxserver.h"
49
__glXFBInitDrawable(__GLXdrawablePrivate *glxPriv, __GLcontextModes *modes)
51
__GLdrawablePrivate *glPriv;
55
glPriv = &glxPriv->glPriv;
56
rgbBits = modes->rgbBits;
57
accumBits = modes->accumRedBits + modes->accumGreenBits +
58
modes->accumBlueBits + modes->accumAlphaBits;
60
#if defined(__GL_ALIGNED_BUFFERS)
61
/* initialize pixel alignments (for more details see context.h) */
62
glPriv->xAlignment = 1;
63
glPriv->yAlignment = 1;
66
glxPriv->swapBuffers = __glXFBMemSwapBuffers;
68
glPriv->yInverted = GL_TRUE; /* Y is upside-down */
70
if (modes->doubleBufferMode) {
71
if (modes->colorIndexMode) {
72
__glXInitFB(&glPriv->frontBuffer, glPriv, modes->indexBits);
73
__glXInitMem(&glPriv->backBuffer, glPriv, modes->indexBits);
75
__glXInitFB(&glPriv->frontBuffer, glPriv, rgbBits);
76
__glXInitMem(&glPriv->backBuffer, glPriv, rgbBits);
79
if (modes->colorIndexMode) {
80
__glXInitFB(&glPriv->frontBuffer, glPriv, modes->indexBits);
82
__glXInitFB(&glPriv->frontBuffer, glPriv, rgbBits);
86
#if defined(__GL_MAX_AUXBUFFERS) && (__GL_MAX_AUXBUFFERS > 0)
87
if (modes->maxAuxBuffers > 0) {
90
for (i=0; i < modes->maxAuxBuffers; i++) {
91
if (modes->colorIndexMode) {
92
__glXInitMem(&glPriv->auxBuffer[i], glPriv, modes->indexBits);
94
__glXInitMem(&glPriv->auxBuffer[i], glPriv, rgbBits);
100
if (modes->haveAccumBuffer) {
101
__glXInitMem(&glPriv->accumBuffer, glPriv, accumBits);
103
if (modes->haveDepthBuffer) {
104
__glXInitMem(&glPriv->depthBuffer, glPriv, modes->depthBits);
106
if (modes->haveStencilBuffer) {
107
__glXInitMem(&glPriv->stencilBuffer, glPriv, modes->stencilBits);
112
__glXPixInitDrawable(__GLXdrawablePrivate *glxPriv, __GLcontextModes *modes)
114
__GLdrawablePrivate *glPriv;
118
assert(glxPriv->pGlxPixmap);
120
glPriv = &glxPriv->glPriv;
121
rgbBits = modes->rgbBits;
122
accumBits = modes->accumRedBits + modes->accumGreenBits +
123
modes->accumBlueBits + modes->accumAlphaBits;
125
#if defined(__GL_ALIGNED_BUFFERS)
126
/* initialize pixel alignments (for more details see context.h) */
127
glPriv->xAlignment = 1;
128
glPriv->yAlignment = 1;
131
glxPriv->swapBuffers = (GLboolean (*)(__GLXdrawablePrivate *))__glXNop;
133
glPriv->yInverted = GL_FALSE;
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);
141
__glXInitPix(&glPriv->frontBuffer, glPriv, rgbBits,
142
glxPriv->drawId, glxPriv->pGlxPixmap);
143
__glXInitMem(&glPriv->backBuffer, glPriv, rgbBits);
146
if (modes->colorIndexMode) {
147
__glXInitPix(&glPriv->frontBuffer, glPriv, rgbBits,
148
glxPriv->drawId, glxPriv->pGlxPixmap);
150
__glXInitPix(&glPriv->frontBuffer, glPriv, rgbBits,
151
glxPriv->drawId, glxPriv->pGlxPixmap);
155
#if defined(__GL_MAX_AUXBUFFERS) && (__GL_MAX_AUXBUFFERS > 0)
156
if (modes->maxAuxBuffers > 0) {
159
for (i=0; i < modes->maxAuxBuffers; i++) {
160
if (modes->colorIndexMode) {
161
__glXInitMem(&glPriv->auxBuffer[i], glPriv, modes->indexBits);
163
__glXInitMem(&glPriv->auxBuffer[i], glPriv, rgbBits);
169
if (modes->haveAccumBuffer) {
170
__glXInitMem(&glPriv->accumBuffer, glPriv, accumBits);
172
if (modes->haveDepthBuffer) {
173
__glXInitMem(&glPriv->depthBuffer, glPriv, modes->depthBits);
175
if (modes->haveStencilBuffer) {
176
__glXInitMem(&glPriv->stencilBuffer, glPriv, modes->stencilBits);
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 */
187
__glXResizeBuffers(__GLdrawablePrivate *glPriv,
188
GLint x, GLint y, GLuint width, GLuint height)
190
__GLcontextModes *modes;
191
__GLdrawableRegion *glRegion;
193
GLuint accelBufferMask;
195
modes = glPriv->modes;
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);
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);
210
#if defined(__GL_MAX_AUXBUFFERS) && (__GL_MAX_AUXBUFFERS > 0)
211
if (modes->maxAuxBuffers > 0) {
214
for (i=0; i < modes->maxAuxBuffers; i++) {
215
status = (*glPriv->auxBuffers[i].resize)(&glPriv->auxBuffer[i],
218
__GL_AUX_BUFFER_MASK(i));
219
__GLX_SET_ACCEL_BUFFER_MASK(__GL_AUX_BUFFER_MASK(i));
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);
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);
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);
245
glPriv->accelBufferMask = accelBufferMask;
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;
259
__glXFreeBuffers(__GLXdrawablePrivate *glxPriv)
261
__GLdrawablePrivate *glPriv = &glxPriv->glPriv;
262
#if defined(__GL_MAX_AUXBUFFERS) && (__GL_MAX_AUXBUFFERS > 0)
263
__GLcontextModes *modes = glPriv->modes;
266
if (glPriv->frontBuffer.free) {
267
(*glPriv->frontBuffer.free)(&glPriv->frontBuffer, glPriv);
269
if (glPriv->backBuffer.free) {
270
(*glPriv->backBuffer.free)(&glPriv->backBuffer, glPriv);
273
#if defined(__GL_MAX_AUXBUFFERS) && (__GL_MAX_AUXBUFFERS > 0)
274
if (modes->maxAuxBuffers > 0) {
277
for (i=0; i < modes->maxAuxBuffers; i++) {
278
if (glPriv->auxBuffer[i].free) {
279
(*glPriv->auxBuffer[i].free)(&glPriv->auxBuffer[i], glPriv);
285
if (glPriv->accumBuffer.free) {
286
(*glPriv->accumBuffer.free)(&glPriv->accumBuffer, glPriv);
289
if (glPriv->depthBuffer.free) {
290
(*glPriv->depthBuffer.free)(&glPriv->depthBuffer, glPriv);
293
if (glPriv->stencilBuffer.free) {
294
(*glPriv->stencilBuffer.free)(&glPriv->stencilBuffer, glPriv);