X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fbuffers.c;h=5c37f3d1a86874d8e85d5fbd86cb0bd039cfec12;hb=ad3dc370d86e3cfdb5e766bbf6dfbf247807044c;hp=d8b5f3b1f4aafe02bbd5f53e27b8644210901682;hpb=8398535331dae39ff5f52e94a69abdbf7507a343;p=mesa.git diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c index d8b5f3b1f4a..5c37f3d1a86 100644 --- a/src/mesa/main/buffers.c +++ b/src/mesa/main/buffers.c @@ -35,8 +35,7 @@ #include "colormac.h" #include "context.h" #include "enums.h" -#include "fbobject.h" -#include "state.h" +#include "mtypes.h" #define BAD_MASK ~0u @@ -52,7 +51,7 @@ * \return bitmask of BUFFER_BIT_* flags */ static GLbitfield -supported_buffer_bitmask(const GLcontext *ctx, const struct gl_framebuffer *fb) +supported_buffer_bitmask(const struct gl_context *ctx, const struct gl_framebuffer *fb) { GLbitfield mask = 0x0; @@ -338,13 +337,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. @@ -357,11 +356,12 @@ _mesa_DrawBuffersARB(GLsizei n, const GLenum *buffers) * BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT). */ void -_mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers, +_mesa_drawbuffers(struct gl_context *ctx, GLuint n, const GLenum *buffers, const GLbitfield *destMask) { struct gl_framebuffer *fb = ctx->DrawBuffer; GLbitfield mask[MAX_DRAW_BUFFERS]; + GLboolean newState = GL_FALSE; if (!destMask) { /* compute destMask values now */ @@ -375,34 +375,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 +433,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); } @@ -429,7 +453,7 @@ _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers, * \param bufferIndex the numerical index corresponding to 'buffer' */ void -_mesa_readbuffer(GLcontext *ctx, GLenum buffer, GLint bufferIndex) +_mesa_readbuffer(struct gl_context *ctx, GLenum buffer, GLint bufferIndex) { struct gl_framebuffer *fb = ctx->ReadBuffer;