Merge commit 'origin/master' into gallium-0.2
[mesa.git] / src / mesa / state_tracker / st_cb_drawpixels.c
index a486581989c375b5a153759407723278f34ef6b4..5b24b9f06874cf0c6eaeb63213f7511bf30f8bde 100644 (file)
@@ -35,6 +35,7 @@
 #include "main/bufferobj.h"
 #include "main/macros.h"
 #include "main/texformat.h"
+#include "main/state.h"
 #include "shader/program.h"
 #include "shader/prog_parameter.h"
 #include "shader/prog_print.h"
@@ -55,7 +56,7 @@
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_inlines.h"
-#include "util/p_tile.h"
+#include "util/u_tile.h"
 #include "util/u_draw_quad.h"
 #include "shader/prog_instruction.h"
 #include "cso_cache/cso_context.h"
@@ -294,7 +295,7 @@ st_make_passthrough_vertex_shader(struct st_context *st, GLboolean passColor)
    }
 
    stvp = (struct st_vertex_program *) p;
-   st_translate_vertex_program(st, stvp, NULL);
+   st_translate_vertex_program(st, stvp, NULL, NULL, NULL);
 
    st->drawpix.vert_shaders[passColor] = stvp;
 
@@ -382,7 +383,7 @@ make_texture(struct st_context *st,
                                     mformat,          /* gl_texture_format */
                                     dest,             /* dest */
                                     0, 0, 0,          /* dstX/Y/Zoffset */
-                                    surface->pitch * cpp, /* dstRowStride, bytes */
+                                    surface->stride,  /* dstRowStride, bytes */
                                     &dstImageOffsets, /* dstImageOffsets */
                                     width, height, 1, /* size */
                                     format, type,     /* src format/type */
@@ -423,14 +424,14 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z,
    /* setup vertex data */
    {
       const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
-      const GLfloat fb_width = fb->Width;
-      const GLfloat fb_height = fb->Height;
-      const GLfloat clip_x0 = x0 / fb_width * 2.0 - 1.0;
-      const GLfloat clip_y0 = y0 / fb_height * 2.0 - 1.0;
-      const GLfloat clip_x1 = x1 / fb_width * 2.0 - 1.0;
-      const GLfloat clip_y1 = y1 / fb_height * 2.0 - 1.0;
-      const GLfloat sLeft = 0.0F, sRight = 1.0F;
-      const GLfloat tTop = invertTex, tBot = 1.0 - tTop;
+      const GLfloat fb_width = (GLfloat) fb->Width;
+      const GLfloat fb_height = (GLfloat) fb->Height;
+      const GLfloat clip_x0 = x0 / fb_width * 2.0f - 1.0f;
+      const GLfloat clip_y0 = y0 / fb_height * 2.0f - 1.0f;
+      const GLfloat clip_x1 = x1 / fb_width * 2.0f - 1.0f;
+      const GLfloat clip_y1 = y1 / fb_height * 2.0f - 1.0f;
+      const GLfloat sLeft = 0.0f, sRight = 1.0f;
+      const GLfloat tTop = invertTex, tBot = 1.0f - tTop;
       GLuint tex, i;
 
       /* upper-left */
@@ -463,21 +464,21 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z,
       if (color) {
          for (i = 0; i < 4; i++) {
             verts[i][0][2] = z;   /*Z*/
-            verts[i][0][3] = 1.0; /*W*/
+            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.0; /*R*/
-            verts[i][2][3] = 1.0; /*Q*/
+            verts[i][2][2] = 0.0f; /*R*/
+            verts[i][2][3] = 1.0f; /*Q*/
          }
       }
       else {
          for (i = 0; i < 4; i++) {
             verts[i][0][2] = z;   /*Z*/
-            verts[i][0][3] = 1.0; /*W*/
-            verts[i][1][2] = 0.0; /*R*/
-            verts[i][1][3] = 1.0; /*Q*/
+            verts[i][0][3] = 1.0f; /*W*/
+            verts[i][1][2] = 0.0f; /*R*/
+            verts[i][1][3] = 1.0f; /*Q*/
          }
       }
    }
@@ -487,17 +488,17 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z,
       ubyte *map;
 
       /* allocate/load buffer object with vertex data */
-      buf = pipe_buffer_create(pipe, 32, PIPE_BUFFER_USAGE_VERTEX,
+      buf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX,
                                sizeof(verts));
-      map = pipe_buffer_map(pipe, buf, PIPE_BUFFER_USAGE_CPU_WRITE);
+      map = pipe_buffer_map(pipe->screen, buf, PIPE_BUFFER_USAGE_CPU_WRITE);
       memcpy(map, verts, sizeof(verts));
-      pipe_buffer_unmap(pipe, buf);
+      pipe_buffer_unmap(pipe->screen, buf);
 
       util_draw_vertex_buffer(pipe, buf,
                               PIPE_PRIM_QUADS,
                               4,  /* verts */
                               3); /* attribs/vert */
-      pipe_buffer_reference(pipe->winsys, &buf, NULL);
+      pipe_buffer_reference(pipe->screen, &buf, NULL);
    }
 }
 
@@ -517,7 +518,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
    struct pipe_context *pipe = ctx->st->pipe;
    struct cso_context *cso = ctx->st->cso_context;
    GLfloat x0, y0, x1, y1;
-   GLuint maxSize;
+   GLsizei maxSize;
 
    /* limit checks */
    /* XXX if DrawPixels image is larger than max texture size, break
@@ -571,17 +572,17 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
 
    /* viewport state: viewport matching window dims */
    {
-      const float width = ctx->DrawBuffer->Width;
-      const float height = ctx->DrawBuffer->Height;
+      const float width = (float) ctx->DrawBuffer->Width;
+      const float height = (float) ctx->DrawBuffer->Height;
       struct pipe_viewport_state vp;
-      vp.scale[0] =  0.5 * width;
-      vp.scale[1] = -0.5 * height;
-      vp.scale[2] = 1.0;
-      vp.scale[3] = 1.0;
-      vp.translate[0] = 0.5 * width;
-      vp.translate[1] = 0.5 * height;
-      vp.translate[2] = 0.0;
-      vp.translate[3] = 0.0;
+      vp.scale[0] =  0.5f * width;
+      vp.scale[1] = -0.5f * height;
+      vp.scale[2] = 1.0f;
+      vp.scale[3] = 1.0f;
+      vp.translate[0] = 0.5f * width;
+      vp.translate[1] = 0.5f * height;
+      vp.translate[2] = 0.0f;
+      vp.translate[3] = 0.0f;
       cso_set_viewport(cso, &vp);
    }
 
@@ -600,9 +601,9 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
     * Recall that these coords are transformed by the current
     * vertex shader and viewport transformation.
     */
-   x0 = x;
+   x0 = (GLfloat) x;
    x1 = x + width * ctx->Pixel.ZoomX;
-   y0 = y;
+   y0 = (GLfloat) y;
    y1 = y + height * ctx->Pixel.ZoomY;
    //if(!color)
    draw_quad(ctx, x0, y0, z, x1, y1, color, invertTex);
@@ -786,13 +787,13 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
             switch (ps->format) {
             case PIPE_FORMAT_S8_UNORM:
                {
-                  ubyte *dest = stmap + spanY * ps->pitch + spanX;
+                  ubyte *dest = stmap + spanY * ps->stride + spanX;
                   memcpy(dest, values, spanWidth);
                }
                break;
             case PIPE_FORMAT_S8Z24_UNORM:
                {
-                  uint *dest = (uint *) stmap + spanY * ps->pitch + spanX;
+                  uint *dest = (uint *) (stmap + spanY * ps->stride + spanX*4);
                   GLint k;
                   for (k = 0; k < spanWidth; k++) {
                      uint p = dest[k];
@@ -835,6 +836,9 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
       return;
    }
 
+   _mesa_set_vp_override( ctx, TRUE );
+   _mesa_update_state( ctx );
+
    st_validate_state(st);
 
    if (format == GL_DEPTH_COMPONENT) {
@@ -874,6 +878,8 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
       /* blit */
       draw_blit(st, width, height, format, type, pixels);
    }
+
+   _mesa_set_vp_override( ctx, FALSE );
 }
 
 
@@ -903,6 +909,9 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
    psDraw = screen->get_tex_surface(screen, rbDraw->texture, 0, 0, 0,
                                     PIPE_BUFFER_USAGE_CPU_WRITE);
 
+   assert(psDraw->block.width == 1);
+   assert(psDraw->block.height == 1);
+   
    /* map the stencil buffer */
    drawMap = screen->surface_map(screen, psDraw, PIPE_BUFFER_USAGE_CPU_WRITE);
 
@@ -919,7 +928,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
          y = ctx->DrawBuffer->Height - y - 1;
       }
 
-      dst = drawMap + (y * psDraw->pitch + dstx) * psDraw->cpp;
+      dst = drawMap + y * psDraw->stride + dstx * psDraw->block.size;
       src = buffer + i * width;
 
       switch (psDraw->format) {
@@ -992,18 +1001,21 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
 
    srcFormat = rbRead->texture->format;
 
-   if (screen->is_format_supported(screen, srcFormat, PIPE_TEXTURE)) {
+   if (screen->is_format_supported(screen, srcFormat, PIPE_TEXTURE_2D, 
+                                   PIPE_TEXTURE_USAGE_SAMPLER, 0)) {
       texFormat = srcFormat;
    }
    else {
       /* srcFormat can't be used as a texture format */
       if (type == GL_DEPTH) {
-         texFormat = st_choose_format(pipe, GL_DEPTH_COMPONENT, PIPE_TEXTURE);
+         texFormat = st_choose_format(pipe, GL_DEPTH_COMPONENT, PIPE_TEXTURE_2D, 
+                                      PIPE_TEXTURE_USAGE_DEPTH_STENCIL);
          assert(texFormat != PIPE_FORMAT_NONE); /* XXX no depth texture formats??? */
       }
       else {
          /* default color format */
-         texFormat = st_choose_format(pipe, GL_RGBA, PIPE_TEXTURE);
+         texFormat = st_choose_format(pipe, GL_RGBA, PIPE_TEXTURE_2D, 
+                                      PIPE_TEXTURE_USAGE_SAMPLER);
          assert(texFormat != PIPE_FORMAT_NONE);
       }
    }
@@ -1046,16 +1058,16 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
          /* alternate path using get/put_tile() */
          GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
 
-         pipe_get_tile_rgba(pipe, psRead, srcx, srcy, width, height, buf);
-         pipe_put_tile_rgba(pipe, psTex, 0, 0, width, height, buf);
+         pipe_get_tile_rgba(psRead, srcx, srcy, width, height, buf);
+         pipe_put_tile_rgba(psTex, 0, 0, width, height, buf);
 
          free(buf);
       }
       else {
          /* GL_DEPTH */
          GLuint *buf = (GLuint *) malloc(width * height * sizeof(GLuint));
-         pipe_get_tile_z(pipe, psRead, srcx, srcy, width, height, buf);
-         pipe_put_tile_z(pipe, psTex, 0, 0, width, height, buf);
+         pipe_get_tile_z(psRead, srcx, srcy, width, height, buf);
+         pipe_put_tile_z(psTex, 0, 0, width, height, buf);
          free(buf);
       }
       pipe_surface_reference(&psRead, NULL);