Merge branch '7.8'
[mesa.git] / src / mesa / state_tracker / st_cb_drawpixels.c
index 85570541ef0084d2f739794157f5691106bfca61..e059002f157d6e6e1f43beb447d1eebdd9e4975c 100644 (file)
@@ -249,13 +249,13 @@ make_passthrough_vertex_shader(struct st_context *st,
                ureg_DECL_output( ureg, TGSI_SEMANTIC_POSITION, 0 ),
                ureg_DECL_vs_input( ureg, 0 ));
       
-      /* MOV result.texcoord0, vertex.texcoord0; */
+      /* MOV result.texcoord0, vertex.attr[1]; */
       ureg_MOV(ureg, 
                ureg_DECL_output( ureg, TGSI_SEMANTIC_GENERIC, 0 ),
                ureg_DECL_vs_input( ureg, 1 ));
       
       if (passColor) {
-         /* MOV result.color0, vertex.color0; */
+         /* MOV result.color0, vertex.attr[2]; */
          ureg_MOV(ureg, 
                   ureg_DECL_output( ureg, TGSI_SEMANTIC_COLOR, 0 ),
                   ureg_DECL_vs_input( ureg, 2 ));
@@ -296,13 +296,13 @@ base_format(GLenum format)
  * If width, height are not POT and the driver only handles POT textures,
  * allocate the next larger size of texture that is POT.
  */
-static struct pipe_texture *
+static struct pipe_resource *
 alloc_texture(struct st_context *st, GLsizei width, GLsizei height,
               enum pipe_format texFormat)
 {
    struct pipe_context *pipe = st->pipe;
    struct pipe_screen *screen = pipe->screen;
-   struct pipe_texture *pt;
+   struct pipe_resource *pt;
    int ptw, pth;
 
    ptw = width;
@@ -330,7 +330,7 @@ alloc_texture(struct st_context *st, GLsizei width, GLsizei height,
    }
 
    pt = st_texture_create(st, PIPE_TEXTURE_2D, texFormat, 0,
-                          ptw, pth, 1, PIPE_TEXTURE_USAGE_SAMPLER);
+                          ptw, pth, 1, PIPE_BIND_SAMPLER_VIEW);
 
    return pt;
 }
@@ -340,7 +340,7 @@ alloc_texture(struct st_context *st, GLsizei width, GLsizei height,
  * Make texture containing an image for glDrawPixels image.
  * If 'pixels' is NULL, leave the texture image data undefined.
  */
-static struct pipe_texture *
+static struct pipe_resource *
 make_texture(struct st_context *st,
             GLsizei width, GLsizei height, GLenum format, GLenum type,
             const struct gl_pixelstore_attrib *unpack,
@@ -349,7 +349,7 @@ make_texture(struct st_context *st,
    GLcontext *ctx = st->ctx;
    struct pipe_context *pipe = st->pipe;
    gl_format mformat;
-   struct pipe_texture *pt;
+   struct pipe_resource *pt;
    enum pipe_format pipeFormat;
    GLuint cpp;
    GLenum baseFormat;
@@ -389,7 +389,7 @@ make_texture(struct st_context *st,
                                              width, height);
 
       /* map texture transfer */
-      dest = pipe->transfer_map(pipe, transfer);
+      dest = pipe_transfer_map(pipe, transfer);
 
 
       /* Put image into texture transfer.
@@ -409,8 +409,8 @@ make_texture(struct st_context *st,
                                unpack);
 
       /* unmap */
-      pipe->transfer_unmap(pipe, transfer);
-      pipe->tex_transfer_destroy(pipe, transfer);
+      pipe_transfer_unmap(pipe, transfer);
+      pipe->transfer_destroy(pipe, transfer);
 
       assert(success);
 
@@ -451,7 +451,7 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z,
       const GLfloat sLeft = 0.0f, sRight = maxXcoord;
       const GLfloat tTop = invertTex ? maxYcoord : 0.0f;
       const GLfloat tBot = invertTex ? 0.0f : maxYcoord;
-      GLuint tex, i;
+      GLuint i;
 
       /* upper-left */
       verts[0][0][0] = clip_x0;    /* v[0].attr[0].x */
@@ -469,32 +469,31 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z,
       verts[3][0][0] = clip_x0;
       verts[3][0][1] = clip_y1;
 
-      tex = color ? 2 : 1;
-      verts[0][tex][0] = sLeft; /* v[0].attr[tex].s */
-      verts[0][tex][1] = tTop;  /* v[0].attr[tex].t */
-      verts[1][tex][0] = sRight;
-      verts[1][tex][1] = tTop;
-      verts[2][tex][0] = sRight;
-      verts[2][tex][1] = tBot;
-      verts[3][tex][0] = sLeft;
-      verts[3][tex][1] = tBot;
+      verts[0][1][0] = sLeft; /* v[0].attr[1].S */
+      verts[0][1][1] = tTop;  /* v[0].attr[1].T */
+      verts[1][1][0] = sRight;
+      verts[1][1][1] = tTop;
+      verts[2][1][0] = sRight;
+      verts[2][1][1] = tBot;
+      verts[3][1][0] = sLeft;
+      verts[3][1][1] = tBot;
 
       /* same for all verts: */
       if (color) {
          for (i = 0; i < 4; i++) {
-            verts[i][0][2] = z;   /*Z*/
-            verts[i][0][3] = 1.0f; /*W*/
-            verts[i][1][0] = color[0];
-            verts[i][1][1] = color[1];
-            verts[i][1][2] = color[2];
-            verts[i][1][3] = color[3];
-            verts[i][2][2] = 0.0f; /*R*/
-            verts[i][2][3] = 1.0f; /*Q*/
+            verts[i][0][2] = z;         /* v[i].attr[0].z */
+            verts[i][0][3] = 1.0f;      /* v[i].attr[0].w */
+            verts[i][2][0] = color[0];  /* v[i].attr[2].r */
+            verts[i][2][1] = color[1];  /* v[i].attr[2].g */
+            verts[i][2][2] = color[2];  /* v[i].attr[2].b */
+            verts[i][2][3] = color[3];  /* v[i].attr[2].a */
+            verts[i][1][2] = 0.0f;      /* v[i].attr[1].R */
+            verts[i][1][3] = 1.0f;      /* v[i].attr[1].Q */
          }
       }
       else {
          for (i = 0; i < 4; i++) {
-            verts[i][0][2] = z;   /*Z*/
+            verts[i][0][2] = z;    /*Z*/
             verts[i][0][3] = 1.0f; /*W*/
             verts[i][1][2] = 0.0f; /*R*/
             verts[i][1][3] = 1.0f; /*Q*/
@@ -503,10 +502,11 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z,
    }
 
    {
-      struct pipe_buffer *buf;
+      struct pipe_resource *buf;
 
       /* allocate/load buffer object with vertex data */
-      buf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX,
+      buf = pipe_buffer_create(pipe->screen,
+                              PIPE_BIND_VERTEX_BUFFER,
                                sizeof(verts));
       st_no_flush_pipe_buffer_write(st, buf, 0, sizeof(verts), verts);
 
@@ -514,7 +514,7 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z,
                               PIPE_PRIM_QUADS,
                               4,  /* verts */
                               3); /* attribs/vert */
-      pipe_buffer_reference(&buf, NULL);
+      pipe_resource_reference(&buf, NULL);
    }
 }
 
@@ -689,7 +689,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
                                       usage, x, y,
                                       width, height);
 
-   stmap = pipe->transfer_map(pipe, pt);
+   stmap = pipe_transfer_map(pipe, pt);
 
    pixels = _mesa_map_pbo_source(ctx, &clippedUnpack, pixels);
    assert(pixels);
@@ -734,7 +734,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
             }
 
             /* now pack the stencil (and Z) values in the dest format */
-            switch (pt->texture->format) {
+            switch (pt->resource->format) {
             case PIPE_FORMAT_S8_USCALED:
                {
                   ubyte *dest = stmap + spanY * pt->stride + spanX;
@@ -789,8 +789,8 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
    _mesa_unmap_pbo_source(ctx, &clippedUnpack);
 
    /* unmap the stencil buffer */
-   pipe->transfer_unmap(pipe, pt);
-   pipe->tex_transfer_destroy(pipe, pt);
+   pipe_transfer_unmap(pipe, pt);
+   pipe->transfer_destroy(pipe, pt);
 }
 
 
@@ -831,10 +831,10 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
 
    /* draw with textured quad */
    {
-      struct pipe_texture *pt
+      struct pipe_resource *pt
          = make_texture(st, width, height, format, type, unpack, pixels);
       if (pt) {
-         struct pipe_sampler_view *sv = st_sampler_view_from_texture(st->pipe, pt);
+         struct pipe_sampler_view *sv = st_create_texture_sampler_view(st->pipe, pt);
 
          if (sv) {
             draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2],
@@ -845,7 +845,7 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
                                color, GL_FALSE);
             pipe_sampler_view_reference(&sv, NULL);
          }
-         pipe_texture_reference(&pt, NULL);
+         pipe_resource_reference(&pt, NULL);
       }
    }
 }
@@ -858,7 +858,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
                     GLint dstx, GLint dsty)
 {
    struct st_renderbuffer *rbDraw = st_renderbuffer(ctx->DrawBuffer->_StencilBuffer);
-   struct pipe_context *pipe = ctx->st->pipe;
+   struct pipe_context *pipe = st_context(ctx)->pipe;
    enum pipe_transfer_usage usage;
    struct pipe_transfer *ptDraw;
    ubyte *drawMap;
@@ -890,11 +890,11 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
                                           usage, dstx, dsty,
                                           width, height);
 
-   assert(util_format_get_blockwidth(ptDraw->texture->format) == 1);
-   assert(util_format_get_blockheight(ptDraw->texture->format) == 1);
+   assert(util_format_get_blockwidth(ptDraw->resource->format) == 1);
+   assert(util_format_get_blockheight(ptDraw->resource->format) == 1);
 
    /* map the stencil buffer */
-   drawMap = pipe->transfer_map(pipe, ptDraw);
+   drawMap = pipe_transfer_map(pipe, ptDraw);
 
    /* draw */
    /* XXX PixelZoom not handled yet */
@@ -912,7 +912,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
       dst = drawMap + y * ptDraw->stride;
       src = buffer + i * width;
 
-      switch (ptDraw->texture->format) {
+      switch (ptDraw->resource->format) {
       case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
          {
             uint *dst4 = (uint *) dst;
@@ -947,8 +947,8 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
    free(buffer);
 
    /* unmap the stencil buffer */
-   pipe->transfer_unmap(pipe, ptDraw);
-   pipe->tex_transfer_destroy(pipe, ptDraw);
+   pipe_transfer_unmap(pipe, ptDraw);
+   pipe->transfer_destroy(pipe, ptDraw);
 }
 
 
@@ -962,7 +962,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
    struct pipe_screen *screen = pipe->screen;
    struct st_renderbuffer *rbRead;
    void *driver_vp, *driver_fp;
-   struct pipe_texture *pt;
+   struct pipe_resource *pt;
    struct pipe_sampler_view *sv;
    GLfloat *color;
    enum pipe_format srcFormat, texFormat;
@@ -997,7 +997,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
    srcFormat = rbRead->texture->format;
 
    if (screen->is_format_supported(screen, srcFormat, PIPE_TEXTURE_2D, 
-                                   PIPE_TEXTURE_USAGE_SAMPLER, 0)) {
+                                   PIPE_BIND_SAMPLER_VIEW, 0)) {
       texFormat = srcFormat;
    }
    else {
@@ -1005,13 +1005,13 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
       if (type == GL_DEPTH) {
          texFormat = st_choose_format(screen, GL_DEPTH_COMPONENT,
                                       PIPE_TEXTURE_2D, 
-                                      PIPE_TEXTURE_USAGE_DEPTH_STENCIL);
+                                      PIPE_BIND_DEPTH_STENCIL);
          assert(texFormat != PIPE_FORMAT_NONE);
       }
       else {
          /* default color format */
          texFormat = st_choose_format(screen, GL_RGBA, PIPE_TEXTURE_2D, 
-                                      PIPE_TEXTURE_USAGE_SAMPLER);
+                                      PIPE_BIND_SAMPLER_VIEW);
          assert(texFormat != PIPE_FORMAT_NONE);
       }
    }
@@ -1041,9 +1041,9 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
    if (!pt)
       return;
 
-   sv = st_sampler_view_from_texture(st->pipe, pt);
+   sv = st_create_texture_sampler_view(st->pipe, pt);
    if (!sv) {
-      pipe_texture_reference(&pt, NULL);
+      pipe_resource_reference(&pt, NULL);
       return;
    }
 
@@ -1053,10 +1053,10 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
       /* copy source framebuffer surface into mipmap/texture */
       struct pipe_surface *psRead = screen->get_tex_surface(screen,
                                        rbRead->texture, 0, 0, 0,
-                                       PIPE_BUFFER_USAGE_GPU_READ);
+                                       PIPE_BIND_BLIT_SOURCE);
       struct pipe_surface *psTex = screen->get_tex_surface(screen, pt, 0, 0, 0, 
-                                      PIPE_BUFFER_USAGE_GPU_WRITE );
-
+                                       PIPE_BIND_RENDER_TARGET |
+                                       PIPE_BIND_BLIT_DESTINATION);
       pipe->surface_copy(pipe,
                          psTex,                               /* dest surf */
                          pack.SkipPixels, pack.SkipRows,      /* dest pos */
@@ -1110,8 +1110,8 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
          free(buf);
       }
 
-      pipe->tex_transfer_destroy(pipe, ptRead);
-      pipe->tex_transfer_destroy(pipe, ptTex);
+      pipe->transfer_destroy(pipe, ptRead);
+      pipe->transfer_destroy(pipe, ptTex);
    }
 
    /* OK, the texture 'pt' contains the src image/pixels.  Now draw a
@@ -1124,7 +1124,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
                       driver_fp,
                       color, invertTex);
 
-   pipe_texture_reference(&pt, NULL);
+   pipe_resource_reference(&pt, NULL);
    pipe_sampler_view_reference(&sv, NULL);
 }