better mipmap queries

This commit is contained in:
David Rose 2008-08-21 20:04:10 +00:00
parent eefc6a19ad
commit 86d753b4f9
3 changed files with 55 additions and 3 deletions

View File

@ -858,8 +858,11 @@ set_keep_ram_image(bool keep_ram_image) {
// Access: Published // Access: Published
// Description: Returns the maximum number of mipmap level images // Description: Returns the maximum number of mipmap level images
// available in system memory. The actual number may be // available in system memory. The actual number may be
// less than this; use has_ram_mipmap_image() to verify // less than this (that is, there might be gaps in the
// each level. // sequence); use has_ram_mipmap_image() to verify each
// level.
//
// Also see get_num_loadable_ram_mipmap_images().
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE int Texture:: INLINE int Texture::
get_num_ram_mipmap_images() const { get_num_ram_mipmap_images() const {

View File

@ -1482,6 +1482,54 @@ get_keep_ram_image() const {
return _keep_ram_image; return _keep_ram_image;
} }
////////////////////////////////////////////////////////////////////
// Function: Texture::get_num_loadable_ram_mipmap_images
// Access: Published
// Description: Returns the number of contiguous mipmap levels that
// exist in RAM, up until the first gap in the sequence.
// It is guaranteed that at least mipmap levels [0,
// get_num_ram_mipmap_images()) exist.
//
// The number returned will never exceed the number of
// required mipmap images based on the size of the
// texture and its filter mode.
//
// This method is different from
// get_num_ram_mipmap_images() in that it returns only
// the number of mipmap levels that can actually be
// usefully loaded, regardless of the actual number that
// may be stored.
////////////////////////////////////////////////////////////////////
int Texture::
get_num_loadable_ram_mipmap_images() const {
ReMutexHolder holder(_lock);
if (_ram_images.empty() || _ram_images[0]._image.empty()) {
// If we don't even have a base image, the answer is none.
return 0;
}
if (!uses_mipmaps()) {
// If we have a base image and don't require mipmapping, the
// answer is 1.
return 1;
}
// Check that we have enough mipmap levels to meet the size
// requirements.
int size = max(_x_size, max(_y_size, _z_size));
int n = 0;
int x = 1;
while (x < size) {
x = (x << 1);
++n;
if (n >= (int)_ram_images.size() || _ram_images[n]._image.empty()) {
return n;
}
}
++n;
return n;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: Texture::has_all_ram_mipmap_images // Function: Texture::has_all_ram_mipmap_images
// Access: Published // Access: Published
@ -1528,7 +1576,7 @@ has_all_ram_mipmap_images() const {
CPTA_uchar Texture:: CPTA_uchar Texture::
get_ram_mipmap_image(int n) { get_ram_mipmap_image(int n) {
ReMutexHolder holder(_lock); ReMutexHolder holder(_lock);
if (n < (int)_ram_images.size()) { if (n < (int)_ram_images.size() || !_ram_images[n]._image.empty()) {
return _ram_images[n]._image; return _ram_images[n]._image;
} }
return CPTA_uchar(get_class_type()); return CPTA_uchar(get_class_type());

View File

@ -310,6 +310,7 @@ PUBLISHED:
INLINE int get_num_ram_mipmap_images() const; INLINE int get_num_ram_mipmap_images() const;
INLINE bool has_ram_mipmap_image(int n) const; INLINE bool has_ram_mipmap_image(int n) const;
int get_num_loadable_ram_mipmap_images() const;
bool has_all_ram_mipmap_images() const; bool has_all_ram_mipmap_images() const;
INLINE size_t get_ram_mipmap_image_size(int n) const; INLINE size_t get_ram_mipmap_image_size(int n) const;
INLINE size_t get_ram_mipmap_page_size(int n) const; INLINE size_t get_ram_mipmap_page_size(int n) const;