[Mesa-dev] [PATCH] mesa: Also set the remaining draw buffers to GL_NONE when updating just the first buffer in _mesa_drawbuffers().

Eric Anholt eric at anholt.net
Thu Sep 22 16:48:23 PDT 2011


On Thu, 22 Sep 2011 23:48:23 +0200, Henri Verbeet <hverbeet at gmail.com> wrote:
> Without this we'd miss the last update in a sequence like {COLOR0, COLOR1},
> {COLOR0}, {COLOR0, COLOR1}. I originally had a patch for this that called
> updated_drawbuffers() when the buffer count changed, but later realized that
> was wrong. The ARB_draw_buffers spec explicitly says "The draw buffer for
> output colors beyond <n> is set to NONE.", and this is queryable state.
> This fixes piglit arb_draw_buffers-state_change.
> 
> NOTE: This is a candidate for the 7.10 and 7.11 branches.
> 
> Signed-off-by: Henri Verbeet <hverbeet at gmail.com>
> ---
>  src/mesa/main/buffers.c |   27 ++++++++++++---------------
>  1 files changed, 12 insertions(+), 15 deletions(-)
> 
> diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c
> index a75c9c2..12103a7 100644
> --- a/src/mesa/main/buffers.c
> +++ b/src/mesa/main/buffers.c
> @@ -381,6 +381,7 @@ _mesa_drawbuffers(struct gl_context *ctx, GLuint n, const GLenum *buffers,
>  {
>     struct gl_framebuffer *fb = ctx->DrawBuffer;
>     GLbitfield mask[MAX_DRAW_BUFFERS];
> +   GLuint buf;
>  
>     if (!destMask) {
>        /* compute destMask values now */
> @@ -410,13 +411,10 @@ _mesa_drawbuffers(struct gl_context *ctx, GLuint n, const GLenum *buffers,
>           destMask0 &= ~(1 << bufIndex);
>        }
>        fb->ColorDrawBuffer[0] = buffers[0];
> -      if (fb->_NumColorDrawBuffers != count) {
> -	 updated_drawbuffers(ctx);
> -         fb->_NumColorDrawBuffers = count;
> -      }
> +      fb->_NumColorDrawBuffers = count;
>     }
>     else {
> -      GLuint buf, count = 0;
> +      GLuint count = 0;
>        for (buf = 0; buf < n; buf++ ) {
>           if (destMask[buf]) {
>              GLint bufIndex = _mesa_ffs(destMask[buf]) - 1;
> @@ -436,21 +434,20 @@ _mesa_drawbuffers(struct gl_context *ctx, GLuint n, const GLenum *buffers,
>           }
>           fb->ColorDrawBuffer[buf] = buffers[buf];
>        }
> -      /* set remaining outputs to -1 (GL_NONE) */
> -      while (buf < ctx->Const.MaxDrawBuffers) {
> -         if (fb->_ColorDrawBufferIndexes[buf] != -1) {
> -	    updated_drawbuffers(ctx);
> -            fb->_ColorDrawBufferIndexes[buf] = -1;
> -         }
> -         fb->ColorDrawBuffer[buf] = GL_NONE;
> -         buf++;
> -      }
>        fb->_NumColorDrawBuffers = count;
>     }
>  
> +   /* set remaining outputs to -1 (GL_NONE) */
> +   for (buf = n; buf < ctx->Const.MaxDrawBuffers; buf++) {
> +      if (fb->_ColorDrawBufferIndexes[buf] != -1) {
> +         updated_drawbuffers(ctx);
> +         fb->_ColorDrawBufferIndexes[buf] = -1;
> +      }
> +      fb->ColorDrawBuffer[buf] = GL_NONE;
> +   }

In the case of n == 1 with more than one bit set, doesn't this stomp the
_ColorDrawBufferIndexes[] we just calculated between n and
_NumColorDrawBuffers - 1?  Looks like splitting that loop into two would
work well.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110922/148d4bca/attachment.pgp>


More information about the mesa-dev mailing list