diff options
author | Brian Paul <brianp@vmware.com> | 2009-12-05 10:35:05 -0700 |
---|---|---|
committer | Brian Paul <brianp@vmware.com> | 2009-12-05 10:35:17 -0700 |
commit | bb09759f141a521f7232f9dff746c5277b617794 (patch) | |
tree | 42e436cd4f7d5fb25c3f0c36c9ba6e7dd731c4df | |
parent | 3aab8d90219bbd06d9acb04af87daaf98f0ed9d1 (diff) |
mesa: use RowStride if it's non-zero in _mesa_alloc_texture_image_data()map-tex-branch
Fixes a regression found in DRI drivers when the row stride is larger
than the image width.
-rw-r--r-- | src/mesa/main/texmem.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/mesa/main/texmem.c b/src/mesa/main/texmem.c index 166e6480e6..8de835ae99 100644 --- a/src/mesa/main/texmem.c +++ b/src/mesa/main/texmem.c @@ -38,13 +38,33 @@ /** * Allocate space for the given texture image. * This is a fallback called via ctx->Driver.AllocTexImageData(). + * Hardware drivers typically won't use this unless they need to temporarily + * store texture data in user memory rather than video memory. */ GLboolean _mesa_alloc_texture_image_data(GLcontext *ctx, struct gl_texture_image *tImage) { - GLint bytes = _mesa_format_image_size(tImage->TexFormat, tImage->Width, - tImage->Height, tImage->Depth); - /* XXX store data on tImgae->DriverData */ + GLuint width, bytes; + + /* + * XXX in the future, we probably don't want to rely on Map.RowStride + * here since it may only be valid while the texture memory is mapped. + * Drivers should implement their own version of this function which + * does the proper alignment. + */ + if (tImage->Map.RowStride > 0) { + /* sanity check: the stride should be at least as large as the width */ + assert(tImage->Map.RowStride >= tImage->Width); + width = tImage->Map.RowStride; + } + else { + width = tImage->Width; + } + + bytes = _mesa_format_image_size(tImage->TexFormat, width, + tImage->Height, tImage->Depth); + + /* XXX future step: store data off of tImage->DriverData */ tImage->Map.Data = _mesa_align_malloc(bytes, 512); return tImage->Map.Data != NULL; } |