summaryrefslogtreecommitdiff
path: root/src/mesa/main/buffers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main/buffers.c')
-rw-r--r--src/mesa/main/buffers.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c
index b23d2f612b..d8b5f3b1f4 100644
--- a/src/mesa/main/buffers.c
+++ b/src/mesa/main/buffers.c
@@ -120,11 +120,9 @@ draw_buffer_enum_to_bitmask(GLenum buffer)
case GL_AUX0:
return BUFFER_BIT_AUX0;
case GL_AUX1:
- return BUFFER_BIT_AUX1;
case GL_AUX2:
- return BUFFER_BIT_AUX2;
case GL_AUX3:
- return BUFFER_BIT_AUX3;
+ return 1 << BUFFER_COUNT; /* invalid, but not BAD_MASK */
case GL_COLOR_ATTACHMENT0_EXT:
return BUFFER_BIT_COLOR0;
case GL_COLOR_ATTACHMENT1_EXT:
@@ -177,11 +175,9 @@ read_buffer_enum_to_index(GLenum buffer)
case GL_AUX0:
return BUFFER_AUX0;
case GL_AUX1:
- return BUFFER_AUX1;
case GL_AUX2:
- return BUFFER_AUX2;
case GL_AUX3:
- return BUFFER_AUX3;
+ return BUFFER_COUNT; /* invalid, but not -1 */
case GL_COLOR_ATTACHMENT0_EXT:
return BUFFER_COLOR0;
case GL_COLOR_ATTACHMENT1_EXT:
@@ -247,13 +243,14 @@ _mesa_DrawBuffer(GLenum buffer)
destMask = draw_buffer_enum_to_bitmask(buffer);
if (destMask == BAD_MASK) {
/* totally bogus buffer */
- _mesa_error(ctx, GL_INVALID_ENUM, "glDrawBuffer(buffer)");
+ _mesa_error(ctx, GL_INVALID_ENUM, "glDrawBuffer(buffer=0x%x)", buffer);
return;
}
destMask &= supportedMask;
if (destMask == 0x0) {
/* none of the named color buffers exist! */
- _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawBuffer(buffer)");
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glDrawBuffer(buffer=0x%x)", buffer);
return;
}
}
@@ -289,11 +286,10 @@ _mesa_DrawBuffersARB(GLsizei n, const GLenum *buffers)
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- if (!ctx->Extensions.ARB_draw_buffers) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawBuffersARB");
- return;
- }
- if (n < 1 || n > (GLsizei) ctx->Const.MaxDrawBuffers) {
+ /* Turns out n==0 is a valid input that should not produce an error.
+ * The remaining code below correctly handles the n==0 case.
+ */
+ if (n < 0 || n > (GLsizei) ctx->Const.MaxDrawBuffers) {
_mesa_error(ctx, GL_INVALID_VALUE, "glDrawBuffersARB(n)");
return;
}
@@ -335,12 +331,14 @@ _mesa_DrawBuffersARB(GLsizei n, const GLenum *buffers)
_mesa_drawbuffers(ctx, n, buffers, destMask);
/*
- * Call device driver function.
+ * Call device driver function. Note that n can be equal to 0,
+ * in which case we don't want to reference buffers[0], which
+ * may not be valid.
*/
if (ctx->Driver.DrawBuffers)
ctx->Driver.DrawBuffers(ctx, n, buffers);
else if (ctx->Driver.DrawBuffer)
- ctx->Driver.DrawBuffer(ctx, buffers[0]);
+ ctx->Driver.DrawBuffer(ctx, n>0? buffers[0]:GL_NONE);
}
@@ -419,7 +417,7 @@ _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers,
}
}
- ctx->NewState |= _NEW_COLOR;
+ ctx->NewState |= _NEW_BUFFERS;
}
@@ -445,7 +443,7 @@ _mesa_readbuffer(GLcontext *ctx, GLenum buffer, GLint bufferIndex)
fb->ColorReadBuffer = buffer;
fb->_ColorReadBufferIndex = bufferIndex;
- ctx->NewState |= _NEW_PIXEL;
+ ctx->NewState |= _NEW_BUFFERS;
}
@@ -494,6 +492,7 @@ _mesa_ReadBuffer(GLenum buffer)
/* OK, all error checking has been completed now */
_mesa_readbuffer(ctx, buffer, srcBuffer);
+ ctx->NewState |= _NEW_BUFFERS;
/*
* Call device driver function.