mesa: added _mesa_format_image_size()
authorBrian Paul <brianp@vmware.com>
Thu, 1 Oct 2009 21:59:13 +0000 (15:59 -0600)
committerBrian Paul <brianp@vmware.com>
Thu, 1 Oct 2009 21:59:13 +0000 (15:59 -0600)
src/mesa/main/formats.c
src/mesa/main/formats.h

index dec3daee7cdfc8f190f295617284b3730ce69553..82843a32910558a5fed91625428f3eb690302662 100644 (file)
@@ -593,6 +593,33 @@ _mesa_is_format_compressed(gl_format format)
 }
 
 
+/**
+ * Return number of bytes needed to store an image of the given size
+ * in the given format.
+ */
+GLuint
+_mesa_format_image_size(gl_format format, GLsizei width,
+                        GLsizei height, GLsizei depth)
+{
+   const struct gl_format_info *info = _mesa_get_format_info(format);
+   if (info->BlockWidth > 1 || info->BlockHeight > 1) {
+      /* compressed format */
+      const GLuint bw = info->BlockWidth, bh = info->BlockHeight;
+      const GLuint wblocks = (width + bw - 1) / bw;
+      const GLuint hblocks = (height + bh - 1) / bh;
+      const GLuint sz  = wblocks * hblocks * info->BytesPerBlock;
+      return sz;
+   }
+   else {
+      /* non-compressed */
+      const GLuint sz = width * height * depth * info->BytesPerBlock;
+      return sz;
+   }
+}
+
+
+
+
 /**
  * Do sanity checking of the format info table.
  */
index 99a6534ff1bc63b07f01bbe4654eead9764c816d..b91682809fd1aa66518d3e472fdbd3e524fce0b0 100644 (file)
@@ -202,6 +202,10 @@ extern void
 _mesa_format_to_type_and_comps2(gl_format format,
                                 GLenum *datatype, GLuint *comps);
 
+extern GLuint
+_mesa_format_image_size(gl_format format, GLsizei width,
+                        GLsizei height, GLsizei depth);
+
 extern void
 _mesa_test_formats(void);