summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2009-12-05 10:35:05 -0700
committerBrian Paul <brianp@vmware.com>2009-12-05 10:35:17 -0700
commitbb09759f141a521f7232f9dff746c5277b617794 (patch)
tree42e436cd4f7d5fb25c3f0c36c9ba6e7dd731c4df
parent3aab8d90219bbd06d9acb04af87daaf98f0ed9d1 (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.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/mesa/main/texmem.c b/src/mesa/main/texmem.c
index 166e6480e68..8de835ae995 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;
}