From 2d11c48223adb78353ca32f0cc07941957310389 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 2 Nov 2009 12:58:51 -0700 Subject: mesa: added assertion, another comment --- src/mesa/main/buffers.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/mesa/main/buffers.c') diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c index d8b5f3b1f4..b5acda8823 100644 --- a/src/mesa/main/buffers.c +++ b/src/mesa/main/buffers.c @@ -344,7 +344,7 @@ _mesa_DrawBuffersARB(GLsizei n, const GLenum *buffers) /** * Helper function to set the GL_DRAW_BUFFER state in the context and - * current FBO. + * current FBO. Called via glDrawBuffer(), glDrawBuffersARB() * * All error checking will have been done prior to calling this function * so nothing should go wrong at this point. @@ -392,6 +392,8 @@ _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers, GLuint buf, count = 0; for (buf = 0; buf < n; buf++ ) { if (destMask[buf]) { + /* only one bit should be set in the destMask[buf] field */ + ASSERT(_mesa_bitcount(destMask[buf]) == 1); fb->_ColorDrawBufferIndexes[buf] = _mesa_ffs(destMask[buf]) - 1; fb->ColorDrawBuffer[buf] = buffers[buf]; count = buf + 1; -- cgit v1.2.3 From b28c637382cd3c3fcd54cd77062dab3df78230a9 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 2 Nov 2009 13:20:19 -0700 Subject: mesa: use ffs() to shorten loop in _mesa_drawbuffers() --- src/mesa/main/buffers.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/mesa/main/buffers.c') diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c index b5acda8823..cdd16a8ad1 100644 --- a/src/mesa/main/buffers.c +++ b/src/mesa/main/buffers.c @@ -375,15 +375,19 @@ _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers, destMask = mask; } + /* + * If n==1, destMask[0] may have up to four bits set. + * Otherwise, destMask[x] can only have one bit set. + */ if (n == 1) { - GLuint buf, count = 0; + GLuint count = 0, destMask0 = destMask[0]; /* init to -1 to help catch errors */ fb->_ColorDrawBufferIndexes[0] = -1; - for (buf = 0; buf < BUFFER_COUNT; buf++) { - if (destMask[0] & (1 << buf)) { - fb->_ColorDrawBufferIndexes[count] = buf; - count++; - } + while (destMask0) { + GLint bufIndex = _mesa_ffs(destMask0) - 1; + fb->_ColorDrawBufferIndexes[count] = bufIndex; + count++; + destMask0 &= ~(1 << bufIndex); } fb->ColorDrawBuffer[0] = buffers[0]; fb->_NumColorDrawBuffers = count; -- cgit v1.2.3 From 8df699b3bb1aa05b633f05b121d09d812c86a22d Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 2 Nov 2009 14:41:17 -0700 Subject: mesa: avoid extraneous _NEW_BUFFER state in _mesa_drawbuffers() --- src/mesa/main/buffers.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'src/mesa/main/buffers.c') diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c index cdd16a8ad1..028644fe4b 100644 --- a/src/mesa/main/buffers.c +++ b/src/mesa/main/buffers.c @@ -362,6 +362,7 @@ _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers, { struct gl_framebuffer *fb = ctx->DrawBuffer; GLbitfield mask[MAX_DRAW_BUFFERS]; + GLboolean newState = GL_FALSE; if (!destMask) { /* compute destMask values now */ @@ -382,35 +383,50 @@ _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers, if (n == 1) { GLuint count = 0, destMask0 = destMask[0]; /* init to -1 to help catch errors */ - fb->_ColorDrawBufferIndexes[0] = -1; + //fb->_ColorDrawBufferIndexes[0] = -1; while (destMask0) { GLint bufIndex = _mesa_ffs(destMask0) - 1; - fb->_ColorDrawBufferIndexes[count] = bufIndex; + if (fb->_ColorDrawBufferIndexes[count] != bufIndex) { + fb->_ColorDrawBufferIndexes[count] = bufIndex; + newState = GL_TRUE; + } count++; destMask0 &= ~(1 << bufIndex); } fb->ColorDrawBuffer[0] = buffers[0]; - fb->_NumColorDrawBuffers = count; + if (fb->_NumColorDrawBuffers != count) { + fb->_NumColorDrawBuffers = count; + newState = GL_TRUE; + } } else { GLuint buf, count = 0; for (buf = 0; buf < n; buf++ ) { if (destMask[buf]) { + GLint bufIndex = _mesa_ffs(destMask[buf]) - 1; /* only one bit should be set in the destMask[buf] field */ ASSERT(_mesa_bitcount(destMask[buf]) == 1); - fb->_ColorDrawBufferIndexes[buf] = _mesa_ffs(destMask[buf]) - 1; + if (fb->_ColorDrawBufferIndexes[buf] != bufIndex) { + fb->_ColorDrawBufferIndexes[buf] = bufIndex; + newState = GL_TRUE; + } fb->ColorDrawBuffer[buf] = buffers[buf]; count = buf + 1; } else { - fb->_ColorDrawBufferIndexes[buf] = -1; + if (fb->_ColorDrawBufferIndexes[buf] != -1) { + fb->_ColorDrawBufferIndexes[buf] = -1; + newState = GL_TRUE; + } } } /* set remaining outputs to -1 (GL_NONE) */ while (buf < ctx->Const.MaxDrawBuffers) { - fb->_ColorDrawBufferIndexes[buf] = -1; + if (fb->_ColorDrawBufferIndexes[buf] != -1) { + fb->_ColorDrawBufferIndexes[buf] = -1; + buf++; + } fb->ColorDrawBuffer[buf] = GL_NONE; - buf++; } fb->_NumColorDrawBuffers = count; } @@ -419,11 +435,15 @@ _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers, /* also set context drawbuffer state */ GLuint buf; for (buf = 0; buf < ctx->Const.MaxDrawBuffers; buf++) { - ctx->Color.DrawBuffer[buf] = fb->ColorDrawBuffer[buf]; + if (ctx->Color.DrawBuffer[buf] != fb->ColorDrawBuffer[buf]) { + ctx->Color.DrawBuffer[buf] = fb->ColorDrawBuffer[buf]; + newState = GL_TRUE; + } } } - ctx->NewState |= _NEW_BUFFERS; + if (newState) + ctx->NewState |= _NEW_BUFFERS; } -- cgit v1.2.3 From c7048f9d9f91ef8c3ef35e31976adbf686349c41 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 2 Nov 2009 15:27:57 -0700 Subject: mesa: use FLUSH_VERTICES() in _mesa_drawbuffers() --- src/mesa/main/buffers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa/main/buffers.c') diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c index 028644fe4b..740ac3f4ae 100644 --- a/src/mesa/main/buffers.c +++ b/src/mesa/main/buffers.c @@ -443,7 +443,7 @@ _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers, } if (newState) - ctx->NewState |= _NEW_BUFFERS; + FLUSH_VERTICES(ctx, _NEW_BUFFERS); } -- cgit v1.2.3 From 5698d7cd7557659440f8417716839ba07cffc5a5 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 2 Nov 2009 15:29:54 -0700 Subject: mesa: clean-up formatting --- src/mesa/main/buffers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa/main/buffers.c') diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c index 740ac3f4ae..e76cf87cb0 100644 --- a/src/mesa/main/buffers.c +++ b/src/mesa/main/buffers.c @@ -338,7 +338,7 @@ _mesa_DrawBuffersARB(GLsizei n, const GLenum *buffers) if (ctx->Driver.DrawBuffers) ctx->Driver.DrawBuffers(ctx, n, buffers); else if (ctx->Driver.DrawBuffer) - ctx->Driver.DrawBuffer(ctx, n>0? buffers[0]:GL_NONE); + ctx->Driver.DrawBuffer(ctx, n > 0 ? buffers[0] : GL_NONE); } -- cgit v1.2.3 From d971069fc6f5dcec64b1f1a60a8a2e7063aaf018 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 5 Nov 2009 13:16:19 -0700 Subject: mesa: fix infinite loop bug in _mesa_drawbuffers() Fixes bug 24946. This regression came from 8df699b3bb1aa05b633f05b121d09d812c86a22d. --- src/mesa/main/buffers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/mesa/main/buffers.c') diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c index e76cf87cb0..7f77c5d772 100644 --- a/src/mesa/main/buffers.c +++ b/src/mesa/main/buffers.c @@ -424,9 +424,10 @@ _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers, while (buf < ctx->Const.MaxDrawBuffers) { if (fb->_ColorDrawBufferIndexes[buf] != -1) { fb->_ColorDrawBufferIndexes[buf] = -1; - buf++; + newState = GL_TRUE; } fb->ColorDrawBuffer[buf] = GL_NONE; + buf++; } fb->_NumColorDrawBuffers = count; } -- cgit v1.2.3 From e36751ec81736a8466b1a6a722c1b2cf578d713b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 17 Nov 2009 16:05:24 -0700 Subject: mesa: remove a bit of old code --- src/mesa/main/buffers.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/mesa/main/buffers.c') diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c index 7f77c5d772..7c31a46ab9 100644 --- a/src/mesa/main/buffers.c +++ b/src/mesa/main/buffers.c @@ -383,7 +383,6 @@ _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers, if (n == 1) { GLuint count = 0, destMask0 = destMask[0]; /* init to -1 to help catch errors */ - //fb->_ColorDrawBufferIndexes[0] = -1; while (destMask0) { GLint bufIndex = _mesa_ffs(destMask0) - 1; if (fb->_ColorDrawBufferIndexes[count] != bufIndex) { -- cgit v1.2.3 From a54033bedb1d3ac7f7a0c1365c25c638e58de566 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 17 Nov 2009 16:18:29 -0700 Subject: mesa: remove old comment --- src/mesa/main/buffers.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/mesa/main/buffers.c') diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c index 7c31a46ab9..97f0659758 100644 --- a/src/mesa/main/buffers.c +++ b/src/mesa/main/buffers.c @@ -382,7 +382,6 @@ _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers, */ if (n == 1) { GLuint count = 0, destMask0 = destMask[0]; - /* init to -1 to help catch errors */ while (destMask0) { GLint bufIndex = _mesa_ffs(destMask0) - 1; if (fb->_ColorDrawBufferIndexes[count] != bufIndex) { -- cgit v1.2.3