mesa: move gl_texture_image::Data, RowStride, ImageOffsets to swrast
authorBrian Paul <brianp@vmware.com>
Sun, 23 Oct 2011 16:44:47 +0000 (10:44 -0600)
committerBrian Paul <brianp@vmware.com>
Sun, 23 Oct 2011 16:44:47 +0000 (10:44 -0600)
Only swrast and the drivers that fall back to swrast need these fields now.
This removes the last of the fields related to software rendering from
gl_texture_image.

27 files changed:
src/mesa/drivers/dri/intel/intel_mipmap_tree.c
src/mesa/drivers/dri/intel/intel_tex.c
src/mesa/drivers/dri/intel/intel_tex_image.c
src/mesa/drivers/dri/intel/intel_tex_validate.c
src/mesa/drivers/dri/nouveau/nouveau_texture.c
src/mesa/drivers/dri/nouveau/nouveau_texture.h
src/mesa/drivers/dri/r200/r200_texstate.c
src/mesa/drivers/dri/r300/r300_texstate.c
src/mesa/drivers/dri/r600/evergreen_tex.c
src/mesa/drivers/dri/r600/r600_texstate.c
src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
src/mesa/drivers/dri/radeon/radeon_texstate.c
src/mesa/drivers/dri/radeon/radeon_texture.c
src/mesa/drivers/dri/swrast/swrast.c
src/mesa/main/mtypes.h
src/mesa/main/texcompress.c
src/mesa/main/texcompress_fxt1.c
src/mesa/main/texcompress_rgtc.c
src/mesa/main/texcompress_s3tc.c
src/mesa/main/teximage.c
src/mesa/main/texstore.c
src/mesa/swrast/s_context.h
src/mesa/swrast/s_texfetch_tmp.h
src/mesa/swrast/s_texfilter.c
src/mesa/swrast/s_texrender.c
src/mesa/swrast/s_texture.c
src/mesa/swrast/s_triangle.c

index bf6a0f6b71e5a125079661dd0ebcb1ccddb7652e..c5ef38b75960f6742d209e16c50a793d2e6c6018 100644 (file)
@@ -417,8 +417,8 @@ intel_miptree_copy_teximage(struct intel_context *intel,
             dst_mt, dst_x, dst_y, dst_mt->region->pitch * dst_mt->region->cpp,
             width, height);
 
-        src = intelImage->base.Base.Data;
-        src += (intelImage->base.Base.RowStride *
+        src = intelImage->base.Data;
+        src += (intelImage->base.RowStride *
                 intelImage->base.Base.Height *
                 dst_mt->region->cpp *
                 slice);
@@ -429,7 +429,7 @@ intel_miptree_copy_teximage(struct intel_context *intel,
                         dst_x, dst_y,
                         width, height,
                         src,
-                        intelImage->base.Base.RowStride,
+                        intelImage->base.RowStride,
                         0, 0);
 
         intel_region_unmap(intel, dst_mt->region);
@@ -437,8 +437,8 @@ intel_miptree_copy_teximage(struct intel_context *intel,
    }
 
    if (!src_mt) {
-      _mesa_free_texmemory(intelImage->base.Base.Data);
-      intelImage->base.Base.Data = NULL;
+      _mesa_free_texmemory(intelImage->base.Data);
+      intelImage->base.Data = NULL;
    }
 
    intel_miptree_reference(&intelImage->mt, dst_mt);
index 054ae42158579d311cf3f670556834856841cd51..c11753b3deb5d145abea546793b1b185b11e9d04 100644 (file)
@@ -59,6 +59,7 @@ intel_alloc_texture_image_buffer(struct gl_context *ctx,
    struct intel_texture_image *intel_image = intel_texture_image(image);
    struct gl_texture_object *texobj = image->TexObject;
    struct intel_texture_object *intel_texobj = intel_texture_object(texobj);
+   GLuint slices;
 
    /* Because the driver uses AllocTextureImageBuffer() internally, it may end
     * up mismatched with FreeTextureImageBuffer(), but that is safe to call
@@ -66,6 +67,26 @@ intel_alloc_texture_image_buffer(struct gl_context *ctx,
     */
    ctx->Driver.FreeTextureImageBuffer(ctx, image);
 
+   if (intel->must_use_separate_stencil
+       && image->TexFormat == MESA_FORMAT_S8_Z24) {
+      intel_tex_image_s8z24_create_renderbuffers(intel, intel_image);
+   }
+
+   /* Allocate the swrast_texture_image::ImageOffsets array now */
+   switch (texobj->Target) {
+   case GL_TEXTURE_3D:
+   case GL_TEXTURE_2D_ARRAY:
+      slices = image->Depth;
+      break;
+   case GL_TEXTURE_1D_ARRAY:
+      slices = image->Height;
+      break;
+   default:
+      slices = 1;
+   }
+   assert(!intel_image->base.ImageOffsets);
+   intel_image->base.ImageOffsets = malloc(slices * sizeof(GLuint));
+
    if (intel_texobj->mt &&
        intel_miptree_match_image(intel_texobj->mt, image)) {
       intel_miptree_reference(&intel_image->mt, intel_texobj->mt);
@@ -113,9 +134,14 @@ intel_free_texture_image_buffer(struct gl_context * ctx,
 
    intel_miptree_release(&intelImage->mt);
 
-   if (texImage->Data) {
-      _mesa_free_texmemory(texImage->Data);
-      texImage->Data = NULL;
+   if (intelImage->base.Data) {
+      _mesa_free_texmemory(intelImage->base.Data);
+      intelImage->base.Data = NULL;
+   }
+
+   if (intelImage->base.ImageOffsets) {
+      free(intelImage->base.ImageOffsets);
+      intelImage->base.ImageOffsets = NULL;
    }
 
    _mesa_reference_renderbuffer(&intelImage->depth_rb, NULL);
@@ -188,11 +214,11 @@ intel_map_texture_image(struct gl_context *ctx,
       assert(map);
 
       *stride = _mesa_format_row_stride(tex_image->TexFormat, width);
-      *map = tex_image->Data + (slice * height + y) * *stride + x * texelSize;
+      *map = intel_image->base.Data + (slice * height + y) * *stride + x * texelSize;
 
       DBG("%s: %d,%d %dx%d from data %p = %p/%d\n", __FUNCTION__,
          x, y, w, h,
-         tex_image->Data, *map, *stride);
+         intel_image->base.Data, *map, *stride);
    }
 }
 
index 4710bf6049bee4b1fd229631971c9b1cbeed1828..cf54a1391c1c1a30265ecc15d0f6ea80b8db23c0 100644 (file)
@@ -454,7 +454,7 @@ intel_set_texture_image_region(struct gl_context *ctx,
    if (intel_image->mt == NULL)
        return;
 
-   image->RowStride = region->pitch;
+   intel_image->base.RowStride = region->pitch;
 }
 
 void
index 40124009437b848c20d8ca5a749320a97869d892..6639de9c2af73875f6375f7cb5f013382483579d 100644 (file)
@@ -147,40 +147,29 @@ intel_tex_map_image_for_swrast(struct intel_context *intel,
        mt->target == GL_TEXTURE_1D_ARRAY) {
       int i;
 
-      if (mt->target == GL_TEXTURE_2D_ARRAY ||
-          mt->target == GL_TEXTURE_1D_ARRAY) {
-         /* Mesa only allocates one entry for these, but we really do have an
-          * offset per depth.
-          */
-         free(intel_image->base.Base.ImageOffsets);
-         intel_image->base.Base.ImageOffsets = malloc(mt->level[level].depth *
-                                                      sizeof(GLuint));
-      }
-
       /* ImageOffsets[] is only used for swrast's fetch_texel_3d, so we can't
        * share code with the normal path.
        */
       for (i = 0; i < mt->level[level].depth; i++) {
         intel_miptree_get_image_offset(mt, level, face, i, &x, &y);
-        intel_image->base.Base.ImageOffsets[i] = x + y * mt->region->pitch;
+        intel_image->base.ImageOffsets[i] = x + y * mt->region->pitch;
       }
 
       DBG("%s \n", __FUNCTION__);
 
-      intel_image->base.Base.Data = intel_region_map(intel, mt->region, mode);
+      intel_image->base.Data = intel_region_map(intel, mt->region, mode);
    } else {
       assert(mt->level[level].depth == 1);
       intel_miptree_get_image_offset(mt, level, face, 0, &x, &y);
-      intel_image->base.Base.ImageOffsets[0] = 0;
 
       DBG("%s: (%d,%d) -> (%d, %d)/%d\n",
          __FUNCTION__, face, level, x, y, mt->region->pitch * mt->cpp);
 
-      intel_image->base.Base.Data = intel_region_map(intel, mt->region, mode) +
+      intel_image->base.Data = intel_region_map(intel, mt->region, mode) +
         (x + y * mt->region->pitch) * mt->cpp;
    }
 
-   intel_image->base.Base.RowStride = mt->region->pitch;
+   intel_image->base.RowStride = mt->region->pitch;
 }
 
 static void
@@ -189,7 +178,7 @@ intel_tex_unmap_image_for_swrast(struct intel_context *intel,
 {
    if (intel_image && intel_image->mt) {
       intel_region_unmap(intel, intel_image->mt->region);
-      intel_image->base.Base.Data = NULL;
+      intel_image->base.Data = NULL;
    }
 }
 
index 2212d895ae4a1b3801220a3ff7a5f2641a41ff44..08ec03ee6c38e1a7c3c9731df69512daebfb48d0 100644 (file)
@@ -68,7 +68,7 @@ nouveau_teximage_new(struct gl_context *ctx)
 {
        struct nouveau_teximage *nti = CALLOC_STRUCT(nouveau_teximage);
 
-       return &nti->base;
+       return &nti->base.Base;
 }
 
 static void
@@ -103,7 +103,7 @@ nouveau_teximage_map(struct gl_context *ctx, struct gl_texture_image *ti,
                        nti->transfer.x = x;
                        nti->transfer.y = y;
 
-                       ti->Data = nouveau_get_scratch(ctx, st->pitch * h,
+                       nti->base.Data = nouveau_get_scratch(ctx, st->pitch * h,
                                                       &st->bo, &st->offset);
 
                } else {
@@ -119,7 +119,7 @@ nouveau_teximage_map(struct gl_context *ctx, struct gl_texture_image *ti,
                                assert(!ret);
                        }
 
-                       ti->Data = s->bo->map + y * s->pitch + x * s->cpp;
+                       nti->base.Data = s->bo->map + y * s->pitch + x * s->cpp;
                }
        }
 }
@@ -141,7 +141,7 @@ nouveau_teximage_unmap(struct gl_context *ctx, struct gl_texture_image *ti)
                nouveau_bo_unmap(s->bo);
        }
 
-       ti->Data = NULL;
+       nti->base.Data = NULL;
 }
 
 
@@ -197,7 +197,7 @@ nouveau_map_texture_image(struct gl_context *ctx,
                        *stride = s->pitch;
                }
        } else {
-               *map = ti->Data + y * s->pitch + x * s->cpp;
+               *map = nti->base.Data + y * s->pitch + x * s->cpp;
                *stride = s->pitch;
        }
 }
@@ -220,7 +220,7 @@ nouveau_unmap_texture_image(struct gl_context *ctx, struct gl_texture_image *ti,
                nouveau_bo_unmap(s->bo);
        }
 
-       ti->Data = NULL;
+       nti->base.Data = NULL;
 }
 
 static gl_format
@@ -461,12 +461,13 @@ nouveau_teximage(struct gl_context *ctx, GLint dims, GLenum target, GLint level,
                 struct gl_texture_image *ti)
 {
        struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface;
+       struct nouveau_teximage *nti = to_nouveau_teximage(ti);
        int ret;
 
        /* Allocate a new bo for the image. */
        nouveau_surface_alloc(ctx, s, LINEAR, get_teximage_placement(ti),
                              ti->TexFormat, width, height);
-       ti->RowStride = s->pitch / s->cpp;
+       nti->base.RowStride = s->pitch / s->cpp;
 
        pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, depth,
                                             format, type, pixels, packing,
@@ -479,7 +480,7 @@ nouveau_teximage(struct gl_context *ctx, GLint dims, GLenum target, GLint level,
                ret = _mesa_texstore(ctx, dims, ti->_BaseFormat,
                                     ti->TexFormat,
                                     0, 0, 0, s->pitch,
-                                     (GLubyte **) &ti->Data,
+                                     &nti->base.Data,
                                     width, height, depth,
                                     format, type, pixels, packing);
                assert(ret);
@@ -555,6 +556,7 @@ nouveau_texsubimage(struct gl_context *ctx, GLint dims, GLenum target, GLint lev
                    struct gl_texture_image *ti)
 {
        struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface;
+       struct nouveau_teximage *nti = to_nouveau_teximage(ti);
        int ret;
 
        pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, depth,
@@ -566,7 +568,7 @@ nouveau_texsubimage(struct gl_context *ctx, GLint dims, GLenum target, GLint lev
 
                ret = _mesa_texstore(ctx, 3, ti->_BaseFormat, ti->TexFormat,
                                      0, 0, 0, s->pitch,
-                                    (GLubyte **) &ti->Data,
+                                    &nti->base.Data,
                                      width, height, depth,
                                     format, type, pixels, packing);
                assert(ret);
@@ -654,10 +656,12 @@ nouveau_set_texbuffer(__DRIcontext *dri_ctx,
                fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
        struct gl_texture_object *t = _mesa_get_current_tex_object(ctx, target);
        struct gl_texture_image *ti;
+       struct nouveau_teximage *nti;
        struct nouveau_surface *s;
 
        _mesa_lock_texture(ctx, t);
        ti = _mesa_get_tex_image(ctx, t, target, 0);
+       nti = to_nouveau_teximage(ti);
        s = &to_nouveau_teximage(ti)->surface;
 
        /* Update the texture surface with the given drawable. */
@@ -669,7 +673,7 @@ nouveau_set_texbuffer(__DRIcontext *dri_ctx,
        /* Update the image fields. */
        _mesa_init_teximage_fields(ctx, target, ti, s->width, s->height,
                                   1, 0, s->cpp, s->format);
-       ti->RowStride = s->pitch / s->cpp;
+       nti->base.RowStride = s->pitch / s->cpp;
 
        /* Try to validate it. */
        if (!validate_teximage(ctx, t, 0, 0, 0, 0, s->width, s->height, 1))
index 56e61c7337bf1d436237c992624e3dbe5445b160..562429f146b0d269d31349c9e874184a2546f350 100644 (file)
 #ifndef __NOUVEAU_TEXTURE_H__
 #define __NOUVEAU_TEXTURE_H__
 
+#include "swrast/s_context.h"
+
 struct nouveau_teximage {
-       struct gl_texture_image base;
+       struct swrast_texture_image base;
        struct nouveau_surface surface;
        struct {
                struct nouveau_surface surface;
index cb3f245c8546d1790a97c0932410b96ad62bc7f0..0261840a1d18b1a741ec91bee038af52fe43a808 100644 (file)
@@ -846,7 +846,7 @@ void r200SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_format
        _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
                                   rb->base.Width, rb->base.Height, 1, 0,
                                   rb->cpp, texFormat);
-       texImage->RowStride = rb->pitch / rb->cpp;
+       rImage->base.RowStride = rb->pitch / rb->cpp;
 
 
         t->pp_txsize = ((rb->base.Width - 1) << RADEON_TEX_USIZE_SHIFT)
index e73e79b9c3a068af9f83ee1bbea17e6ad071028e..26ab0e5bf801e852637a2dea02d42607bd497ffd 100644 (file)
@@ -498,7 +498,7 @@ void r300SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_format
        _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
                                   rb->base.Width, rb->base.Height, 1, 0,
                                   rb->cpp, texFormat);
-       texImage->RowStride = rb->pitch / rb->cpp;
+       rImage->base.RowStride = rb->pitch / rb->cpp;
 
 
        pitch_val--;
index b2b67b00f125e2e5c5e382919afe26b3a00b9fb9..c94a717c0aeba59b393ac7240161a6774f56f7e8 100644 (file)
@@ -1404,7 +1404,7 @@ void evergreenSetTexBuffer(__DRIcontext *pDRICtx, GLint target, GLint glx_textur
        _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
                                   rb->base.Width, rb->base.Height, 1, 0,
                                   rb->cpp, texFormat);
-       texImage->RowStride = rb->pitch / rb->cpp;
+       rImage->base.RowStride = rb->pitch / rb->cpp;
 
        pitch_val = (pitch_val + R700_TEXEL_PITCH_ALIGNMENT_MASK)
                & ~R700_TEXEL_PITCH_ALIGNMENT_MASK;
index b3fe544019a88ffbdad6ea448ef11de97e19aaa2..e0c5011c63c1dc82abea2178d31761e9b1c99766 100644 (file)
@@ -1257,7 +1257,7 @@ void r600SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint glx_texture_fo
        _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
                                   rb->base.Width, rb->base.Height, 1, 0,
                                   rb->cpp, texFormat);
-       texImage->RowStride = rb->pitch / rb->cpp;
+       rImage->base.RowStride = rb->pitch / rb->cpp;
 
        pitch_val = (pitch_val + R700_TEXEL_PITCH_ALIGNMENT_MASK)
                & ~R700_TEXEL_PITCH_ALIGNMENT_MASK;
index f1febd36ef098a3d32d33237ea8397e7a9e92743..8daeb5e8dd2eebff168a86d8cc0c909631cee657 100644 (file)
@@ -480,7 +480,7 @@ static void migrate_image_to_miptree(radeon_mipmap_tree *mt,
                radeon_bo_unmap(image->mt->bo);
 
                radeon_miptree_unreference(&image->mt);
-       } else if (image->base.Base.Data) {
+       } else if (image->base.Data) {
                /* This condition should be removed, it's here to workaround
                 * a segfault when mapping textures during software fallbacks.
                 */
@@ -496,11 +496,11 @@ static void migrate_image_to_miptree(radeon_mipmap_tree *mt,
                        rows = (rows + blockHeight - 1) / blockHeight;
                }
 
-               copy_rows(dest, dstlvl->rowstride, image->base.Base.Data, srcrowstride,
+               copy_rows(dest, dstlvl->rowstride, image->base.Data, srcrowstride,
                                  rows, srcrowstride);
 
-               _mesa_free_texmemory(image->base.Base.Data);
-               image->base.Base.Data = 0;
+               _mesa_free_texmemory(image->base.Data);
+               image->base.Data = 0;
        }
 
        radeon_bo_unmap(mt->bo);
index 5c5cd8b176ff4e66369143a9b3ff0b5ff2e88e17..b67767893d97998377338ce71fc97d842b27698b 100644 (file)
@@ -720,7 +720,7 @@ void radeonSetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_form
        _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
                                   rb->base.Width, rb->base.Height, 1, 0,
                                   rb->cpp, texFormat);
-       texImage->RowStride = rb->pitch / rb->cpp;
+       rImage->base.RowStride = rb->pitch / rb->cpp;
 
        t->pp_txpitch &= (1 << 13) -1;
        pitch_val = rb->pitch;
index 24e40e9853beb4c358bf3e016446173449a76182..2d17d30bb50ce8874ce392bdaa32afefa702fcec 100644 (file)
@@ -104,7 +104,7 @@ void radeonFreeTextureImageBuffer(struct gl_context *ctx, struct gl_texture_imag
 
        if (image->mt) {
                radeon_miptree_unreference(&image->mt);
-               assert(!image->base.Base.Data);
+               assert(!image->base.Data);
        } else {
                _mesa_free_texture_image_data(ctx, timage);
        }
@@ -112,9 +112,14 @@ void radeonFreeTextureImageBuffer(struct gl_context *ctx, struct gl_texture_imag
                radeon_bo_unref(image->bo);
                image->bo = NULL;
        }
-       if (timage->Data) {
-               _mesa_free_texmemory(timage->Data);
-               timage->Data = NULL;
+       if (image->base.Data) {
+               _mesa_free_texmemory(image->base.Data);
+               image->base.Data = NULL;
+       }
+
+       if (image->base.ImageOffsets) {
+               free(image->base.ImageOffsets);
+               image->base.ImageOffsets = NULL;
        }
 }
 
@@ -132,8 +137,8 @@ static void teximage_set_map_data(radeon_texture_image *image)
 
        lvl = &image->mt->levels[image->mtlevel];
 
-       image->base.Base.Data = image->mt->bo->ptr + lvl->faces[image->mtface].offset;
-       image->base.Base.RowStride = lvl->rowstride / _mesa_get_format_bytes(image->base.Base.TexFormat);
+       image->base.Data = image->mt->bo->ptr + lvl->faces[image->mtface].offset;
+       image->base.RowStride = lvl->rowstride / _mesa_get_format_bytes(image->base.Base.TexFormat);
 }
 
 
@@ -147,7 +152,7 @@ void radeon_teximage_map(radeon_texture_image *image, GLboolean write_enable)
                        __func__, image,
                        write_enable ? "true": "false");
        if (image->mt) {
-               assert(!image->base.Base.Data);
+               assert(!image->base.Data);
 
                radeon_bo_map(image->mt->bo, write_enable);
                teximage_set_map_data(image);
@@ -161,9 +166,9 @@ void radeon_teximage_unmap(radeon_texture_image *image)
                        "%s(img %p)\n",
                        __func__, image);
        if (image->mt) {
-               assert(image->base.Base.Data);
+               assert(image->base.Data);
 
-               image->base.Base.Data = 0;
+               image->base.Data = 0;
                radeon_bo_unmap(image->mt->bo);
        }
 }
@@ -174,7 +179,7 @@ static void map_override(struct gl_context *ctx, radeonTexObj *t)
 
        radeon_bo_map(t->bo, GL_FALSE);
 
-       img->base.Base.Data = t->bo->ptr;
+       img->base.Data = t->bo->ptr;
 }
 
 static void unmap_override(struct gl_context *ctx, radeonTexObj *t)
@@ -183,7 +188,7 @@ static void unmap_override(struct gl_context *ctx, radeonTexObj *t)
 
        radeon_bo_unmap(t->bo);
 
-       img->base.Base.Data = NULL;
+       img->base.Data = NULL;
 }
 
 /**
@@ -243,8 +248,11 @@ void radeonUnmapTexture(struct gl_context *ctx, struct gl_texture_object *texObj
          return;
 
        for(face = 0; face < t->mt->faces; ++face) {
-               for(level = t->minLod; level <= t->maxLod; ++level)
-                       texObj->Image[face][level]->Data = 0;
+               for(level = t->minLod; level <= t->maxLod; ++level) {
+                       radeon_texture_image *image =
+                               get_radeon_texture_image(texObj->Image[face][level]);
+                       image->base.Data = NULL;
+               }
        }
        radeon_bo_unmap(t->mt->bo);
 }
@@ -306,7 +314,7 @@ radeon_map_texture_image(struct gl_context *ctx,
                assert(map);
 
                *stride = _mesa_format_row_stride(texImage->TexFormat, width);
-               *map = texImage->Data + (slice * height) * *stride;
+               *map = image->base.Data + (slice * height) * *stride;
        }
 
        *map += y * *stride + x * texel_size;
@@ -690,26 +698,6 @@ static void teximage_assign_miptree(radeonContextPtr rmesa,
                                "%s Failed to allocate miptree.\n", __func__);
 }
 
-static GLuint * allocate_image_offsets(struct gl_context *ctx,
-       unsigned alignedWidth,
-       unsigned height,
-       unsigned depth)
-{
-       int i;
-       GLuint *offsets;
-
-       offsets = malloc(depth * sizeof(GLuint)) ;
-       if (!offsets) {
-               _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTex[Sub]Image");
-               return NULL;
-       }
-
-       for (i = 0; i < depth; ++i) {
-               offsets[i] = alignedWidth * height * i;
-       }
-
-       return offsets;
-}
 
 /**
  * Update a subregion of the given texture image.
@@ -728,9 +716,11 @@ static void radeon_store_teximage(struct gl_context* ctx, int dims,
        radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
        radeonTexObj *t = radeon_tex_obj(texObj);
        radeon_texture_image* image = get_radeon_texture_image(texImage);
+       GLuint texel_size = _mesa_get_format_bytes(texImage->TexFormat);
 
        GLuint dstRowStride;
-       GLuint *dstImageOffsets;
+       GLuint alignedWidth;
+       GLint i;
 
        radeon_print(RADEON_TEXTURE, RADEON_TRACE,
                        "%s(%p, tex %p, image %p) compressed %d\n",
@@ -747,16 +737,13 @@ static void radeon_store_teximage(struct gl_context* ctx, int dims,
 
        assert(dstRowStride);
 
-       if (dims == 3) {
-               unsigned alignedWidth = dstRowStride/_mesa_get_format_bytes(texImage->TexFormat);
-               dstImageOffsets = allocate_image_offsets(ctx, alignedWidth, texImage->Height, texImage->Depth);
-               if (!dstImageOffsets) {
-                       radeon_warning("%s Failed to allocate dstImaeOffset.\n", __func__);
-                       return;
-               }
-       } else {
-               dstImageOffsets = texImage->ImageOffsets;
+       /* fill in the ImageOffsets array */
+       alignedWidth = dstRowStride / texel_size;
+       for (i = 0; i < texImage->Depth; ++i) {
+               image->base.ImageOffsets[i] = alignedWidth * texImage->Height * i;
        }
+       /* and fill in RowStride (in texels) */
+       image->base.RowStride = alignedWidth;
 
        radeon_teximage_map(image, GL_TRUE);
 
@@ -770,13 +757,13 @@ static void radeon_store_teximage(struct gl_context* ctx, int dims,
                        dstRowStride = _mesa_format_row_stride(texImage->TexFormat, texImage->Width);
                        img_start = _mesa_compressed_image_address(xoffset, yoffset, 0,
                                                                        texImage->TexFormat,
-                                                                       texImage->Width, texImage->Data);
+                                                                       texImage->Width, image->base.Data);
                }
                else {
                        uint32_t offset;
-                       offset = dstRowStride / _mesa_get_format_bytes(texImage->TexFormat) * yoffset / block_height + xoffset / block_width;
-                       offset *= _mesa_get_format_bytes(texImage->TexFormat);
-                       img_start = texImage->Data + offset;
+                       offset = dstRowStride / texel_size * yoffset / block_height + xoffset / block_width;
+                       offset *= texel_size;
+                       img_start = image->base.Data + offset;
                }
                srcRowStride = _mesa_format_row_stride(texImage->TexFormat, width);
                bytesPerRow = srcRowStride;
@@ -786,12 +773,11 @@ static void radeon_store_teximage(struct gl_context* ctx, int dims,
        }
        else {
                GLubyte *slices[512];
-               GLuint texelBytes = _mesa_get_format_bytes(texImage->TexFormat);
                GLuint i;
                assert(depth <= 512);
                for (i = 0; i < depth; i++) {
-                       slices[i] = (GLubyte *) texImage->Data
-                               + dstImageOffsets[i] * texelBytes;
+                       slices[i] = (GLubyte *) image->base.Data
+                               + image->base.ImageOffsets[i] * texel_size;
                }
                if (!_mesa_texstore(ctx, dims, texImage->_BaseFormat,
                                        texImage->TexFormat,
@@ -804,10 +790,6 @@ static void radeon_store_teximage(struct gl_context* ctx, int dims,
                }
        }
 
-       if (dims == 3) {
-               free(dstImageOffsets);
-       }
-
        radeon_teximage_unmap(image);
 }
 
@@ -837,7 +819,6 @@ static void radeon_teximage(
 
        t->validated = GL_FALSE;
 
-       /* Mesa core only clears texImage->Data but not image->mt */
        radeonFreeTextureImageBuffer(ctx, texImage);
 
        if (!t->bo) {
@@ -847,11 +828,11 @@ static void radeon_teximage(
                                                                texImage->Width,
                                                                texImage->Height,
                                                                texImage->Depth);
-                       texImage->Data = _mesa_alloc_texmemory(size);
+                       image->base.Data = _mesa_alloc_texmemory(size);
                        radeon_print(RADEON_TEXTURE, RADEON_VERBOSE,
                                        "%s %dd: texObj %p, texImage %p, "
                                        " no miptree assigned, using local memory %p\n",
-                                       __func__, dims, texObj, texImage, texImage->Data);
+                                       __func__, dims, texObj, texImage, image->base.Data);
                }
        }
 
@@ -867,6 +848,10 @@ static void radeon_teximage(
                }
        }
 
+       image->base.ImageOffsets =
+               (GLuint *) malloc(texImage->Depth * sizeof(GLuint));
+
+
        /* Upload texture image; note that the spec allows pixels to be NULL */
        if (compressed) {
                pixels = _mesa_validate_pbo_compressed_teximage(
@@ -1090,7 +1075,7 @@ void radeon_image_target_texture_2d(struct gl_context *ctx, GLenum target,
        texImage->Depth = 1;
        texImage->_BaseFormat = GL_RGBA;
        texImage->TexFormat = image->format;
-       texImage->RowStride = image->pitch;
+       radeonImage->base.RowStride = image->pitch;
        texImage->InternalFormat = image->internal_format;
 
        if(t->mt)
index d2c74b91dd10896e16e7554f0ed45fd38f550fd5..75d25253eb4a869a67bc4cfdb074e6ec1a6bd6c0 100644 (file)
@@ -52,6 +52,7 @@
 #include "main/texstate.h"
 
 #include "swrast_priv.h"
+#include "swrast/s_context.h"
 
 
 /**
@@ -67,6 +68,7 @@ static void swrastSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
     struct gl_texture_unit *texUnit;
     struct gl_texture_object *texObj;
     struct gl_texture_image *texImage;
+    struct swrast_texture_image *swImage;
     uint32_t internalFormat;
     gl_format texFormat;
 
@@ -77,6 +79,7 @@ static void swrastSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
     texUnit = _mesa_get_current_tex_unit(&dri_ctx->Base);
     texObj = _mesa_select_tex_object(&dri_ctx->Base, texUnit, target);
     texImage = _mesa_get_tex_image(&dri_ctx->Base, texObj, target, 0);
+    swImage = swrast_texture_image(texImage);
 
     _mesa_lock_texture(&dri_ctx->Base, texObj);
 
@@ -90,7 +93,7 @@ static void swrastSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
     _mesa_init_teximage_fields(&dri_ctx->Base, target, texImage,
                               w, h, 1, 0, internalFormat, texFormat);
 
-    sPriv->swrast_loader->getImage(dPriv, x, y, w, h, (char *)texImage->Data,
+    sPriv->swrast_loader->getImage(dPriv, x, y, w, h, (char *)swImage->Data,
                                   dPriv->loaderPrivate);
 
     _mesa_unlock_texture(&dri_ctx->Base, texObj);
index 17c645a7ee5e25eeadfb0c4b5953cb9c53b85e43..d02bc16764340b5d0df92d292bd6652b54f61764 100644 (file)
@@ -1261,11 +1261,6 @@ struct gl_texture_image
    GLuint Level;                /**< Which mipmap level am I? */
    /** Cube map face: index into gl_texture_object::Image[] array */
    GLuint Face;
-
-   GLuint RowStride;           /**< Padded width in units of texels */
-   GLuint *ImageOffsets;        /**< if 3D texture: array [Depth] of offsets to
-                                     each 2D slice in 'Data', in texels */
-   GLvoid *Data;               /**< Image data, accessed via FetchTexel() */
 };
 
 
index 03e05d5ef7b02a8d0dbc16346a0f31f0623b676d..0458b9b689ef1786905cd9a4756c0298f95f99ca 100644 (file)
@@ -461,8 +461,8 @@ _mesa_decompress_image(gl_format format, GLuint width, GLuint height,
 
    /* setup dummy texture image info */
    memset(&texImage, 0, sizeof(texImage));
-   texImage.Base.Data = (void *) src;
-   texImage.Base.RowStride = srcRowStride;
+   texImage.Data = (void *) src;
+   texImage.RowStride = srcRowStride;
 
    switch (format) {
    /* DXT formats */
index 41630a47c6433cac555f320ab16f50b1e4ada216..d5c73e3b424a5a18f636c4e0dbb4707381eeb5ef 100644 (file)
@@ -177,7 +177,7 @@ _mesa_fetch_texel_2d_f_rgba_fxt1( const struct swrast_texture_image *texImage,
    /* just sample as GLubyte and convert to float here */
    GLubyte rgba[4];
    (void) k;
-   fxt1_decode_1(texImage->Base.Data, texImage->Base.RowStride, i, j, rgba);
+   fxt1_decode_1(texImage->Data, texImage->RowStride, i, j, rgba);
    texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]);
    texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]);
    texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]);
@@ -192,7 +192,7 @@ _mesa_fetch_texel_2d_f_rgb_fxt1( const struct swrast_texture_image *texImage,
    /* just sample as GLubyte and convert to float here */
    GLubyte rgba[4];
    (void) k;
-   fxt1_decode_1(texImage->Base.Data, texImage->Base.RowStride, i, j, rgba);
+   fxt1_decode_1(texImage->Data, texImage->RowStride, i, j, rgba);
    texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]);
    texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]);
    texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]);
index b03cd28b8585d3299a0936011e16143bd654fc25..3586fc39daf23afe946eeb2d52ae895472e70eeb 100644 (file)
@@ -325,7 +325,7 @@ _mesa_fetch_texel_2d_f_red_rgtc1(const struct swrast_texture_image *texImage,
                                 GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLubyte red;
-   unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data),
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
                       i, j, &red, 1);
    texel[RCOMP] = UBYTE_TO_FLOAT(red);
    texel[GCOMP] = 0.0;
@@ -338,7 +338,7 @@ _mesa_fetch_texel_2d_f_signed_red_rgtc1(const struct swrast_texture_image *texIm
                                        GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLbyte red;
-   signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data),
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
                       i, j, &red, 1);
    texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);
    texel[GCOMP] = 0.0;
@@ -351,9 +351,9 @@ _mesa_fetch_texel_2d_f_rg_rgtc2(const struct swrast_texture_image *texImage,
                                 GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLubyte red, green;
-   unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data),
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
                     i, j, &red, 2);
-   unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data) + 8,
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data + 8,
                     i, j, &green, 2);
    texel[RCOMP] = UBYTE_TO_FLOAT(red);
    texel[GCOMP] = UBYTE_TO_FLOAT(green);
@@ -366,9 +366,9 @@ _mesa_fetch_texel_2d_f_signed_rg_rgtc2(const struct swrast_texture_image *texIma
                                       GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLbyte red, green;
-   signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data),
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
                     i, j, &red, 2);
-   signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data) + 8,
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data) + 8,
                     i, j, &green, 2);
    texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);
    texel[GCOMP] = BYTE_TO_FLOAT_TEX(green);
@@ -381,7 +381,7 @@ _mesa_fetch_texel_2d_f_l_latc1(const struct swrast_texture_image *texImage,
                                  GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLubyte red;
-   unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data),
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
                        i, j, &red, 1);
    texel[RCOMP] =
    texel[GCOMP] =
@@ -394,7 +394,7 @@ _mesa_fetch_texel_2d_f_signed_l_latc1(const struct swrast_texture_image *texImag
                                         GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLbyte red;
-   signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data),
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
                        i, j, &red, 1);
    texel[RCOMP] =
    texel[GCOMP] =
@@ -407,9 +407,9 @@ _mesa_fetch_texel_2d_f_la_latc2(const struct swrast_texture_image *texImage,
                                  GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLubyte red, green;
-   unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data),
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
                      i, j, &red, 2);
-   unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data) + 8,
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data + 8,
                      i, j, &green, 2);
    texel[RCOMP] =
    texel[GCOMP] =
@@ -422,9 +422,9 @@ _mesa_fetch_texel_2d_f_signed_la_latc2(const struct swrast_texture_image *texIma
                                        GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLbyte red, green;
-   signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data),
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
                      i, j, &red, 2);
-   signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data) + 8,
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data) + 8,
                      i, j, &green, 2);
    texel[RCOMP] =
    texel[GCOMP] =
index 904aa457ecc9df210ac2bed9723596303b22169a..ed7eae4f46d2e84cdd35be4e740c17a29a9af60e 100644 (file)
@@ -398,8 +398,8 @@ fetch_texel_2d_rgb_dxt1( const struct swrast_texture_image *texImage,
 {
    (void) k;
    if (fetch_ext_rgb_dxt1) {
-      fetch_ext_rgb_dxt1(texImage->Base.RowStride,
-                         (GLubyte *)(texImage)->Base.Data, i, j, texel);
+      fetch_ext_rgb_dxt1(texImage->RowStride,
+                         texImage->Data, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgb_dxt1");
@@ -426,8 +426,8 @@ fetch_texel_2d_rgba_dxt1( const struct swrast_texture_image *texImage,
 {
    (void) k;
    if (fetch_ext_rgba_dxt1) {
-      fetch_ext_rgba_dxt1(texImage->Base.RowStride,
-                          (GLubyte *)(texImage)->Base.Data, i, j, texel);
+      fetch_ext_rgba_dxt1(texImage->RowStride,
+                          texImage->Data, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt1\n");
@@ -454,9 +454,8 @@ fetch_texel_2d_rgba_dxt3( const struct swrast_texture_image *texImage,
 {
    (void) k;
    if (fetch_ext_rgba_dxt3) {
-      fetch_ext_rgba_dxt3(texImage->Base.RowStride,
-                          (GLubyte *)(texImage)->Base.Data,
-                          i, j, texel);
+      fetch_ext_rgba_dxt3(texImage->RowStride,
+                          texImage->Data, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt3\n");
@@ -483,9 +482,8 @@ fetch_texel_2d_rgba_dxt5( const struct swrast_texture_image *texImage,
 {
    (void) k;
    if (fetch_ext_rgba_dxt5) {
-      fetch_ext_rgba_dxt5(texImage->Base.RowStride,
-                          (GLubyte *)(texImage)->Base.Data,
-                          i, j, texel);
+      fetch_ext_rgba_dxt5(texImage->RowStride,
+                          texImage->Data, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt5\n");
index 2d06f84bf685c0ba34a780bf9a3d1aa62e6c0d08..69b958505365c1c053c03f795c20adbfc20c5514 100644 (file)
@@ -612,12 +612,14 @@ _mesa_free_texture_image_data(struct gl_context *ctx,
 {
    (void) ctx;
 
+#if 0
    if (texImage->Data) {
       /* free the old texture data */
       _mesa_free_texmemory(texImage->Data);
    }
 
    texImage->Data = NULL;
+#endif
 }
 
 
@@ -639,10 +641,12 @@ _mesa_delete_texture_image(struct gl_context *ctx,
    ASSERT(ctx->Driver.FreeTextureImageBuffer);
    ctx->Driver.FreeTextureImageBuffer( ctx, texImage );
 
+#if 0
    ASSERT(texImage->Data == NULL);
    if (texImage->ImageOffsets)
       free(texImage->ImageOffsets);
    free(texImage);
+#endif
 }
 
 
@@ -1084,18 +1088,19 @@ clear_teximage_fields(struct gl_texture_image *img)
    img->Width = 0;
    img->Height = 0;
    img->Depth = 0;
+#if 0
    img->RowStride = 0;
    if (img->ImageOffsets) {
       free(img->ImageOffsets);
       img->ImageOffsets = NULL;
    }
+#endif
    img->Width2 = 0;
    img->Height2 = 0;
    img->Depth2 = 0;
    img->WidthLog2 = 0;
    img->HeightLog2 = 0;
    img->DepthLog2 = 0;
-   img->Data = NULL;
    img->TexFormat = MESA_FORMAT_NONE;
 }
 
@@ -1123,8 +1128,6 @@ _mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
                            GLint border, GLenum internalFormat,
                            gl_format format)
 {
-   GLint i;
-
    ASSERT(img);
    ASSERT(width >= 0);
    ASSERT(height >= 0);
@@ -1161,6 +1164,7 @@ _mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
 
    img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2);
 
+#if 0
    /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
    img->RowStride = width;
    /* Allocate the ImageOffsets array and initialize to typical values.
@@ -1173,6 +1177,7 @@ _mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
    for (i = 0; i < depth; i++) {
       img->ImageOffsets[i] = i * width * height;
    }
+#endif
 
    img->TexFormat = format;
 }
@@ -2409,7 +2414,6 @@ teximage(struct gl_context *ctx, GLuint dims,
 
             ctx->Driver.FreeTextureImageBuffer(ctx, texImage);
 
-            ASSERT(texImage->Data == NULL);
             texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
                                                     internalFormat, format,
                                                     type);
@@ -2548,7 +2552,6 @@ _mesa_EGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image)
    } else {
       ctx->Driver.FreeTextureImageBuffer(ctx, texImage);
 
-      ASSERT(texImage->Data == NULL);
       ctx->Driver.EGLImageTargetTexture2D(ctx, target,
                                          texObj, texImage, image);
 
@@ -3370,7 +3373,6 @@ compressedteximage(struct gl_context *ctx, GLuint dims,
             gl_format texFormat;
 
             ctx->Driver.FreeTextureImageBuffer(ctx, texImage);
-            ASSERT(texImage->Data == NULL);
 
             texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
                                                     internalFormat, GL_NONE,
index cc9fbc0208f908c45b79c957606051db46eb45cd..cd9249630be24945177966626a8189bd7087c915 100644 (file)
@@ -4906,7 +4906,6 @@ _mesa_store_compressed_teximage2d(struct gl_context *ctx,
    ASSERT(texImage->Width > 0);
    ASSERT(texImage->Height > 0);
    ASSERT(texImage->Depth == 1);
-   ASSERT(texImage->Data == NULL); /* was freed in glCompressedTexImage2DARB */
 
    /* allocate storage for texture data */
    if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
index ec8451eb8f05d3d1e9462f4ba14cf04a2d892b65..55f7c31ce51a6c8f3007f6c382795293c37370c4 100644 (file)
@@ -138,20 +138,14 @@ struct swrast_texture_image
    /** used for mipmap LOD computation */
    GLfloat WidthScale, HeightScale, DepthScale;
 
-#if 0
-   GLubyte *Data;    /**< The actual texture data in malloc'd memory */
-
-   GLint TexelSize;  /**< bytes per texel block */
-#endif
+   /** These fields only valid when texture memory is mapped */
+   GLint RowStride;            /**< Padded width in units of texels */
+   GLuint *ImageOffsets;        /**< if 3D texture: array [Depth] of offsets to
+                                     each 2D slice in 'Data', in texels */
+   GLubyte *Data;              /**< Image data, accessed via FetchTexel() */
 
    FetchTexelFunc FetchTexel;
    StoreTexelFunc Store;
-
-#if 0
-   /** These fields only valid when texture memory is mapped */
-   GLubyte **SliceMaps;  /**< points to OneMap or a malloc'd array */
-   GLint RowStride;  /**< bytes per row of blocks */
-#endif
 };
 
 
index c63b2043c747ea8b42641231cb61dde1086017f7..8b7e930f905d323a3a7ae18aea64c396b01840e0 100644 (file)
@@ -43,7 +43,7 @@
 #if DIM == 1
 
 #define TEXEL_ADDR( type, image, i, j, k, size ) \
-       ((void) (j), (void) (k), ((type *)(image)->Base.Data + (i) * (size)))
+       ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
 
 #define FETCH(x) fetch_texel_1d_##x
 
 
 #define TEXEL_ADDR( type, image, i, j, k, size )                       \
        ((void) (k),                                                    \
-        ((type *)(image)->Base.Data + ((image)->Base.RowStride * (j) + (i)) * (size)))
+        ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
 
 #define FETCH(x) fetch_texel_2d_##x
 
 #elif DIM == 3
 
 #define TEXEL_ADDR( type, image, i, j, k, size )                       \
-       ((type *)(image)->Base.Data + ((image)->Base.ImageOffsets[k]            \
-             + (image)->Base.RowStride * (j) + (i)) * (size))
+       ((type *)(image)->Data + ((image)->ImageOffsets[k]              \
+             + (image)->RowStride * (j) + (i)) * (size))
 
 #define FETCH(x) fetch_texel_3d_##x
 
index f8b0fa1aa73a1ee94d39fdc21a1ac2db4742b1b1..9de5c0276e14eaa27bd0b613524d5237da0310ef 100644 (file)
@@ -1375,7 +1375,7 @@ opt_sample_rgb_2d(struct gl_context *ctx,
       GLint i = IFLOOR(texcoords[k][0] * width) & colMask;
       GLint j = IFLOOR(texcoords[k][1] * height) & rowMask;
       GLint pos = (j << shift) | i;
-      GLubyte *texel = ((GLubyte *) img->Data) + 3*pos;
+      GLubyte *texel = swImg->Data + 3 * pos;
       rgba[k][RCOMP] = UBYTE_TO_FLOAT(texel[2]);
       rgba[k][GCOMP] = UBYTE_TO_FLOAT(texel[1]);
       rgba[k][BCOMP] = UBYTE_TO_FLOAT(texel[0]);
@@ -1419,7 +1419,7 @@ opt_sample_rgba_2d(struct gl_context *ctx,
       const GLint col = IFLOOR(texcoords[i][0] * width) & colMask;
       const GLint row = IFLOOR(texcoords[i][1] * height) & rowMask;
       const GLint pos = (row << shift) | col;
-      const GLuint texel = *((GLuint *) img->Data + pos);
+      const GLuint texel = *((GLuint *) swImg->Data + pos);
       rgba[i][RCOMP] = UBYTE_TO_FLOAT( (texel >> 24)        );
       rgba[i][GCOMP] = UBYTE_TO_FLOAT( (texel >> 16) & 0xff );
       rgba[i][BCOMP] = UBYTE_TO_FLOAT( (texel >>  8) & 0xff );
@@ -1442,7 +1442,7 @@ sample_lambda_2d(struct gl_context *ctx,
 
    const GLboolean repeatNoBorderPOT = (tObj->Sampler.WrapS == GL_REPEAT)
       && (tObj->Sampler.WrapT == GL_REPEAT)
-      && (tImg->Border == 0 && (tImg->Width == tImg->RowStride))
+      && (tImg->Border == 0 && (tImg->Width == swImg->RowStride))
       && swImg->_IsPowerOfTwo;
 
    ASSERT(lambda != NULL);
index 47e458e1c5c70de25663a5b789fd82c2c7ed300b..caa17f983e3e210287cefce0ae0b1f42746caa5c 100644 (file)
@@ -610,7 +610,7 @@ update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
       trb->Base.DataType = CHAN_TYPE;
       trb->Base._BaseFormat = GL_RGBA;
    }
-   trb->Base.Data = trb->TexImage->Base.Data;
+   trb->Base.Data = trb->TexImage->Data;
 }
 
 
index 36b429cfab9535b7fe784722a68f9890deeee540..df371c30e3cf4f8ea882a4b87b9b052a6ea19081 100644 (file)
@@ -69,14 +69,32 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
 {
    struct swrast_texture_image *swImg = swrast_texture_image(texImage);
    GLuint bytes = _mesa_format_image_size(format, width, height, depth);
+   GLuint i;
 
    /* This _should_ be true (revisit if these ever fail) */
    assert(texImage->Width == width);
    assert(texImage->Height == height);
    assert(texImage->Depth == depth);
 
-   assert(!texImage->Data);
-   texImage->Data = _mesa_align_malloc(bytes, 512);
+   assert(!swImg->Data);
+   swImg->Data = _mesa_align_malloc(bytes, 512);
+   if (!swImg->Data)
+      return GL_FALSE;
+
+   /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
+   swImg->RowStride = width;
+
+   /* Allocate the ImageOffsets array and initialize to typical values.
+    * We allocate the array for 1D/2D textures too in order to avoid special-
+    * case code in the texstore routines.
+    */
+   swImg->ImageOffsets = (GLuint *) malloc(depth * sizeof(GLuint));
+   if (!swImg->ImageOffsets)
+      return GL_FALSE;
+
+   for (i = 0; i < depth; i++) {
+      swImg->ImageOffsets[i] = i * width * height;
+   }
 
    if ((width == 1 || _mesa_is_pow_two(texImage->Width2)) &&
        (height == 1 || _mesa_is_pow_two(texImage->Height2)) &&
@@ -98,7 +116,7 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
       swImg->DepthScale = (GLfloat) texImage->Depth;
    }
 
-   return texImage->Data != NULL;
+   return GL_TRUE;
 }
 
 
@@ -109,11 +127,16 @@ void
 _swrast_free_texture_image_buffer(struct gl_context *ctx,
                                   struct gl_texture_image *texImage)
 {
-   if (texImage->Data) {
-      _mesa_align_free(texImage->Data);
+   struct swrast_texture_image *swImage = swrast_texture_image(texImage);
+   if (swImage->Data) {
+      _mesa_align_free(swImage->Data);
+      swImage->Data = NULL;
    }
 
-   texImage->Data = NULL;
+   if (swImage->ImageOffsets) {
+      free(swImage->ImageOffsets);
+      swImage->ImageOffsets = NULL;
+   }
 }
 
 
@@ -155,6 +178,7 @@ _swrast_map_teximage(struct gl_context *ctx,
                      GLubyte **mapOut,
                      GLint *rowStrideOut)
 {
+   struct swrast_texture_image *swImage = swrast_texture_image(texImage);
    GLubyte *map;
    GLint stride, texelSize;
    GLuint bw, bh;
@@ -165,9 +189,9 @@ _swrast_map_teximage(struct gl_context *ctx,
    stride = _mesa_format_row_stride(texImage->TexFormat, texImage->Width);
    _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh);
 
-   assert(texImage->Data);
+   assert(swImage->Data);
 
-   map = texImage->Data;
+   map = swImage->Data;
 
    if (texImage->TexObject->Target == GL_TEXTURE_3D ||
        texImage->TexObject->Target == GL_TEXTURE_2D_ARRAY) {
index 839c4fd0855e03770b1c3c480d319d30a34e0d4e..b4f8e7479290f6519194916f44e9d2c2af922f37 100644 (file)
@@ -127,10 +127,12 @@ _swrast_culltriangle( struct gl_context *ctx,
       ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];               \
    const struct gl_texture_image *texImg =                             \
       obj->Image[0][obj->BaseLevel];                                   \
+   const struct swrast_texture_image *swImg =                          \
+      swrast_texture_image_const(texImg);                              \
    const GLfloat twidth = (GLfloat) texImg->Width;                     \
    const GLfloat theight = (GLfloat) texImg->Height;                   \
    const GLint twidth_log2 = texImg->WidthLog2;                                \
-   const GLubyte *texture = (const GLubyte *) texImg->Data;            \
+   const GLubyte *texture = (const GLubyte *) swImg->Data;             \
    const GLint smask = texImg->Width - 1;                              \
    const GLint tmask = texImg->Height - 1;                             \
    ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888);                    \
@@ -181,10 +183,12 @@ _swrast_culltriangle( struct gl_context *ctx,
       ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];               \
    const struct gl_texture_image *texImg =                             \
        obj->Image[0][obj->BaseLevel];                                  \
+   const struct swrast_texture_image *swImg =                          \
+      swrast_texture_image_const(texImg);                              \
    const GLfloat twidth = (GLfloat) texImg->Width;                     \
    const GLfloat theight = (GLfloat) texImg->Height;                   \
    const GLint twidth_log2 = texImg->WidthLog2;                                \
-   const GLubyte *texture = (const GLubyte *) texImg->Data;            \
+   const GLubyte *texture = (const GLubyte *) swImg->Data;             \
    const GLint smask = texImg->Width - 1;                              \
    const GLint tmask = texImg->Height - 1;                             \
    ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888);                    \
@@ -533,9 +537,11 @@ affine_span(struct gl_context *ctx, SWspan *span,
       ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];               \
    const struct gl_texture_image *texImg =                             \
       obj->Image[0][obj->BaseLevel];                                   \
+   const struct swrast_texture_image *swImg =                          \
+      swrast_texture_image_const(texImg);                              \
    const GLfloat twidth = (GLfloat) texImg->Width;                     \
    const GLfloat theight = (GLfloat) texImg->Height;                   \
-   info.texture = (const GLchan *) texImg->Data;                       \
+   info.texture = (const GLchan *) swImg->Data;                                \
    info.twidth_log2 = texImg->WidthLog2;                               \
    info.smask = texImg->Width - 1;                                     \
    info.tmask = texImg->Height - 1;                                    \
@@ -800,7 +806,9 @@ fast_persp_span(struct gl_context *ctx, SWspan *span,
       ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];               \
    const struct gl_texture_image *texImg =                             \
       obj->Image[0][obj->BaseLevel];                                   \
-   info.texture = (const GLchan *) texImg->Data;                       \
+   const struct swrast_texture_image *swImg =                          \
+      swrast_texture_image_const(texImg);                              \
+   info.texture = (const GLchan *) swImg->Data;                                \
    info.twidth_log2 = texImg->WidthLog2;                               \
    info.smask = texImg->Width - 1;                                     \
    info.tmask = texImg->Height - 1;                                    \
@@ -1062,7 +1070,7 @@ _swrast_choose_triangle( struct gl_context *ctx )
              && texObj2D->_Swizzle == SWIZZLE_NOOP
              && swImg->_IsPowerOfTwo
              && texImg->Border == 0
-             && texImg->Width == texImg->RowStride
+             && texImg->Width == swImg->RowStride
              && (format == MESA_FORMAT_RGB888 || format == MESA_FORMAT_RGBA8888)
              && minFilter == magFilter
              && ctx->Light.Model.ColorControl == GL_SINGLE_COLOR