radeon-common: Fix crash in glGetTexImage
authorNicolai Haehnle <nhaehnle@gmail.com>
Sat, 14 Feb 2009 20:43:30 +0000 (21:43 +0100)
committerNicolai Haehnle <nhaehnle@gmail.com>
Sat, 14 Feb 2009 20:46:44 +0000 (21:46 +0100)
Since texture images are now stored in miptrees, we cannot usually
access them directly via the Data pointer.

So we wrap Mesa's implementation by map/unmap calls.

This crash was triggered by Sauerbraten, Piglit now contains a
regression test.

Signed-off-by: Nicolai Haehnle <nhaehnle@gmail.com>
src/mesa/drivers/dri/r200/r200_tex.c
src/mesa/drivers/dri/r300/r300_tex.c
src/mesa/drivers/dri/radeon/radeon_tex.c
src/mesa/drivers/dri/radeon/radeon_texture.c
src/mesa/drivers/dri/radeon/radeon_texture.h

index c0d1723c77c718ab42735a0bf198d9efeceaaf82..5daacb8c95a95b5dc04bbd5034d4329b697ddf7b 100644 (file)
@@ -512,6 +512,8 @@ void r200InitTextureFuncs( struct dd_function_table *functions )
 #else
    functions->TexSubImage3D            = _mesa_store_texsubimage3d;
 #endif
+   functions->GetTexImage               = radeonGetTexImage;
+   functions->GetCompressedTexImage     = radeonGetCompressedTexImage;
    functions->NewTextureObject         = r200NewTextureObject;
    //   functions->BindTexture         = r200BindTexture;
    functions->DeleteTexture            = r200DeleteTexture;
index e316e2d822bce896ff0038b009d0ac6ad4be5001..27b907019e367c1c0611d2e83c0772fd5d6ff1df 100644 (file)
@@ -325,6 +325,8 @@ void r300InitTextureFuncs(struct dd_function_table *functions)
        functions->TexSubImage1D = radeonTexSubImage1D;
        functions->TexSubImage2D = radeonTexSubImage2D;
        functions->TexSubImage3D = radeonTexSubImage3D;
+       functions->GetTexImage = radeonGetTexImage;
+       functions->GetCompressedTexImage = radeonGetCompressedTexImage;
        functions->NewTextureObject = r300NewTextureObject;
        functions->DeleteTexture = r300DeleteTexture;
        functions->IsTextureResident = driIsTextureResident;
index e1b988bf4dca5d4eb076dccb181a776f21244417..4d98b72612b1a3f8c0a3d94a09d2d49263d7bc13 100644 (file)
@@ -456,6 +456,8 @@ void radeonInitTextureFuncs( struct dd_function_table *functions )
    functions->TexImage2D               = radeonTexImage2D;
    functions->TexSubImage1D            = radeonTexSubImage1D;
    functions->TexSubImage2D            = radeonTexSubImage2D;
+   functions->GetTexImage               = radeonGetTexImage;
+   functions->GetCompressedTexImage     = radeonGetCompressedTexImage;
 
    functions->NewTextureObject         = radeonNewTextureObject;
    //   functions->BindTexture         = radeonBindTexture;
index 55dda29eaf9c157ba1236b1b1a6fc9e7a9347401..93ab5f7260404bc94fb05c4e47b900bd28ed728a 100644 (file)
@@ -883,3 +883,56 @@ int radeon_validate_texture_miptree(GLcontext * ctx, struct gl_texture_object *t
        return GL_TRUE;
 }
 
+
+/**
+ * Need to map texture image into memory before copying image data,
+ * then unmap it.
+ */
+static void
+radeon_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
+                    GLenum format, GLenum type, GLvoid * pixels,
+                    struct gl_texture_object *texObj,
+                    struct gl_texture_image *texImage, int compressed)
+{
+       radeon_texture_image *image = get_radeon_texture_image(texImage);
+
+       if (image->mt) {
+               /* Map the texture image read-only */
+               radeon_teximage_map(image, GL_FALSE);
+       } else {
+               /* Image hasn't been uploaded to a miptree yet */
+               assert(image->base.Data);
+       }
+
+       if (compressed) {
+               _mesa_get_compressed_teximage(ctx, target, level, pixels,
+                                             texObj, texImage);
+       } else {
+               _mesa_get_teximage(ctx, target, level, format, type, pixels,
+                                  texObj, texImage);
+       }
+     
+       if (image->mt) {
+               radeon_teximage_unmap(image);
+       }
+}
+
+void
+radeonGetTexImage(GLcontext * ctx, GLenum target, GLint level,
+                 GLenum format, GLenum type, GLvoid * pixels,
+                 struct gl_texture_object *texObj,
+                 struct gl_texture_image *texImage)
+{
+       radeon_get_tex_image(ctx, target, level, format, type, pixels,
+                            texObj, texImage, 0);
+}
+
+void
+radeonGetCompressedTexImage(GLcontext *ctx, GLenum target, GLint level,
+                           GLvoid *pixels,
+                           struct gl_texture_object *texObj,
+                           struct gl_texture_image *texImage)
+{
+       radeon_get_tex_image(ctx, target, level, 0, 0, pixels,
+                            texObj, texImage, 1);
+}
index ff0e1d061edf086e9eed8ece09c498657373e6ed..d90fda7868fa03337509c020587c81eeecbc238f 100644 (file)
@@ -105,4 +105,14 @@ void radeonTexSubImage3D(GLcontext * ctx, GLenum target, GLint level,
                         const struct gl_pixelstore_attrib *packing,
                         struct gl_texture_object *texObj,
                         struct gl_texture_image *texImage);
+
+void radeonGetTexImage(GLcontext * ctx, GLenum target, GLint level,
+                      GLenum format, GLenum type, GLvoid * pixels,
+                      struct gl_texture_object *texObj,
+                      struct gl_texture_image *texImage);
+void radeonGetCompressedTexImage(GLcontext *ctx, GLenum target, GLint level,
+                                GLvoid *pixels,
+                                struct gl_texture_object *texObj,
+                                struct gl_texture_image *texImage);
+
 #endif