+/**
+ * Called via ctx->Driver.AllocTextureImageBuffer()
+ */
+GLboolean
+_swrast_alloc_texture_image_buffer(struct gl_context *ctx,
+ struct gl_texture_image *texImage)
+{
+ struct swrast_texture_image *swImg = swrast_texture_image(texImage);
+ GLuint bytes = _mesa_format_image_size(texImage->TexFormat, texImage->Width,
+ texImage->Height, texImage->Depth);
+ GLuint i;
+
+ assert(!swImg->Buffer);
+ swImg->Buffer = _mesa_align_malloc(bytes, 512);
+ if (!swImg->Buffer)
+ return GL_FALSE;
+
+ /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
+ swImg->RowStride = texImage->Width;
+
+ /* Allocate the ImageOffsets array and initialize to typical values.
+ * We allocate the array for 1D/2D textures too in order to avoid special-
+ * case code in the texstore routines.
+ */
+ swImg->ImageOffsets = malloc(texImage->Depth * sizeof(GLuint));
+ if (!swImg->ImageOffsets)
+ return GL_FALSE;
+
+ for (i = 0; i < texImage->Depth; i++) {
+ swImg->ImageOffsets[i] = i * texImage->Width * texImage->Height;
+ }
+
+ _swrast_init_texture_image(texImage);
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Code that overrides ctx->Driver.AllocTextureImageBuffer may use this to
+ * initialize the fields of swrast_texture_image without allocating the image
+ * buffer or initializing ImageOffsets or RowStride.
+ *
+ * Returns GL_TRUE on success, GL_FALSE on memory allocation failure.
+ */
+void
+_swrast_init_texture_image(struct gl_texture_image *texImage)
+{
+ struct swrast_texture_image *swImg = swrast_texture_image(texImage);
+
+ if ((texImage->Width == 1 || _mesa_is_pow_two(texImage->Width2)) &&
+ (texImage->Height == 1 || _mesa_is_pow_two(texImage->Height2)) &&
+ (texImage->Depth == 1 || _mesa_is_pow_two(texImage->Depth2)))
+ swImg->_IsPowerOfTwo = GL_TRUE;
+ else
+ swImg->_IsPowerOfTwo = GL_FALSE;
+
+ /* Compute Width/Height/DepthScale for mipmap lod computation */
+ if (texImage->TexObject->Target == GL_TEXTURE_RECTANGLE_NV) {
+ /* scale = 1.0 since texture coords directly map to texels */
+ swImg->WidthScale = 1.0;
+ swImg->HeightScale = 1.0;
+ swImg->DepthScale = 1.0;
+ }
+ else {
+ swImg->WidthScale = (GLfloat) texImage->Width;
+ swImg->HeightScale = (GLfloat) texImage->Height;
+ swImg->DepthScale = (GLfloat) texImage->Depth;
+ }
+}
+
+
+/**
+ * Called via ctx->Driver.FreeTextureImageBuffer()
+ */
+void
+_swrast_free_texture_image_buffer(struct gl_context *ctx,
+ struct gl_texture_image *texImage)
+{
+ struct swrast_texture_image *swImage = swrast_texture_image(texImage);
+ if (swImage->Buffer) {
+ _mesa_align_free(swImage->Buffer);
+ swImage->Buffer = NULL;
+ }
+
+ free(swImage->ImageOffsets);
+ swImage->ImageOffsets = NULL;
+}
+
+