dri/nouveau: Fix up software mipmap generation.
authorFrancisco Jerez <currojerez@riseup.net>
Wed, 28 Jul 2010 16:37:24 +0000 (18:37 +0200)
committerFrancisco Jerez <currojerez@riseup.net>
Wed, 4 Aug 2010 23:48:14 +0000 (01:48 +0200)
src/mesa/drivers/dri/nouveau/nouveau_fbo.c
src/mesa/drivers/dri/nouveau/nouveau_texture.c

index 8be7edb150bf8bbde835eed86ee0ecdcf3fd9a37..bd1273beea709805225688220d57af4ae0192255 100644 (file)
@@ -220,7 +220,7 @@ get_tex_format(struct gl_texture_image *ti)
        case MESA_FORMAT_RGB565:
                return GL_RGB5;
        default:
-               assert(0);
+               return GL_NONE;
        }
 }
 
@@ -231,7 +231,6 @@ nouveau_render_texture(GLcontext *ctx, struct gl_framebuffer *fb,
        struct gl_renderbuffer *rb = att->Renderbuffer;
        struct gl_texture_image *ti =
                att->Texture->Image[att->CubeMapFace][att->TextureLevel];
-       int ret;
 
        /* Allocate a renderbuffer object for the texture if we
         * haven't already done so. */
@@ -244,9 +243,7 @@ nouveau_render_texture(GLcontext *ctx, struct gl_framebuffer *fb,
        }
 
        /* Update the renderbuffer fields from the texture. */
-       ret = set_renderbuffer_format(rb, get_tex_format(ti));
-       assert(ret);
-
+       set_renderbuffer_format(rb, get_tex_format(ti));
        rb->Width = ti->Width;
        rb->Height = ti->Height;
        nouveau_surface_ref(&to_nouveau_teximage(ti)->surface,
index dbf9a5cc613f0469881458e39817c6f631c09854..79b67575866af199439990a2bce498df4af829b5 100644 (file)
@@ -38,6 +38,7 @@
 #include "main/mipmap.h"
 #include "main/texfetch.h"
 #include "main/teximage.h"
+#include "drivers/common/meta.h"
 
 static struct gl_texture_object *
 nouveau_texture_new(GLcontext *ctx, GLuint name, GLenum target)
@@ -589,6 +590,53 @@ nouveau_texture_unmap(GLcontext *ctx, struct gl_texture_object *t)
        }
 }
 
+static void
+store_mipmap(GLcontext *ctx, GLenum target, int first, int last,
+            struct gl_texture_object *t)
+{
+       struct gl_pixelstore_attrib packing = {
+               .BufferObj = ctx->Shared->NullBufferObj,
+               .Alignment = 1
+       };
+       GLenum format = t->Image[0][first]->TexFormat;
+       unsigned base_format, type, comps;
+       int i;
+
+       base_format = _mesa_get_format_base_format(format);
+       _mesa_format_to_type_and_comps(format, &type, &comps);
+
+       for (i = first; i <= last; i++) {
+               struct gl_texture_image *ti = t->Image[0][i];
+               void *data = ti->Data;
+
+               nouveau_teximage(ctx, 3, target, i, ti->InternalFormat,
+                                ti->Width, ti->Height, ti->Depth,
+                                ti->Border, base_format, type, data,
+                                &packing, t, ti);
+
+               _mesa_free_texmemory(data);
+       }
+}
+
+static void
+nouveau_generate_mipmap(GLcontext *ctx, GLenum target,
+                       struct gl_texture_object *t)
+{
+       if (_mesa_meta_check_generate_mipmap_fallback(ctx, target, t)) {
+               struct gl_texture_image *base = t->Image[0][t->BaseLevel];
+
+               nouveau_teximage_map(ctx, base);
+               _mesa_generate_mipmap(ctx, target, t);
+               nouveau_teximage_unmap(ctx, base);
+
+               store_mipmap(ctx, target, t->BaseLevel + 1,
+                            get_last_level(t), t);
+
+       } else {
+               _mesa_meta_GenerateMipmap(ctx, target, t);
+       }
+}
+
 void
 nouveau_texture_functions_init(struct dd_function_table *functions)
 {
@@ -607,4 +655,5 @@ nouveau_texture_functions_init(struct dd_function_table *functions)
        functions->BindTexture = nouveau_bind_texture;
        functions->MapTexture = nouveau_texture_map;
        functions->UnmapTexture = nouveau_texture_unmap;
+       functions->GenerateMipmap = nouveau_generate_mipmap;
 }