gallium: add some temporary code for testing draw module vertex passthrough
[mesa.git] / src / mesa / state_tracker / st_texture.c
index 844a9f80d851d12848c6b3875533bec236e2c8a7..cbc6f849982978f883c01b0513129a6be4fc611f 100644 (file)
@@ -62,40 +62,47 @@ target_to_target(GLenum target)
 
 /**
  * Allocate a new pipe_texture object
+ * width0, height0, depth0 are the dimensions of the level 0 image
+ * (the highest resolution).  last_level indicates how many mipmap levels
+ * to allocate storage for.  For non-mipmapped textures, this will be zero.
  */
 struct pipe_texture *
 st_texture_create(struct st_context *st,
                   enum pipe_texture_target target,
                  enum pipe_format format,
-                 GLuint first_level,
                  GLuint last_level,
                  GLuint width0,
                  GLuint height0,
                  GLuint depth0,
                  GLuint compress_byte)
 {
-   struct pipe_texture pt;
+   struct pipe_texture pt, *newtex;
+   struct pipe_screen *screen = st->pipe->screen;
 
    assert(target <= PIPE_TEXTURE_CUBE);
 
-   DBG("%s target %s format %s level %d..%d\n", __FUNCTION__,
+   DBG("%s target %s format %s last_level %d\n", __FUNCTION__,
        _mesa_lookup_enum_by_nr(target),
-       _mesa_lookup_enum_by_nr(format), first_level, last_level);
+       _mesa_lookup_enum_by_nr(format), last_level);
 
    assert(format);
+   assert(screen->is_format_supported(screen, format, PIPE_TEXTURE));
 
+   memset(&pt, 0, sizeof(pt));
    pt.target = target;
    pt.format = format;
-   pt.first_level = first_level;
    pt.last_level = last_level;
    pt.width[0] = width0;
    pt.height[0] = height0;
    pt.depth[0] = depth0;
    pt.compressed = compress_byte ? 1 : 0;
    pt.cpp = pt.compressed ? compress_byte : st_sizeof_format(format);
-   pt.refcount = 1; 
 
-   return st->pipe->texture_create(st->pipe, &pt);
+   newtex = screen->texture_create(screen, &pt);
+
+   assert(!newtex || newtex->refcount == 1);
+
+   return newtex;
 }
 
 
@@ -178,11 +185,12 @@ GLubyte *
 st_texture_image_map(struct st_context *st, struct st_texture_image *stImage,
                     GLuint zoffset)
 {
+   struct pipe_screen *screen = st->pipe->screen;
    struct pipe_texture *pt = stImage->pt;
    DBG("%s \n", __FUNCTION__);
 
-   stImage->surface = st->pipe->get_tex_surface(st->pipe, pt, stImage->face,
-                                               stImage->level, zoffset);
+   stImage->surface = screen->get_tex_surface(screen, pt, stImage->face,
+                                              stImage->level, zoffset);
 
    return pipe_surface_map(stImage->surface);
 }
@@ -234,6 +242,7 @@ st_texture_image_data(struct pipe_context *pipe,
                       void *src,
                       GLuint src_row_pitch, GLuint src_image_pitch)
 {
+   struct pipe_screen *screen = pipe->screen;
    GLuint depth = dst->depth[level];
    GLuint i;
    GLuint height = 0;
@@ -246,7 +255,7 @@ st_texture_image_data(struct pipe_context *pipe,
       if(dst->compressed)
         height /= 4;
 
-      dst_surface = pipe->get_tex_surface(pipe, dst, face, level, i);
+      dst_surface = screen->get_tex_surface(screen, dst, face, level, i);
 
       st_surface_data(pipe, dst_surface,
                      0, 0,                             /* dstx, dsty */
@@ -266,25 +275,40 @@ st_texture_image_data(struct pipe_context *pipe,
  */
 void
 st_texture_image_copy(struct pipe_context *pipe,
-                      struct pipe_texture *dst,
-                      GLuint face, GLuint level,
-                      struct pipe_texture *src)
+                      struct pipe_texture *dst, GLuint dstLevel,
+                      struct pipe_texture *src,
+                      GLuint face)
 {
-   GLuint width = src->width[level];
-   GLuint height = src->height[level];
-   GLuint depth = src->depth[level];
+   struct pipe_screen *screen = pipe->screen;
+   GLuint width = dst->width[dstLevel];
+   GLuint height = dst->height[dstLevel];
+   GLuint depth = dst->depth[dstLevel];
    struct pipe_surface *src_surface;
    struct pipe_surface *dst_surface;
    GLuint i;
 
+   /* XXX this is a hack */
    if (dst->compressed)
       height /= 4;
 
    for (i = 0; i < depth; i++) {
-      dst_surface = pipe->get_tex_surface(pipe, dst, face, level, i);
-      src_surface = pipe->get_tex_surface(pipe, src, face, level, i);
+      GLuint srcLevel;
+
+      /* find src texture level of needed size */
+      for (srcLevel = 0; srcLevel <= src->last_level; srcLevel++) {
+         if (src->width[srcLevel] == width &&
+             src->height[srcLevel] == height) {
+            break;
+         }
+      }
+      assert(src->width[srcLevel] == width);
+      assert(src->height[srcLevel] == height);
+
+      dst_surface = screen->get_tex_surface(screen, dst, face, dstLevel, i);
+      src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i);
 
       pipe->surface_copy(pipe,
+                         FALSE,
                         dst_surface,
                         0, 0, /* destX, Y */
                         src_surface,