Merge branch 'const-buffer-changes'
[mesa.git] / src / mesa / drivers / dri / intel / intel_clear.c
index a47c4d4050e3193115e9e7048badb49b6e488658..aed95c7c56157776a3bb04e27614d29565b34d68 100644 (file)
@@ -38,6 +38,7 @@
 #include "main/enable.h"
 #include "main/macros.h"
 #include "main/matrix.h"
+#include "main/polygon.h"
 #include "main/texstate.h"
 #include "main/shaders.h"
 #include "main/stencil.h"
 
 #define FILE_DEBUG_FLAG DEBUG_BLIT
 
+#define TRI_CLEAR_COLOR_BITS (BUFFER_BIT_BACK_LEFT |                   \
+                             BUFFER_BIT_FRONT_LEFT |                   \
+                             BUFFER_BIT_COLOR0 |                       \
+                             BUFFER_BIT_COLOR1 |                       \
+                             BUFFER_BIT_COLOR2 |                       \
+                             BUFFER_BIT_COLOR3 |                       \
+                             BUFFER_BIT_COLOR4 |                       \
+                             BUFFER_BIT_COLOR5 |                       \
+                             BUFFER_BIT_COLOR6 |                       \
+                             BUFFER_BIT_COLOR7)
+
 /**
  * Perform glClear where mask contains only color, depth, and/or stencil.
  *
@@ -72,16 +84,17 @@ intel_clear_tris(GLcontext *ctx, GLbitfield mask)
    struct gl_framebuffer *fb = ctx->DrawBuffer;
    int i;
    GLboolean saved_fp_enable = GL_FALSE, saved_vp_enable = GL_FALSE;
-   GLboolean saved_shader_program = 0;
+   GLuint saved_shader_program = 0;
    unsigned int saved_active_texture;
 
-   assert((mask & ~(BUFFER_BIT_BACK_LEFT | BUFFER_BIT_FRONT_LEFT |
-                   BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL)) == 0);
+   assert((mask & ~(TRI_CLEAR_COLOR_BITS | BUFFER_BIT_DEPTH |
+                   BUFFER_BIT_STENCIL)) == 0);
 
    _mesa_PushAttrib(GL_COLOR_BUFFER_BIT |
                    GL_CURRENT_BIT |
                    GL_DEPTH_BUFFER_BIT |
                    GL_ENABLE_BIT |
+                   GL_POLYGON_BIT |
                    GL_STENCIL_BUFFER_BIT |
                    GL_TRANSFORM_BIT |
                    GL_CURRENT_BIT);
@@ -103,6 +116,7 @@ intel_clear_tris(GLcontext *ctx, GLbitfield mask)
    _mesa_Disable(GL_CLIP_PLANE3);
    _mesa_Disable(GL_CLIP_PLANE4);
    _mesa_Disable(GL_CLIP_PLANE5);
+   _mesa_PolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    if (ctx->Extensions.ARB_fragment_program && ctx->FragmentProgram.Enabled) {
       saved_fp_enable = GL_TRUE;
       _mesa_Disable(GL_FRAGMENT_PROGRAM_ARB);
@@ -135,6 +149,11 @@ intel_clear_tris(GLcontext *ctx, GLbitfield mask)
       }
    }
 
+#if FEATURE_ARB_vertex_buffer_object
+   _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
+   _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
+#endif
+
    intel_meta_set_passthrough_transform(intel);
 
    for (i = 0; i < 4; i++) {
@@ -170,11 +189,11 @@ intel_clear_tris(GLcontext *ctx, GLbitfield mask)
 
    while (mask != 0) {
       GLuint this_mask = 0;
+      GLuint color_bit;
 
-      if (mask & BUFFER_BIT_BACK_LEFT)
-        this_mask = BUFFER_BIT_BACK_LEFT;
-      else if (mask & BUFFER_BIT_FRONT_LEFT)
-        this_mask = BUFFER_BIT_FRONT_LEFT;
+      color_bit = _mesa_ffs(mask & TRI_CLEAR_COLOR_BITS);
+      if (color_bit != 0)
+        this_mask |= (1 << (color_bit - 1));
 
       /* Clear depth/stencil in the same pass as color. */
       this_mask |= (mask & (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL));
@@ -186,6 +205,9 @@ intel_clear_tris(GLcontext *ctx, GLbitfield mask)
         _mesa_DrawBuffer(GL_FRONT_LEFT);
       else if (this_mask & BUFFER_BIT_BACK_LEFT)
         _mesa_DrawBuffer(GL_BACK_LEFT);
+      else if (color_bit != 0)
+        _mesa_DrawBuffer(GL_COLOR_ATTACHMENT0 +
+                         (color_bit - BUFFER_COLOR0 - 1));
       else
         _mesa_ColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
 
@@ -233,13 +255,10 @@ static const char *buffer_names[] = {
    [BUFFER_BACK_LEFT] = "back",
    [BUFFER_FRONT_RIGHT] = "front right",
    [BUFFER_BACK_RIGHT] = "back right",
-   [BUFFER_AUX0] = "aux0",
-   [BUFFER_AUX1] = "aux1",
-   [BUFFER_AUX2] = "aux2",
-   [BUFFER_AUX3] = "aux3",
    [BUFFER_DEPTH] = "depth",
    [BUFFER_STENCIL] = "stencil",
    [BUFFER_ACCUM] = "accum",
+   [BUFFER_AUX0] = "aux0",
    [BUFFER_COLOR0] = "color0",
    [BUFFER_COLOR1] = "color1",
    [BUFFER_COLOR2] = "color2",
@@ -275,7 +294,7 @@ intelClear(GLcontext *ctx, GLbitfield mask)
    }
    else {
       /* glColorMask in effect */
-      tri_mask |= (mask & BUFFER_BITS_COLOR);
+      tri_mask |= (mask & (BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT));
    }
 
    /* HW stencil */
@@ -313,8 +332,11 @@ intelClear(GLcontext *ctx, GLbitfield mask)
     * buffer with it.
     */
    if (mask & (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL)) {
-      tri_mask |= blit_mask & BUFFER_BIT_BACK_LEFT;
-      blit_mask &= ~BUFFER_BIT_BACK_LEFT;
+      int color_bit = _mesa_ffs(mask & TRI_CLEAR_COLOR_BITS);
+      if (color_bit != 0) {
+        tri_mask |= blit_mask & (1 << (color_bit - 1));
+        blit_mask &= ~(1 << (color_bit - 1));
+      }
    }
 
    /* SW fallback clearing */