Merge commit 'origin/master' into gallium-0.2
[mesa.git] / src / mesa / state_tracker / st_cb_clear.c
index 95a5fb8db47b4ef54582788929deec68eb0e6807..47ad3c2bc1264d5e56b8c42197ee6521e4e29371 100644 (file)
@@ -34,8 +34,8 @@
 #include "main/glheader.h"
 #include "main/macros.h"
 #include "shader/prog_instruction.h"
-#include "st_atom.h"
 #include "st_context.h"
+#include "st_atom.h"
 #include "st_cb_accum.h"
 #include "st_cb_clear.h"
 #include "st_cb_fbo.h"
@@ -45,9 +45,9 @@
 #include "st_mesa_to_tgsi.h"
 
 #include "pipe/p_context.h"
+#include "pipe/p_inlines.h"
 #include "pipe/p_state.h"
 #include "pipe/p_defines.h"
-#include "pipe/p_winsys.h"
 #include "util/u_pack_color.h"
 #include "util/u_simple_shaders.h"
 #include "util/u_draw_quad.h"
@@ -97,6 +97,16 @@ 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);
+      st->clear.vert_shader.tokens = NULL;
+   }
+
+   if (st->clear.frag_shader.tokens) {
+      FREE((void *) st->clear.frag_shader.tokens);
+      st->clear.frag_shader.tokens = NULL;
+   }
+
    if (st->clear.fs) {
       cso_delete_fragment_shader(st->cso_context, st->clear.fs);
       st->clear.fs = NULL;
@@ -106,7 +116,7 @@ st_destroy_clear(struct st_context *st)
       st->clear.vs = NULL;
    }
    if (st->clear.vbuf) {
-      pipe->winsys->buffer_destroy(pipe->winsys, st->clear.vbuf);
+      pipe_buffer_destroy(pipe->screen, st->clear.vbuf);
       st->clear.vbuf = NULL;
    }
 }
@@ -142,9 +152,8 @@ draw_quad(GLcontext *ctx,
    void *buf;
 
    if (!st->clear.vbuf) {
-      st->clear.vbuf = pipe->winsys->buffer_create(pipe->winsys, 32,
-                                                   PIPE_BUFFER_USAGE_VERTEX,
-                                                   sizeof(st->clear.vertices));
+      st->clear.vbuf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX,
+                                          sizeof(st->clear.vertices));
    }
 
    /* positions */
@@ -171,10 +180,9 @@ draw_quad(GLcontext *ctx,
    }
 
    /* put vertex data into vbuf */
-   buf = pipe->winsys->buffer_map(pipe->winsys, st->clear.vbuf,
-                                  PIPE_BUFFER_USAGE_CPU_WRITE);
+   buf = pipe_buffer_map(pipe->screen, st->clear.vbuf, PIPE_BUFFER_USAGE_CPU_WRITE);
    memcpy(buf, st->clear.vertices, sizeof(st->clear.vertices));
-   pipe->winsys->buffer_unmap(pipe->winsys, st->clear.vbuf);
+   pipe_buffer_unmap(pipe->screen, st->clear.vbuf);
 
    /* draw */
    util_draw_vertex_buffer(pipe, st->clear.vbuf,
@@ -195,17 +203,17 @@ clear_with_quad(GLcontext *ctx,
                 GLboolean color, GLboolean depth, GLboolean stencil)
 {
    struct st_context *st = ctx->st;
-   const GLfloat x0 = ctx->DrawBuffer->_Xmin;
-   const GLfloat x1 = ctx->DrawBuffer->_Xmax;
+   const GLfloat x0 = (GLfloat) ctx->DrawBuffer->_Xmin;
+   const GLfloat x1 = (GLfloat) ctx->DrawBuffer->_Xmax;
    GLfloat y0, y1;
 
    if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
-      y0 = ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymax;
-      y1 = ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymin;
+      y0 = (GLfloat) (ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymax);
+      y1 = (GLfloat) (ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymin);
    }
    else {
-      y0 = ctx->DrawBuffer->_Ymin;
-      y1 = ctx->DrawBuffer->_Ymax;
+      y0 = (GLfloat) ctx->DrawBuffer->_Ymin;
+      y1 = (GLfloat) ctx->DrawBuffer->_Ymax;
    }
 
    /*
@@ -278,7 +286,7 @@ 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, ctx->Depth.Clear, ctx->Color.ClearColor);
+   draw_quad(ctx, x0, y0, x1, y1, (GLfloat) ctx->Depth.Clear, ctx->Color.ClearColor);
 
    /* Restore pipe state */
    cso_restore_blend(st->cso_context);
@@ -406,6 +414,9 @@ clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
       /* 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!
+       */
       util_pack_color(ctx->Color.ClearColor, PIPE_FORMAT_A8R8G8B8_UNORM, &clearValue);
       ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
    }