<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 13, 2014 at 6:42 AM, Brian Paul <span dir="ltr"><<a href="mailto:brianp@vmware.com" target="_blank">brianp@vmware.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In preparation for getting texture sub images.<br>
---<br>
 src/mesa/drivers/common/meta.c                 | 88 +++++++++++++++++---------<br>
 src/mesa/drivers/common/meta.h                 |  4 ++<br>
 src/mesa/drivers/common/meta_generate_mipmap.c |  4 +-<br>
 3 files changed, 64 insertions(+), 32 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c<br>
index 87532c1..a84e512 100644<br>
--- a/src/mesa/drivers/common/meta.c<br>
+++ b/src/mesa/drivers/common/meta.c<br>
@@ -2450,30 +2450,53 @@ _mesa_meta_Bitmap(struct gl_context *ctx,<br>
<br>
 /**<br>
  * Compute the texture coordinates for the four vertices of a quad for<br>
- * drawing a 2D texture image or slice of a cube/3D texture.<br>
+ * drawing a 2D texture image or slice of a cube/3D texture.  The offset<br>
+ * and width, height specify a sub-region of the 2D image.<br>
+ *<br>
  * \param faceTarget  GL_TEXTURE_1D/2D/3D or cube face name<br>
  * \param slice  slice of a 1D/2D array texture or 3D texture<br>
- * \param width  width of the texture image<br>
- * \param height  height of the texture image<br>
+ * \param xoffset  X position of sub texture<br>
+ * \param yoffset  Y position of sub texture<br>
+ * \param width  width of the sub texture image<br>
+ * \param height  height of the sub texture image<br>
+ * \param total_width  total width of the texture image<br>
+ * \param total_height  total height of the texture image<br>
+ * \param total_depth  total depth of the texture image<br>
  * \param coords0/1/2/3  returns the computed texcoords<br>
  */<br></blockquote><br>I'm confused.  Here you take the args width, height, then total_width, total_height, and total_depth.  But in the definition of _mesa_meta_setup_texture_coords in meta.h, you have width, height, depth, total_width, and total_height.<br><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 void<br>
 _mesa_meta_setup_texture_coords(GLenum faceTarget,<br>
                                 GLint slice,<br>
+                                GLint xoffset,<br>
+                                GLint yoffset,<br>
                                 GLint width,<br>
                                 GLint height,<br>
-                                GLint depth,<br>
+                                GLint total_width,<br>
+                                GLint total_height,<br>
+                                GLint total_depth,<br>
                                 GLfloat coords0[4],<br>
                                 GLfloat coords1[4],<br>
                                 GLfloat coords2[4],<br>
                                 GLfloat coords3[4])<br>
 {<br>
-   static const GLfloat st[4][2] = {<br>
-      {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}<br>
-   };<br>
+   float st[4][2];<br>
    GLuint i;<br>
+   const float s0 = (float) xoffset / (float) total_width;<br>
+   const float s1 = (float) (xoffset + width) / (float) total_width;<br>
+   const float t0 = (float) yoffset / (float) total_height;<br>
+   const float t1 = (float) (yoffset + height) / (float) total_height;<br>
    GLfloat r;<br>
<br>
+   /* setup the reference texcoords */<br>
+   st[0][0] = s0;<br>
+   st[0][1] = t0;<br>
+   st[1][0] = s1;<br>
+   st[1][1] = t0;<br>
+   st[2][0] = s1;<br>
+   st[2][1] = t1;<br>
+   st[3][0] = s0;<br>
+   st[3][1] = t1;<br>
+<br>
    if (faceTarget == GL_TEXTURE_CUBE_MAP_ARRAY)<br>
       faceTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice % 6;<br>
<br>
@@ -2490,52 +2513,52 @@ _mesa_meta_setup_texture_coords(GLenum faceTarget,<br>
    case GL_TEXTURE_3D:<br>
    case GL_TEXTURE_2D_ARRAY:<br>
       if (faceTarget == GL_TEXTURE_3D) {<br>
-         assert(slice < depth);<br>
-         assert(depth >= 1);<br>
-         r = (slice + 0.5f) / depth;<br>
+         assert(slice < total_depth);<br>
+         assert(total_depth >= 1);<br>
+         r = (slice + 0.5f) / total_depth;<br>
       }<br>
       else if (faceTarget == GL_TEXTURE_2D_ARRAY)<br>
          r = (float) slice;<br>
       else<br>
          r = 0.0F;<br>
-      coords0[0] = 0.0F; /* s */<br>
-      coords0[1] = 0.0F; /* t */<br>
+      coords0[0] = st[0][0]; /* s */<br>
+      coords0[1] = st[0][1]; /* t */<br>
       coords0[2] = r; /* r */<br>
-      coords1[0] = 1.0F;<br>
-      coords1[1] = 0.0F;<br>
+      coords1[0] = st[1][0];<br>
+      coords1[1] = st[1][1];<br>
       coords1[2] = r;<br>
-      coords2[0] = 1.0F;<br>
-      coords2[1] = 1.0F;<br>
+      coords2[0] = st[2][0];<br>
+      coords2[1] = st[2][1];<br>
       coords2[2] = r;<br>
-      coords3[0] = 0.0F;<br>
-      coords3[1] = 1.0F;<br>
+      coords3[0] = st[3][0];<br>
+      coords3[1] = st[3][1];<br>
       coords3[2] = r;<br>
       break;<br>
    case GL_TEXTURE_RECTANGLE_ARB:<br>
-      coords0[0] = 0.0F; /* s */<br>
-      coords0[1] = 0.0F; /* t */<br>
+      coords0[0] = (float) xoffset; /* s */<br>
+      coords0[1] = (float) yoffset; /* t */<br>
       coords0[2] = 0.0F; /* r */<br>
-      coords1[0] = (float) width;<br>
-      coords1[1] = 0.0F;<br>
+      coords1[0] = (float) (xoffset + width);<br>
+      coords1[1] = (float) yoffset;<br>
       coords1[2] = 0.0F;<br>
-      coords2[0] = (float) width;<br>
-      coords2[1] = (float) height;<br>
+      coords2[0] = (float) (xoffset + width);<br>
+      coords2[1] = (float) (yoffset + height);<br>
       coords2[2] = 0.0F;<br>
-      coords3[0] = 0.0F;<br>
-      coords3[1] = (float) height;<br>
+      coords3[0] = (float) xoffset;<br>
+      coords3[1] = (float) (yoffset + height);<br>
       coords3[2] = 0.0F;<br>
       break;<br>
    case GL_TEXTURE_1D_ARRAY:<br>
-      coords0[0] = 0.0F; /* s */<br>
+      coords0[0] = st[0][0]; /* s */<br>
       coords0[1] = (float) slice; /* t */<br>
       coords0[2] = 0.0F; /* r */<br>
-      coords1[0] = 1.0f;<br>
+      coords1[0] = st[1][0];<br>
       coords1[1] = (float) slice;<br>
       coords1[2] = 0.0F;<br>
-      coords2[0] = 1.0F;<br>
+      coords2[0] = st[2][0];<br>
       coords2[1] = (float) slice;<br>
       coords2[2] = 0.0F;<br>
-      coords3[0] = 0.0F;<br>
+      coords3[0] = st[3][0];<br>
       coords3[1] = (float) slice;<br>
       coords3[2] = 0.0F;<br>
       break;<br>
@@ -3069,7 +3092,10 @@ decompress_texture_image(struct gl_context *ctx,<br>
    /* Silence valgrind warnings about reading uninitialized stack. */<br>
    memset(verts, 0, sizeof(verts));<br>
<br>
-   _mesa_meta_setup_texture_coords(faceTarget, slice, width, height, depth,<br>
+   _mesa_meta_setup_texture_coords(faceTarget, slice,<br>
+                                   0, 0, width, height,<br>
+                                   texImage->Width, texImage->Height,<br>
+                                   texImage->Depth,<br>
                                    verts[0].tex,<br>
                                    verts[1].tex,<br>
                                    verts[2].tex,<br>
diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h<br>
index 6ecf3c0..03e5191 100644<br>
--- a/src/mesa/drivers/common/meta.h<br>
+++ b/src/mesa/drivers/common/meta.h<br>
@@ -569,9 +569,13 @@ _mesa_meta_alloc_texture(struct temp_texture *tex,<br>
 void<br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 _mesa_meta_setup_texture_coords(GLenum faceTarget,<br>
                                 GLint slice,<br>
+                                GLint xoffset,<br>
+                                GLint yoffset,<br>
                                 GLint width,<br>
                                 GLint height,<br>
                                 GLint depth,<br>
+                                GLint total_width,<br>
+                                GLint total_height,<br>
                                 GLfloat coords0[4],<br>
                                 GLfloat coords1[4],<br>
                                 GLfloat coords2[4],<br>
diff --git a/src/mesa/drivers/common/meta_generate_mipmap.c b/src/mesa/drivers/common/meta_generate_mipmap.c<br>
index 8ffd8da..58b9a53 100644<br>
--- a/src/mesa/drivers/common/meta_generate_mipmap.c<br>
+++ b/src/mesa/drivers/common/meta_generate_mipmap.c<br>
@@ -317,7 +317,9 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,<br>
          /* Setup texture coordinates */<br>
          _mesa_meta_setup_texture_coords(faceTarget,<br>
                                          layer,<br>
-                                         0, 0, 1, /* width, height never used here */<br>
+                                         0, 0, /* xoffset, yoffset */<br>
+                                         srcWidth, srcHeight, /* img size */<br>
+                                         srcWidth, srcHeight, srcDepth,<br>
                                          verts[0].tex,<br>
                                          verts[1].tex,<br>
                                          verts[2].tex,<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.1<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div></div></div>