28TextureMemoryCounter() {
56 nassertv(texture !=
nullptr);
60 nassertv(image !=
nullptr);
65 add_texture(texture, bytes);
70 if (dest !=
nullptr) {
71 int bytes = count_bytes(dest);
72 add_texture(texture, bytes);
84report(std::ostream &out,
int indent_level) {
86 << _num_placed <<
" of " << _num_textures <<
" textures appear on "
87 << _num_palettes <<
" palette images with " << _num_unplaced
91 << (_bytes + 512) / 1024 <<
"k estimated texture memory required.\n";
94 if (_unused_bytes != 0) {
95 indent(out, indent_level + 2);
96 format_memory_fraction(out, _unused_bytes, _bytes)
97 <<
" is wasted because of unused palette space.\n";
100 if (_coverage_bytes > 0) {
101 indent(out, indent_level + 2);
102 format_memory_fraction(out, _coverage_bytes, _bytes)
103 <<
" is wasted for repeating textures and margins.\n";
105 }
else if (_coverage_bytes < 0) {
106 indent(out, indent_level + 2);
107 format_memory_fraction(out, -_coverage_bytes, _bytes)
108 <<
" is *saved* for palettizing partial textures.\n";
111 if (_duplicate_bytes != 0) {
112 indent(out, indent_level + 2);
113 format_memory_fraction(out, _duplicate_bytes, _bytes)
114 <<
" is wasted because of a texture appearing in multiple groups.\n";
123std::ostream &TextureMemoryCounter::
124format_memory_fraction(std::ostream &out,
int fraction_bytes,
int palette_bytes) {
125 out << floor(1000.0 * (
double)fraction_bytes / (
double)palette_bytes + 0.5) / 10.0
126 <<
"% (" << (fraction_bytes + 512) / 1024 <<
"k)";
134void TextureMemoryCounter::
136 bool inserted = _palettes.insert(image).second;
142 int bytes = count_bytes(image);
147 _unused_bytes += (int)(unused * bytes);
148 _coverage_bytes += (int)(coverage * bytes);
157void TextureMemoryCounter::
159 std::pair<Textures::iterator, bool> result;
160 result = _textures.insert(Textures::value_type(texture, bytes));
168 Textures::iterator ti = result.first;
170 _duplicate_bytes += std::min(bytes, (*ti).second);
171 (*ti).second = std::max(bytes, (*ti).second);
178int TextureMemoryCounter::
187int TextureMemoryCounter::
188count_bytes(
ImageFile *image,
int x_size,
int y_size) {
189 int pixels = x_size * y_size;
197 case EggTexture::F_rgba12:
201 case EggTexture::F_rgba:
202 case EggTexture::F_rgbm:
203 case EggTexture::F_rgba8:
207 case EggTexture::F_rgb:
208 case EggTexture::F_rgb12:
212 case EggTexture::F_rgba4:
213 case EggTexture::F_rgba5:
214 case EggTexture::F_rgb8:
215 case EggTexture::F_rgb5:
216 case EggTexture::F_luminance_alpha:
217 case EggTexture::F_luminance_alphamask:
221 case EggTexture::F_rgb332:
222 case EggTexture::F_red:
223 case EggTexture::F_green:
224 case EggTexture::F_blue:
225 case EggTexture::F_alpha:
226 case EggTexture::F_luminance:
234 int bytes = pixels * bpp;
238 case EggTexture::FT_nearest_mipmap_nearest:
239 case EggTexture::FT_linear_mipmap_nearest:
240 case EggTexture::FT_nearest_mipmap_linear:
241 case EggTexture::FT_linear_mipmap_linear:
242 bytes = (bytes * 4) / 3;
This represents a texture filename as it has been resized and copied to the map directory (e....
This is the base class of both TextureImage and PaletteImage.
int get_num_channels() const
Returns the number of channels of the image.
int get_x_size() const
Returns the size of the image file in pixels in the X direction.
const TextureProperties & get_properties() const
Returns the grouping properties of the image.
int get_y_size() const
Returns the size of the image file in pixels in the Y direction.
This is a single palette image, one of several within a PalettePage, which is in turn one of several ...
double count_utilization() const
Returns the fraction of the PaletteImage that is actually used by any textures.
double count_coverage() const
Returns the a weighted average of the fraction of coverage represented by all of the textures placed ...
This represents a single source texture that is referenced by one or more egg files.
void add_placement(TexturePlacement *placement)
Adds the indicated TexturePlacement to the counter.
void report(std::ostream &out, int indent_level)
Reports the measured texture memory usage.
void reset()
Resets the count to zero.
This corresponds to a particular assignment of a TextureImage with a PaletteGroup,...
OmitReason get_omit_reason() const
Returns the reason the texture has been omitted from a palette image, or OR_none if it has not.
DestTextureImage * get_dest() const
Returns the DestTextureImage that corresponds to this texture as it was copied to the install directo...
int get_placed_x_size() const
Returns the size in the X dimension, in pixels, of the texture image as it has been placed within the...
PaletteImage * get_image() const
Returns the particular PaletteImage on which the texture has been placed.
TextureImage * get_texture() const
Returns the texture that this placement represents.
int get_placed_y_size() const
Returns the size in the Y dimension, in pixels, of the texture image as it has been placed within the...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.