summaryrefslogtreecommitdiff
path: root/src/mesa/main/buffers.c
diff options
context:
space:
mode:
authorKeith Whitwell <keithw@vmware.com>2009-12-21 19:18:41 +0000
committerKeith Whitwell <keithw@vmware.com>2009-12-21 19:18:41 +0000
commita5585cb533af3d4e5d5324d5f526447b98597402 (patch)
tree6706dbb8b4f994b919e247647c3e8853d067b45c /src/mesa/main/buffers.c
parentd288a30610767f87e3e7c069730d4bc255246568 (diff)
parent574715d8368f99c0a5720a9676385d58d6cfdf30 (diff)
Merge commit 'origin/master' into i965g-restart
Conflicts: SConstruct configs/default configs/linux-dri
Diffstat (limited to 'src/mesa/main/buffers.c')
-rw-r--r--src/mesa/main/buffers.c55
1 files changed, 40 insertions, 15 deletions
diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c
index d8b5f3b1f4..97f0659758 100644
--- a/src/mesa/main/buffers.c
+++ b/src/mesa/main/buffers.c
@@ -338,13 +338,13 @@ _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);
}
/**
* 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.
@@ -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 */
@@ -375,34 +376,54 @@ _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;
- /* 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++;
+ GLuint count = 0, destMask0 = destMask[0];
+ while (destMask0) {
+ GLint bufIndex = _mesa_ffs(destMask0) - 1;
+ 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]) {
- fb->_ColorDrawBufferIndexes[buf] = _mesa_ffs(destMask[buf]) - 1;
+ GLint bufIndex = _mesa_ffs(destMask[buf]) - 1;
+ /* only one bit should be set in the destMask[buf] field */
+ ASSERT(_mesa_bitcount(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;
+ newState = GL_TRUE;
+ }
fb->ColorDrawBuffer[buf] = GL_NONE;
buf++;
}
@@ -413,11 +434,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)
+ FLUSH_VERTICES(ctx, _NEW_BUFFERS);
}