Mesa (master): glDrawBuffers(n==0) is valid

Robert Ellison papillo at kemper.freedesktop.org
Thu Feb 12 20:51:27 UTC 2009


Module: Mesa
Branch: master
Commit: 5de5ab428cf5516d91daa3f193a76b0d87853f55
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=5de5ab428cf5516d91daa3f193a76b0d87853f55

Author: Robert Ellison <papillo at i965-laptop.(none)>
Date:   Thu Feb 12 13:47:36 2009 -0700

glDrawBuffers(n==0) is valid

According to the GL spec, calling glDrawBuffers() with n == 0 is a
valid operation (and essentially prevents drawing to any buffers).
But _msa_DrawBuffersARB() was producing a GL_INVALID_VALUE error in
this case.

This fix adjusts the error check, and makes a small change to the
ctx->Driver.DrawBuffer() call below to ensure that, if n == 0,
Driver.DrawBuffer() is called with GL_NONE and that buffers[0] is
*not* referenced in this case (since we don't know whether it is valid).

Internal identifier: 365833

---

 src/mesa/main/buffers.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c
index 818d068..85db386 100644
--- a/src/mesa/main/buffers.c
+++ b/src/mesa/main/buffers.c
@@ -290,7 +290,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 +335,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);
 }
 
 




More information about the mesa-commit mailing list