swrast: silence unused var warnings in non-debug builds
[mesa.git] / src / mesa / swrast / s_texture.c
index 6cc72c582f769c3b5f67dfc453e43d2e920ca689..36b429cfab9535b7fe784722a68f9890deeee540 100644 (file)
 
 #include "main/context.h"
 #include "main/fbobject.h"
+#include "main/teximage.h"
 #include "swrast/swrast.h"
 #include "swrast/s_context.h"
 
+
+/**
+ * Allocate a new swrast_texture_image (a subclass of gl_texture_image).
+ * Called via ctx->Driver.NewTextureImage().
+ */
+struct gl_texture_image *
+_swrast_new_texture_image( struct gl_context *ctx )
+{
+   (void) ctx;
+   return (struct gl_texture_image *) CALLOC_STRUCT(swrast_texture_image);
+}
+
+
+/**
+ * Free a swrast_texture_image (a subclass of gl_texture_image).
+ * Called via ctx->Driver.DeleteTextureImage().
+ */
+void
+_swrast_delete_texture_image(struct gl_context *ctx,
+                             struct gl_texture_image *texImage)
+{
+   /* Nothing special for the subclass yet */
+   _mesa_delete_texture_image(ctx, texImage);
+}
+
+
+/**
+ * Called via ctx->Driver.AllocTextureImageBuffer()
+ */
+GLboolean
+_swrast_alloc_texture_image_buffer(struct gl_context *ctx,
+                                   struct gl_texture_image *texImage,
+                                   gl_format format, GLsizei width,
+                                   GLsizei height, GLsizei depth)
+{
+   struct swrast_texture_image *swImg = swrast_texture_image(texImage);
+   GLuint bytes = _mesa_format_image_size(format, width, height, depth);
+
+   /* This _should_ be true (revisit if these ever fail) */
+   assert(texImage->Width == width);
+   assert(texImage->Height == height);
+   assert(texImage->Depth == depth);
+
+   assert(!texImage->Data);
+   texImage->Data = _mesa_align_malloc(bytes, 512);
+
+   if ((width == 1 || _mesa_is_pow_two(texImage->Width2)) &&
+       (height == 1 || _mesa_is_pow_two(texImage->Height2)) &&
+       (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;
+   }
+
+   return texImage->Data != NULL;
+}
+
+
+/**
+ * Called via ctx->Driver.FreeTextureImageBuffer()
+ */
+void
+_swrast_free_texture_image_buffer(struct gl_context *ctx,
+                                  struct gl_texture_image *texImage)
+{
+   if (texImage->Data) {
+      _mesa_align_free(texImage->Data);
+   }
+
+   texImage->Data = NULL;
+}
+
+
 /**
  * Error checking for debugging only.
  */
@@ -91,6 +177,13 @@ _swrast_map_teximage(struct gl_context *ctx,
                                                  1);
       assert(slice < texImage->Depth);
       map += slice * sliceSize;
+   } else if (texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY) {
+      GLuint sliceSize = _mesa_format_image_size(texImage->TexFormat,
+                                                 texImage->Width,
+                                                 1,
+                                                 1);
+      assert(slice < texImage->Height);
+      map += slice * sliceSize;
    }
 
    /* apply x/y offset to map address */