summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2009-10-01 15:59:13 -0600
committerBrian Paul <[email protected]>2009-10-01 15:59:13 -0600
commit1c7ec97ec47f294dcfc0c6a87ee26bb3565f95d4 (patch)
treee4630b2160c82a7071d25282b25d20282d2586c5 /src/mesa
parent8c36ca707ca8879d6f888de7733ffb6b04ddc48a (diff)
mesa: added _mesa_format_image_size()
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/main/formats.c27
-rw-r--r--src/mesa/main/formats.h4
2 files changed, 31 insertions, 0 deletions
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index dec3daee7cd..82843a32910 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -594,6 +594,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.
*/
void
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index 99a6534ff1b..b91682809fd 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -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);