mesa: Introduce a globally-available minify() macro.
[mesa.git] / src / mesa / drivers / dri / nouveau / nouveau_texture.c
index 0060f464307f895c21b459adb033ac689b5d26bf..4e3c26bab87c9956c76056c8ca8300094fc1c9fa 100644 (file)
@@ -232,7 +232,8 @@ nouveau_unmap_texture_image(struct gl_context *ctx, struct gl_texture_image *ti,
 }
 
 static gl_format
-nouveau_choose_tex_format(struct gl_context *ctx, GLint internalFormat,
+nouveau_choose_tex_format(struct gl_context *ctx, GLenum target,
+                          GLint internalFormat,
                          GLenum srcFormat, GLenum srcType)
 {
        switch (internalFormat) {
@@ -368,7 +369,7 @@ get_last_level(struct gl_texture_object *t)
            t->Sampler.MinFilter == GL_LINEAR || !base)
                return t->BaseLevel;
        else
-               return MIN2(t->BaseLevel + base->MaxLog2, t->MaxLevel);
+               return MIN2(t->BaseLevel + base->MaxNumLevels - 1, t->MaxLevel);
 }
 
 static void
@@ -410,8 +411,8 @@ relayout_texture(struct gl_context *ctx, struct gl_texture_object *t)
                        };
 
                        offset += size;
-                       width = MAX2(1, width / 2);
-                       height = MAX2(1, height / 2);
+                       width = minify(width, 1);
+                       height = minify(height, 1);
                }
 
                /* Get new storage. */
@@ -481,8 +482,6 @@ get_teximage_placement(struct gl_texture_image *ti)
 static void
 nouveau_teximage(struct gl_context *ctx, GLint dims,
                 struct gl_texture_image *ti,
-                GLint internalFormat,
-                GLint width, GLint height, GLint depth, GLint border,
                 GLsizei imageSize,
                 GLenum format, GLenum type, const GLvoid *pixels,
                 const struct gl_pixelstore_attrib *packing,
@@ -493,31 +492,32 @@ nouveau_teximage(struct gl_context *ctx, GLint dims,
        struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface;
        struct nouveau_teximage *nti = to_nouveau_teximage(ti);
        int ret;
+       GLuint depth = compressed ? 1 : ti->Depth;
 
        /* Allocate a new bo for the image. */
        nouveau_surface_alloc(ctx, s, LINEAR, get_teximage_placement(ti),
-                             ti->TexFormat, width, height);
+                             ti->TexFormat, ti->Width, ti->Height);
        nti->base.RowStride = s->pitch / s->cpp;
 
        if (compressed)
                pixels = _mesa_validate_pbo_compressed_teximage(ctx,
-                       imageSize,
+                       dims, imageSize,
                        pixels, packing, "glCompressedTexImage");
        else
                pixels = _mesa_validate_pbo_teximage(ctx,
-                       dims, width, height, depth, format, type,
+                       dims, ti->Width, ti->Height, depth, format, type,
                        pixels, packing, "glTexImage");
 
        if (pixels) {
                /* Store the pixel data. */
                nouveau_teximage_map(ctx, ti, GL_MAP_WRITE_BIT,
-                                    0, 0, width, height);
+                                    0, 0, ti->Width, ti->Height);
 
                ret = _mesa_texstore(ctx, dims, ti->_BaseFormat,
                                     ti->TexFormat,
                                     s->pitch,
                                      &nti->base.Map,
-                                    width, height, depth,
+                                    ti->Width, ti->Height, depth,
                                     format, type, pixels, packing);
                assert(ret);
 
@@ -525,7 +525,7 @@ nouveau_teximage(struct gl_context *ctx, GLint dims,
                _mesa_unmap_teximage_pbo(ctx, packing);
 
                if (!validate_teximage(ctx, t, level, 0, 0, 0,
-                                      width, height, depth))
+                                      ti->Width, ti->Height, depth))
                        /* It doesn't fit, mark it as dirty. */
                        texture_dirty(t);
        }
@@ -544,25 +544,19 @@ nouveau_teximage(struct gl_context *ctx, GLint dims,
 static void
 nouveau_teximage_123d(struct gl_context *ctx, GLuint dims,
                       struct gl_texture_image *ti,
-                      GLint internalFormat,
-                      GLint width, GLint height, GLint depth, GLint border,
                       GLenum format, GLenum type, const GLvoid *pixels,
                       const struct gl_pixelstore_attrib *packing)
 {
-       nouveau_teximage(ctx, dims, ti, internalFormat,
-                        width, height, depth, border, 0, format, type, pixels,
+       nouveau_teximage(ctx, dims, ti, 0, format, type, pixels,
                         packing, GL_FALSE);
 }
 
 static void
 nouveau_compressed_teximage(struct gl_context *ctx, GLuint dims,
                    struct gl_texture_image *ti,
-                   GLint internalFormat,
-                   GLint width, GLint height, GLint depth, GLint border,
                    GLsizei imageSize, const GLvoid *data)
 {
-       nouveau_teximage(ctx, 2, ti, internalFormat,
-                        width, height, 1, border, imageSize, 0, 0, data,
+       nouveau_teximage(ctx, 2, ti, imageSize, 0, 0, data,
                         &ctx->Unpack, GL_TRUE);
 }
 
@@ -582,7 +576,7 @@ nouveau_texsubimage(struct gl_context *ctx, GLint dims,
 
        if (compressed)
                pixels = _mesa_validate_pbo_compressed_teximage(ctx,
-                               imageSize,
+                               dims, imageSize,
                                pixels, packing, "glCompressedTexSubImage");
        else
                pixels = _mesa_validate_pbo_teximage(ctx,