s_clear.c revision 7f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298
1e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
2e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Mesa 3-D graphics library
3810e0549afad45469bef532c1f2d355f3fde0bbbBrian * Version:  7.1
422144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *
5810e0549afad45469bef532c1f2d355f3fde0bbbBrian * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *
7e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
8e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * copy of this software and associated documentation files (the "Software"),
9e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * to deal in the Software without restriction, including without limitation
10e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * and/or sell copies of the Software, and to permit persons to whom the
12e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Software is furnished to do so, subject to the following conditions:
1322144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *
14e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * The above copyright notice and this permission notice shall be included
15e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * in all copies or substantial portions of the Software.
1622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *
17e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
24e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
25bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/glheader.h"
26bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/colormac.h"
27ab26682eb4db0dbe160b13f1e320ec9164c3afc5Brian Paul#include "main/condrender.h"
28bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/macros.h"
29bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/imports.h"
30bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/mtypes.h"
31e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
32e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_accum.h"
33709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell#include "s_context.h"
34e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_depth.h"
35e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_masking.h"
36e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_stencil.h"
37e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
38e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
39894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul/**
40e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul * Clear the color buffer when glColorMask is in effect.
41e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
42e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwellstatic void
43f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergclear_rgba_buffer_with_masking(struct gl_context *ctx, struct gl_renderbuffer *rb,
44fd5511d27fc44096117c47ab503fb5b47f993061Brian Paul                               GLuint buf)
45e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{
461e1aac034c986a08248861363c0baa27dc2ae2d5Keith Whitwell   const GLint x = ctx->DrawBuffer->_Xmin;
471e1aac034c986a08248861363c0baa27dc2ae2d5Keith Whitwell   const GLint y = ctx->DrawBuffer->_Ymin;
481e1aac034c986a08248861363c0baa27dc2ae2d5Keith Whitwell   const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
491e1aac034c986a08248861363c0baa27dc2ae2d5Keith Whitwell   const GLint width  = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
50cdb27e8242215271364602995d85607cfc06d441Brian Paul   SWspan span;
51e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul   GLint i;
52e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
53863bd565204c7fec515457dfd6c59066309cb136Brian Paul   ASSERT(rb->PutRow);
54e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul
55f11508c29f4e2cbe50c5580e054342a4c3ddb4c0Brian Paul   /* Initialize color span with clear color */
56524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul   /* XXX optimize for clearcolor == black/zero (bzero) */
57f4b103dc993491355ec3e3640d9cb060138175c2Brian   INIT_SPAN(span, GL_BITMAP);
58f4b103dc993491355ec3e3640d9cb060138175c2Brian   span.end = width;
59f4b103dc993491355ec3e3640d9cb060138175c2Brian   span.arrayMask = SPAN_RGBA;
60524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul   span.array->ChanType = rb->DataType;
61524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul   if (span.array->ChanType == GL_UNSIGNED_BYTE) {
62524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      GLubyte clearColor[4];
63524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      UNCLAMPED_FLOAT_TO_UBYTE(clearColor[RCOMP], ctx->Color.ClearColor[0]);
64524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      UNCLAMPED_FLOAT_TO_UBYTE(clearColor[GCOMP], ctx->Color.ClearColor[1]);
65524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      UNCLAMPED_FLOAT_TO_UBYTE(clearColor[BCOMP], ctx->Color.ClearColor[2]);
66524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      UNCLAMPED_FLOAT_TO_UBYTE(clearColor[ACOMP], ctx->Color.ClearColor[3]);
67524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      for (i = 0; i < width; i++) {
68524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul         COPY_4UBV(span.array->rgba[i], clearColor);
69524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      }
70524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul   }
71524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul   else if (span.array->ChanType == GL_UNSIGNED_SHORT) {
72524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      GLushort clearColor[4];
73524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      UNCLAMPED_FLOAT_TO_USHORT(clearColor[RCOMP], ctx->Color.ClearColor[0]);
74524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      UNCLAMPED_FLOAT_TO_USHORT(clearColor[GCOMP], ctx->Color.ClearColor[1]);
75524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      UNCLAMPED_FLOAT_TO_USHORT(clearColor[BCOMP], ctx->Color.ClearColor[2]);
76524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      UNCLAMPED_FLOAT_TO_USHORT(clearColor[ACOMP], ctx->Color.ClearColor[3]);
77524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      for (i = 0; i < width; i++) {
78b30898f4ab533085d97a33638ad0a1cf9ddb1d67Karl Schultz         COPY_4V_CAST(span.array->rgba[i], clearColor, GLchan);
79524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      }
80524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul   }
81524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul   else {
82524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      ASSERT(span.array->ChanType == GL_FLOAT);
83524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      for (i = 0; i < width; i++) {
847e85b0a025a82c3ffed060a757a3b4adae03d269Brian         CLAMPED_FLOAT_TO_CHAN(span.array->rgba[i][0], ctx->Color.ClearColor[0]);
857e85b0a025a82c3ffed060a757a3b4adae03d269Brian         CLAMPED_FLOAT_TO_CHAN(span.array->rgba[i][1], ctx->Color.ClearColor[1]);
867e85b0a025a82c3ffed060a757a3b4adae03d269Brian         CLAMPED_FLOAT_TO_CHAN(span.array->rgba[i][2], ctx->Color.ClearColor[2]);
877e85b0a025a82c3ffed060a757a3b4adae03d269Brian         CLAMPED_FLOAT_TO_CHAN(span.array->rgba[i][3], ctx->Color.ClearColor[3]);
88524bf7bbcf75bc4887dbc0f2f87ed79a8c44ab20Brian Paul      }
89f11508c29f4e2cbe50c5580e054342a4c3ddb4c0Brian Paul   }
90f11508c29f4e2cbe50c5580e054342a4c3ddb4c0Brian Paul
91f11508c29f4e2cbe50c5580e054342a4c3ddb4c0Brian Paul   /* Note that masking will change the color values, but only the
92f11508c29f4e2cbe50c5580e054342a4c3ddb4c0Brian Paul    * channels for which the write mask is GL_FALSE.  The channels
93f11508c29f4e2cbe50c5580e054342a4c3ddb4c0Brian Paul    * which which are write-enabled won't get modified.
94f11508c29f4e2cbe50c5580e054342a4c3ddb4c0Brian Paul    */
95e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul   for (i = 0; i < height; i++) {
9643715c711d2c1d1e7624cd7c9c8a44b8866510fdBrian Paul      span.x = x;
9743715c711d2c1d1e7624cd7c9c8a44b8866510fdBrian Paul      span.y = y + i;
98fd5511d27fc44096117c47ab503fb5b47f993061Brian Paul      _swrast_mask_rgba_span(ctx, rb, &span, buf);
9943715c711d2c1d1e7624cd7c9c8a44b8866510fdBrian Paul      /* write masked row */
100f11508c29f4e2cbe50c5580e054342a4c3ddb4c0Brian Paul      rb->PutRow(ctx, rb, width, x, y + i, span.array->rgba, NULL);
101e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
102e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul}
103e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul
104e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul
105e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul/**
106e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul * Clear an rgba color buffer without channel masking.
107e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
108e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwellstatic void
109f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergclear_rgba_buffer(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint buf)
110e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{
1111e1aac034c986a08248861363c0baa27dc2ae2d5Keith Whitwell   const GLint x = ctx->DrawBuffer->_Xmin;
1121e1aac034c986a08248861363c0baa27dc2ae2d5Keith Whitwell   const GLint y = ctx->DrawBuffer->_Ymin;
1131e1aac034c986a08248861363c0baa27dc2ae2d5Keith Whitwell   const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
1141e1aac034c986a08248861363c0baa27dc2ae2d5Keith Whitwell   const GLint width  = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
115863bd565204c7fec515457dfd6c59066309cb136Brian Paul   GLubyte clear8[4];
116863bd565204c7fec515457dfd6c59066309cb136Brian Paul   GLushort clear16[4];
117863bd565204c7fec515457dfd6c59066309cb136Brian Paul   GLvoid *clearVal;
118e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul   GLint i;
119e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul
120fd5511d27fc44096117c47ab503fb5b47f993061Brian Paul   ASSERT(ctx->Color.ColorMask[buf][0] &&
121fd5511d27fc44096117c47ab503fb5b47f993061Brian Paul          ctx->Color.ColorMask[buf][1] &&
122fd5511d27fc44096117c47ab503fb5b47f993061Brian Paul          ctx->Color.ColorMask[buf][2] &&
123fd5511d27fc44096117c47ab503fb5b47f993061Brian Paul          ctx->Color.ColorMask[buf][3]);
124e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul
125863bd565204c7fec515457dfd6c59066309cb136Brian Paul   ASSERT(rb->PutMonoRow);
126863bd565204c7fec515457dfd6c59066309cb136Brian Paul
127863bd565204c7fec515457dfd6c59066309cb136Brian Paul   switch (rb->DataType) {
128e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul      case GL_UNSIGNED_BYTE:
129cfca72cfb19367d824a3254b40566b3fc01723eaBrian Paul         UNCLAMPED_FLOAT_TO_UBYTE(clear8[0], ctx->Color.ClearColor[0]);
130cfca72cfb19367d824a3254b40566b3fc01723eaBrian Paul         UNCLAMPED_FLOAT_TO_UBYTE(clear8[1], ctx->Color.ClearColor[1]);
131cfca72cfb19367d824a3254b40566b3fc01723eaBrian Paul         UNCLAMPED_FLOAT_TO_UBYTE(clear8[2], ctx->Color.ClearColor[2]);
132cfca72cfb19367d824a3254b40566b3fc01723eaBrian Paul         UNCLAMPED_FLOAT_TO_UBYTE(clear8[3], ctx->Color.ClearColor[3]);
133e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul         clearVal = clear8;
134e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul         break;
135e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul      case GL_UNSIGNED_SHORT:
136cfca72cfb19367d824a3254b40566b3fc01723eaBrian Paul         UNCLAMPED_FLOAT_TO_USHORT(clear16[0], ctx->Color.ClearColor[0]);
137cfca72cfb19367d824a3254b40566b3fc01723eaBrian Paul         UNCLAMPED_FLOAT_TO_USHORT(clear16[1], ctx->Color.ClearColor[1]);
138cfca72cfb19367d824a3254b40566b3fc01723eaBrian Paul         UNCLAMPED_FLOAT_TO_USHORT(clear16[2], ctx->Color.ClearColor[2]);
139cfca72cfb19367d824a3254b40566b3fc01723eaBrian Paul         UNCLAMPED_FLOAT_TO_USHORT(clear16[3], ctx->Color.ClearColor[3]);
140e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul         clearVal = clear16;
141e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul         break;
142e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul      case GL_FLOAT:
143e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul         clearVal = ctx->Color.ClearColor;
144e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul         break;
145e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul      default:
146e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul         _mesa_problem(ctx, "Bad rb DataType in clear_color_buffer");
147e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul         return;
148e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul   }
149863bd565204c7fec515457dfd6c59066309cb136Brian Paul
150863bd565204c7fec515457dfd6c59066309cb136Brian Paul   for (i = 0; i < height; i++) {
151863bd565204c7fec515457dfd6c59066309cb136Brian Paul      rb->PutMonoRow(ctx, rb, width, x, y + i, clearVal, NULL);
152e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
153e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul}
154e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul
155e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul
156e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul/**
157894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul * Clear the front/back/left/right/aux color buffers.
158894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul * This function is usually only called if the device driver can't
159894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul * clear its own color buffers for some reason (such as with masking).
160e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
161e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwellstatic void
162f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergclear_color_buffers(struct gl_context *ctx)
163e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{
164ff73c783cc47361ff0dd819c82d067b4b85870ddBrian   GLuint buf;
165e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
166ff73c783cc47361ff0dd819c82d067b4b85870ddBrian   for (buf = 0; buf < ctx->DrawBuffer->_NumColorDrawBuffers; buf++) {
167ff73c783cc47361ff0dd819c82d067b4b85870ddBrian      struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[buf];
1687f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick
1697f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick      /* If this is an ES2 context or GL_ARB_ES2_compatibility is supported,
1707f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick       * the framebuffer can be complete with some attachments be missing.  In
1717f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick       * this case the _ColorDrawBuffers pointer will be NULL.
1727f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick       */
1737f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick      if (rb == NULL)
1747f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick	 continue;
1757f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick
1769e2d30e0b8242d1e4afcf05513bd3d7e0de504a2Ian Romanick      if (ctx->Color.ColorMask[buf][0] == 0 ||
1779e2d30e0b8242d1e4afcf05513bd3d7e0de504a2Ian Romanick          ctx->Color.ColorMask[buf][1] == 0 ||
1789e2d30e0b8242d1e4afcf05513bd3d7e0de504a2Ian Romanick          ctx->Color.ColorMask[buf][2] == 0 ||
1799e2d30e0b8242d1e4afcf05513bd3d7e0de504a2Ian Romanick          ctx->Color.ColorMask[buf][3] == 0) {
1809e2d30e0b8242d1e4afcf05513bd3d7e0de504a2Ian Romanick         clear_rgba_buffer_with_masking(ctx, rb, buf);
181e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul      }
182e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul      else {
1839e2d30e0b8242d1e4afcf05513bd3d7e0de504a2Ian Romanick         clear_rgba_buffer(ctx, rb, buf);
184e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      }
185e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
186e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell}
187e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
188e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
189894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul/**
190894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul * Called via the device driver's ctx->Driver.Clear() function if the
191894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul * device driver can't clear one or more of the buffers itself.
192a5676795cfe2e24979b5da65c2f499049ab009d9Brian Paul * \param buffers  bitfield of BUFFER_BIT_* values indicating which
193a5676795cfe2e24979b5da65c2f499049ab009d9Brian Paul *                 renderbuffers are to be cleared.
194894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul * \param all  if GL_TRUE, clear whole buffer, else clear specified region.
195894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul */
19622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughesvoid
197f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_swrast_Clear(struct gl_context *ctx, GLbitfield buffers)
198e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{
199e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul#ifdef DEBUG_FOO
200e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   {
201894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul      const GLbitfield legalBits =
202e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul         BUFFER_BIT_FRONT_LEFT |
203e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul	 BUFFER_BIT_FRONT_RIGHT |
204e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul	 BUFFER_BIT_BACK_LEFT |
205e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul	 BUFFER_BIT_BACK_RIGHT |
206e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul	 BUFFER_BIT_DEPTH |
207e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul	 BUFFER_BIT_STENCIL |
208e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul	 BUFFER_BIT_ACCUM |
209555f0a88182e2b1af809b2d97abdac02814a2f28Brian Paul         BUFFER_BIT_AUX0;
210a5676795cfe2e24979b5da65c2f499049ab009d9Brian Paul      assert((buffers & (~legalBits)) == 0);
211e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
212e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#endif
213e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
214ab26682eb4db0dbe160b13f1e320ec9164c3afc5Brian Paul   if (!_mesa_check_conditional_render(ctx))
215ab26682eb4db0dbe160b13f1e320ec9164c3afc5Brian Paul      return; /* don't clear */
216ab26682eb4db0dbe160b13f1e320ec9164c3afc5Brian Paul
2172d5b86be25a7ccb729e746aa5e1bdd537d76df68Brian Paul   swrast_render_start(ctx);
218e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
219e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   /* do software clearing here */
220a5676795cfe2e24979b5da65c2f499049ab009d9Brian Paul   if (buffers) {
221810e0549afad45469bef532c1f2d355f3fde0bbbBrian      if ((buffers & BUFFER_BITS_COLOR)
222810e0549afad45469bef532c1f2d355f3fde0bbbBrian          && (ctx->DrawBuffer->_NumColorDrawBuffers > 0)) {
223894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul         clear_color_buffers(ctx);
224894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul      }
225a5676795cfe2e24979b5da65c2f499049ab009d9Brian Paul      if (buffers & BUFFER_BIT_DEPTH) {
2261a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul         _swrast_clear_depth_buffer(ctx, ctx->DrawBuffer->_DepthBuffer);
227894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul      }
228a5676795cfe2e24979b5da65c2f499049ab009d9Brian Paul      if (buffers & BUFFER_BIT_ACCUM) {
2291a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul         _swrast_clear_accum_buffer(ctx,
2301a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul                       ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
231894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul      }
232a5676795cfe2e24979b5da65c2f499049ab009d9Brian Paul      if (buffers & BUFFER_BIT_STENCIL) {
2331a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul         _swrast_clear_stencil_buffer(ctx, ctx->DrawBuffer->_StencilBuffer);
234894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul      }
235e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
236e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
2372d5b86be25a7ccb729e746aa5e1bdd537d76df68Brian Paul   swrast_render_finish(ctx);
238e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell}
239