st/mesa: unify common code in st_draw_vbo functions
[mesa.git] / src / mesa / state_tracker / st_cb_clear.c
index aa728409f70520e410132d503b97ed5875ff94f1..f507775da20efe6b20591b46259705c122fe3391 100644 (file)
@@ -203,14 +203,11 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
                         CSO_BIT_SAMPLE_MASK |
                         CSO_BIT_MIN_SAMPLES |
                         CSO_BIT_VIEWPORT |
-                        CSO_BIT_FRAGMENT_SHADER |
                         CSO_BIT_STREAM_OUTPUTS |
-                        CSO_BIT_VERTEX_SHADER |
-                        CSO_BIT_TESSCTRL_SHADER |
-                        CSO_BIT_TESSEVAL_SHADER |
-                        CSO_BIT_GEOMETRY_SHADER |
                         CSO_BIT_VERTEX_ELEMENTS |
-                        CSO_BIT_AUX_VERTEX_BUFFER_SLOT));
+                        CSO_BIT_AUX_VERTEX_BUFFER_SLOT |
+                        CSO_BIT_PAUSE_QUERIES |
+                        CSO_BITS_ALL_SHADERS));
 
    /* blend state: RGBA masking */
    {
@@ -237,7 +234,7 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
                blend.rt[i].colormask |= PIPE_MASK_A;
          }
 
-         if (st->ctx->Color.DitherFlag)
+         if (ctx->Color.DitherFlag)
             blend.dither = 1;
       }
       cso_set_blend(cso, &blend);
@@ -316,11 +313,25 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
 static inline GLboolean
 is_scissor_enabled(struct gl_context *ctx, struct gl_renderbuffer *rb)
 {
+   const struct gl_scissor_rect *scissor = &ctx->Scissor.ScissorArray[0];
+
    return (ctx->Scissor.EnableFlags & 1) &&
-          (ctx->Scissor.ScissorArray[0].X > 0 ||
-           ctx->Scissor.ScissorArray[0].Y > 0 ||
-           (unsigned) ctx->Scissor.ScissorArray[0].Width < rb->Width ||
-           (unsigned) ctx->Scissor.ScissorArray[0].Height < rb->Height);
+          (scissor->X > 0 ||
+           scissor->Y > 0 ||
+           scissor->X + scissor->Width < (int)rb->Width ||
+           scissor->Y + scissor->Height < (int)rb->Height);
+}
+
+/**
+ * Return if window rectangles must be enabled during the clear.
+ */
+static inline bool
+is_window_rectangle_enabled(struct gl_context *ctx)
+{
+   if (ctx->DrawBuffer == ctx->WinSysDrawBuffer)
+      return false;
+   return ctx->Scissor.NumWindowRects > 0 ||
+      ctx->Scissor.WindowRectMode == GL_INCLUSIVE_EXT;
 }
 
 
@@ -392,9 +403,10 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
    GLuint i;
 
    st_flush_bitmap_cache(st);
+   st_invalidate_readpix_cache(st);
 
    /* This makes sure the pipe has the latest scissor, etc values */
-   st_validate_state( st, ST_PIPELINE_RENDER );
+   st_validate_state(st, ST_PIPELINE_CLEAR);
 
    if (mask & BUFFER_BITS_COLOR) {
       for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
@@ -413,6 +425,7 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
                continue;
 
             if (is_scissor_enabled(ctx, rb) ||
+                is_window_rectangle_enabled(ctx) ||
                 is_color_masked(ctx, colormask_index))
                quad_buffers |= PIPE_CLEAR_COLOR0 << i;
             else
@@ -425,7 +438,8 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
       struct st_renderbuffer *strb = st_renderbuffer(depthRb);
 
       if (strb->surface && ctx->Depth.Mask) {
-         if (is_scissor_enabled(ctx, depthRb))
+         if (is_scissor_enabled(ctx, depthRb) ||
+             is_window_rectangle_enabled(ctx))
             quad_buffers |= PIPE_CLEAR_DEPTH;
          else
             clear_buffers |= PIPE_CLEAR_DEPTH;
@@ -436,6 +450,7 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
 
       if (strb->surface && !is_stencil_disabled(ctx, stencilRb)) {
          if (is_scissor_enabled(ctx, stencilRb) ||
+             is_window_rectangle_enabled(ctx) ||
              is_stencil_masked(ctx, stencilRb))
             quad_buffers |= PIPE_CLEAR_STENCIL;
          else