aboutsummaryrefslogtreecommitdiffstats
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.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c
index 818d068a12b..c5f13345f04 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:
@@ -290,7 +286,10 @@ _mesa_DrawBuffersARB(GLsizei n, const GLenum *buffers)
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- 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;
}
@@ -332,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);
}