Browse Source

Texture::get_data_size_bytes() etc.

David Rose 17 years ago
parent
commit
aca2606187
2 changed files with 64 additions and 0 deletions
  1. 60 0
      panda/src/gobj/texture.cxx
  2. 4 0
      panda/src/gobj/texture.h

+ 60 - 0
panda/src/gobj/texture.cxx

@@ -1128,6 +1128,66 @@ was_image_modified(PreparedGraphicsObjects *prepared_objects) const {
   return true;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: Texture::get_data_size_bytes
+//       Access: Public
+//  Description: Returns the number of bytes which the texture is
+//               reported to consume within graphics memory, for the
+//               indicated GSG.  This may return a nonzero value even
+//               if the texture is not currently resident; you should
+//               also check get_resident() if you want to know how
+//               much space the texture is actually consuming right
+//               now.
+////////////////////////////////////////////////////////////////////
+size_t Texture::
+get_data_size_bytes(PreparedGraphicsObjects *prepared_objects) const {
+  MutexHolder holder(_lock);
+  Contexts::const_iterator ci;
+  ci = _contexts.find(prepared_objects);
+  if (ci != _contexts.end()) {
+    TextureContext *tc = (*ci).second;
+    return tc->get_data_size_bytes();
+  }
+  return 0;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: Texture::get_active
+//       Access: Public
+//  Description: Returns true if this Texture was rendered in the most
+//               recent frame within the indicated GSG.
+////////////////////////////////////////////////////////////////////
+bool Texture::
+get_active(PreparedGraphicsObjects *prepared_objects) const {
+  MutexHolder holder(_lock);
+  Contexts::const_iterator ci;
+  ci = _contexts.find(prepared_objects);
+  if (ci != _contexts.end()) {
+    TextureContext *tc = (*ci).second;
+    return tc->get_active();
+  }
+  return false;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: Texture::get_resident
+//       Access: Public
+//  Description: Returns true if this Texture is reported to be
+//               resident within graphics memory for the indicated
+//               GSG.
+////////////////////////////////////////////////////////////////////
+bool Texture::
+get_resident(PreparedGraphicsObjects *prepared_objects) const {
+  MutexHolder holder(_lock);
+  Contexts::const_iterator ci;
+  ci = _contexts.find(prepared_objects);
+  if (ci != _contexts.end()) {
+    TextureContext *tc = (*ci).second;
+    return tc->get_resident();
+  }
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: Texture::release
 //       Access: Published

+ 4 - 0
panda/src/gobj/texture.h

@@ -355,6 +355,10 @@ PUBLISHED:
   void prepare(PreparedGraphicsObjects *prepared_objects);
   bool is_prepared(PreparedGraphicsObjects *prepared_objects) const;
   bool was_image_modified(PreparedGraphicsObjects *prepared_objects) const;
+  size_t get_data_size_bytes(PreparedGraphicsObjects *prepared_objects) const;
+  bool get_active(PreparedGraphicsObjects *prepared_objects) const;
+  bool get_resident(PreparedGraphicsObjects *prepared_objects) const;
+
   bool release(PreparedGraphicsObjects *prepared_objects);
   int release_all();