mesa: consistantly use mesa memory-functions in gallium state tracker
[mesa.git] / src / mesa / state_tracker / st_cb_clear.c
index 47ad3c2bc1264d5e56b8c42197ee6521e4e29371..0eddda23a7ae651cdd431144dd5dbda7351970a3 100644 (file)
@@ -98,12 +98,12 @@ st_destroy_clear(struct st_context *st)
    struct pipe_context *pipe = st->pipe;
 
    if (st->clear.vert_shader.tokens) {
-      FREE((void *) st->clear.vert_shader.tokens);
+      _mesa_free((void *) st->clear.vert_shader.tokens);
       st->clear.vert_shader.tokens = NULL;
    }
 
    if (st->clear.frag_shader.tokens) {
-      FREE((void *) st->clear.frag_shader.tokens);
+      _mesa_free((void *) st->clear.frag_shader.tokens);
       st->clear.frag_shader.tokens = NULL;
    }
 
@@ -116,7 +116,7 @@ st_destroy_clear(struct st_context *st)
       st->clear.vs = NULL;
    }
    if (st->clear.vbuf) {
-      pipe_buffer_destroy(pipe->screen, st->clear.vbuf);
+      pipe_buffer_reference(pipe->screen, &st->clear.vbuf, NULL);
       st->clear.vbuf = NULL;
    }
 }
@@ -148,12 +148,18 @@ draw_quad(GLcontext *ctx,
 {
    struct st_context *st = ctx->st;
    struct pipe_context *pipe = st->pipe;
+   const GLuint max_slots = 1024 / sizeof(st->clear.vertices);
    GLuint i;
    void *buf;
 
+   if (st->clear.vbuf_slot >= max_slots) {
+      pipe_buffer_reference(pipe->screen, &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,
-                                          sizeof(st->clear.vertices));
+                                          max_slots * sizeof(st->clear.vertices));
    }
 
    /* positions */
@@ -181,14 +187,23 @@ draw_quad(GLcontext *ctx,
 
    /* put vertex data into vbuf */
    buf = pipe_buffer_map(pipe->screen, st->clear.vbuf, PIPE_BUFFER_USAGE_CPU_WRITE);
-   memcpy(buf, st->clear.vertices, sizeof(st->clear.vertices));
+
+   memcpy((char *)buf + st->clear.vbuf_slot * sizeof(st->clear.vertices), 
+          st->clear.vertices, 
+          sizeof(st->clear.vertices));
+
    pipe_buffer_unmap(pipe->screen, st->clear.vbuf);
 
    /* draw */
-   util_draw_vertex_buffer(pipe, st->clear.vbuf,
+   util_draw_vertex_buffer(pipe, 
+                           st->clear.vbuf, 
+                           st->clear.vbuf_slot * sizeof(st->clear.vertices),
                            PIPE_PRIM_TRIANGLE_FAN,
                            4,  /* verts */
                            2); /* attribs/vert */
+
+   /* Increment slot */
+   st->clear.vbuf_slot++;
 }
 
 
@@ -272,8 +287,8 @@ clear_with_quad(GLcontext *ctx,
          depth_stencil.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE;
          depth_stencil.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE;
          depth_stencil.stencil[0].ref_value = ctx->Stencil.Clear;
-         depth_stencil.stencil[0].value_mask = 0xff;
-         depth_stencil.stencil[0].write_mask = ctx->Stencil.WriteMask[0] & 0xff;
+         depth_stencil.stencil[0].valuemask = 0xff;
+         depth_stencil.stencil[0].writemask = ctx->Stencil.WriteMask[0] & 0xff;
       }
 
       cso_set_depth_stencil_alpha(st->cso_context, &depth_stencil);
@@ -406,13 +421,17 @@ check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb)
 static void
 clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
 {
+   struct st_renderbuffer *strb = st_renderbuffer(rb);
+
+   if (!strb->surface)
+      return;
+
    if (check_clear_color_with_quad( ctx, rb )) {
       /* masking or scissoring */
       clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE);
    }
    else {
       /* clear whole buffer w/out masking */
-      struct st_renderbuffer *strb = st_renderbuffer(rb);
       uint clearValue;
       /* NOTE: we always pass the clear color as PIPE_FORMAT_A8R8G8B8_UNORM
        * at this time!
@@ -426,13 +445,16 @@ clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
 static void
 clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
 {
+   struct st_renderbuffer *strb = st_renderbuffer(rb);
+
+   if (!strb->surface)
+      return;
+
    if (check_clear_depth_with_quad(ctx, rb)) {
       /* scissoring or we have a combined depth/stencil buffer */
       clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE);
    }
    else {
-      struct st_renderbuffer *strb = st_renderbuffer(rb);
-
       /* simple clear of whole buffer */
       uint clearValue = util_pack_z(strb->surface->format, ctx->Depth.Clear);
       ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
@@ -443,13 +465,16 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
 static void
 clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
 {
+   struct st_renderbuffer *strb = st_renderbuffer(rb);
+
+   if (!strb->surface)
+      return;
+
    if (check_clear_stencil_with_quad(ctx, rb)) {
       /* masking or scissoring or combined depth/stencil buffer */
       clear_with_quad(ctx, GL_FALSE, GL_FALSE, GL_TRUE);
    }
    else {
-      struct st_renderbuffer *strb = st_renderbuffer(rb);
-
       /* simple clear of whole buffer */
       GLuint clearValue = ctx->Stencil.Clear;
 
@@ -469,14 +494,16 @@ clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
 static void
 clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
 {
+   struct st_renderbuffer *strb = st_renderbuffer(rb);
+
+   if (!strb->surface)
+      return;
 
    if (check_clear_depth_stencil_with_quad(ctx, rb)) {
       /* masking or scissoring */
       clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_TRUE);
    }
    else {
-      struct st_renderbuffer *strb = st_renderbuffer(rb);
-
       /* clear whole buffer w/out masking */
       GLuint clearValue = util_pack_z(strb->surface->format, ctx->Depth.Clear);
 
@@ -496,6 +523,16 @@ clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
 }
 
 
+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->pipe->screen, &st->clear.vbuf, NULL);
+   st->clear.vbuf_slot = 0;
+}
+
 
 /**
  * Called via ctx->Driver.Clear()