mesa/st: enable carry/borrow lowering pass
[mesa.git] / src / mesa / main / clear.c
index f0b525fa017fa47213e3362f62eae5ab21930692..9df1f5e098c4b4996e05b5a5ab2793d3ecf5c14c 100644 (file)
@@ -106,6 +106,31 @@ _mesa_ClearColorIuiEXT(GLuint r, GLuint g, GLuint b, GLuint a)
 }
 
 
+/**
+ * Returns true if color writes are enabled for the given color attachment.
+ *
+ * Beyond checking ColorMask, this uses _mesa_format_has_color_component to
+ * ignore components that don't actually exist in the format (such as X in
+ * XRGB).
+ */
+static bool
+color_buffer_writes_enabled(const struct gl_context *ctx, unsigned idx)
+{
+   struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[idx];
+   GLuint c;
+   GLubyte colorMask = 0;
+
+   if (rb) {
+      for (c = 0; c < 4; c++) {
+         if (_mesa_format_has_color_component(rb->Format, c))
+            colorMask |= ctx->Color.ColorMask[idx][c];
+      }
+   }
+
+   return colorMask != 0;
+}
+
+
 /**
  * Clear buffers.
  * 
@@ -179,7 +204,11 @@ _mesa_Clear( GLbitfield mask )
       if (mask & GL_COLOR_BUFFER_BIT) {
          GLuint i;
          for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
-            bufferMask |= (1 << ctx->DrawBuffer->_ColorDrawBufferIndexes[i]);
+            GLint buf = ctx->DrawBuffer->_ColorDrawBufferIndexes[i];
+
+            if (buf >= 0 && color_buffer_writes_enabled(ctx, i)) {
+               bufferMask |= 1 << buf;
+            }
          }
       }
 
@@ -274,7 +303,7 @@ make_color_buffer_mask(struct gl_context *ctx, GLint drawbuffer)
       break;
    default:
       {
-         GLuint buf = ctx->DrawBuffer->_ColorDrawBufferIndexes[drawbuffer];
+         GLint buf = ctx->DrawBuffer->_ColorDrawBufferIndexes[drawbuffer];
 
          if (buf >= 0 && att[buf].Renderbuffer) {
             mask |= 1 << buf;