mesa: minor whitespace fixes in teximage.c
[mesa.git] / src / mesa / main / buffers.c
index ef6ca9f96e7937f50d0aa89102a8e9be0e4a5bac..216b6ee876fec0ded698adc0b60ef0b33b040524 100644 (file)
@@ -35,6 +35,7 @@
 #include "colormac.h"
 #include "context.h"
 #include "enums.h"
+#include "fbobject.h"
 #include "mtypes.h"
 
 
  * \return  bitmask of BUFFER_BIT_* flags
  */
 static GLbitfield
-supported_buffer_bitmask(const struct gl_context *ctx, const struct gl_framebuffer *fb)
+supported_buffer_bitmask(const struct gl_context *ctx,
+                         const struct gl_framebuffer *fb)
 {
    GLbitfield mask = 0x0;
 
-   if (fb->Name > 0) {
+   if (_mesa_is_user_fbo(fb)) {
       /* A user-created renderbuffer */
       GLuint i;
       ASSERT(ctx->Extensions.EXT_framebuffer_object);
@@ -242,7 +244,8 @@ _mesa_DrawBuffer(GLenum buffer)
       destMask = draw_buffer_enum_to_bitmask(buffer);
       if (destMask == BAD_MASK) {
          /* totally bogus buffer */
-         _mesa_error(ctx, GL_INVALID_ENUM, "glDrawBuffer(buffer=0x%x)", buffer);
+         _mesa_error(ctx, GL_INVALID_ENUM,
+                     "glDrawBuffer(buffer=0x%x)", buffer);
          return;
       }
       destMask &= supportedMask;
@@ -340,6 +343,7 @@ _mesa_DrawBuffersARB(GLsizei n, const GLenum *buffers)
       ctx->Driver.DrawBuffer(ctx, n > 0 ? buffers[0] : GL_NONE);
 }
 
+
 /**
  * Performs necessary state updates when _mesa_drawbuffers makes an
  * actual change.
@@ -350,17 +354,18 @@ updated_drawbuffers(struct gl_context *ctx)
    FLUSH_VERTICES(ctx, _NEW_BUFFERS);
 
 #if FEATURE_GL
-   if (ctx->API == API_OPENGL) {
+   if (ctx->API == API_OPENGL && !ctx->Extensions.ARB_ES2_compatibility) {
       struct gl_framebuffer *fb = ctx->DrawBuffer;
 
       /* Flag the FBO as requiring validation. */
-      if (fb->Name != 0) {
+      if (_mesa_is_user_fbo(fb)) {
         fb->_Status = 0;
       }
    }
 #endif
 }
 
+
 /**
  * Helper function to set the GL_DRAW_BUFFER state in the context and
  * current FBO.  Called via glDrawBuffer(), glDrawBuffersARB()
@@ -381,6 +386,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 */
@@ -401,66 +407,85 @@ _mesa_drawbuffers(struct gl_context *ctx, GLuint n, const GLenum *buffers,
    if (n == 1) {
       GLuint count = 0, destMask0 = destMask[0];
       while (destMask0) {
-         GLint bufIndex = _mesa_ffs(destMask0) - 1;
+         GLint bufIndex = ffs(destMask0) - 1;
          if (fb->_ColorDrawBufferIndexes[count] != bufIndex) {
-            fb->_ColorDrawBufferIndexes[count] = bufIndex;
             updated_drawbuffers(ctx);
+            fb->_ColorDrawBufferIndexes[count] = bufIndex;
          }
          count++;
          destMask0 &= ~(1 << bufIndex);
       }
       fb->ColorDrawBuffer[0] = buffers[0];
-      if (fb->_NumColorDrawBuffers != count) {
-         fb->_NumColorDrawBuffers = count;
-        updated_drawbuffers(ctx);
-      }
+      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;
+            GLint bufIndex = 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;
               updated_drawbuffers(ctx);
+               fb->_ColorDrawBufferIndexes[buf] = bufIndex;
             }
             count = buf + 1;
          }
          else {
             if (fb->_ColorDrawBufferIndexes[buf] != -1) {
-               fb->_ColorDrawBufferIndexes[buf] = -1;
               updated_drawbuffers(ctx);
+               fb->_ColorDrawBufferIndexes[buf] = -1;
             }
          }
          fb->ColorDrawBuffer[buf] = buffers[buf];
       }
-      /* set remaining outputs to -1 (GL_NONE) */
-      while (buf < ctx->Const.MaxDrawBuffers) {
-         if (fb->_ColorDrawBufferIndexes[buf] != -1) {
-            fb->_ColorDrawBufferIndexes[buf] = -1;
-           updated_drawbuffers(ctx);
-         }
-         fb->ColorDrawBuffer[buf] = GL_NONE;
-         buf++;
-      }
       fb->_NumColorDrawBuffers = count;
    }
 
-   if (fb->Name == 0) {
+   /* set remaining outputs to -1 (GL_NONE) */
+   for (buf = fb->_NumColorDrawBuffers; buf < ctx->Const.MaxDrawBuffers; buf++) {
+      if (fb->_ColorDrawBufferIndexes[buf] != -1) {
+         updated_drawbuffers(ctx);
+         fb->_ColorDrawBufferIndexes[buf] = -1;
+      }
+   }
+   for (buf = n; buf < ctx->Const.MaxDrawBuffers; buf++) {
+      fb->ColorDrawBuffer[buf] = GL_NONE;
+   }
+
+   if (_mesa_is_winsys_fbo(fb)) {
       /* also set context drawbuffer state */
-      GLuint buf;
       for (buf = 0; buf < ctx->Const.MaxDrawBuffers; buf++) {
          if (ctx->Color.DrawBuffer[buf] != fb->ColorDrawBuffer[buf]) {
-            ctx->Color.DrawBuffer[buf] = fb->ColorDrawBuffer[buf];
            updated_drawbuffers(ctx);
+            ctx->Color.DrawBuffer[buf] = fb->ColorDrawBuffer[buf];
          }
       }
    }
 }
 
 
+/**
+ * Update the current drawbuffer's _ColorDrawBufferIndex[] list, etc.
+ * from the context's Color.DrawBuffer[] state.
+ * Use when changing contexts.
+ */
+void
+_mesa_update_draw_buffers(struct gl_context *ctx)
+{
+   GLenum buffers[MAX_DRAW_BUFFERS];
+   GLuint i;
+
+   /* should be a window system FBO */
+   assert(_mesa_is_winsys_fbo(ctx->DrawBuffer));
+
+   for (i = 0; i < ctx->Const.MaxDrawBuffers; i++)
+      buffers[i] = ctx->Color.DrawBuffer[i];
+
+   _mesa_drawbuffers(ctx, ctx->Const.MaxDrawBuffers, buffers, NULL);
+}
+
+
 /**
  * Like \sa _mesa_drawbuffers(), this is a helper function for setting
  * GL_READ_BUFFER state in the context and current FBO.
@@ -473,7 +498,7 @@ _mesa_readbuffer(struct gl_context *ctx, GLenum buffer, GLint bufferIndex)
 {
    struct gl_framebuffer *fb = ctx->ReadBuffer;
 
-   if (fb->Name == 0) {
+   if (_mesa_is_winsys_fbo(fb)) {
       /* Only update the per-context READ_BUFFER state if we're bound to
        * a window-system framebuffer.
        */
@@ -509,7 +534,7 @@ _mesa_ReadBuffer(GLenum buffer)
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glReadBuffer %s\n", _mesa_lookup_enum_by_nr(buffer));
 
-   if (fb->Name > 0 && buffer == GL_NONE) {
+   if (_mesa_is_user_fbo(fb) && buffer == GL_NONE) {
       /* This is legal for user-created framebuffer objects */
       srcBuffer = -1;
    }