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" 26122c6768e3d4c1d1b57203eca70569f9301baab5Brian Paul#include "main/accum.h" 27ab26682eb4db0dbe160b13f1e320ec9164c3afc5Brian Paul#include "main/condrender.h" 28c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul#include "main/format_pack.h" 29bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/macros.h" 30bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/imports.h" 31bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/mtypes.h" 32e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 33709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell#include "s_context.h" 34e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_depth.h" 35e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_stencil.h" 36e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 37e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 38c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul 39894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul/** 40c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul * Clear an rgba color buffer with masking if needed. 41e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */ 42e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwellstatic void 43c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paulclear_rgba_buffer(struct gl_context *ctx, struct gl_renderbuffer *rb, 44c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul const GLubyte colorMask[4]) 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; 50c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul const GLuint pixelSize = _mesa_get_format_bytes(rb->Format); 51c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul const GLboolean doMasking = (colorMask[0] == 0 || 52c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul colorMask[1] == 0 || 53c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul colorMask[2] == 0 || 54c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul colorMask[3] == 0); 55c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul const GLfloat (*clearColor)[4] = 56c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul (const GLfloat (*)[4]) ctx->Color.ClearColor.f; 57c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul GLbitfield mapMode = GL_MAP_WRITE_BIT; 58c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul GLubyte *map; 59c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul GLint rowStride; 60c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul GLint i, j; 61e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul 62c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul if (doMasking) { 63c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul /* we'll need to read buffer values too */ 64c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul mapMode |= GL_MAP_READ_BIT; 65f11508c29f4e2cbe50c5580e054342a4c3ddb4c0Brian Paul } 66f11508c29f4e2cbe50c5580e054342a4c3ddb4c0Brian Paul 67c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul /* map dest buffer */ 68c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, 69c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul mapMode, &map, &rowStride); 70c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul if (!map) { 71c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul _mesa_error(ctx, GL_OUT_OF_MEMORY, "glClear(color)"); 72c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul return; 73e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 74e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul 75c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul /* for 1, 2, 4-byte clearing */ 76c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul#define SIMPLE_TYPE_CLEAR(TYPE) \ 77c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul do { \ 78c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul TYPE pixel, pixelMask; \ 79c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul _mesa_pack_float_rgba_row(rb->Format, 1, clearColor, &pixel); \ 80c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul if (doMasking) { \ 81c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul _mesa_pack_colormask(rb->Format, colorMask, &pixelMask); \ 82c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul pixel &= pixelMask; \ 83c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul pixelMask = ~pixelMask; \ 84c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } \ 85c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul for (i = 0; i < height; i++) { \ 86c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul TYPE *row = (TYPE *) map; \ 87c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul if (doMasking) { \ 88c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul for (j = 0; j < width; j++) { \ 89c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul row[j] = (row[j] & pixelMask) | pixel; \ 90c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } \ 91c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } \ 92c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul else { \ 93c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul for (j = 0; j < width; j++) { \ 94c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul row[j] = pixel; \ 95c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } \ 96c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } \ 97c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul map += rowStride; \ 98c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } \ 99c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } while (0) 100e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul 101e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul 102c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul /* for 3, 6, 8, 12, 16-byte clearing */ 103c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul#define MULTI_WORD_CLEAR(TYPE, N) \ 104c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul do { \ 105c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul TYPE pixel[N], pixelMask[N]; \ 106c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul GLuint k; \ 107c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul _mesa_pack_float_rgba_row(rb->Format, 1, clearColor, pixel); \ 108c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul if (doMasking) { \ 109c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul _mesa_pack_colormask(rb->Format, colorMask, pixelMask); \ 110c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul for (k = 0; k < N; k++) { \ 111c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul pixel[k] &= pixelMask[k]; \ 112c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul pixelMask[k] = ~pixelMask[k]; \ 113c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } \ 114c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } \ 115c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul for (i = 0; i < height; i++) { \ 116c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul TYPE *row = (TYPE *) map; \ 117c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul if (doMasking) { \ 118c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul for (j = 0; j < width; j++) { \ 119c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul for (k = 0; k < N; k++) { \ 120c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul row[j * N + k] = \ 121c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul (row[j * N + k] & pixelMask[k]) | pixel[k]; \ 122c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } \ 123c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } \ 124c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } \ 125c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul else { \ 126c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul for (j = 0; j < width; j++) { \ 127c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul for (k = 0; k < N; k++) { \ 128c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul row[j * N + k] = pixel[k]; \ 129c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } \ 130c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } \ 131c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } \ 132c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul map += rowStride; \ 133c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } \ 134c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul } while(0) 135863bd565204c7fec515457dfd6c59066309cb136Brian Paul 136c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul switch (pixelSize) { 137c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul case 1: 138c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul SIMPLE_TYPE_CLEAR(GLubyte); 139c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul break; 140c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul case 2: 141c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul SIMPLE_TYPE_CLEAR(GLushort); 142c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul break; 143c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul case 3: 144c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul MULTI_WORD_CLEAR(GLubyte, 3); 145c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul break; 146c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul case 4: 147c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul SIMPLE_TYPE_CLEAR(GLuint); 148c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul break; 149c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul case 6: 150c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul MULTI_WORD_CLEAR(GLushort, 3); 151c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul break; 152c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul case 8: 153c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul MULTI_WORD_CLEAR(GLuint, 2); 154c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul break; 155c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul case 12: 156c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul MULTI_WORD_CLEAR(GLuint, 3); 157c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul break; 158c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul case 16: 159c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul MULTI_WORD_CLEAR(GLuint, 4); 160c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul break; 161c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul default: 162c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul _mesa_problem(ctx, "bad pixel size in clear_rgba_buffer()"); 163e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul } 164863bd565204c7fec515457dfd6c59066309cb136Brian Paul 165c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul /* unmap buffer */ 166c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul ctx->Driver.UnmapRenderbuffer(ctx, rb); 167e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul} 168e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul 169e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul 170e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul/** 171894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul * Clear the front/back/left/right/aux color buffers. 172894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul * This function is usually only called if the device driver can't 173894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul * clear its own color buffers for some reason (such as with masking). 174e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */ 175e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwellstatic void 176f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergclear_color_buffers(struct gl_context *ctx) 177e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{ 178ff73c783cc47361ff0dd819c82d067b4b85870ddBrian GLuint buf; 179e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 180ff73c783cc47361ff0dd819c82d067b4b85870ddBrian for (buf = 0; buf < ctx->DrawBuffer->_NumColorDrawBuffers; buf++) { 181ff73c783cc47361ff0dd819c82d067b4b85870ddBrian struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[buf]; 1827f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick 1837f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick /* If this is an ES2 context or GL_ARB_ES2_compatibility is supported, 1847f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick * the framebuffer can be complete with some attachments be missing. In 1857f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick * this case the _ColorDrawBuffers pointer will be NULL. 1867f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick */ 1877f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick if (rb == NULL) 1887f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick continue; 1897f9c17aaa82f5a8a1d5f077eba4d5889d3c3b298Ian Romanick 190c4b5f0cadb18bad22b4c28424723a09832209c6fBrian Paul clear_rgba_buffer(ctx, rb, ctx->Color.ColorMask[buf]); 191e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 192e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell} 193e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 194e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 195894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul/** 196894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul * Called via the device driver's ctx->Driver.Clear() function if the 197894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul * device driver can't clear one or more of the buffers itself. 198a5676795cfe2e24979b5da65c2f499049ab009d9Brian Paul * \param buffers bitfield of BUFFER_BIT_* values indicating which 199a5676795cfe2e24979b5da65c2f499049ab009d9Brian Paul * renderbuffers are to be cleared. 200894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul * \param all if GL_TRUE, clear whole buffer, else clear specified region. 201894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul */ 20222144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughesvoid 203f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_swrast_Clear(struct gl_context *ctx, GLbitfield buffers) 204e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{ 205fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul const GLbitfield BUFFER_DS = BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL; 206fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul 207e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul#ifdef DEBUG_FOO 208e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell { 209894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul const GLbitfield legalBits = 210e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul BUFFER_BIT_FRONT_LEFT | 211e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul BUFFER_BIT_FRONT_RIGHT | 212e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul BUFFER_BIT_BACK_LEFT | 213e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul BUFFER_BIT_BACK_RIGHT | 214e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul BUFFER_BIT_DEPTH | 215e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul BUFFER_BIT_STENCIL | 216e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul BUFFER_BIT_ACCUM | 217555f0a88182e2b1af809b2d97abdac02814a2f28Brian Paul BUFFER_BIT_AUX0; 218a5676795cfe2e24979b5da65c2f499049ab009d9Brian Paul assert((buffers & (~legalBits)) == 0); 219e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 220e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#endif 221e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 222ab26682eb4db0dbe160b13f1e320ec9164c3afc5Brian Paul if (!_mesa_check_conditional_render(ctx)) 223ab26682eb4db0dbe160b13f1e320ec9164c3afc5Brian Paul return; /* don't clear */ 224ab26682eb4db0dbe160b13f1e320ec9164c3afc5Brian Paul 22522e806f57013b2c116b5bfab228e0f28e25198f4Brian Paul if (SWRAST_CONTEXT(ctx)->NewState) 22622e806f57013b2c116b5bfab228e0f28e25198f4Brian Paul _swrast_validate_derived(ctx); 22722e806f57013b2c116b5bfab228e0f28e25198f4Brian Paul 228fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul if ((buffers & BUFFER_BITS_COLOR) 229fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul && (ctx->DrawBuffer->_NumColorDrawBuffers > 0)) { 230fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul clear_color_buffers(ctx); 231fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul } 232e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 233fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul if (buffers & BUFFER_BIT_ACCUM) { 234fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul _mesa_clear_accum_buffer(ctx); 235fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul } 236fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul 237fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul if (buffers & BUFFER_DS) { 238fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul struct gl_renderbuffer *depthRb = 239fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer; 240fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul struct gl_renderbuffer *stencilRb = 241fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer; 242fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul 243fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul if ((buffers & BUFFER_DS) == BUFFER_DS && depthRb == stencilRb) { 244fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul /* clear depth and stencil together */ 245fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul _swrast_clear_depth_stencil_buffer(ctx); 246894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul } 247fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul else { 248fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul /* clear depth, stencil separately */ 249fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul if (buffers & BUFFER_BIT_DEPTH) { 250fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul _swrast_clear_depth_buffer(ctx); 251fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul } 252fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul if (buffers & BUFFER_BIT_STENCIL) { 253fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul _swrast_clear_stencil_buffer(ctx); 254fd104a84591ae854c5d6adc81e2dc31ef6ab9e8aBrian Paul } 255894844a8d956a0ee5f95836331dc318f49fdb845Brian Paul } 256e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 257e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell} 258