summaryrefslogtreecommitdiffstats
path: root/src/mesa/swrast
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2002-07-09 01:22:50 +0000
committerBrian Paul <[email protected]>2002-07-09 01:22:50 +0000
commit3b4fbbc129c711a5aec8d653d5c6eb2e195f947c (patch)
treeececa2d3a08ab45afd2068d9cabf5609a0c374d1 /src/mesa/swrast
parentb4338e58879a4f2eabf8af09f9dfa7adf6e9f9f2 (diff)
Overhaul of glRead/DrawBuffer() code. Now, swrast->Driver.SetBuffer()
indicates the read AND draw color buffer for all software rasterization. Lots of related clean-ups. See RELNOTES-4.1 for details.
Diffstat (limited to 'src/mesa/swrast')
-rw-r--r--src/mesa/swrast/s_accum.c16
-rw-r--r--src/mesa/swrast/s_alphabuf.c87
-rw-r--r--src/mesa/swrast/s_buffers.c88
-rw-r--r--src/mesa/swrast/s_context.c9
-rw-r--r--src/mesa/swrast/s_copypix.c116
-rw-r--r--src/mesa/swrast/s_imaging.c28
-rw-r--r--src/mesa/swrast/s_readpix.c15
-rw-r--r--src/mesa/swrast/s_span.c38
-rw-r--r--src/mesa/swrast/s_texstore.c8
-rw-r--r--src/mesa/swrast/s_triangle.c12
-rw-r--r--src/mesa/swrast/swrast.h23
11 files changed, 244 insertions, 196 deletions
diff --git a/src/mesa/swrast/s_accum.c b/src/mesa/swrast/s_accum.c
index 09c4d8647b0..0159304c172 100644
--- a/src/mesa/swrast/s_accum.c
+++ b/src/mesa/swrast/s_accum.c
@@ -1,4 +1,4 @@
-/* $Id: s_accum.c,v 1.17 2002/06/15 02:38:17 brianp Exp $ */
+/* $Id: s_accum.c,v 1.18 2002/07/09 01:22:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -306,8 +306,7 @@ _swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value,
if (value == 0.0F)
return;
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
+ _swrast_use_read_buffer(ctx);
/* May have to leave optimized accum buffer mode */
if (swrast->_IntegerAccumScaler == 0.0 && value > 0.0 && value <= 1.0)
@@ -359,14 +358,13 @@ _swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value,
}
}
/* restore read buffer = draw buffer (the default) */
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer );
+ _swrast_use_draw_buffer(ctx);
+
RENDER_FINISH(swrast,ctx);
break;
case GL_LOAD:
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
+ _swrast_use_read_buffer(ctx);
/* This is a change to go into optimized accum buffer mode */
if (value > 0.0 && value <= 1.0) {
@@ -433,8 +431,8 @@ _swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value,
}
/* restore read buffer = draw buffer (the default) */
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer );
+ _swrast_use_draw_buffer(ctx);
+
RENDER_FINISH(swrast,ctx);
break;
diff --git a/src/mesa/swrast/s_alphabuf.c b/src/mesa/swrast/s_alphabuf.c
index 56c4d552da2..b303c0fc76c 100644
--- a/src/mesa/swrast/s_alphabuf.c
+++ b/src/mesa/swrast/s_alphabuf.c
@@ -1,4 +1,4 @@
-/* $Id: s_alphabuf.c,v 1.10 2002/03/19 16:47:05 brianp Exp $ */
+/* $Id: s_alphabuf.c,v 1.11 2002/07/09 01:22:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -38,20 +38,12 @@
#include "s_alphabuf.h"
-#define ALPHA_DRAW_ADDR(X,Y) \
- (ctx->DrawBuffer->Alpha + (Y) * ctx->DrawBuffer->Width + (X))
-
-#define ALPHA_READ_ADDR(X,Y) \
- (ctx->ReadBuffer->Alpha + (Y) * ctx->ReadBuffer->Width + (X))
-
-
/*
* Allocate a new front and back alpha buffer.
*/
void
_mesa_alloc_alpha_buffers( GLframebuffer *buffer )
{
- GET_CURRENT_CONTEXT(ctx);
const GLint bytes = buffer->Width * buffer->Height * sizeof(GLchan);
ASSERT(buffer->UseSoftwareAlphaBuffers);
@@ -101,17 +93,6 @@ _mesa_alloc_alpha_buffers( GLframebuffer *buffer )
}
}
}
-
- if (ctx) {
- if (ctx->Color.DriverDrawBuffer == GL_FRONT_LEFT)
- buffer->Alpha = buffer->FrontLeftAlpha;
- else if (ctx->Color.DriverDrawBuffer == GL_BACK_LEFT)
- buffer->Alpha = buffer->BackLeftAlpha;
- else if (ctx->Color.DriverDrawBuffer == GL_FRONT_RIGHT)
- buffer->Alpha = buffer->FrontRightAlpha;
- else if (ctx->Color.DriverDrawBuffer == GL_BACK_RIGHT)
- buffer->Alpha = buffer->BackRightAlpha;
- }
}
@@ -129,7 +110,7 @@ _mesa_clear_alpha_buffers( GLcontext *ctx )
/* loop over four possible alpha buffers */
for (bufferBit = 1; bufferBit <= 8; bufferBit = bufferBit << 1) {
- if (bufferBit & ctx->Color.DrawDestMask) {
+ if (bufferBit & ctx->Color._DrawDestMask) {
GLchan *buffer;
if (bufferBit == FRONT_LEFT_BIT) {
buffer = ctx->DrawBuffer->FrontLeftAlpha;
@@ -187,13 +168,39 @@ _mesa_clear_alpha_buffers( GLcontext *ctx )
+static INLINE
+GLchan *get_alpha_buffer( GLcontext *ctx )
+{
+ switch (ctx->Color._DriverDrawBuffer) {
+ case GL_FRONT_LEFT:
+ return ctx->DrawBuffer->FrontLeftAlpha;
+ break;
+ case GL_BACK_LEFT:
+ return ctx->DrawBuffer->BackLeftAlpha;
+ break;
+ case GL_FRONT_RIGHT:
+ return ctx->DrawBuffer->FrontRightAlpha;
+ break;
+ case GL_BACK_RIGHT:
+ return ctx->DrawBuffer->BackRightAlpha;
+ break;
+ default:
+ _mesa_problem(ctx, "Bad DriverDrawBuffer in _mesa_write_alpha_span()");
+ return ctx->DrawBuffer->FrontLeftAlpha; /* aribitrary */
+ }
+}
+
+
void
_mesa_write_alpha_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
CONST GLchan rgba[][4], const GLubyte mask[] )
{
- GLchan *aptr = ALPHA_DRAW_ADDR( x, y );
+ GLchan *buffer, *aptr;
GLuint i;
+ buffer = get_alpha_buffer(ctx);
+ aptr = buffer + y * ctx->DrawBuffer->Width + x;
+
if (mask) {
for (i=0;i<n;i++) {
if (mask[i]) {
@@ -214,9 +221,12 @@ void
_mesa_write_mono_alpha_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
GLchan alpha, const GLubyte mask[] )
{
- GLchan *aptr = ALPHA_DRAW_ADDR( x, y );
+ GLchan *buffer, *aptr;
GLuint i;
+ buffer = get_alpha_buffer(ctx);
+ aptr = buffer + y * ctx->DrawBuffer->Width + x;
+
if (mask) {
for (i=0;i<n;i++) {
if (mask[i]) {
@@ -238,19 +248,22 @@ _mesa_write_alpha_pixels( GLcontext *ctx,
GLuint n, const GLint x[], const GLint y[],
CONST GLchan rgba[][4], const GLubyte mask[] )
{
+ GLchan *buffer;
GLuint i;
+ buffer = get_alpha_buffer(ctx);
+
if (mask) {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLchan *aptr = ALPHA_DRAW_ADDR( x[i], y[i] );
+ GLchan *aptr = buffer + y[i] * ctx->DrawBuffer->Width + x[i];
*aptr = rgba[i][ACOMP];
}
}
}
else {
for (i=0;i<n;i++) {
- GLchan *aptr = ALPHA_DRAW_ADDR( x[i], y[i] );
+ GLchan *aptr = buffer + y[i] * ctx->DrawBuffer->Width + x[i];
*aptr = rgba[i][ACOMP];
}
}
@@ -262,19 +275,22 @@ _mesa_write_mono_alpha_pixels( GLcontext *ctx,
GLuint n, const GLint x[], const GLint y[],
GLchan alpha, const GLubyte mask[] )
{
+ GLchan *buffer;
GLuint i;
+ buffer = get_alpha_buffer(ctx);
+
if (mask) {
for (i=0;i<n;i++) {
if (mask[i]) {
- GLchan *aptr = ALPHA_DRAW_ADDR( x[i], y[i] );
+ GLchan *aptr = buffer + y[i] * ctx->DrawBuffer->Width + x[i];
*aptr = alpha;
}
}
}
else {
for (i=0;i<n;i++) {
- GLchan *aptr = ALPHA_DRAW_ADDR( x[i], y[i] );
+ GLchan *aptr = buffer + y[i] * ctx->DrawBuffer->Width + x[i];
*aptr = alpha;
}
}
@@ -286,11 +302,14 @@ void
_mesa_read_alpha_span( GLcontext *ctx,
GLuint n, GLint x, GLint y, GLchan rgba[][4] )
{
- GLchan *aptr = ALPHA_READ_ADDR( x, y );
+ const GLchan *buffer, *aptr;
GLuint i;
- for (i=0;i<n;i++) {
+
+ buffer = get_alpha_buffer(ctx);
+ aptr = buffer + y * ctx->DrawBuffer->Width + x;
+
+ for (i = 0; i < n; i++)
rgba[i][ACOMP] = *aptr++;
- }
}
@@ -299,10 +318,14 @@ _mesa_read_alpha_pixels( GLcontext *ctx,
GLuint n, const GLint x[], const GLint y[],
GLchan rgba[][4], const GLubyte mask[] )
{
+ const GLchan *buffer;
GLuint i;
- for (i=0;i<n;i++) {
+
+ buffer = get_alpha_buffer(ctx);
+
+ for (i = 0; i < n; i++) {
if (mask[i]) {
- GLchan *aptr = ALPHA_READ_ADDR( x[i], y[i] );
+ const GLchan *aptr = buffer + y[i] * ctx->DrawBuffer->Width + x[i];
rgba[i][ACOMP] = *aptr;
}
}
diff --git a/src/mesa/swrast/s_buffers.c b/src/mesa/swrast/s_buffers.c
index 6c7b447aba8..dcfa26f5e20 100644
--- a/src/mesa/swrast/s_buffers.c
+++ b/src/mesa/swrast/s_buffers.c
@@ -1,4 +1,4 @@
-/* $Id: s_buffers.c,v 1.11 2002/06/15 02:38:17 brianp Exp $ */
+/* $Id: s_buffers.c,v 1.12 2002/07/09 01:22:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -167,22 +167,18 @@ clear_color_buffers(GLcontext *ctx)
/* loop over four possible dest color buffers */
for (bufferBit = 1; bufferBit <= 8; bufferBit = bufferBit << 1) {
- if (bufferBit & ctx->Color.DrawDestMask) {
+ if (bufferBit & ctx->Color._DrawDestMask) {
if (bufferBit == FRONT_LEFT_BIT) {
- (*ctx->Driver.SetDrawBuffer)( ctx, GL_FRONT_LEFT);
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer, GL_FRONT_LEFT);
+ (*swrast->Driver.SetBuffer)(ctx, ctx->DrawBuffer, GL_FRONT_LEFT);
}
else if (bufferBit == FRONT_RIGHT_BIT) {
- (*ctx->Driver.SetDrawBuffer)( ctx, GL_FRONT_RIGHT);
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer, GL_FRONT_RIGHT);
+ (*swrast->Driver.SetBuffer)(ctx, ctx->DrawBuffer, GL_FRONT_RIGHT);
}
else if (bufferBit == BACK_LEFT_BIT) {
- (*ctx->Driver.SetDrawBuffer)( ctx, GL_BACK_LEFT);
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer, GL_BACK_LEFT);
+ (*swrast->Driver.SetBuffer)(ctx, ctx->DrawBuffer, GL_BACK_LEFT);
}
else {
- (*ctx->Driver.SetDrawBuffer)( ctx, GL_BACK_RIGHT);
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer, GL_BACK_RIGHT);
+ (*swrast->Driver.SetBuffer)(ctx, ctx->DrawBuffer, GL_BACK_RIGHT);
}
if (colorMask != 0xffffffff) {
@@ -194,9 +190,8 @@ clear_color_buffers(GLcontext *ctx)
}
}
- /* restore default read/draw buffers */
- (void) (*ctx->Driver.SetDrawBuffer)( ctx, ctx->Color.DriverDrawBuffer );
- (void) (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer, ctx->Pixel.DriverReadBuffer );
+ /* restore default read/draw buffer */
+ _swrast_use_draw_buffer(ctx);
}
@@ -224,7 +219,7 @@ _swrast_Clear( GLcontext *ctx, GLbitfield mask,
/* do software clearing here */
if (mask) {
- if (mask & ctx->Color.DrawDestMask) clear_color_buffers(ctx);
+ if (mask & ctx->Color._DrawDestMask) clear_color_buffers(ctx);
if (mask & GL_DEPTH_BUFFER_BIT) _mesa_clear_depth_buffer(ctx);
if (mask & GL_ACCUM_BUFFER_BIT) _mesa_clear_accum_buffer(ctx);
if (mask & GL_STENCIL_BUFFER_BIT) _mesa_clear_stencil_buffer(ctx);
@@ -258,3 +253,68 @@ _swrast_alloc_buffers( GLframebuffer *buffer )
_mesa_alloc_alpha_buffers( buffer );
}
}
+
+
+/*
+ * Fallback for ctx->Driver.DrawBuffer()
+ */
+void
+_swrast_DrawBuffer( GLcontext *ctx, GLenum mode )
+{
+ _swrast_use_draw_buffer(ctx);
+}
+
+
+/*
+ * Setup things so that we read/write spans from the user-designated
+ * read buffer (set via glReadPixels). We usually just have to call
+ * this for glReadPixels, glCopyPixels, etc.
+ */
+void
+_swrast_use_read_buffer( GLcontext *ctx )
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+
+ /* Do this so the software-emulated alpha plane span functions work! */
+ ctx->Color._DriverDrawBuffer = ctx->Pixel._DriverReadBuffer;
+ /* Tell the device driver where to read/write spans */
+ (*swrast->Driver.SetBuffer)( ctx, ctx->ReadBuffer,
+ ctx->Pixel._DriverReadBuffer );
+}
+
+
+/*
+ * Setup things so that we read/write spans from the default draw buffer.
+ * This is the usual mode that Mesa's software rasterizer operates in.
+ */
+void
+_swrast_use_draw_buffer( GLcontext *ctx )
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+
+ /* The user can specify rendering to zero, one, two, or four color
+ * buffers simultaneously with glDrawBuffer()!
+ * We don't expect the span/point/line/triangle functions to deal with
+ * that mess so we'll iterate over the multiple buffers as needed.
+ * But usually we only render to one color buffer at a time.
+ * We set ctx->Color._DriverDrawBuffer to that buffer and tell the
+ * device driver to use that buffer.
+ * Look in s_span.c's multi_write_rgba_span() function to see how
+ * we loop over multiple color buffers when needed.
+ */
+
+ if (ctx->Color._DrawDestMask & FRONT_LEFT_BIT)
+ ctx->Color._DriverDrawBuffer = GL_FRONT_LEFT;
+ else if (ctx->Color._DrawDestMask & BACK_LEFT_BIT)
+ ctx->Color._DriverDrawBuffer = GL_BACK_LEFT;
+ else if (ctx->Color._DrawDestMask & FRONT_RIGHT_BIT)
+ ctx->Color._DriverDrawBuffer = GL_FRONT_RIGHT;
+ else if (ctx->Color._DrawDestMask & BACK_RIGHT_BIT)
+ ctx->Color._DriverDrawBuffer = GL_BACK_RIGHT;
+ else
+ /* glDrawBuffer(GL_NONE) */
+ ctx->Color._DriverDrawBuffer = GL_FRONT_LEFT; /* always have this */
+
+ (*swrast->Driver.SetBuffer)( ctx, ctx->DrawBuffer,
+ ctx->Color._DriverDrawBuffer );
+}
diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index a4f59df8ae3..105b562d90f 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -1,4 +1,4 @@
-/* $Id: s_context.c,v 1.35 2002/06/15 03:03:11 brianp Exp $ */
+/* $Id: s_context.c,v 1.36 2002/07/09 01:22:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -87,8 +87,11 @@ _swrast_update_rasterflags( GLcontext *ctx )
* MULTI_DRAW_BIT flag. Also set it if we're drawing to no
* buffers or the RGBA or CI mask disables all writes.
*/
- if (ctx->Color.DrawBuffer == GL_FRONT_AND_BACK ||
- ctx->Color.DrawBuffer == GL_NONE) {
+ if (ctx->Color._DrawDestMask != FRONT_LEFT_BIT &&
+ ctx->Color._DrawDestMask != BACK_LEFT_BIT &&
+ ctx->Color._DrawDestMask != FRONT_RIGHT_BIT &&
+ ctx->Color._DrawDestMask != BACK_RIGHT_BIT) {
+ /* more than one color buffer designated for writing (or zero buffers) */
RasterMask |= MULTI_DRAW_BIT;
}
else if (ctx->Visual.rgbMode && *((GLuint *) ctx->Color.ColorMask) == 0) {
diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c
index 2c6bd263123..7f5f41b78f6 100644
--- a/src/mesa/swrast/s_copypix.c
+++ b/src/mesa/swrast/s_copypix.c
@@ -1,4 +1,4 @@
-/* $Id: s_copypix.c,v 1.38 2002/06/15 03:03:11 brianp Exp $ */
+/* $Id: s_copypix.c,v 1.39 2002/07/09 01:22:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -103,7 +103,6 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
GLboolean quick_draw;
GLint row;
GLboolean changeBuffer;
- GLchan *saveReadAlpha;
const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
const GLuint transferOps = ctx->_ImageTransferState;
GLfloat *dest, *tmpImage, *convImage;
@@ -128,7 +127,6 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
}
/* If read and draw buffer are different we must do buffer switching */
- saveReadAlpha = ctx->ReadBuffer->Alpha;
changeBuffer = ctx->Pixel.ReadBuffer != ctx->Color.DrawBuffer
|| ctx->DrawBuffer != ctx->ReadBuffer;
@@ -149,16 +147,8 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
dest = tmpImage;
if (changeBuffer) {
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
- if (ctx->Pixel.DriverReadBuffer == GL_FRONT_LEFT)
- ctx->ReadBuffer->Alpha = ctx->ReadBuffer->FrontLeftAlpha;
- else if (ctx->Pixel.DriverReadBuffer == GL_BACK_LEFT)
- ctx->ReadBuffer->Alpha = ctx->ReadBuffer->BackLeftAlpha;
- else if (ctx->Pixel.DriverReadBuffer == GL_FRONT_RIGHT)
- ctx->ReadBuffer->Alpha = ctx->ReadBuffer->FrontRightAlpha;
- else
- ctx->ReadBuffer->Alpha = ctx->ReadBuffer->BackRightAlpha;
+ /* choose the read buffer */
+ _swrast_use_read_buffer(ctx);
}
/* read source image */
@@ -176,11 +166,9 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
}
}
- /* read from the draw buffer again (in case of blending) */
if (changeBuffer) {
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer );
- ctx->ReadBuffer->Alpha = saveReadAlpha;
+ /* restore default src/dst buffer */
+ _swrast_use_draw_buffer(ctx);
}
/* do image transfer ops up until convolution */
@@ -301,7 +289,6 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
GLboolean quick_draw;
GLint sy, dy, stepy, j;
GLboolean changeBuffer;
- GLchan *saveReadAlpha;
const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
GLint overlapping;
const GLuint transferOps = ctx->_ImageTransferState;
@@ -347,13 +334,9 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
}
/* If read and draw buffer are different we must do buffer switching */
- saveReadAlpha = ctx->ReadBuffer->Alpha;
changeBuffer = ctx->Pixel.ReadBuffer != ctx->Color.DrawBuffer
|| ctx->DrawBuffer != ctx->ReadBuffer;
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
-
if (overlapping) {
GLint ssy = sy;
tmpImage = (GLchan *) MALLOC(width * height * sizeof(GLchan) * 4);
@@ -361,25 +344,22 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
_mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
return;
}
+ /* setup source */
+ if (changeBuffer)
+ _swrast_use_read_buffer(ctx);
+ /* read the source image */
p = tmpImage;
- if (changeBuffer) {
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
- if (ctx->Pixel.DriverReadBuffer == GL_FRONT_LEFT)
- ctx->ReadBuffer->Alpha = ctx->ReadBuffer->FrontLeftAlpha;
- else if (ctx->Pixel.DriverReadBuffer == GL_BACK_LEFT)
- ctx->ReadBuffer->Alpha = ctx->ReadBuffer->BackLeftAlpha;
- else if (ctx->Pixel.DriverReadBuffer == GL_FRONT_RIGHT)
- ctx->ReadBuffer->Alpha = ctx->ReadBuffer->FrontRightAlpha;
- else
- ctx->ReadBuffer->Alpha = ctx->ReadBuffer->BackRightAlpha;
- }
for (j = 0; j < height; j++, ssy += stepy) {
_mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, srcx, ssy,
(GLchan (*)[4]) p );
p += width * 4;
}
p = tmpImage;
+ /* restore dest */
+ if (changeBuffer) {
+ _swrast_use_draw_buffer(ctx);
+ changeBuffer = GL_FALSE;
+ }
}
else {
tmpImage = NULL; /* silence compiler warnings */
@@ -395,30 +375,12 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
}
else {
/* get from framebuffer */
- if (changeBuffer) {
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
- if (ctx->Pixel.DriverReadBuffer == GL_FRONT_LEFT) {
- ctx->ReadBuffer->Alpha = ctx->ReadBuffer->FrontLeftAlpha;
- }
- else if (ctx->Pixel.DriverReadBuffer == GL_BACK_LEFT) {
- ctx->ReadBuffer->Alpha = ctx->ReadBuffer->BackLeftAlpha;
- }
- else if (ctx->Pixel.DriverReadBuffer == GL_FRONT_RIGHT) {
- ctx->ReadBuffer->Alpha = ctx->ReadBuffer->FrontRightAlpha;
- }
- else {
- ctx->ReadBuffer->Alpha = ctx->ReadBuffer->BackRightAlpha;
- }
- }
- _mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, srcx, sy, span->color.rgba );
- }
-
- if (changeBuffer) {
- /* read from the draw buffer again (in case of blending) */
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer );
- ctx->ReadBuffer->Alpha = saveReadAlpha;
+ if (changeBuffer)
+ _swrast_use_read_buffer(ctx);
+ _mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, srcx, sy,
+ span->color.rgba );
+ if (changeBuffer)
+ _swrast_use_draw_buffer(ctx);
}
if (transferOps) {
@@ -525,10 +487,6 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
}
}
- /* Restore pixel source to be the draw buffer (for blending, etc) */
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer );
-
if (overlapping)
FREE(tmpImage);
}
@@ -576,9 +534,6 @@ static void copy_ci_pixels( GLcontext *ctx,
changeBuffer = ctx->Pixel.ReadBuffer != ctx->Color.DrawBuffer
|| ctx->DrawBuffer != ctx->ReadBuffer;
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
-
if (overlapping) {
GLint ssy = sy;
tmpImage = (GLuint *) MALLOC(width * height * sizeof(GLuint));
@@ -586,16 +541,21 @@ static void copy_ci_pixels( GLcontext *ctx,
_mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
return;
}
+ /* setup source */
+ if (changeBuffer)
+ _swrast_use_read_buffer(ctx);
+ /* read the image */
p = tmpImage;
- if (changeBuffer) {
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
- }
for (j = 0; j < height; j++, ssy += stepy) {
_mesa_read_index_span( ctx, ctx->ReadBuffer, width, srcx, ssy, p );
p += width;
}
p = tmpImage;
+ /* restore to draw buffer */
+ if (changeBuffer) {
+ _swrast_use_draw_buffer(ctx);
+ changeBuffer = GL_FALSE;
+ }
}
else {
tmpImage = NULL; /* silence compiler warning */
@@ -608,18 +568,12 @@ static void copy_ci_pixels( GLcontext *ctx,
p += width;
}
else {
- if (changeBuffer) {
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
- }
+ if (changeBuffer)
+ _swrast_use_read_buffer(ctx);
_mesa_read_index_span( ctx, ctx->ReadBuffer, width, srcx, sy,
span->color.index );
- }
-
- if (changeBuffer) {
- /* set read buffer back to draw buffer (in case of logicops) */
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer );
+ if (changeBuffer)
+ _swrast_use_draw_buffer(ctx);
}
if (shift_or_offset) {
@@ -638,10 +592,6 @@ static void copy_ci_pixels( GLcontext *ctx,
_mesa_write_index_span(ctx, span);
}
- /* Restore pixel source to be the draw buffer (for blending, etc) */
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer );
-
if (overlapping)
FREE(tmpImage);
}
diff --git a/src/mesa/swrast/s_imaging.c b/src/mesa/swrast/s_imaging.c
index 1c63f5c3416..98cbe347a72 100644
--- a/src/mesa/swrast/s_imaging.c
+++ b/src/mesa/swrast/s_imaging.c
@@ -1,4 +1,4 @@
-/* $Id: s_imaging.c,v 1.5 2002/04/04 16:53:00 brianp Exp $ */
+/* $Id: s_imaging.c,v 1.6 2002/07/09 01:22:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -37,12 +37,10 @@ _swrast_CopyColorTable( GLcontext *ctx,
GLenum target, GLenum internalformat,
GLint x, GLint y, GLsizei width)
{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
GLchan data[MAX_WIDTH][4];
/* Select buffer to read from */
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
+ _swrast_use_read_buffer(ctx);
if (width > MAX_WIDTH)
width = MAX_WIDTH;
@@ -51,8 +49,7 @@ _swrast_CopyColorTable( GLcontext *ctx,
_mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y, data );
/* Restore reading from draw buffer (the default) */
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer );
+ _swrast_use_draw_buffer(ctx);
glColorTable(target, internalformat, width, GL_RGBA, CHAN_TYPE, data);
}
@@ -61,12 +58,10 @@ void
_swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
GLint x, GLint y, GLsizei width)
{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
GLchan data[MAX_WIDTH][4];
/* Select buffer to read from */
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
+ _swrast_use_read_buffer(ctx);
if (width > MAX_WIDTH)
width = MAX_WIDTH;
@@ -75,8 +70,7 @@ _swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
_mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y, data );
/* Restore reading from draw buffer (the default) */
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer );
+ _swrast_use_draw_buffer(ctx);
glColorSubTable(target, start, width, GL_RGBA, CHAN_TYPE, data);
}
@@ -90,6 +84,9 @@ _swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target,
SWcontext *swrast = SWRAST_CONTEXT(ctx);
GLchan rgba[MAX_CONVOLUTION_WIDTH][4];
+ /* Select buffer to read from */
+ _swrast_use_read_buffer(ctx);
+
RENDER_START( swrast, ctx );
/* read the data from framebuffer */
@@ -98,6 +95,9 @@ _swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target,
RENDER_FINISH( swrast, ctx );
+ /* Restore reading from draw buffer (the default) */
+ _swrast_use_draw_buffer(ctx);
+
/* store as convolution filter */
glConvolutionFilter1D(target, internalFormat, width,
GL_RGBA, CHAN_TYPE, rgba);
@@ -114,6 +114,9 @@ _swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target,
GLchan rgba[MAX_CONVOLUTION_HEIGHT][MAX_CONVOLUTION_WIDTH][4];
GLint i;
+ /* Select buffer to read from */
+ _swrast_use_read_buffer(ctx);
+
RENDER_START(swrast,ctx);
/* read pixels from framebuffer */
@@ -124,6 +127,9 @@ _swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target,
RENDER_FINISH(swrast,ctx);
+ /* Restore reading from draw buffer (the default) */
+ _swrast_use_draw_buffer(ctx);
+
/*
* HACK: save & restore context state so we can store this as a
* convolution filter via the GL api. Doesn't call any callbacks
diff --git a/src/mesa/swrast/s_readpix.c b/src/mesa/swrast/s_readpix.c
index a52cd8e7c0b..f925e791162 100644
--- a/src/mesa/swrast/s_readpix.c
+++ b/src/mesa/swrast/s_readpix.c
@@ -1,4 +1,4 @@
-/* $Id: s_readpix.c,v 1.14 2002/04/19 00:38:27 brianp Exp $ */
+/* $Id: s_readpix.c,v 1.15 2002/07/09 01:22:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -62,9 +62,7 @@ read_index_pixels( GLcontext *ctx,
return;
}
- ASSERT(swrast->Driver.SetReadBuffer);
- (*swrast->Driver.SetReadBuffer)(ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer);
+ _swrast_use_read_buffer(ctx);
readWidth = (width > MAX_WIDTH) ? MAX_WIDTH : width;
@@ -82,8 +80,7 @@ read_index_pixels( GLcontext *ctx,
&ctx->Pack, ctx->_ImageTransferState);
}
- (*swrast->Driver.SetReadBuffer)(ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer);
+ _swrast_use_draw_buffer(ctx);
}
@@ -318,13 +315,13 @@ read_rgba_pixels( GLcontext *ctx,
SWcontext *swrast = SWRAST_CONTEXT(ctx);
GLint readWidth;
- (*swrast->Driver.SetReadBuffer)(ctx, ctx->ReadBuffer, ctx->Pixel.DriverReadBuffer);
+ _swrast_use_read_buffer(ctx);
/* Try optimized path first */
if (read_fast_rgba_pixels( ctx, x, y, width, height,
format, type, pixels, packing )) {
- (*swrast->Driver.SetReadBuffer)(ctx, ctx->DrawBuffer, ctx->Color.DriverDrawBuffer);
+ _swrast_use_draw_buffer(ctx);
return; /* done! */
}
@@ -470,7 +467,7 @@ read_rgba_pixels( GLcontext *ctx,
}
}
- (*swrast->Driver.SetReadBuffer)(ctx, ctx->DrawBuffer, ctx->Color.DriverDrawBuffer);
+ _swrast_use_draw_buffer(ctx);
}
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index a3271d7806d..94cd4a9ce83 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -1,4 +1,4 @@
-/* $Id: s_span.c,v 1.44 2002/06/15 03:03:11 brianp Exp $ */
+/* $Id: s_span.c,v 1.45 2002/07/09 01:22:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -608,19 +608,19 @@ multi_write_index_span( GLcontext *ctx, struct sw_span *span )
GLuint bufferBit;
/* loop over four possible dest color buffers */
- for (bufferBit = 1; bufferBit <= 8; bufferBit = bufferBit << 1) {
- if (bufferBit & ctx->Color.DrawDestMask) {
+ for (bufferBit = 1; bufferBit <= 8; bufferBit <<= 1) {
+ if (bufferBit & ctx->Color._DrawDestMask) {
GLuint indexTmp[MAX_WIDTH];
ASSERT(span->end < MAX_WIDTH);
if (bufferBit == FRONT_LEFT_BIT)
- (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_FRONT_LEFT);
+ (*swrast->Driver.SetBuffer)(ctx, ctx->DrawBuffer, GL_FRONT_LEFT);
else if (bufferBit == FRONT_RIGHT_BIT)
- (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_FRONT_RIGHT);
+ (*swrast->Driver.SetBuffer)(ctx, ctx->DrawBuffer, GL_FRONT_RIGHT);
else if (bufferBit == BACK_LEFT_BIT)
- (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_BACK_LEFT);
+ (*swrast->Driver.SetBuffer)(ctx, ctx->DrawBuffer, GL_BACK_LEFT);
else
- (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_BACK_RIGHT);
+ (*swrast->Driver.SetBuffer)(ctx, ctx->DrawBuffer, GL_BACK_RIGHT);
/* make copy of incoming indexes */
MEMCPY( indexTmp, span->color.index, span->end * sizeof(GLuint) );
@@ -648,7 +648,7 @@ multi_write_index_span( GLcontext *ctx, struct sw_span *span )
}
/* restore default dest buffer */
- (void) (*ctx->Driver.SetDrawBuffer)( ctx, ctx->Color.DriverDrawBuffer);
+ _swrast_use_draw_buffer(ctx);
}
@@ -670,26 +670,26 @@ multi_write_rgba_span( GLcontext *ctx, struct sw_span *span )
return;
/* loop over four possible dest color buffers */
- for (bufferBit = 1; bufferBit <= 8; bufferBit = bufferBit << 1) {
- if (bufferBit & ctx->Color.DrawDestMask) {
+ for (bufferBit = 1; bufferBit <= 8; bufferBit <<= 1) {
+ if (bufferBit & ctx->Color._DrawDestMask) {
GLchan rgbaTmp[MAX_WIDTH][4];
ASSERT(span->end < MAX_WIDTH);
if (bufferBit == FRONT_LEFT_BIT) {
- (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_FRONT_LEFT);
- ctx->DrawBuffer->Alpha = ctx->DrawBuffer->FrontLeftAlpha;
+ ctx->Color._DriverDrawBuffer = GL_FRONT_LEFT;
+ (*swrast->Driver.SetBuffer)(ctx, ctx->DrawBuffer, GL_FRONT_LEFT);
}
else if (bufferBit == FRONT_RIGHT_BIT) {
- (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_FRONT_RIGHT);
- ctx->DrawBuffer->Alpha = ctx->DrawBuffer->FrontRightAlpha;
+ ctx->Color._DriverDrawBuffer = GL_FRONT_RIGHT;
+ (*swrast->Driver.SetBuffer)(ctx, ctx->DrawBuffer, GL_FRONT_RIGHT);
}
else if (bufferBit == BACK_LEFT_BIT) {
- (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_BACK_LEFT);
- ctx->DrawBuffer->Alpha = ctx->DrawBuffer->BackLeftAlpha;
+ ctx->Color._DriverDrawBuffer = GL_BACK_LEFT;
+ (*swrast->Driver.SetBuffer)(ctx, ctx->DrawBuffer, GL_BACK_LEFT);
}
else {
- (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_BACK_RIGHT);
- ctx->DrawBuffer->Alpha = ctx->DrawBuffer->BackRightAlpha;
+ ctx->Color._DriverDrawBuffer = GL_BACK_RIGHT;
+ (*swrast->Driver.SetBuffer)(ctx, ctx->DrawBuffer, GL_BACK_RIGHT);
}
/* make copy of incoming colors */
@@ -734,7 +734,7 @@ multi_write_rgba_span( GLcontext *ctx, struct sw_span *span )
}
/* restore default dest buffer */
- (void) (*ctx->Driver.SetDrawBuffer)( ctx, ctx->Color.DriverDrawBuffer );
+ _swrast_use_draw_buffer(ctx);
}
diff --git a/src/mesa/swrast/s_texstore.c b/src/mesa/swrast/s_texstore.c
index e1adeded7fc..88fe786ef8c 100644
--- a/src/mesa/swrast/s_texstore.c
+++ b/src/mesa/swrast/s_texstore.c
@@ -1,4 +1,4 @@
-/* $Id: s_texstore.c,v 1.5 2001/05/21 16:41:04 brianp Exp $ */
+/* $Id: s_texstore.c,v 1.6 2002/07/09 01:22:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -73,8 +73,7 @@ read_color_image( GLcontext *ctx, GLint x, GLint y,
return NULL;
/* Select buffer to read from */
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
+ _swrast_use_read_buffer(ctx);
RENDER_START(swrast,ctx);
@@ -89,8 +88,7 @@ read_color_image( GLcontext *ctx, GLint x, GLint y,
RENDER_FINISH(swrast,ctx);
/* Read from draw buffer (the default) */
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer );
+ _swrast_use_draw_buffer(ctx);
return image;
}
diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c
index bdbdde76b83..634664371bd 100644
--- a/src/mesa/swrast/s_triangle.c
+++ b/src/mesa/swrast/s_triangle.c
@@ -1,4 +1,4 @@
-/* $Id: s_triangle.c,v 1.59 2002/06/15 03:03:12 brianp Exp $ */
+/* $Id: s_triangle.c,v 1.60 2002/07/09 01:22:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -218,7 +218,7 @@ static void simple_textured_triangle( GLcontext *ctx,
span->intTex[1] += span->intTexStep[1]; \
} \
(*swrast->Driver.WriteRGBSpan)(ctx, span->end, span->x, span->y, \
- (CONST GLchan (*)[3]) span->color.rgb, \
+ (CONST GLchan (*)[3]) span->color.rgb,\
NULL );
#include "s_tritemp.h"
@@ -283,7 +283,7 @@ static void simple_z_textured_triangle( GLcontext *ctx,
span->z += span->zStep; \
} \
(*swrast->Driver.WriteRGBSpan)(ctx, span->end, span->x, span->y, \
- (CONST GLchan (*)[3]) span->color.rgb, \
+ (CONST GLchan (*)[3]) span->color.rgb,\
span->mask );
#include "s_tritemp.h"
@@ -589,7 +589,7 @@ static void affine_textured_triangle( GLcontext *ctx,
info.format = obj->Image[b]->Format; \
info.filter = obj->MinFilter; \
info.envmode = unit->EnvMode; \
- span->arrayMask |= SPAN_RGBA; \
+ span->arrayMask |= SPAN_RGBA; \
\
if (info.envmode == GL_BLEND) { \
/* potential off-by-one error here? (1.0f -> 2048 -> 0) */ \
@@ -896,7 +896,7 @@ static void persp_textured_triangle( GLcontext *ctx,
#define RENDER_SPAN( span ) \
span->interpMask &= ~SPAN_RGBA; \
- span->arrayMask |= SPAN_RGBA; \
+ span->arrayMask |= SPAN_RGBA; \
fast_persp_span(ctx, span, &info);
#include "s_tritemp.h"
@@ -976,7 +976,7 @@ static void occlusion_zless_triangle( GLcontext *ctx,
#define RENDER_SPAN( span ) \
GLuint i; \
for (i = 0; i < span->end; i++) { \
- GLdepth z = FixedToDepth(span->z); \
+ GLdepth z = FixedToDepth(span->z); \
if (z < zRow[i]) { \
ctx->OcclusionResult = GL_TRUE; \
return; \
diff --git a/src/mesa/swrast/swrast.h b/src/mesa/swrast/swrast.h
index f36031cfb4a..a33e97ec017 100644
--- a/src/mesa/swrast/swrast.h
+++ b/src/mesa/swrast/swrast.h
@@ -1,4 +1,4 @@
-/* $Id: swrast.h,v 1.24 2002/04/19 14:05:50 brianp Exp $ */
+/* $Id: swrast.h,v 1.25 2002/07/09 01:22:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -204,6 +204,12 @@ struct swrast_device_driver;
extern void
_swrast_alloc_buffers( GLframebuffer *buffer );
+extern void
+_swrast_use_read_buffer( GLcontext *ctx );
+
+extern void
+_swrast_use_draw_buffer( GLcontext *ctx );
+
extern GLboolean
_swrast_CreateContext( GLcontext *ctx );
@@ -254,6 +260,10 @@ _swrast_Accum( GLcontext *ctx, GLenum op,
GLint width, GLint height );
+extern void
+_swrast_DrawBuffer( GLcontext *ctx, GLenum mode );
+
+
/* Reset the stipple counter
*/
extern void
@@ -363,11 +373,14 @@ _swrast_copy_texsubimage3d(GLcontext *ctx,
*/
struct swrast_device_driver {
- void (*SetReadBuffer)( GLcontext *ctx, GLframebuffer *colorBuffer,
- GLenum buffer );
+ void (*SetBuffer)( GLcontext *ctx, GLframebuffer *buffer,
+ GLenum colorBuffer );
/*
- * Specifies the current buffer for span/pixel reading.
- * colorBuffer will be one of:
+ * Specifies the current buffer for span/pixel writing/reading.
+ * buffer indicates which window to write to / read from. Normally,
+ * this'll be the buffer currently bound to the context, but it doesn't
+ * have to be!
+ * colorBuffer indicates which color buffer, one of:
* GL_FRONT_LEFT - this buffer always exists
* GL_BACK_LEFT - when double buffering
* GL_FRONT_RIGHT - when using stereo