mesa: pass gl_format to _mesa_init_teximage_fields()
authorBrian Paul <brianp@vmware.com>
Thu, 18 Nov 2010 23:15:33 +0000 (16:15 -0700)
committerBrian Paul <brianp@vmware.com>
Thu, 18 Nov 2010 23:15:38 +0000 (16:15 -0700)
This should prevent the field going unset in the future.  See bug
http://bugs.freedesktop.org/show_bug.cgi?id=31544 for background.

Also remove unneeded calls to clear_teximage_fields().

Finally, call _mesa_set_fetch_functions() from the
_mesa_init_teximage_fields() function so callers have one less
thing to worry about.

18 files changed:
src/mesa/drivers/common/meta.c
src/mesa/drivers/dri/intel/intel_tex_image.c
src/mesa/drivers/dri/nouveau/nouveau_texture.c
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_texstate.c
src/mesa/drivers/dri/swrast/swrast.c
src/mesa/main/mipmap.c
src/mesa/main/texfetch.c
src/mesa/main/teximage.c
src/mesa/main/teximage.h
src/mesa/main/texobj.c
src/mesa/state_tracker/st_cb_eglimage.c
src/mesa/state_tracker/st_cb_texture.c
src/mesa/state_tracker/st_gen_mipmap.c
src/mesa/state_tracker/st_manager.c

index 4533d8274326a083dc278814a6dbaa22322751b2..ba8be125718d27411550606752901cd3000a1a7e 100644 (file)
@@ -2593,7 +2593,6 @@ copy_tex_image(struct gl_context *ctx, GLuint dims, GLenum target, GLint level,
 {
    struct gl_texture_object *texObj;
    struct gl_texture_image *texImage;
-   GLsizei postConvWidth = width, postConvHeight = height;
    GLenum format, type;
    GLint bpp;
    void *buf;
@@ -2601,6 +2600,7 @@ copy_tex_image(struct gl_context *ctx, GLuint dims, GLenum target, GLint level,
    texObj = _mesa_get_current_tex_object(ctx, target);
    texImage = _mesa_get_tex_image(ctx, texObj, target, level);
 
+   /* Choose format/type for temporary image buffer */
    format = _mesa_base_tex_format(ctx, internalFormat);
    type = get_temp_image_type(ctx, format);
    bpp = _mesa_bytes_per_pixel(format, type);
@@ -2632,12 +2632,8 @@ copy_tex_image(struct gl_context *ctx, GLuint dims, GLenum target, GLint level,
       ctx->Driver.FreeTexImageData(ctx, texImage);
    }
 
-   _mesa_init_teximage_fields(ctx, target, texImage,
-                              postConvWidth, postConvHeight, 1,
-                              border, internalFormat);
-
-   _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-                               internalFormat, GL_NONE, GL_NONE);
+   /* The texture's format was already chosen in _mesa_CopyTexImage() */
+   ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
 
    /*
     * Store texture data (with pixel transfer ops)
@@ -2690,7 +2686,8 @@ _mesa_meta_CopyTexImage2D(struct gl_context *ctx, GLenum target, GLint level,
  * Have to be careful with locking and meta state for pixel transfer.
  */
 static void
-copy_tex_sub_image(struct gl_context *ctx, GLuint dims, GLenum target, GLint level,
+copy_tex_sub_image(struct gl_context *ctx,
+                   GLuint dims, GLenum target, GLint level,
                    GLint xoffset, GLint yoffset, GLint zoffset,
                    GLint x, GLint y,
                    GLsizei width, GLsizei height)
@@ -2704,6 +2701,7 @@ copy_tex_sub_image(struct gl_context *ctx, GLuint dims, GLenum target, GLint lev
    texObj = _mesa_get_current_tex_object(ctx, target);
    texImage = _mesa_select_tex_image(ctx, texObj, target, level);
 
+   /* Choose format/type for temporary image buffer */
    format = _mesa_get_format_base_format(texImage->TexFormat);
    type = get_temp_image_type(ctx, format);
    bpp = _mesa_bytes_per_pixel(format, type);
index 50fe9bd9f331717c0d176446d60d3f6b22d3a63e..41cdbfd2cbdf42e4b2eb408cefb5834f9c2e8d41 100644 (file)
@@ -682,6 +682,7 @@ intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
    struct gl_texture_object *texObj;
    struct gl_texture_image *texImage;
    int level = 0, internalFormat;
+   gl_format texFormat;
 
    texObj = _mesa_get_current_tex_object(ctx, target);
    intelObj = intel_texture_object(texObj);
@@ -700,10 +701,14 @@ intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
    if (rb->region == NULL)
       return;
 
-   if (texture_format == __DRI_TEXTURE_FORMAT_RGB)
+   if (texture_format == __DRI_TEXTURE_FORMAT_RGB) {
       internalFormat = GL_RGB;
-   else
+      texFormat = MESA_FORMAT_XRGB8888;
+   }
+   else {
       internalFormat = GL_RGBA;
+      texFormat = MESA_FORMAT_ARGB8888;
+   }
 
    mt = intel_miptree_create_for_region(intel, target,
                                        internalFormat,
@@ -724,16 +729,13 @@ intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
       intel_miptree_release(intel, &intelObj->mt);
 
    intelObj->mt = mt;
+
    _mesa_init_teximage_fields(&intel->ctx, target, texImage,
                              rb->region->width, rb->region->height, 1,
-                             0, internalFormat);
+                             0, internalFormat, texFormat);
 
    intelImage->face = target_to_face(target);
    intelImage->level = level;
-   if (texture_format == __DRI_TEXTURE_FORMAT_RGB)
-      texImage->TexFormat = MESA_FORMAT_XRGB8888;
-   else
-      texImage->TexFormat = MESA_FORMAT_ARGB8888;
    texImage->RowStride = rb->region->pitch;
    intel_miptree_reference(&intelImage->mt, intelObj->mt);
 
@@ -789,11 +791,10 @@ intel_image_target_texture_2d(struct gl_context *ctx, GLenum target,
    intelObj->mt = mt;
    _mesa_init_teximage_fields(&intel->ctx, target, texImage,
                              image->region->width, image->region->height, 1,
-                             0, image->internal_format);
+                             0, image->internal_format, image->format);
 
    intelImage->face = target_to_face(target);
    intelImage->level = 0;
-   texImage->TexFormat = image->format;
    texImage->RowStride = image->region->pitch;
    intel_miptree_reference(&intelImage->mt, intelObj->mt);
 
index 060c2c5bcc0a0ac88654a152e2cb06f5341cd1c2..2480b1ea5004666539b7e297f89108f3442c5419 100644 (file)
@@ -603,11 +603,12 @@ nouveau_set_texbuffer(__DRIcontext *dri_ctx,
        nouveau_update_renderbuffers(dri_ctx, draw);
        nouveau_surface_ref(&to_nouveau_renderbuffer(rb)->surface, s);
 
+        s->format = get_texbuffer_format(rb, format);
+
        /* Update the image fields. */
        _mesa_init_teximage_fields(ctx, target, ti, s->width, s->height,
-                                  1, 0, s->cpp);
+                                  1, 0, s->cpp, s->format);
        ti->RowStride = s->pitch / s->cpp;
-       ti->TexFormat = s->format = get_texbuffer_format(rb, format);
 
        /* Try to validate it. */
        if (!validate_teximage(ctx, t, 0, 0, 0, 0, s->width, s->height, 1))
index ee968d69f66c522b65181a657c2e068b6d110e20..24fb031ecb90b182815605c045cf4eaafed4610c 100644 (file)
@@ -778,6 +778,7 @@ void r200SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_format
        radeonTexObjPtr t;
        uint32_t pitch_val;
        uint32_t internalFormat, type, format;
+       gl_format texFormat;
 
        type = GL_BGRA;
        format = GL_UNSIGNED_BYTE;
@@ -817,10 +818,6 @@ void r200SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_format
        radeon_miptree_unreference(&t->mt);
        radeon_miptree_unreference(&rImage->mt);
 
-       _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
-                                  rb->base.Width, rb->base.Height, 1, 0, rb->cpp);
-       texImage->RowStride = rb->pitch / rb->cpp;
-
        rImage->bo = rb->bo;
        radeon_bo_ref(rImage->bo);
        t->bo = rb->bo;
@@ -833,27 +830,34 @@ void r200SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_format
        switch (rb->cpp) {
        case 4:
                if (texture_format == __DRI_TEXTURE_FORMAT_RGB) {
-                       texImage->TexFormat = MESA_FORMAT_RGB888;
+                       texFormat = MESA_FORMAT_RGB888;
                        t->pp_txformat = tx_table_le[MESA_FORMAT_RGB888].format;
                }
                else {
-                       texImage->TexFormat = MESA_FORMAT_ARGB8888;
+                       texFormat = MESA_FORMAT_ARGB8888;
                        t->pp_txformat = tx_table_le[MESA_FORMAT_ARGB8888].format;
                }
                t->pp_txfilter |= tx_table_le[MESA_FORMAT_ARGB8888].filter;
                break;
        case 3:
        default:
-               texImage->TexFormat = MESA_FORMAT_RGB888;
+               texFormat = MESA_FORMAT_RGB888;
                t->pp_txformat = tx_table_le[MESA_FORMAT_RGB888].format;
                t->pp_txfilter |= tx_table_le[MESA_FORMAT_RGB888].filter;
                break;
        case 2:
-               texImage->TexFormat = MESA_FORMAT_RGB565;
+               texFormat = MESA_FORMAT_RGB565;
                t->pp_txformat = tx_table_le[MESA_FORMAT_RGB565].format;
                t->pp_txfilter |= tx_table_le[MESA_FORMAT_RGB565].filter;
                break;
        }
+
+       _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;
+
+
         t->pp_txsize = ((rb->base.Width - 1) << RADEON_TEX_USIZE_SHIFT)
                   | ((rb->base.Height - 1) << RADEON_TEX_VSIZE_SHIFT);
         t->pp_txformat |= R200_TXFORMAT_NON_POWER2;
index a4fbd99308b61973c03321ad7b1363fbf468f328..ed9955b05d8dcb2502b892e86d8b9e24cb444658 100644 (file)
@@ -428,6 +428,7 @@ void r300SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_format
        radeonTexObjPtr t;
        uint32_t pitch_val;
        uint32_t internalFormat, type, format;
+       gl_format texFormat;
 
        type = GL_BGRA;
        format = GL_UNSIGNED_BYTE;
@@ -467,9 +468,6 @@ void r300SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_format
        radeon_miptree_unreference(&t->mt);
        radeon_miptree_unreference(&rImage->mt);
 
-       _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
-                                  rb->base.Width, rb->base.Height, 1, 0, rb->cpp);
-       texImage->RowStride = rb->pitch / rb->cpp;
        rImage->bo = rb->bo;
        radeon_bo_ref(rImage->bo);
        t->bo = rb->bo;
@@ -482,27 +480,34 @@ void r300SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_format
        switch (rb->cpp) {
        case 4:
                if (texture_format == __DRI_TEXTURE_FORMAT_RGB) {
-                       texImage->TexFormat = MESA_FORMAT_RGB888;
+                       texFormat = MESA_FORMAT_RGB888;
                        t->pp_txformat = R300_EASY_TX_FORMAT(X, Y, Z, ONE, W8Z8Y8X8);
                }
                else {
-                       texImage->TexFormat = MESA_FORMAT_ARGB8888;
+                       texFormat = MESA_FORMAT_ARGB8888;
                        t->pp_txformat = R300_EASY_TX_FORMAT(X, Y, Z, W, W8Z8Y8X8);
                }
                pitch_val /= 4;
                break;
        case 3:
        default:
-               texImage->TexFormat = MESA_FORMAT_RGB888;
+               texFormat = MESA_FORMAT_RGB888;
                t->pp_txformat = R300_EASY_TX_FORMAT(X, Y, Z, ONE, W8Z8Y8X8);
                pitch_val /= 4;
                break;
        case 2:
-               texImage->TexFormat = MESA_FORMAT_RGB565;
+               texFormat = MESA_FORMAT_RGB565;
                t->pp_txformat = R300_EASY_TX_FORMAT(X, Y, Z, ONE, Z5Y6X5);
                pitch_val /= 2;
                break;
        }
+
+       _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;
+
+
        pitch_val--;
        t->pp_txsize = (((R300_TX_WIDTHMASK_MASK & ((rb->base.Width - 1) << R300_TX_WIDTHMASK_SHIFT)))
                        | ((R300_TX_HEIGHTMASK_MASK & ((rb->base.Height - 1) << R300_TX_HEIGHTMASK_SHIFT))));
index d4c2cb96862c0909a357cdee4be37c9b90a6f1da..40a465b878e8471292c6c504789983e4814c52d7 100644 (file)
@@ -1152,6 +1152,7 @@ void evergreenSetTexBuffer(__DRIcontext *pDRICtx, GLint target, GLint glx_textur
        radeonTexObjPtr t;
        uint32_t pitch_val;
        uint32_t internalFormat, type, format;
+       gl_format texFormat;
 
        type = GL_BGRA;
        format = GL_UNSIGNED_BYTE;
@@ -1191,10 +1192,6 @@ void evergreenSetTexBuffer(__DRIcontext *pDRICtx, GLint target, GLint glx_textur
        radeon_miptree_unreference(&t->mt);
        radeon_miptree_unreference(&rImage->mt);
 
-       _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
-                                  rb->base.Width, rb->base.Height, 1, 0, rb->cpp);
-       texImage->RowStride = rb->pitch / rb->cpp;
-
        rImage->bo = rb->bo;
        radeon_bo_ref(rImage->bo);
        t->bo = rb->bo;
@@ -1205,7 +1202,7 @@ void evergreenSetTexBuffer(__DRIcontext *pDRICtx, GLint target, GLint glx_textur
        switch (rb->cpp) {
        case 4:
                if (glx_texture_format == __DRI_TEXTURE_FORMAT_RGB) {
-                       texImage->TexFormat = MESA_FORMAT_RGB888;
+                       texFormat = MESA_FORMAT_RGB888;
                        SETfield(t->SQ_TEX_RESOURCE7, FMT_8_8_8_8,
                                     EG_SQ_TEX_RESOURCE_WORD7_0__DATA_FORMAT_shift, 
                      EG_SQ_TEX_RESOURCE_WORD7_0__DATA_FORMAT_mask);
@@ -1219,7 +1216,7 @@ void evergreenSetTexBuffer(__DRIcontext *pDRICtx, GLint target, GLint glx_textur
                        SETfield(t->SQ_TEX_RESOURCE4, SQ_SEL_1,
                                 SQ_TEX_RESOURCE_WORD4_0__DST_SEL_W_shift, SQ_TEX_RESOURCE_WORD4_0__DST_SEL_W_mask);
                } else {
-                       texImage->TexFormat = MESA_FORMAT_ARGB8888;
+                       texFormat = MESA_FORMAT_ARGB8888;
                        SETfield(t->SQ_TEX_RESOURCE7, FMT_8_8_8_8,
                                     EG_SQ_TEX_RESOURCE_WORD7_0__DATA_FORMAT_shift, 
                      EG_SQ_TEX_RESOURCE_WORD7_0__DATA_FORMAT_mask);
@@ -1238,7 +1235,7 @@ void evergreenSetTexBuffer(__DRIcontext *pDRICtx, GLint target, GLint glx_textur
        case 3:
        default:
                // FMT_8_8_8 ???
-               texImage->TexFormat = MESA_FORMAT_RGB888;
+               texFormat = MESA_FORMAT_RGB888;
                SETfield(t->SQ_TEX_RESOURCE7, FMT_8_8_8_8,
                             EG_SQ_TEX_RESOURCE_WORD7_0__DATA_FORMAT_shift, 
                  EG_SQ_TEX_RESOURCE_WORD7_0__DATA_FORMAT_mask);
@@ -1254,7 +1251,7 @@ void evergreenSetTexBuffer(__DRIcontext *pDRICtx, GLint target, GLint glx_textur
                pitch_val /= 4;
                break;
        case 2:
-               texImage->TexFormat = MESA_FORMAT_RGB565;
+               texFormat = MESA_FORMAT_RGB565;
                SETfield(t->SQ_TEX_RESOURCE7, FMT_5_6_5,
                             EG_SQ_TEX_RESOURCE_WORD7_0__DATA_FORMAT_shift, 
                  EG_SQ_TEX_RESOURCE_WORD7_0__DATA_FORMAT_mask);
@@ -1271,6 +1268,11 @@ void evergreenSetTexBuffer(__DRIcontext *pDRICtx, GLint target, GLint glx_textur
                break;
        }
 
+       _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;
+
        pitch_val = (pitch_val + R700_TEXEL_PITCH_ALIGNMENT_MASK)
                & ~R700_TEXEL_PITCH_ALIGNMENT_MASK;
 
index 20fe32ae9ec7f275784437fd4391fc0875bbbe67..aafa6875774b124d90f85f355e8941a345b082df 100644 (file)
@@ -1001,6 +1001,7 @@ void r600SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint glx_texture_fo
        radeonTexObjPtr t;
        uint32_t pitch_val;
        uint32_t internalFormat, type, format;
+        gl_format texFormat;
 
        type = GL_BGRA;
        format = GL_UNSIGNED_BYTE;
@@ -1046,10 +1047,6 @@ void r600SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint glx_texture_fo
        radeon_miptree_unreference(&t->mt);
        radeon_miptree_unreference(&rImage->mt);
 
-       _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
-                                  rb->base.Width, rb->base.Height, 1, 0, rb->cpp);
-       texImage->RowStride = rb->pitch / rb->cpp;
-
        rImage->bo = rb->bo;
        radeon_bo_ref(rImage->bo);
        t->bo = rb->bo;
@@ -1060,7 +1057,7 @@ void r600SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint glx_texture_fo
        switch (rb->cpp) {
        case 4:
                if (glx_texture_format == __DRI_TEXTURE_FORMAT_RGB) {
-                       texImage->TexFormat = MESA_FORMAT_RGB888;
+                       texFormat = MESA_FORMAT_RGB888;
                        SETfield(t->SQ_TEX_RESOURCE1, FMT_8_8_8_8,
                                 SQ_TEX_RESOURCE_WORD1_0__DATA_FORMAT_shift, SQ_TEX_RESOURCE_WORD1_0__DATA_FORMAT_mask);
 
@@ -1073,7 +1070,7 @@ void r600SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint glx_texture_fo
                        SETfield(t->SQ_TEX_RESOURCE4, SQ_SEL_1,
                                 SQ_TEX_RESOURCE_WORD4_0__DST_SEL_W_shift, SQ_TEX_RESOURCE_WORD4_0__DST_SEL_W_mask);
                } else {
-                       texImage->TexFormat = MESA_FORMAT_ARGB8888;
+                       texFormat = MESA_FORMAT_ARGB8888;
                        SETfield(t->SQ_TEX_RESOURCE1, FMT_8_8_8_8,
                                 SQ_TEX_RESOURCE_WORD1_0__DATA_FORMAT_shift, SQ_TEX_RESOURCE_WORD1_0__DATA_FORMAT_mask);
 
@@ -1091,7 +1088,7 @@ void r600SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint glx_texture_fo
        case 3:
        default:
                // FMT_8_8_8 ???
-               texImage->TexFormat = MESA_FORMAT_RGB888;
+               texFormat = MESA_FORMAT_RGB888;
                SETfield(t->SQ_TEX_RESOURCE1, FMT_8_8_8_8,
                         SQ_TEX_RESOURCE_WORD1_0__DATA_FORMAT_shift, SQ_TEX_RESOURCE_WORD1_0__DATA_FORMAT_mask);
 
@@ -1106,7 +1103,7 @@ void r600SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint glx_texture_fo
                pitch_val /= 4;
                break;
        case 2:
-               texImage->TexFormat = MESA_FORMAT_RGB565;
+               texFormat = MESA_FORMAT_RGB565;
                SETfield(t->SQ_TEX_RESOURCE1, FMT_5_6_5,
                         SQ_TEX_RESOURCE_WORD1_0__DATA_FORMAT_shift, SQ_TEX_RESOURCE_WORD1_0__DATA_FORMAT_mask);
 
@@ -1122,6 +1119,11 @@ void r600SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint glx_texture_fo
                break;
        }
 
+       _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;
+
        pitch_val = (pitch_val + R700_TEXEL_PITCH_ALIGNMENT_MASK)
                & ~R700_TEXEL_PITCH_ALIGNMENT_MASK;
 
index 7409aeeeaa8cd5eba4b7391fe34540c7d63bdb92..32c021cb5459905f43d73a31f306b3c8ef9e7ac6 100644 (file)
@@ -653,6 +653,7 @@ void radeonSetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_form
        radeonTexObjPtr t;
        uint32_t pitch_val;
        uint32_t internalFormat, type, format;
+       gl_format texFormat;
 
        type = GL_BGRA;
        format = GL_UNSIGNED_BYTE;
@@ -692,10 +693,6 @@ void radeonSetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_form
        radeon_miptree_unreference(&t->mt);
        radeon_miptree_unreference(&rImage->mt);
 
-       _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
-                                  rb->base.Width, rb->base.Height, 1, 0, rb->cpp);
-       texImage->RowStride = rb->pitch / rb->cpp;
-
        rImage->bo = rb->bo;
        radeon_bo_ref(rImage->bo);
        t->bo = rb->bo;
@@ -707,27 +704,32 @@ void radeonSetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_form
        case 4:
                if (texture_format == __DRI_TEXTURE_FORMAT_RGB) {
                        t->pp_txformat = tx_table[MESA_FORMAT_RGB888].format;
-                       texImage->TexFormat = MESA_FORMAT_RGB888;
+                       texFormat = MESA_FORMAT_RGB888;
                }
                else {
                        t->pp_txformat = tx_table[MESA_FORMAT_ARGB8888].format;
-                       texImage->TexFormat = MESA_FORMAT_ARGB8888;
+                       texFormat = MESA_FORMAT_ARGB8888;
                }
                t->pp_txfilter |= tx_table[MESA_FORMAT_ARGB8888].filter;
                break;
        case 3:
        default:
-               texImage->TexFormat = MESA_FORMAT_RGB888;
+               texFormat = MESA_FORMAT_RGB888;
                t->pp_txformat = tx_table[MESA_FORMAT_RGB888].format;
                t->pp_txfilter |= tx_table[MESA_FORMAT_RGB888].filter;
                break;
        case 2:
-               texImage->TexFormat = MESA_FORMAT_RGB565;
+               texFormat = MESA_FORMAT_RGB565;
                t->pp_txformat = tx_table[MESA_FORMAT_RGB565].format;
                t->pp_txfilter |= tx_table[MESA_FORMAT_RGB565].filter;
                break;
        }
 
+       _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;
+
        t->pp_txpitch &= (1 << 13) -1;
        pitch_val = rb->pitch;
 
index 52ba3acf658359639e6e9989cde82f57866ae2fa..c7aaafcee8c28cbb4f3305a07242a38fa96ed048 100644 (file)
@@ -69,6 +69,7 @@ static void swrastSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
     struct gl_texture_object *texObj;
     struct gl_texture_image *texImage;
     uint32_t internalFormat;
+    gl_format texFormat;
 
     dri_ctx = pDRICtx->driverPrivate;
 
@@ -82,15 +83,13 @@ static void swrastSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
 
     sPriv->swrast_loader->getDrawableInfo(dPriv, &x, &y, &w, &h, dPriv->loaderPrivate);
 
-    _mesa_init_teximage_fields(&dri_ctx->Base, target, texImage,
-                              w, h, 1, 0, internalFormat);
-
     if (texture_format == __DRI_TEXTURE_FORMAT_RGB)
-       texImage->TexFormat = MESA_FORMAT_XRGB8888;
+       texFormat = MESA_FORMAT_XRGB8888;
     else
-       texImage->TexFormat = MESA_FORMAT_ARGB8888;
+       texFormat = MESA_FORMAT_ARGB8888;
 
-    _mesa_set_fetch_functions(texImage, 2);
+    _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,
                                   dPriv->loaderPrivate);
index b1989b4b91e274b5048adf3bcdc3de149b6e6edf..ad63b178df8c688d78947c93a342704e31380588 100644 (file)
@@ -1790,9 +1790,9 @@ _mesa_generate_mipmap(struct gl_context *ctx, GLenum target,
 
       /* initialize new image */
       _mesa_init_teximage_fields(ctx, target, dstImage, dstWidth, dstHeight,
-                                 dstDepth, border, srcImage->InternalFormat);
+                                 dstDepth, border, srcImage->InternalFormat,
+                                 srcImage->TexFormat);
       dstImage->DriverData = NULL;
-      dstImage->TexFormat = srcImage->TexFormat;
       dstImage->FetchTexelc = srcImage->FetchTexelc;
       dstImage->FetchTexelf = srcImage->FetchTexelf;
 
index aa3a6961b6442be0931005187bf39863757f4c60..372ef2654a78462b2c11c3c0e6c57f7763c5603b 100644 (file)
@@ -823,17 +823,11 @@ void
 _mesa_set_fetch_functions(struct gl_texture_image *texImage, GLuint dims)
 {
    ASSERT(dims == 1 || dims == 2 || dims == 3);
-   ASSERT(texImage->TexFormat);
 
-   if (!texImage->FetchTexelf) {
-      texImage->FetchTexelf =
-         _mesa_get_texel_fetch_func(texImage->TexFormat, dims);
-   }
+   texImage->FetchTexelf =
+      _mesa_get_texel_fetch_func(texImage->TexFormat, dims);
 
-   /* now check if we need to use a float/chan adaptor */
-   if (!texImage->FetchTexelc) {
-      texImage->FetchTexelc = fetch_texel_float_to_chan;
-   }
+   texImage->FetchTexelc = fetch_texel_float_to_chan;
 
    ASSERT(texImage->FetchTexelc);
    ASSERT(texImage->FetchTexelf);
index e196e700f762569d61f3966b6b04dcdb173a6395..b3ce5d95b773dac068ffaa4a256c4afcdc02b1ae 100644 (file)
@@ -887,6 +887,45 @@ _mesa_max_texture_levels(struct gl_context *ctx, GLenum target)
 }
 
 
+/**
+ * Return number of dimenions per image for the given texture target.
+ */
+static GLint
+get_texture_dimensions(GLenum target)
+{
+   switch (target) {
+   case GL_TEXTURE_1D:
+   case GL_TEXTURE_1D_ARRAY:
+   case GL_PROXY_TEXTURE_1D:
+   case GL_PROXY_TEXTURE_1D_ARRAY:
+      return 1;
+   case GL_TEXTURE_2D:
+   case GL_TEXTURE_2D_ARRAY:
+   case GL_TEXTURE_RECTANGLE:
+   case GL_TEXTURE_CUBE_MAP:
+   case GL_PROXY_TEXTURE_2D:
+   case GL_PROXY_TEXTURE_2D_ARRAY:
+   case GL_PROXY_TEXTURE_RECTANGLE:
+   case GL_PROXY_TEXTURE_CUBE_MAP:
+   case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+      return 2;
+   case GL_TEXTURE_3D:
+   case GL_PROXY_TEXTURE_3D:
+      return 3;
+   default:
+      _mesa_problem(NULL, "invalid target 0x%x in get_texture_dimensions()",
+                    target);
+      return 2;
+   }
+}
+
+
+
 
 #if 000 /* not used anymore */
 /*
@@ -992,6 +1031,7 @@ clear_teximage_fields(struct gl_texture_image *img)
  * \param depth image depth.
  * \param border image border.
  * \param internalFormat internal format.
+ * \param format  the actual hardware format (one of MESA_FORMAT_*)
  *
  * Fills in the fields of \p img with the given information.
  * Note: width, height and depth include the border.
@@ -1000,9 +1040,10 @@ void
 _mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
                            struct gl_texture_image *img,
                            GLsizei width, GLsizei height, GLsizei depth,
-                           GLint border, GLenum internalFormat)
+                           GLint border, GLenum internalFormat,
+                           gl_format format)
 {
-   GLint i;
+   GLint i, dims;
 
    ASSERT(img);
    ASSERT(width >= 0);
@@ -1073,8 +1114,11 @@ _mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
       img->DepthScale = (GLfloat) img->Depth;
    }
 
-   img->FetchTexelc = NULL;
-   img->FetchTexelf = NULL;
+   img->TexFormat = format;
+
+   dims = get_texture_dimensions(target);
+
+   _mesa_set_fetch_functions(img, dims);
 }
 
 
@@ -2262,13 +2306,14 @@ override_internal_format(GLenum internalFormat, GLint width, GLint height)
  * for efficient texture memory layout/allocation.  In particular, this
  * comes up during automatic mipmap generation.
  */
-void
+gl_format
 _mesa_choose_texture_format(struct gl_context *ctx,
                             struct gl_texture_object *texObj,
-                            struct gl_texture_image *texImage,
                             GLenum target, GLint level,
                             GLenum internalFormat, GLenum format, GLenum type)
 {
+   gl_format f;
+
    /* see if we've already chosen a format for the previous level */
    if (level > 0) {
       struct gl_texture_image *prevImage =
@@ -2280,16 +2325,15 @@ _mesa_choose_texture_format(struct gl_context *ctx,
           prevImage->Width > 0 &&
           prevImage->InternalFormat == internalFormat) {
          /* use the same format */
-         texImage->TexFormat = prevImage->TexFormat;
-         ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
-         return;
+         ASSERT(prevImage->TexFormat != MESA_FORMAT_NONE);
+         return prevImage->TexFormat;
       }
    }
 
    /* choose format from scratch */
-   texImage->TexFormat = ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
-                                                         format, type);
-   ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
+   f = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type);
+   ASSERT(f != MESA_FORMAT_NONE);
+   return f;
 }
 
 
@@ -2336,19 +2380,22 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
         }
          else {
+            gl_format texFormat;
+
             if (texImage->Data) {
                ctx->Driver.FreeTexImageData( ctx, texImage );
             }
 
             ASSERT(texImage->Data == NULL);
 
-            clear_teximage_fields(texImage); /* not really needed, but helpful */
+            texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+                                                    internalFormat, format,
+                                                    type);
+
             _mesa_init_teximage_fields(ctx, target, texImage,
                                        width, 1, 1,
-                                       border, internalFormat);
-
-            _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-                                        internalFormat, format, type);
+                                       border, internalFormat,
+                                       texFormat);
 
             /* Give the texture to the driver.  <pixels> may be null. */
             ASSERT(ctx->Driver.TexImage1D);
@@ -2356,8 +2403,6 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
                                    width, border, format, type, pixels,
                                    &ctx->Unpack, texObj, texImage);
 
-            _mesa_set_fetch_functions(texImage, 1);
-
             check_gen_mipmap(ctx, target, texObj, level);
 
             update_fbo_texture(ctx, texObj, face, level);
@@ -2383,12 +2428,12 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
          /* no error, set the tex image parameters */
          struct gl_texture_object *texObj =
             _mesa_get_current_tex_object(ctx, target);
-         ASSERT(texImage);
-         _mesa_init_teximage_fields(ctx, target, texImage,
-                                    width, 1, 1,
-                                    border, internalFormat);
-         _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-                                     internalFormat, format, type);
+         gl_format texFormat = _mesa_choose_texture_format(ctx, texObj, target,
+                                                           level,
+                                                           internalFormat,
+                                                           format, type);
+         _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1,
+                                    border, internalFormat, texFormat);
       }
    }
    else {
@@ -2445,18 +2490,20 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
         }
          else {
+            gl_format texFormat;
+
             if (texImage->Data) {
                ctx->Driver.FreeTexImageData( ctx, texImage );
             }
 
             ASSERT(texImage->Data == NULL);
-            clear_teximage_fields(texImage); /* not really needed, but helpful */
-            _mesa_init_teximage_fields(ctx, target, texImage,
-                                       width, height, 1,
-                                       border, internalFormat);
 
-            _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-                                        internalFormat, format, type);
+            texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+                                                    internalFormat, format,
+                                                    type);
+
+            _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1,
+                                       border, internalFormat, texFormat);
 
             /* Give the texture to the driver.  <pixels> may be null. */
             ASSERT(ctx->Driver.TexImage2D);
@@ -2464,8 +2511,6 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
                                    width, height, border, format, type,
                                    pixels, &ctx->Unpack, texObj, texImage);
 
-            _mesa_set_fetch_functions(texImage, 2);
-
             check_gen_mipmap(ctx, target, texObj, level);
 
             update_fbo_texture(ctx, texObj, face, level);
@@ -2497,11 +2542,12 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
          /* no error, set the tex image parameters */
          struct gl_texture_object *texObj =
             _mesa_get_current_tex_object(ctx, target);
-         _mesa_init_teximage_fields(ctx, target, texImage,
-                                    width, height, 1,
-                                    border, internalFormat);
-         _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-                                     internalFormat, format, type);
+         gl_format texFormat = _mesa_choose_texture_format(ctx, texObj,
+                                                           target, level,
+                                                           internalFormat,
+                                                           format, type);
+         _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1,
+                                    border, internalFormat, texFormat);
       }
    }
    else {
@@ -2557,18 +2603,19 @@ _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
         }
          else {
+            gl_format texFormat;
+
             if (texImage->Data) {
                ctx->Driver.FreeTexImageData( ctx, texImage );
             }
 
             ASSERT(texImage->Data == NULL);
-            clear_teximage_fields(texImage); /* not really needed, but helpful */
+            texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+                                                    internalFormat, format,
+                                                    type);
             _mesa_init_teximage_fields(ctx, target, texImage,
                                        width, height, depth,
-                                       border, internalFormat);
-
-            _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-                                        internalFormat, format, type);
+                                       border, internalFormat, texFormat);
 
             /* Give the texture to the driver.  <pixels> may be null. */
             ASSERT(ctx->Driver.TexImage3D);
@@ -2576,8 +2623,6 @@ _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
                                    width, height, depth, border, format, type,
                                    pixels, &ctx->Unpack, texObj, texImage);
 
-            _mesa_set_fetch_functions(texImage, 3);
-
             check_gen_mipmap(ctx, target, texObj, level);
 
             update_fbo_texture(ctx, texObj, face, level);
@@ -2605,10 +2650,12 @@ _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
          /* no error, set the tex image parameters */
          struct gl_texture_object *texObj =
             _mesa_get_current_tex_object(ctx, target);
+         gl_format texFormat = _mesa_choose_texture_format(ctx, texObj,
+                                                           target, level,
+                                                           internalFormat,
+                                                           format, type);
          _mesa_init_teximage_fields(ctx, target, texImage, width, height,
-                                    depth, border, internalFormat);
-         _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-                                     internalFormat, format, type);
+                                    depth, border, internalFormat, texFormat);
       }
    }
    else {
@@ -2885,25 +2932,25 @@ _mesa_CopyTexImage1D( GLenum target, GLint level,
         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D");
       }
       else {
+         gl_format texFormat;
+
          if (texImage->Data) {
             ctx->Driver.FreeTexImageData( ctx, texImage );
          }
 
          ASSERT(texImage->Data == NULL);
 
-         clear_teximage_fields(texImage); /* not really needed, but helpful */
-         _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1,
-                                    border, internalFormat);
+         texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+                                                 internalFormat, GL_NONE,
+                                                 GL_NONE);
 
-         _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-                                     internalFormat, GL_NONE, GL_NONE);
+         _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1,
+                                    border, internalFormat, texFormat);
 
          ASSERT(ctx->Driver.CopyTexImage1D);
          ctx->Driver.CopyTexImage1D(ctx, target, level, internalFormat,
                                     x, y, width, border);
 
-         _mesa_set_fetch_functions(texImage, 1);
-
          check_gen_mipmap(ctx, target, texObj, level);
 
          update_fbo_texture(ctx, texObj, face, level);
@@ -2952,26 +2999,25 @@ _mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat,
         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D");
       }
       else {
+         gl_format texFormat;
+
          if (texImage->Data) {
             ctx->Driver.FreeTexImageData( ctx, texImage );
          }
 
          ASSERT(texImage->Data == NULL);
 
-         clear_teximage_fields(texImage); /* not really needed, but helpful */
-         _mesa_init_teximage_fields(ctx, target, texImage,
-                                    width, height, 1,
-                                    border, internalFormat);
+         texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+                                                 internalFormat, GL_NONE,
+                                                 GL_NONE);
 
-         _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-                                     internalFormat, GL_NONE, GL_NONE);
+         _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1,
+                                    border, internalFormat, texFormat);
 
          ASSERT(ctx->Driver.CopyTexImage2D);
          ctx->Driver.CopyTexImage2D(ctx, target, level, internalFormat,
                                     x, y, width, height, border);
 
-         _mesa_set_fetch_functions(texImage, 2);
-
          check_gen_mipmap(ctx, target, texObj, level);
 
          update_fbo_texture(ctx, texObj, face, level);
@@ -3453,16 +3499,19 @@ _mesa_CompressedTexImage1DARB(GLenum target, GLint level,
            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1D");
         }
          else {
+            gl_format texFormat;
+
             if (texImage->Data) {
                ctx->Driver.FreeTexImageData( ctx, texImage );
             }
             ASSERT(texImage->Data == NULL);
 
-            _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1,
-                                       border, internalFormat);
+            texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+                                                    internalFormat, GL_NONE,
+                                                    GL_NONE);
 
-            _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-                                        internalFormat, GL_NONE, GL_NONE);
+            _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1,
+                                       border, internalFormat, texFormat);
 
             ASSERT(ctx->Driver.CompressedTexImage1D);
             ctx->Driver.CompressedTexImage1D(ctx, target, level,
@@ -3470,8 +3519,6 @@ _mesa_CompressedTexImage1DARB(GLenum target, GLint level,
                                              imageSize, data,
                                              texObj, texImage);
 
-            _mesa_set_fetch_functions(texImage, 1);
-
             check_gen_mipmap(ctx, target, texObj, level);
 
             /* state update */
@@ -3502,16 +3549,18 @@ _mesa_CompressedTexImage1DARB(GLenum target, GLint level,
          /* store the teximage parameters */
          struct gl_texture_object *texObj;
          struct gl_texture_image *texImage;
+         gl_format texFormat;
 
          texObj = _mesa_get_current_tex_object(ctx, target);
 
         _mesa_lock_texture(ctx, texObj);
         {
            texImage = _mesa_select_tex_image(ctx, texObj, target, level);
+            texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+                                                    internalFormat, GL_NONE,
+                                                    GL_NONE);
            _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1,
-                                      border, internalFormat);
-            _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-                                        internalFormat, GL_NONE, GL_NONE);
+                                      border, internalFormat, texFormat);
         }
         _mesa_unlock_texture(ctx, texObj);
       }
@@ -3579,16 +3628,19 @@ _mesa_CompressedTexImage2DARB(GLenum target, GLint level,
            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
         }
          else {
+            gl_format texFormat;
+
             if (texImage->Data) {
                ctx->Driver.FreeTexImageData( ctx, texImage );
             }
             ASSERT(texImage->Data == NULL);
 
-            _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1,
-                                       border, internalFormat);
+            texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+                                                    internalFormat, GL_NONE,
+                                                    GL_NONE);
 
-            _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-                                        internalFormat, GL_NONE, GL_NONE);
+            _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1,
+                                       border, internalFormat, texFormat);
 
             ASSERT(ctx->Driver.CompressedTexImage2D);
             ctx->Driver.CompressedTexImage2D(ctx, target, level,
@@ -3596,8 +3648,6 @@ _mesa_CompressedTexImage2DARB(GLenum target, GLint level,
                                              border, imageSize, data,
                                              texObj, texImage);
 
-            _mesa_set_fetch_functions(texImage, 2);
-
             check_gen_mipmap(ctx, target, texObj, level);
 
             /* state update */
@@ -3630,16 +3680,18 @@ _mesa_CompressedTexImage2DARB(GLenum target, GLint level,
          /* store the teximage parameters */
          struct gl_texture_object *texObj;
          struct gl_texture_image *texImage;
+         gl_format texFormat;
 
          texObj = _mesa_get_current_tex_object(ctx, target);
 
         _mesa_lock_texture(ctx, texObj);
         {
            texImage = _mesa_select_tex_image(ctx, texObj, target, level);
+            texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+                                                    internalFormat, GL_NONE,
+                                                    GL_NONE);
            _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1,
-                                      border, internalFormat);
-            _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-                                        internalFormat, GL_NONE, GL_NONE);
+                                      border, internalFormat, texFormat);
         }
         _mesa_unlock_texture(ctx, texObj);
       }
@@ -3686,18 +3738,20 @@ _mesa_CompressedTexImage3DARB(GLenum target, GLint level,
            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3D");
         }
          else {
+            gl_format texFormat;
+
             if (texImage->Data) {
                ctx->Driver.FreeTexImageData( ctx, texImage );
             }
             ASSERT(texImage->Data == NULL);
 
+            texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+                                                    internalFormat, GL_NONE,
+                                                    GL_NONE);
+
             _mesa_init_teximage_fields(ctx, target, texImage,
                                        width, height, depth,
-                                       border, internalFormat);
-
-            /* Choose actual texture format */
-            _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-                                        internalFormat, GL_NONE, GL_NONE);
+                                       border, internalFormat, texFormat);
 
             ASSERT(ctx->Driver.CompressedTexImage3D);
             ctx->Driver.CompressedTexImage3D(ctx, target, level,
@@ -3706,8 +3760,6 @@ _mesa_CompressedTexImage3DARB(GLenum target, GLint level,
                                              border, imageSize, data,
                                              texObj, texImage);
 
-            _mesa_set_fetch_functions(texImage, 3);
-
             check_gen_mipmap(ctx, target, texObj, level);
 
             /* state update */
@@ -3738,16 +3790,19 @@ _mesa_CompressedTexImage3DARB(GLenum target, GLint level,
          /* store the teximage parameters */
          struct gl_texture_object *texObj;
          struct gl_texture_image *texImage;
+         gl_format texFormat;
 
          texObj = _mesa_get_current_tex_object(ctx, target);
 
         _mesa_lock_texture(ctx, texObj);
         {
            texImage = _mesa_select_tex_image(ctx, texObj, target, level);
+            texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+                                                    internalFormat, GL_NONE,
+                                                    GL_NONE);
            _mesa_init_teximage_fields(ctx, target, texImage, width, height,
-                                      depth, border, internalFormat);
-            _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-                                        internalFormat, GL_NONE, GL_NONE);
+                                      depth, border, internalFormat,
+                                       texFormat);
         }
         _mesa_unlock_texture(ctx, texObj);
       }
index d4317c301b78b3a2a77624b61b7cd8b3b3ce2021..5bb9d492e932f8680a934e82b5742d5fa10ddf93 100644 (file)
@@ -33,6 +33,7 @@
 
 
 #include "mtypes.h"
+#include "formats.h"
 
 
 extern void *
@@ -69,13 +70,13 @@ extern void
 _mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
                            struct gl_texture_image *img,
                            GLsizei width, GLsizei height, GLsizei depth,
-                           GLint border, GLenum internalFormat);
+                           GLint border, GLenum internalFormat,
+                           gl_format format);
 
 
-extern void
+extern gl_format
 _mesa_choose_texture_format(struct gl_context *ctx,
                             struct gl_texture_object *texObj,
-                            struct gl_texture_image *texImage,
                             GLenum target, GLint level,
                             GLenum internalFormat, GLenum format, GLenum type);
 
index 495903df556843b4eee990e166262aff0b407919..72dbf10cc4b40e3cd8b85cbaa24070548e99f784 100644 (file)
@@ -719,6 +719,7 @@ _mesa_get_fallback_texture(struct gl_context *ctx)
       static GLubyte texels[8 * 8][4];
       struct gl_texture_object *texObj;
       struct gl_texture_image *texImage;
+      gl_format texFormat;
       GLuint i;
 
       for (i = 0; i < 8 * 8; i++) {
@@ -737,12 +738,13 @@ _mesa_get_fallback_texture(struct gl_context *ctx)
       /* create level[0] texture image */
       texImage = _mesa_get_tex_image(ctx, texObj, GL_TEXTURE_2D, 0);
 
+      texFormat = ctx->Driver.ChooseTextureFormat(ctx, GL_RGBA, GL_RGBA,
+                                                  GL_UNSIGNED_BYTE);
+
       /* init the image fields */
       _mesa_init_teximage_fields(ctx, GL_TEXTURE_2D, texImage,
-                                    8, 8, 1, 0, GL_RGBA); 
+                                 8, 8, 1, 0, GL_RGBA, texFormat); 
 
-      texImage->TexFormat =
-         ctx->Driver.ChooseTextureFormat(ctx, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
       ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
 
       /* set image data */
index b39a624a612c4f20be026ee8909dbd86645700f1..c4b84de790c3867a9b8f8f84e9223ce027b83b4e 100644 (file)
@@ -106,6 +106,7 @@ st_bind_surface(struct gl_context *ctx, GLenum target,
    struct st_texture_object *stObj;
    struct st_texture_image *stImage;
    GLenum internalFormat;
+   gl_format texFormat;
 
    /* map pipe format to base format */
    if (util_format_get_component_bits(ps->format, UTIL_FORMAT_COLORSPACE_RGB, 3) > 0)
@@ -122,10 +123,11 @@ st_bind_surface(struct gl_context *ctx, GLenum target,
       stObj->surface_based = GL_TRUE;
    }
 
+   texFormat = st_pipe_format_to_mesa_format(ps->format);
+
    _mesa_init_teximage_fields(ctx, target, texImage,
-                              ps->width, ps->height, 1, 0, internalFormat);
-   texImage->TexFormat = st_pipe_format_to_mesa_format(ps->format);
-   _mesa_set_fetch_functions(texImage, 2);
+                              ps->width, ps->height, 1, 0, internalFormat,
+                              texFormat);
 
    /* FIXME create a non-default sampler view from the pipe_surface? */
    pipe_resource_reference(&stObj->pt, ps->texture);
index 4c2f7d789600189408e5d738003d23c097b458c8..15e69e1fa076e4bf776931254986adb5af8a850a 100644 (file)
@@ -549,14 +549,18 @@ st_TexImage(struct gl_context * ctx,
 
    /* switch to "normal" */
    if (stObj->surface_based) {
+      gl_format texFormat;
+
       _mesa_clear_texture_object(ctx, texObj);
       pipe_resource_reference(&stObj->pt, NULL);
 
       /* oops, need to init this image again */
+      texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+                                              internalFormat, format, type);
+
       _mesa_init_teximage_fields(ctx, target, texImage,
-            width, height, depth, border, internalFormat);
-      _mesa_choose_texture_format(ctx, texObj, texImage, target, level,
-            internalFormat, format, type);
+                                 width, height, depth, border,
+                                 internalFormat, texFormat);
 
       stObj->surface_based = GL_FALSE;
    }
@@ -1950,7 +1954,7 @@ st_get_default_texture(struct st_context *st)
 
       _mesa_init_teximage_fields(st->ctx, target, texImg,
                                  16, 16, 1, 0,  /* w, h, d, border */
-                                 GL_RGBA);
+                                 GL_RGBA, MESA_FORMAT_RGBA8888);
 
       st_TexImage(st->ctx, 2, target,
                   0, GL_RGBA,    /* level, intformat */
index fe31418ddd13876b7754ff9d08fdb82c5e3e0b29..a4011b22b9b8e2275ea6e8cd7705695a9fb2c7e3 100644 (file)
@@ -400,9 +400,8 @@ st_generate_mipmap(struct gl_context *ctx, GLenum target,
 
       /* initialize new image */
       _mesa_init_teximage_fields(ctx, target, dstImage, dstWidth, dstHeight,
-                                 dstDepth, border, srcImage->InternalFormat);
-
-      dstImage->TexFormat = srcImage->TexFormat;
+                                 dstDepth, border, srcImage->InternalFormat,
+                                 srcImage->TexFormat);
 
       stImage = st_texture_image(dstImage);
       stImage->level = dstLevel;
index 15e7b8921c397200cb360493ea31660f3c750f3f..98e95e239e517c5c8bc4fe5fb87ba55272df91d1 100644 (file)
@@ -556,6 +556,8 @@ st_context_teximage(struct st_context_iface *stctxi, enum st_texture_type target
    texImage = _mesa_get_tex_image(ctx, texObj, target, level);
    stImage = st_texture_image(texImage);
    if (tex) {
+      gl_format texFormat;
+
       /*
        * XXX When internal_format and tex->format differ, st_finalize_texture
        * needs to allocate a new texture with internal_format and copy the
@@ -573,11 +575,13 @@ st_context_teximage(struct st_context_iface *stctxi, enum st_texture_type target
          internalFormat = GL_RGBA;
       else
          internalFormat = GL_RGB;
+
+      texFormat = st_ChooseTextureFormat(ctx, internalFormat,
+                                         GL_RGBA, GL_UNSIGNED_BYTE);
+
       _mesa_init_teximage_fields(ctx, target, texImage,
-            tex->width0, tex->height0, 1, 0, internalFormat);
-      texImage->TexFormat = st_ChooseTextureFormat(ctx, internalFormat,
-            GL_RGBA, GL_UNSIGNED_BYTE);
-      _mesa_set_fetch_functions(texImage, 2);
+                                 tex->width0, tex->height0, 1, 0,
+                                 internalFormat, texFormat);
 
       width = tex->width0;
       height = tex->height0;