st/mesa: call is_format_supported() for compressed formats
[mesa.git] / src / mesa / state_tracker / st_cb_clear.c
index 27775059fa6f5797ba54eba308c15eb010bdb750..736180ddc6c2d1d203322baef10f20e1a160d623 100644 (file)
 #include "st_cb_clear.h"
 #include "st_cb_fbo.h"
 #include "st_program.h"
-#include "st_public.h"
 #include "st_inlines.h"
 
 #include "pipe/p_context.h"
-#include "util/u_inlines.h"
 #include "pipe/p_state.h"
 #include "pipe/p_defines.h"
 #include "util/u_format.h"
+#include "util/u_inlines.h"
 #include "util/u_simple_shaders.h"
 #include "util/u_draw_quad.h"
 
 #include "cso_cache/cso_context.h"
 
 
+/**
+ * Do per-context initialization for glClear.
+ */
 void
 st_init_clear(struct st_context *st)
 {
@@ -67,8 +69,7 @@ st_init_clear(struct st_context *st)
    st->clear.raster.gl_rasterization_rules = 1;
 
    /* fragment shader state: color pass-through program */
-   st->clear.fs =
-      util_make_fragment_passthrough_shader(pipe);
+   st->clear.fs = util_make_fragment_passthrough_shader(pipe);
 
    /* vertex shader state: color/position pass-through */
    {
@@ -82,6 +83,9 @@ st_init_clear(struct st_context *st)
 }
 
 
+/**
+ * Free per-context state for glClear.
+ */
 void
 st_destroy_clear(struct st_context *st)
 {
@@ -94,7 +98,7 @@ st_destroy_clear(struct st_context *st)
       st->clear.vs = NULL;
    }
    if (st->clear.vbuf) {
-      pipe_buffer_reference(&st->clear.vbuf, NULL);
+      pipe_resource_reference(&st->clear.vbuf, NULL);
       st->clear.vbuf = NULL;
    }
 }
@@ -105,11 +109,10 @@ st_destroy_clear(struct st_context *st)
  * Coords are clip coords with y=0=bottom.
  */
 static void
-draw_quad(GLcontext *ctx,
+draw_quad(struct st_context *st,
           float x0, float y0, float x1, float y1, GLfloat z,
           const GLfloat color[4])
 {
-   struct st_context *st = ctx->st;
    struct pipe_context *pipe = st->pipe;
 
    /* XXX: Need to improve buffer_write to allow NO_WAIT (as well as
@@ -126,12 +129,13 @@ draw_quad(GLcontext *ctx,
    GLuint i;
 
    if (st->clear.vbuf_slot >= max_slots) {
-      pipe_buffer_reference(&st->clear.vbuf, NULL);
+      pipe_resource_reference(&st->clear.vbuf, NULL);
       st->clear.vbuf_slot = 0;
    }
 
    if (!st->clear.vbuf) {
-      st->clear.vbuf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX,
+      st->clear.vbuf = pipe_buffer_create(pipe->screen,
+                                          PIPE_BIND_VERTEX_BUFFER,
                                           max_slots * sizeof(st->clear.vertices));
    }
 
@@ -160,7 +164,8 @@ draw_quad(GLcontext *ctx,
 
    /* put vertex data into vbuf */
    st_no_flush_pipe_buffer_write_nooverlap(st, st->clear.vbuf,
-                                           st->clear.vbuf_slot * sizeof(st->clear.vertices),
+                                           st->clear.vbuf_slot
+                                             * sizeof(st->clear.vertices),
                                            sizeof(st->clear.vertices),
                                            st->clear.vertices);
 
@@ -187,7 +192,7 @@ static void
 clear_with_quad(GLcontext *ctx,
                 GLboolean color, GLboolean depth, GLboolean stencil)
 {
-   struct st_context *st = ctx->st;
+   struct st_context *st = st_context(ctx);
    const struct gl_framebuffer *fb = ctx->DrawBuffer;
    const GLfloat fb_width = (GLfloat) fb->Width;
    const GLfloat fb_height = (GLfloat) fb->Height;
@@ -289,7 +294,8 @@ clear_with_quad(GLcontext *ctx,
    cso_set_vertex_shader_handle(st->cso_context, st->clear.vs);
 
    /* draw quad matching scissor rect (XXX verify coord round-off) */
-   draw_quad(ctx, x0, y0, x1, y1, (GLfloat) ctx->Depth.Clear, ctx->Color.ClearColor);
+   draw_quad(st, x0, y0, x1, y1,
+             (GLfloat) ctx->Depth.Clear, ctx->Color.ClearColor);
 
    /* Restore pipe state */
    cso_restore_blend(st->cso_context);
@@ -301,7 +307,6 @@ clear_with_quad(GLcontext *ctx,
    cso_restore_fragment_shader(st->cso_context);
    cso_restore_vertex_shader(st->cso_context);
    cso_restore_vertex_elements(st->cso_context);
-
 }
 
 
@@ -328,6 +333,10 @@ check_clear_color_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb)
 }
 
 
+/**
+ * Determine if we need to clear the combiend depth/stencil buffer by
+ * drawing a quad.
+ */
 static INLINE GLboolean
 check_clear_depth_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb)
 {
@@ -369,8 +378,7 @@ check_clear_depth_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb)
         ctx->Scissor.Height < rb->Height))
       return GL_TRUE;
 
-   if (isDS && 
-       ctx->DrawBuffer->Visual.stencilBits > 0)
+   if (isDS && ctx->DrawBuffer->Visual.stencilBits > 0)
       return GL_TRUE;
 
    return GL_FALSE;
@@ -408,8 +416,7 @@ check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb)
     * rather than taking depth and stencil clear values from the
     * current state.
     */
-   if (isDS && 
-       ctx->DrawBuffer->Visual.depthBits > 0)
+   if (isDS && ctx->DrawBuffer->Visual.depthBits > 0)
       return GL_TRUE;
 
    return GL_FALSE;
@@ -417,12 +424,16 @@ check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb)
 
 
 
-void st_flush_clear( struct st_context *st )
+/**
+ * Called when we need to flush.
+ */
+void
+st_flush_clear(struct st_context *st)
 {
    /* Release vertex buffer to avoid synchronous rendering if we were
     * to map it in the next frame.
     */
-   pipe_buffer_reference(&st->clear.vbuf, NULL);
+   pipe_resource_reference(&st->clear.vbuf, NULL);
    st->clear.vbuf_slot = 0;
 }
  
@@ -431,17 +442,18 @@ void st_flush_clear( struct st_context *st )
 /**
  * Called via ctx->Driver.Clear()
  */
-static void st_clear(GLcontext *ctx, GLbitfield mask)
+static void
+st_Clear(GLcontext *ctx, GLbitfield mask)
 {
    static const GLbitfield BUFFER_BITS_DS
       = (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL);
-   struct st_context *st = ctx->st;
+   struct st_context *st = st_context(ctx);
    struct gl_renderbuffer *depthRb
       = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
    struct gl_renderbuffer *stencilRb
       = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
-   GLbitfield quad_buffers = 0;
-   GLbitfield clear_buffers = 0;
+   GLbitfield quad_buffers = 0x0;
+   GLbitfield clear_buffers = 0x0;
    GLuint i;
 
    /* This makes sure the pipe has the latest scissor, etc values */
@@ -517,8 +529,8 @@ static void st_clear(GLcontext *ctx, GLbitfield mask)
                       mask & BUFFER_BIT_DEPTH,
                       mask & BUFFER_BIT_STENCIL);
    } else if (clear_buffers)
-      ctx->st->pipe->clear(ctx->st->pipe, clear_buffers, ctx->Color.ClearColor,
-                           ctx->Depth.Clear, ctx->Stencil.Clear);
+      st->pipe->clear(st->pipe, clear_buffers, ctx->Color.ClearColor,
+                      ctx->Depth.Clear, ctx->Stencil.Clear);
 
    if (mask & BUFFER_BIT_ACCUM)
       st_clear_accum_buffer(ctx,
@@ -526,7 +538,8 @@ static void st_clear(GLcontext *ctx, GLbitfield mask)
 }
 
 
-void st_init_clear_functions(struct dd_function_table *functions)
+void
+st_init_clear_functions(struct dd_function_table *functions)
 {
-   functions->Clear = st_clear;
+   functions->Clear = st_Clear;
 }