summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dri/nouveau/nouveau_texture.c
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2011-08-15 10:20:25 -0700
committerEric Anholt <[email protected]>2011-08-29 10:10:03 -0700
commit5b257442a8a46fdabdaad54c5f18a44f02696590 (patch)
treef7f9d7a41fe14c6c97a2eb34c5c497bf4ae22424 /src/mesa/drivers/dri/nouveau/nouveau_texture.c
parent587fdf07da1ca8fdc4fdadbe5a78dd9d0088a880 (diff)
nouveau: Add MapTextureImage() implementation.
This is untested, but should be close to working since it's basically a copy of nouveau_teximage_map(). Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/mesa/drivers/dri/nouveau/nouveau_texture.c')
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_texture.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_texture.c b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
index df1467df69b..38b89de92e3 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_texture.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
@@ -144,6 +144,85 @@ nouveau_teximage_unmap(struct gl_context *ctx, struct gl_texture_image *ti)
ti->Data = NULL;
}
+
+static void
+nouveau_map_texture_image(struct gl_context *ctx,
+ struct gl_texture_image *ti,
+ GLuint slice,
+ GLuint x, GLuint y, GLuint w, GLuint h,
+ GLbitfield mode,
+ GLubyte **map,
+ GLint *stride)
+{
+ struct nouveau_teximage *nti = to_nouveau_teximage(ti);
+ struct nouveau_surface *s = &nti->surface;
+ struct nouveau_surface *st = &nti->transfer.surface;
+
+ /* Nouveau has no support for 3D or cubemap textures. */
+ assert(slice == 0);
+
+ if (s->bo) {
+ if (!(mode & GL_MAP_READ_BIT) &&
+ nouveau_bo_pending(s->bo)) {
+ /*
+ * 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;
+
+ *map = nouveau_get_scratch(ctx, st->pitch * h,
+ &st->bo, &st->offset);
+ *stride = st->pitch;
+ } else {
+ int ret, flags = 0;
+
+ if (mode & GL_MAP_READ_BIT)
+ flags |= NOUVEAU_BO_RD;
+ if (mode & GL_MAP_WRITE_BIT)
+ flags |= NOUVEAU_BO_WR;
+
+ if (!s->bo->map) {
+ ret = nouveau_bo_map(s->bo, flags);
+ assert(!ret);
+ }
+
+ *map = s->bo->map + y * s->pitch + x * s->cpp;
+ *stride = s->pitch;
+ }
+ } else {
+ *map = ti->Data + y * s->pitch + x * s->cpp;
+ *stride = s->pitch;
+ }
+}
+
+static void
+nouveau_unmap_texture_image(struct gl_context *ctx, struct gl_texture_image *ti,
+ GLuint slice)
+{
+ 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);
+
+ } else if (s->bo) {
+ nouveau_bo_unmap(s->bo);
+ }
+
+ ti->Data = NULL;
+}
+
static gl_format
nouveau_choose_tex_format(struct gl_context *ctx, GLint internalFormat,
GLenum srcFormat, GLenum srcType)
@@ -716,5 +795,7 @@ 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->MapTextureImage = nouveau_map_texture_image;
+ functions->UnmapTextureImage = nouveau_unmap_texture_image;
functions->GenerateMipmap = nouveau_generate_mipmap;
}