aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/texobj.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-04-13 11:42:04 +0200
committermarha <marha@users.sourceforge.net>2012-04-13 11:42:04 +0200
commitd2d4fd66a0c1fca50d07fce3f383d6a84a57f09a (patch)
treeb50ae20ca22bc564b145906d6c84395285933859 /mesalib/src/mesa/main/texobj.c
parent120bd371deb2b73a0bae5ce331511e4ea27bcff2 (diff)
parentfffd436e9c2ec6f5aa501ee57d0e4ade7293ee60 (diff)
downloadvcxsrv-d2d4fd66a0c1fca50d07fce3f383d6a84a57f09a.tar.gz
vcxsrv-d2d4fd66a0c1fca50d07fce3f383d6a84a57f09a.tar.bz2
vcxsrv-d2d4fd66a0c1fca50d07fce3f383d6a84a57f09a.zip
Merge remote-tracking branch 'origin/released'
Diffstat (limited to 'mesalib/src/mesa/main/texobj.c')
-rw-r--r--mesalib/src/mesa/main/texobj.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/mesalib/src/mesa/main/texobj.c b/mesalib/src/mesa/main/texobj.c
index 4c3eed2b6..155b255a7 100644
--- a/mesalib/src/mesa/main/texobj.c
+++ b/mesalib/src/mesa/main/texobj.c
@@ -841,6 +841,65 @@ _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex)
}
+/**
+ * Compute the size of the given texture object, in bytes.
+ */
+static GLuint
+texture_size(const struct gl_texture_object *texObj)
+{
+ const GLuint numFaces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
+ GLuint face, level, size = 0;
+
+ for (face = 0; face < numFaces; face++) {
+ for (level = 0; level < MAX_TEXTURE_LEVELS; level++) {
+ const struct gl_texture_image *img = texObj->Image[face][level];
+ if (img) {
+ GLuint sz = _mesa_format_image_size(img->TexFormat, img->Width,
+ img->Height, img->Depth);
+ size += sz;
+ }
+ }
+ }
+
+ return size;
+}
+
+
+/**
+ * Callback called from _mesa_HashWalk()
+ */
+static void
+count_tex_size(GLuint key, void *data, void *userData)
+{
+ const struct gl_texture_object *texObj =
+ (const struct gl_texture_object *) data;
+ GLuint *total = (GLuint *) userData;
+
+ *total = *total + texture_size(texObj);
+}
+
+
+/**
+ * Compute total size (in bytes) of all textures for the given context.
+ * For debugging purposes.
+ */
+GLuint
+_mesa_total_texture_memory(struct gl_context *ctx)
+{
+ GLuint tgt, total = 0;
+
+ _mesa_HashWalk(ctx->Shared->TexObjects, count_tex_size, &total);
+
+ /* plus, the default texture objects */
+ for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
+ total += texture_size(ctx->Shared->DefaultTex[tgt]);
+ }
+
+ return total;
+}
+
+
+
/*@}*/