Squashed commit of the following:
[mesa.git] / src / gallium / state_trackers / vega / polygon.c
index b6d282d803be2f8151bf65ae1242f44d22e03eda..d2b7e489124ad607cf11cf43f40c32eba61af839 100644 (file)
@@ -37,7 +37,7 @@
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
 #include "pipe/p_screen.h"
 
 #include "util/u_draw_quad.h"
@@ -58,7 +58,7 @@ struct polygon
    VGint    num_verts;
 
    VGboolean dirty;
-   struct pipe_buffer *vbuf;
+   struct pipe_resource *vbuf;
    struct pipe_screen *screen;
 };
 
@@ -110,7 +110,7 @@ struct polygon * polygon_create_from_data(float *data, int size)
 void polygon_destroy(struct polygon *poly)
 {
    if (poly->vbuf)
-      pipe_buffer_reference(&poly->vbuf, NULL);
+      pipe_resource_reference(&poly->vbuf, NULL);
 
    free(poly->data);
    free(poly);
@@ -248,12 +248,12 @@ VGboolean polygon_is_closed(struct polygon *p)
 static void set_blend_for_fill(struct pipe_blend_state *blend)
 {
    memset(blend, 0, sizeof(struct pipe_blend_state));
-   blend->colormask = 0; /*disable colorwrites*/
+   blend->rt[0].colormask = 0; /*disable colorwrites*/
 
-   blend->rgb_src_factor = PIPE_BLENDFACTOR_ONE;
-   blend->alpha_src_factor = PIPE_BLENDFACTOR_ONE;
-   blend->rgb_dst_factor = PIPE_BLENDFACTOR_INV_SRC_ALPHA;
-   blend->alpha_dst_factor = PIPE_BLENDFACTOR_INV_SRC_ALPHA;
+   blend->rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
+   blend->rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
+   blend->rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_INV_SRC_ALPHA;
+   blend->rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_INV_SRC_ALPHA;
 }
 
 static void draw_polygon(struct vg_context *ctx,
@@ -272,13 +272,14 @@ static void draw_polygon(struct vg_context *ctx,
 
    if (poly->vbuf == NULL || poly->dirty) {
       if (poly->vbuf) {
-         pipe_buffer_reference(&poly->vbuf,
+         pipe_resource_reference(&poly->vbuf,
                                NULL);
       }
       poly->screen = pipe->screen;
       poly->vbuf= pipe_user_buffer_create(poly->screen,
                                           poly->data,
-                                          vert_size);
+                                          vert_size,
+                                         PIPE_BIND_VERTEX_BUFFER);
       poly->dirty = VG_FALSE;
    }
 
@@ -292,11 +293,12 @@ static void draw_polygon(struct vg_context *ctx,
    pipe->set_vertex_buffers(pipe, 1, &vbuffer);
 
    /* tell pipe about the vertex attributes */
+   memset(&velement, 0, sizeof(velement));
    velement.src_offset = 0;
+   velement.instance_divisor = 0;
    velement.vertex_buffer_index = 0;
    velement.src_format = PIPE_FORMAT_R32G32_FLOAT;
-   velement.nr_components = COMPONENTS;
-   pipe->set_vertex_elements(pipe, 1, &velement);
+   cso_set_vertex_elements(ctx->cso_context, 1, &velement);
 
    /* draw */
    pipe->draw_arrays(pipe, PIPE_PRIM_TRIANGLE_FAN, 
@@ -306,6 +308,7 @@ static void draw_polygon(struct vg_context *ctx,
 void polygon_fill(struct polygon *poly, struct vg_context *ctx)
 {
    struct pipe_depth_stencil_alpha_state dsa;
+   struct pipe_stencil_ref sr;
    struct pipe_blend_state blend;
    VGfloat bounds[4];
    VGfloat min_x, min_y, max_x, max_y;
@@ -324,6 +327,9 @@ void polygon_fill(struct polygon *poly, struct vg_context *ctx)
    set_blend_for_fill(&blend);
 
    memset(&dsa, 0, sizeof(struct pipe_depth_stencil_alpha_state));
+   memset(&sr, 0, sizeof(struct pipe_stencil_ref));
+   /* only need a fixed 0. Rely on default or move it out at least? */
+   cso_set_stencil_ref(ctx->cso_context, &sr);
 
    cso_save_blend(ctx->cso_context);
    cso_save_depth_stencil_alpha(ctx->cso_context);
@@ -335,7 +341,6 @@ void polygon_fill(struct polygon *poly, struct vg_context *ctx)
       dsa.stencil[0].zfail_op = PIPE_STENCIL_OP_KEEP;
       dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_INVERT;
       dsa.stencil[0].func = PIPE_FUNC_ALWAYS;
-      dsa.stencil[0].ref_value = 0;
       dsa.stencil[0].valuemask = ~0;
 
       cso_set_blend(ctx->cso_context, &blend);
@@ -351,7 +356,6 @@ void polygon_fill(struct polygon *poly, struct vg_context *ctx)
          dsa.stencil[0].zfail_op = PIPE_STENCIL_OP_KEEP;
          dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_INCR_WRAP;
          dsa.stencil[0].func = PIPE_FUNC_ALWAYS;
-         dsa.stencil[0].ref_value = 0;
          dsa.stencil[0].valuemask = ~0;
 
          /* back */
@@ -361,7 +365,6 @@ void polygon_fill(struct polygon *poly, struct vg_context *ctx)
          dsa.stencil[1].zfail_op = PIPE_STENCIL_OP_KEEP;
          dsa.stencil[1].zpass_op = PIPE_STENCIL_OP_DECR_WRAP;
          dsa.stencil[1].func = PIPE_FUNC_ALWAYS;
-         dsa.stencil[1].ref_value = 0;
          dsa.stencil[1].valuemask = ~0;
 
          cso_set_blend(ctx->cso_context, &blend);
@@ -374,7 +377,6 @@ void polygon_fill(struct polygon *poly, struct vg_context *ctx)
 
          cso_save_rasterizer(ctx->cso_context);
          dsa.stencil[0].func = PIPE_FUNC_ALWAYS;
-         dsa.stencil[0].ref_value = 0;
          dsa.stencil[0].valuemask = ~0;
 
          raster.cull_mode = raster.front_winding ^ PIPE_WINDING_BOTH;
@@ -406,7 +408,6 @@ void polygon_fill(struct polygon *poly, struct vg_context *ctx)
    dsa.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE;
    dsa.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE;
    dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE;
-   dsa.stencil[0].ref_value = 0;
    dsa.stencil[0].valuemask = dsa.stencil[0].writemask;
    dsa.stencil[1].enabled = 0;
    memcpy(&dsa.depth, &ctx->state.g3d.dsa.depth,
@@ -424,6 +425,7 @@ void polygon_array_fill(struct polygon_array *polyarray, struct vg_context *ctx)
 {
    struct array *polys = polyarray->array;
    struct pipe_depth_stencil_alpha_state dsa;
+   struct pipe_stencil_ref sr;
    struct pipe_blend_state blend;
    VGfloat min_x = polyarray->min_x;
    VGfloat min_y = polyarray->min_y;
@@ -441,6 +443,9 @@ void polygon_array_fill(struct polygon_array *polyarray, struct vg_context *ctx)
    set_blend_for_fill(&blend);
 
    memset(&dsa, 0, sizeof(struct pipe_depth_stencil_alpha_state));
+   memset(&sr, 0, sizeof(struct pipe_stencil_ref));
+   /* only need a fixed 0. Rely on default or move it out at least? */
+   cso_set_stencil_ref(ctx->cso_context, &sr);
 
    cso_save_blend(ctx->cso_context);
    cso_save_depth_stencil_alpha(ctx->cso_context);
@@ -452,7 +457,6 @@ void polygon_array_fill(struct polygon_array *polyarray, struct vg_context *ctx)
       dsa.stencil[0].zfail_op = PIPE_STENCIL_OP_KEEP;
       dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_INVERT;
       dsa.stencil[0].func = PIPE_FUNC_ALWAYS;
-      dsa.stencil[0].ref_value = 0;
       dsa.stencil[0].valuemask = ~0;
 
       cso_set_blend(ctx->cso_context, &blend);
@@ -471,7 +475,6 @@ void polygon_array_fill(struct polygon_array *polyarray, struct vg_context *ctx)
          dsa.stencil[0].zfail_op = PIPE_STENCIL_OP_KEEP;
          dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_INCR_WRAP;
          dsa.stencil[0].func = PIPE_FUNC_ALWAYS;
-         dsa.stencil[0].ref_value = 0;
          dsa.stencil[0].valuemask = ~0;
 
          /* back */
@@ -481,7 +484,6 @@ void polygon_array_fill(struct polygon_array *polyarray, struct vg_context *ctx)
          dsa.stencil[1].zfail_op = PIPE_STENCIL_OP_KEEP;
          dsa.stencil[1].zpass_op = PIPE_STENCIL_OP_DECR_WRAP;
          dsa.stencil[1].func = PIPE_FUNC_ALWAYS;
-         dsa.stencil[1].ref_value = 0;
          dsa.stencil[1].valuemask = ~0;
 
          cso_set_blend(ctx->cso_context, &blend);
@@ -497,7 +499,6 @@ void polygon_array_fill(struct polygon_array *polyarray, struct vg_context *ctx)
 
          cso_save_rasterizer(ctx->cso_context);
          dsa.stencil[0].func = PIPE_FUNC_ALWAYS;
-         dsa.stencil[0].ref_value = 0;
          dsa.stencil[0].valuemask = ~0;
 
          raster.cull_mode = raster.front_winding ^ PIPE_WINDING_BOTH;
@@ -535,7 +536,6 @@ void polygon_array_fill(struct polygon_array *polyarray, struct vg_context *ctx)
    dsa.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE;
    dsa.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE;
    dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE;
-   dsa.stencil[0].ref_value = 0;
    dsa.stencil[0].valuemask = dsa.stencil[0].writemask;
    dsa.stencil[1].enabled = 0;
    memcpy(&dsa.depth, &ctx->state.g3d.dsa.depth,