aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/swrast/s_buffers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/swrast/s_buffers.c')
-rw-r--r--src/mesa/swrast/s_buffers.c370
1 files changed, 235 insertions, 135 deletions
diff --git a/src/mesa/swrast/s_buffers.c b/src/mesa/swrast/s_buffers.c
index d05c8dfbf9b..cf469f8c626 100644
--- a/src/mesa/swrast/s_buffers.c
+++ b/src/mesa/swrast/s_buffers.c
@@ -2,7 +2,7 @@
* Mesa 3-D graphics library
* Version: 6.3
*
- * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -27,10 +27,10 @@
#include "colormac.h"
#include "macros.h"
#include "imports.h"
+#include "mtypes.h"
+#include "fbobject.h"
#include "s_accum.h"
-#include "s_alphabuf.h"
-#include "s_auxbuffer.h"
#include "s_context.h"
#include "s_depth.h"
#include "s_masking.h"
@@ -38,98 +38,190 @@
/**
- * Clear the color buffer when glColorMask or glIndexMask is in effect.
- * We'll have specified which color buffer to clear by previously
- * calling Driver.SetBuffer().
+ * Clear the color buffer when glColorMask is in effect.
*/
static void
-clear_color_buffer_with_masking( GLcontext *ctx )
+clear_rgba_buffer_with_masking(GLcontext *ctx, struct gl_renderbuffer *rb)
{
SWcontext *swrast = SWRAST_CONTEXT(ctx);
const GLint x = ctx->DrawBuffer->_Xmin;
const GLint y = ctx->DrawBuffer->_Ymin;
const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
const GLint width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
+ GLchan clearColor[4];
+ GLint i;
- if (ctx->Visual.rgbMode) {
- /* RGBA mode */
- GLchan clearColor[4];
- GLint i;
- CLAMPED_FLOAT_TO_CHAN(clearColor[RCOMP], ctx->Color.ClearColor[0]);
- CLAMPED_FLOAT_TO_CHAN(clearColor[GCOMP], ctx->Color.ClearColor[1]);
- CLAMPED_FLOAT_TO_CHAN(clearColor[BCOMP], ctx->Color.ClearColor[2]);
- CLAMPED_FLOAT_TO_CHAN(clearColor[ACOMP], ctx->Color.ClearColor[3]);
- for (i = 0; i < height; i++) {
- GLchan rgba[MAX_WIDTH][4];
- GLint j;
- for (j = 0; j < width; j++) {
- COPY_CHAN4(rgba[j], clearColor);
- }
- _swrast_mask_rgba_array( ctx, width, x, y + i, rgba );
- (*swrast->Driver.WriteRGBASpan)( ctx, width, x, y + i,
- (CONST GLchan (*)[4]) rgba, NULL );
+ ASSERT(ctx->Visual.rgbMode);
+
+ CLAMPED_FLOAT_TO_CHAN(clearColor[RCOMP], ctx->Color.ClearColor[0]);
+ CLAMPED_FLOAT_TO_CHAN(clearColor[GCOMP], ctx->Color.ClearColor[1]);
+ CLAMPED_FLOAT_TO_CHAN(clearColor[BCOMP], ctx->Color.ClearColor[2]);
+ CLAMPED_FLOAT_TO_CHAN(clearColor[ACOMP], ctx->Color.ClearColor[3]);
+
+ for (i = 0; i < height; i++) {
+ GLchan rgba[MAX_WIDTH][4];
+ GLint j;
+ for (j = 0; j < width; j++) {
+ COPY_CHAN4(rgba[j], clearColor);
}
+ _swrast_mask_rgba_array( ctx, rb, width, x, y + i, rgba );
+#if NEW_RENDERBUFFER
+ if (rb->PutRow) {
+ rb->PutRow(ctx, rb, width, x, y + i, rgba, NULL);
+ }
+#endif
+#if OLD_RENDERBUFFER
+ else {
+ swrast->Driver.WriteRGBASpan(ctx, rb, width, x, y + i,
+ (CONST GLchan (*)[4]) rgba, NULL);
+ }
+#endif
}
- else {
- /* Color index mode */
- GLuint span[MAX_WIDTH];
- GLubyte mask[MAX_WIDTH];
- GLint i, j;
- MEMSET( mask, 1, width );
- for (i=0;i<height;i++) {
- for (j=0;j<width;j++) {
- span[j] = ctx->Color.ClearIndex;
- }
- _swrast_mask_index_array( ctx, width, x, y + i, span );
- (*swrast->Driver.WriteCI32Span)( ctx, width, x, y + i, span, mask );
+}
+
+
+/**
+ * Clear color index buffer with masking.
+ */
+static void
+clear_ci_buffer_with_masking(GLcontext *ctx, struct gl_renderbuffer *rb)
+{
+ const GLint x = ctx->DrawBuffer->_Xmin;
+ const GLint y = ctx->DrawBuffer->_Ymin;
+ const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
+ const GLint width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
+ GLuint span[MAX_WIDTH];
+ GLubyte mask[MAX_WIDTH];
+ GLint i, j;
+
+ ASSERT(!ctx->Visual.rgbMode);
+
+ MEMSET( mask, 1, width );
+ for (i = 0; i < height;i++) {
+ for (j = 0; j < width;j++) {
+ span[j] = ctx->Color.ClearIndex;
}
+ _swrast_mask_ci_array(ctx, rb, width, x, y + i, span);
+ ASSERT(rb->PutRow);
+ ASSERT(rb->DataType == GL_UNSIGNED_INT);
+ rb->PutRow(ctx, rb, width, x, y + i, span, mask);
}
}
/**
- * Clear a color buffer without index/channel masking.
- * We'll have specified which color buffer to clear by previously
- * calling Driver.SetBuffer().
+ * Clear an rgba color buffer without channel masking.
*/
static void
-clear_color_buffer(GLcontext *ctx)
+clear_rgba_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
{
SWcontext *swrast = SWRAST_CONTEXT(ctx);
const GLint x = ctx->DrawBuffer->_Xmin;
const GLint y = ctx->DrawBuffer->_Ymin;
const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
const GLint width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
-
- if (ctx->Visual.rgbMode) {
- /* RGBA mode */
+ GLint i;
+
+ ASSERT(ctx->Visual.rgbMode);
+
+ ASSERT(ctx->Color.ColorMask[0] &&
+ ctx->Color.ColorMask[1] &&
+ ctx->Color.ColorMask[2] &&
+ ctx->Color.ColorMask[3]);
+
+#if NEW_RENDERBUFFER
+ if (rb->PutMonoRow) { /* XXX assert this */
+ GLubyte clear8[4];
+ GLushort clear16[4];
+ GLvoid *clearVal;
+ switch (rb->DataType) {
+ case GL_UNSIGNED_BYTE:
+ clear8[0] = FLOAT_TO_UBYTE(ctx->Color.ClearColor[0]);
+ clear8[1] = FLOAT_TO_UBYTE(ctx->Color.ClearColor[1]);
+ clear8[2] = FLOAT_TO_UBYTE(ctx->Color.ClearColor[2]);
+ clear8[3] = FLOAT_TO_UBYTE(ctx->Color.ClearColor[3]);
+ clearVal = clear8;
+ break;
+ case GL_UNSIGNED_SHORT:
+ clear16[0] = FLOAT_TO_USHORT(ctx->Color.ClearColor[0]);
+ clear16[1] = FLOAT_TO_USHORT(ctx->Color.ClearColor[1]);
+ clear16[2] = FLOAT_TO_USHORT(ctx->Color.ClearColor[2]);
+ clear16[3] = FLOAT_TO_USHORT(ctx->Color.ClearColor[3]);
+ clearVal = clear16;
+ break;
+ case GL_FLOAT:
+ clearVal = ctx->Color.ClearColor;
+ break;
+ default:
+ _mesa_problem(ctx, "Bad rb DataType in clear_color_buffer");
+ return;
+ }
+ for (i = 0; i < height; i++) {
+ rb->PutMonoRow(ctx, rb, width, x, y + i, clearVal, NULL);
+ }
+ }
+#endif
+#if OLD_RENDERBUFFER
+ else {
GLchan clearColor[4];
- GLint i;
-
CLAMPED_FLOAT_TO_CHAN(clearColor[RCOMP], ctx->Color.ClearColor[0]);
CLAMPED_FLOAT_TO_CHAN(clearColor[GCOMP], ctx->Color.ClearColor[1]);
CLAMPED_FLOAT_TO_CHAN(clearColor[BCOMP], ctx->Color.ClearColor[2]);
CLAMPED_FLOAT_TO_CHAN(clearColor[ACOMP], ctx->Color.ClearColor[3]);
-
- ASSERT(*((GLuint *) &ctx->Color.ColorMask) == 0xffffffff);
ASSERT(swrast->Driver.WriteRGBASpan);
-
for (i = 0; i < height; i++) {
- (*swrast->Driver.WriteMonoRGBASpan)( ctx, width, x, y + i,
- clearColor, NULL );
+ swrast->Driver.WriteMonoRGBASpan(ctx, rb, width, x, y + i,
+ clearColor, NULL );
}
}
- else {
- /* Color index mode */
+#endif
+}
+
+
+/**
+ * Clear color index buffer without masking.
+ */
+static void
+clear_ci_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
+{
+ const GLint x = ctx->DrawBuffer->_Xmin;
+ const GLint y = ctx->DrawBuffer->_Ymin;
+ const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
+ const GLint width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
+
+ ASSERT(!ctx->Visual.rgbMode);
+
+ ASSERT((ctx->Color.IndexMask & ((1 << ctx->Visual.indexBits) - 1))
+ == (GLuint) ((1 << ctx->Visual.indexBits) - 1));
+
+#if NEW_RENDERBUFFER
+ if (rb->PutMonoRow) { /* XXX assert this */
+ GLubyte clear8;
+ GLushort clear16;
+ GLuint clear32;
+ GLvoid *clearVal;
GLint i;
- ASSERT((ctx->Color.IndexMask & ((1 << ctx->Visual.indexBits) - 1))
- == (GLuint) ((1 << ctx->Visual.indexBits) - 1));
- ASSERT(swrast->Driver.WriteMonoCISpan);
- for (i = 0; i < height; i++) {
- (*swrast->Driver.WriteMonoCISpan)( ctx, width, x, y + i,
- ctx->Color.ClearIndex, NULL);
+ switch (rb->DataType) {
+ case GL_UNSIGNED_BYTE:
+ clear8 = (GLubyte) ctx->Color.ClearIndex;
+ clearVal = &clear8;
+ break;
+ case GL_UNSIGNED_SHORT:
+ clear16 = (GLushort) ctx->Color.ClearIndex;
+ clearVal = &clear16;
+ break;
+ case GL_UNSIGNED_INT:
+ clear32 = ctx->Color.ClearIndex;
+ clearVal = &clear32;
+ break;
+ default:
+ _mesa_problem(ctx, "Bad rb DataType in clear_color_buffer");
+ return;
}
+ for (i = 0; i < height; i++)
+ rb->PutMonoRow(ctx, rb, width, x, y + i, clearVal, NULL);
}
+#endif
}
@@ -141,20 +233,46 @@ clear_color_buffer(GLcontext *ctx)
static void
clear_color_buffers(GLcontext *ctx)
{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- const GLuint colorMask = *((GLuint *) &ctx->Color.ColorMask);
- GLuint bufferBit;
+ GLboolean masking;
+ GLuint i;
- /* loop over four possible dest color buffers */
- for (bufferBit = 1; bufferBit <= DD_AUX3_BIT; bufferBit <<= 1) {
- if (bufferBit & ctx->Color._DrawDestMask[0]) {
- (*swrast->Driver.SetBuffer)(ctx, ctx->DrawBuffer, bufferBit);
+ if (ctx->Visual.rgbMode) {
+ if (ctx->Color.ColorMask[0] &&
+ ctx->Color.ColorMask[1] &&
+ ctx->Color.ColorMask[2] &&
+ ctx->Color.ColorMask[3]) {
+ masking = GL_FALSE;
+ }
+ else {
+ masking = GL_TRUE;
+ }
+ }
+ else {
+ const GLuint indexBits = (1 << ctx->Visual.indexBits) - 1;
+ if ((ctx->Color.IndexMask & indexBits) == indexBits) {
+ masking = GL_FALSE;
+ }
+ else {
+ masking = GL_TRUE;
+ }
+ }
- if (colorMask != 0xffffffff) {
- clear_color_buffer_with_masking(ctx);
+ for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers[0]; i++) {
+ struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0][i];
+ if (ctx->Visual.rgbMode) {
+ if (masking) {
+ clear_rgba_buffer_with_masking(ctx, rb);
}
else {
- clear_color_buffer(ctx);
+ clear_rgba_buffer(ctx, rb);
+ }
+ }
+ else {
+ if (masking) {
+ clear_ci_buffer_with_masking(ctx, rb);
+ }
+ else {
+ clear_ci_buffer(ctx, rb);
}
}
}
@@ -171,26 +289,27 @@ clear_color_buffers(GLcontext *ctx)
* \param all if GL_TRUE, clear whole buffer, else clear specified region.
*/
void
-_swrast_Clear( GLcontext *ctx, GLbitfield mask,
- GLboolean all,
- GLint x, GLint y, GLint width, GLint height )
+_swrast_Clear(GLcontext *ctx, GLbitfield mask,
+ GLboolean all, GLint x, GLint y, GLint width, GLint height)
{
SWcontext *swrast = SWRAST_CONTEXT(ctx);
+
(void) all; (void) x; (void) y; (void) width; (void) height;
-#ifdef DEBUG
+
+#ifdef DEBUG_FOO
{
const GLbitfield legalBits =
- DD_FRONT_LEFT_BIT |
- DD_FRONT_RIGHT_BIT |
- DD_BACK_LEFT_BIT |
- DD_BACK_RIGHT_BIT |
- DD_DEPTH_BIT |
- DD_STENCIL_BIT |
- DD_ACCUM_BIT |
- DD_AUX0_BIT |
- DD_AUX1_BIT |
- DD_AUX2_BIT |
- DD_AUX3_BIT;
+ BUFFER_BIT_FRONT_LEFT |
+ BUFFER_BIT_FRONT_RIGHT |
+ BUFFER_BIT_BACK_LEFT |
+ BUFFER_BIT_BACK_RIGHT |
+ BUFFER_BIT_DEPTH |
+ BUFFER_BIT_STENCIL |
+ BUFFER_BIT_ACCUM |
+ BUFFER_BIT_AUX0 |
+ BUFFER_BIT_AUX1 |
+ BUFFER_BIT_AUX2 |
+ BUFFER_BIT_AUX3;
assert((mask & (~legalBits)) == 0);
}
#endif
@@ -199,22 +318,30 @@ _swrast_Clear( GLcontext *ctx, GLbitfield mask,
/* do software clearing here */
if (mask) {
- if (mask & ctx->Color._DrawDestMask[0]) {
+ if (mask & ctx->DrawBuffer->_ColorDrawBufferMask[0]) {
clear_color_buffers(ctx);
/* clear software-based alpha buffer(s) */
+#if OLD_RENDERBUFFER && 0
if (ctx->DrawBuffer->UseSoftwareAlphaBuffers
&& ctx->Color.ColorMask[ACOMP]) {
_swrast_clear_alpha_buffers( ctx );
}
+#endif
}
- if (mask & DD_DEPTH_BIT) {
- _swrast_clear_depth_buffer(ctx);
+ if (mask & BUFFER_BIT_DEPTH) {
+ struct gl_renderbuffer *rb
+ = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
+ _swrast_clear_depth_buffer(ctx, rb);
}
- if (mask & DD_ACCUM_BIT) {
- _swrast_clear_accum_buffer(ctx);
+ if (mask & BUFFER_BIT_ACCUM) {
+ struct gl_renderbuffer *rb
+ = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer;
+ _swrast_clear_accum_buffer(ctx, rb);
}
- if (mask & DD_STENCIL_BIT) {
- _swrast_clear_stencil_buffer(ctx);
+ if (mask & BUFFER_BIT_STENCIL) {
+ struct gl_renderbuffer *rb
+ = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
+ _swrast_clear_stencil_buffer(ctx, rb);
}
}
@@ -222,33 +349,6 @@ _swrast_Clear( GLcontext *ctx, GLbitfield mask,
}
-/**
- * Typically called via ctx->Driver.ResizeBuffers().
- * Reallocate all software-based depth/stencil/accum/etc buffers
- * to match current window dimensions.
- */
-void
-_swrast_alloc_buffers( GLframebuffer *buffer )
-{
- /* Reallocate other buffers if needed. */
- if (buffer->UseSoftwareDepthBuffer) {
- _swrast_alloc_depth_buffer( buffer );
- }
- if (buffer->UseSoftwareStencilBuffer) {
- _swrast_alloc_stencil_buffer( buffer );
- }
- if (buffer->UseSoftwareAccumBuffer) {
- _swrast_alloc_accum_buffer( buffer );
- }
- if (buffer->UseSoftwareAlphaBuffers) {
- _swrast_alloc_alpha_buffers( buffer );
- }
- if (buffer->UseSoftwareAuxBuffers) {
- _swrast_alloc_aux_buffers( buffer );
- }
-}
-
-
/*
* Fallback for ctx->Driver.DrawBuffer()
*/
@@ -281,7 +381,7 @@ _swrast_use_read_buffer( GLcontext *ctx )
SWcontext *swrast = SWRAST_CONTEXT(ctx);
/* Do this so the software-emulated alpha plane span functions work! */
- swrast->CurrentBufferBit = ctx->Pixel._ReadSrcMask;
+ swrast->CurrentBufferBit = ctx->ReadBuffer->_ColorReadBufferMask;
/* Tell the device driver where to read/write spans */
swrast->Driver.SetBuffer(ctx, ctx->ReadBuffer, swrast->CurrentBufferBit);
}
@@ -307,25 +407,25 @@ _swrast_use_draw_buffer( GLcontext *ctx )
* we loop over multiple color buffers when needed.
*/
- if (ctx->Color._DrawDestMask[0] & DD_FRONT_LEFT_BIT)
- swrast->CurrentBufferBit = DD_FRONT_LEFT_BIT;
- else if (ctx->Color._DrawDestMask[0] & DD_BACK_LEFT_BIT)
- swrast->CurrentBufferBit = DD_BACK_LEFT_BIT;
- else if (ctx->Color._DrawDestMask[0] & DD_FRONT_RIGHT_BIT)
- swrast->CurrentBufferBit = DD_FRONT_RIGHT_BIT;
- else if (ctx->Color._DrawDestMask[0] & DD_BACK_RIGHT_BIT)
- swrast->CurrentBufferBit = DD_BACK_RIGHT_BIT;
- else if (ctx->Color._DrawDestMask[0] & DD_AUX0_BIT)
- swrast->CurrentBufferBit = DD_AUX0_BIT;
- else if (ctx->Color._DrawDestMask[0] & DD_AUX1_BIT)
- swrast->CurrentBufferBit = DD_AUX1_BIT;
- else if (ctx->Color._DrawDestMask[0] & DD_AUX2_BIT)
- swrast->CurrentBufferBit = DD_AUX2_BIT;
- else if (ctx->Color._DrawDestMask[0] & DD_AUX3_BIT)
- swrast->CurrentBufferBit = DD_AUX3_BIT;
+ if (ctx->DrawBuffer->_ColorDrawBufferMask[0] & BUFFER_BIT_FRONT_LEFT)
+ swrast->CurrentBufferBit = BUFFER_BIT_FRONT_LEFT;
+ else if (ctx->DrawBuffer->_ColorDrawBufferMask[0] & BUFFER_BIT_BACK_LEFT)
+ swrast->CurrentBufferBit = BUFFER_BIT_BACK_LEFT;
+ else if (ctx->DrawBuffer->_ColorDrawBufferMask[0] & BUFFER_BIT_FRONT_RIGHT)
+ swrast->CurrentBufferBit = BUFFER_BIT_FRONT_RIGHT;
+ else if (ctx->DrawBuffer->_ColorDrawBufferMask[0] & BUFFER_BIT_BACK_RIGHT)
+ swrast->CurrentBufferBit = BUFFER_BIT_BACK_RIGHT;
+ else if (ctx->DrawBuffer->_ColorDrawBufferMask[0] & BUFFER_BIT_AUX0)
+ swrast->CurrentBufferBit = BUFFER_BIT_AUX0;
+ else if (ctx->DrawBuffer->_ColorDrawBufferMask[0] & BUFFER_BIT_AUX1)
+ swrast->CurrentBufferBit = BUFFER_BIT_AUX1;
+ else if (ctx->DrawBuffer->_ColorDrawBufferMask[0] & BUFFER_BIT_AUX2)
+ swrast->CurrentBufferBit = BUFFER_BIT_AUX2;
+ else if (ctx->DrawBuffer->_ColorDrawBufferMask[0] & BUFFER_BIT_AUX3)
+ swrast->CurrentBufferBit = BUFFER_BIT_AUX3;
else
/* glDrawBuffer(GL_NONE) */
- swrast->CurrentBufferBit = DD_FRONT_LEFT_BIT; /* we always have this buffer */
+ swrast->CurrentBufferBit = BUFFER_BIT_FRONT_LEFT; /* we always have this buffer */
swrast->Driver.SetBuffer(ctx, ctx->DrawBuffer, swrast->CurrentBufferBit);
}