<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Apr 22, 2013 at 11:14 AM, Eric Anholt <span dir="ltr"><<a href="mailto:eric@anholt.net" target="_blank">eric@anholt.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This function going to get used a lot more in upcoming patches.<br>
---<br>
 src/mesa/swrast/s_texture.c |   16 ++++++++++++----<br>
 1 file changed, 12 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c<br>
index 51048be..36a90dd 100644<br>
--- a/src/mesa/swrast/s_texture.c<br>
+++ b/src/mesa/swrast/s_texture.c<br>
@@ -58,6 +58,14 @@ _swrast_delete_texture_image(struct gl_context *ctx,<br>
    _mesa_delete_texture_image(ctx, texImage);<br>
 }<br>
<br>
+static unsigned int<br>
+texture_slices(struct gl_texture_image *texImage)<br>
+{<br>
+   if (texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY)<br>
+      return texImage->Height;<br>
+   else<br>
+      return texImage->Depth;<br>
+}<br>
<br></blockquote><div><br></div><div style>I think you can const-qualify 'texImage'.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 /**<br>
  * Called via ctx->Driver.AllocTextureImageBuffer()<br>
@@ -83,11 +91,11 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,<br>
     * We allocate the array for 1D/2D textures too in order to avoid special-<br>
     * case code in the texstore routines.<br>
     */<br>
-   swImg->ImageOffsets = malloc(texImage->Depth * sizeof(GLuint));<br>
+   swImg->ImageOffsets = malloc(texture_slices(texImage) * sizeof(GLuint));<br>
    if (!swImg->ImageOffsets)<br>
       return GL_FALSE;<br>
<br>
-   for (i = 0; i < texImage->Depth; i++) {<br>
+   for (i = 0; i < texture_slices(texImage); i++) {<br>
       swImg->ImageOffsets[i] = i * texImage->Width * texImage->Height;<br>
    }<br>
<br>
@@ -209,20 +217,20 @@ _swrast_map_teximage(struct gl_context *ctx,<br>
<br>
    map = swImage->Buffer;<br>
<br>
+   assert(slice < texture_slices(texImage));<br>
+<br>
    if (texImage->TexObject->Target == GL_TEXTURE_3D ||<br>
        texImage->TexObject->Target == GL_TEXTURE_2D_ARRAY) {<br>
       GLuint sliceSize = _mesa_format_image_size(texImage->TexFormat,<br>
                                                  texImage->Width,<br>
                                                  texImage->Height,<br>
                                                  1);<br>
-      assert(slice < texImage->Depth);<br>
       map += slice * sliceSize;<br>
    } else if (texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY) {<br>
       GLuint sliceSize = _mesa_format_image_size(texImage->TexFormat,<br>
                                                  texImage->Width,<br>
                                                  1,<br>
                                                  1);<br>
-      assert(slice < texImage->Height);<br>
       map += slice * sliceSize;<br>
    }<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
1.7.10.4<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><br></div></div>