mesa: default DEPTH_TEXTURE_MODE should be RED in the core profile
[mesa.git] / src / mesa / drivers / dri / nouveau / nouveau_texture.c
index 281d1dda4584018ddffd801fa72550821dc7c78c..da74e8f4207a6463c72e3f6921b5721552cedd67 100644 (file)
@@ -46,7 +46,7 @@ nouveau_texture_new(struct gl_context *ctx, GLuint name, GLenum target)
 {
        struct nouveau_texture *nt = CALLOC_STRUCT(nouveau_texture);
 
-       _mesa_initialize_texture_object(&nt->base, name, target);
+       _mesa_initialize_texture_object(ctx, &nt->base, name, target);
 
        return &nt->base;
 }
@@ -79,75 +79,6 @@ nouveau_teximage_free(struct gl_context *ctx, struct gl_texture_image *ti)
        nouveau_surface_ref(NULL, &nti->surface);
 }
 
-static void
-nouveau_teximage_map(struct gl_context *ctx, struct gl_texture_image *ti,
-                    int access, int x, int y, int w, int h)
-{
-       struct nouveau_teximage *nti = to_nouveau_teximage(ti);
-       struct nouveau_surface *s = &nti->surface;
-       struct nouveau_surface *st = &nti->transfer.surface;
-       struct nouveau_client *client = context_client(ctx);
-
-       if (s->bo) {
-               if (!(access & GL_MAP_READ_BIT) &&
-                   nouveau_pushbuf_refd(context_push(ctx), s->bo)) {
-                       unsigned size;
-                       /*
-                        * Heuristic: use a bounce buffer to pipeline
-                        * teximage transfers.
-                        */
-                       st->layout = LINEAR;
-                       st->format = s->format;
-                       st->cpp = s->cpp;
-                       st->width = w;
-                       st->height = h;
-                       st->pitch = s->pitch;
-                       nti->transfer.x = x;
-                       nti->transfer.y = y;
-
-                       size = get_format_blocksy(st->format, h) * st->pitch;
-                       nti->base.Map = nouveau_get_scratch(ctx, size,
-                                                      &st->bo, &st->offset);
-
-               } else {
-                       int ret, flags = 0;
-
-                       if (access & GL_MAP_READ_BIT)
-                               flags |= NOUVEAU_BO_RD;
-                       if (access & GL_MAP_WRITE_BIT)
-                               flags |= NOUVEAU_BO_WR;
-
-                       if (!s->bo->map) {
-                               ret = nouveau_bo_map(s->bo, flags, client);
-                               assert(!ret);
-                       }
-
-                       nti->base.Map = s->bo->map +
-                               get_format_blocksy(s->format, y) * s->pitch +
-                               get_format_blocksx(s->format, x) * s->cpp;
-
-               }
-       }
-}
-
-static void
-nouveau_teximage_unmap(struct gl_context *ctx, struct gl_texture_image *ti)
-{
-       struct nouveau_teximage *nti = to_nouveau_teximage(ti);
-       struct nouveau_surface *s = &nti->surface;
-       struct nouveau_surface *st = &nti->transfer.surface;
-
-       if (st->bo) {
-               context_drv(ctx)->surface_copy(ctx, s, st, nti->transfer.x,
-                                              nti->transfer.y, 0, 0,
-                                              st->width, st->height);
-               nouveau_surface_ref(NULL, st);
-
-       }
-       nti->base.Map = NULL;
-}
-
-
 static void
 nouveau_map_texture_image(struct gl_context *ctx,
                          struct gl_texture_image *ti,
@@ -205,7 +136,7 @@ nouveau_map_texture_image(struct gl_context *ctx,
                        *stride = s->pitch;
                }
        } else {
-               *map = nti->base.Map +
+               *map = nti->base.Buffer +
                        get_format_blocksy(s->format, y) * s->pitch +
                        get_format_blocksx(s->format, x) * s->cpp;
                *stride = s->pitch;
@@ -227,12 +158,11 @@ nouveau_unmap_texture_image(struct gl_context *ctx, struct gl_texture_image *ti,
                nouveau_surface_ref(NULL, st);
 
        }
-
-       nti->base.Map = NULL;
 }
 
 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 +298,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 +340,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 +411,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,39 +421,45 @@ 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) {
+               GLubyte *map;
+               int row_stride;
+
                /* Store the pixel data. */
-               nouveau_teximage_map(ctx, ti, GL_MAP_WRITE_BIT,
-                                    0, 0, width, height);
+               nouveau_map_texture_image(ctx, ti, 0,
+                                         0, 0, ti->Width, ti->Height,
+                                         GL_MAP_WRITE_BIT,
+                                         &map, &row_stride);
 
                ret = _mesa_texstore(ctx, dims, ti->_BaseFormat,
                                     ti->TexFormat,
-                                    s->pitch,
-                                     &nti->base.Map,
-                                    width, height, depth,
+                                    row_stride,
+                                    &map,
+                                    ti->Width, ti->Height, depth,
                                     format, type, pixels, packing);
                assert(ret);
 
-               nouveau_teximage_unmap(ctx, ti);
+               nouveau_unmap_texture_image(ctx, ti, 0);
                _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 +478,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);
 }
 
@@ -576,13 +504,11 @@ nouveau_texsubimage(struct gl_context *ctx, GLint dims,
                    const struct gl_pixelstore_attrib *packing,
                    GLboolean compressed)
 {
-       struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface;
-       struct nouveau_teximage *nti = to_nouveau_teximage(ti);
        int ret;
 
        if (compressed)
                pixels = _mesa_validate_pbo_compressed_teximage(ctx,
-                               imageSize,
+                               dims, imageSize,
                                pixels, packing, "glCompressedTexSubImage");
        else
                pixels = _mesa_validate_pbo_teximage(ctx,
@@ -590,17 +516,20 @@ nouveau_texsubimage(struct gl_context *ctx, GLint dims,
                                pixels, packing, "glTexSubImage");
 
        if (pixels) {
-               nouveau_teximage_map(ctx, ti, GL_MAP_WRITE_BIT,
-                                    xoffset, yoffset, width, height);
+               GLubyte *map;
+               int row_stride;
+
+               nouveau_map_texture_image(ctx, ti, 0,
+                                         xoffset, yoffset, width, height,
+                                         GL_MAP_WRITE_BIT, &map, &row_stride);
 
                ret = _mesa_texstore(ctx, dims, ti->_BaseFormat, ti->TexFormat,
-                                     s->pitch,
-                                    &nti->base.Map,
+                                    row_stride, &map,
                                      width, height, depth,
                                     format, type, pixels, packing);
                assert(ret);
 
-               nouveau_teximage_unmap(ctx, ti);
+               nouveau_unmap_texture_image(ctx, ti, 0);
                _mesa_unmap_teximage_pbo(ctx, packing);
        }
 
@@ -624,15 +553,15 @@ nouveau_texsubimage_123d(struct gl_context *ctx, GLuint dims,
 }
 
 static void
-nouveau_compressed_texsubimage_2d(struct gl_context *ctx,
+nouveau_compressed_texsubimage(struct gl_context *ctx, GLuint dims,
                       struct gl_texture_image *ti,
-                      GLint xoffset, GLint yoffset,
-                      GLsizei width, GLint height,
+                      GLint xoffset, GLint yoffset, GLint zoffset,
+                      GLsizei width, GLint height, GLint depth,
                       GLenum format,
                       GLint imageSize, const void *data)
 {
-       nouveau_texsubimage(ctx, 2, ti, xoffset, yoffset, 0,
-                         width, height, 1, imageSize, format, 0, data,
+       nouveau_texsubimage(ctx, dims, ti, xoffset, yoffset, zoffset,
+                         width, height, depth, imageSize, format, 0, data,
                          &ctx->Unpack, GL_TRUE);
 }
 
@@ -709,7 +638,7 @@ nouveau_texture_functions_init(struct dd_function_table *functions)
        functions->TexImage = nouveau_teximage_123d;
        functions->TexSubImage = nouveau_texsubimage_123d;
        functions->CompressedTexImage = nouveau_compressed_teximage;
-       functions->CompressedTexSubImage2D = nouveau_compressed_texsubimage_2d;
+       functions->CompressedTexSubImage = nouveau_compressed_texsubimage;
        functions->BindTexture = nouveau_bind_texture;
        functions->MapTextureImage = nouveau_map_texture_image;
        functions->UnmapTextureImage = nouveau_unmap_texture_image;