32 _got_num_channels =
false;
34 _effective_num_channels = 0;
35 _format = EggTexture::F_unspecified;
36 _force_format =
false;
37 _generic_format =
false;
39 _minfilter = EggTexture::FT_unspecified;
40 _magfilter = EggTexture::FT_unspecified;
41 _quality_level = EggTexture::QL_unspecified;
42 _anisotropic_degree = 0;
43 _color_type =
nullptr;
44 _alpha_type =
nullptr;
52 _format(copy._format),
53 _force_format(copy._force_format),
54 _generic_format(copy._generic_format),
55 _keep_format(copy._keep_format),
56 _minfilter(copy._minfilter),
57 _magfilter(copy._magfilter),
58 _quality_level(copy._quality_level),
59 _anisotropic_degree(copy._anisotropic_degree),
60 _color_type(copy._color_type),
61 _alpha_type(copy._alpha_type),
62 _got_num_channels(copy._got_num_channels),
63 _num_channels(copy._num_channels),
64 _effective_num_channels(copy._effective_num_channels)
71 void TextureProperties::
73 _force_format = copy._force_format;
74 _generic_format = copy._generic_format;
75 _keep_format = copy._keep_format;
76 _minfilter = copy._minfilter;
77 _magfilter = copy._magfilter;
78 _quality_level = copy._quality_level;
79 _anisotropic_degree = copy._anisotropic_degree;
80 _color_type = copy._color_type;
81 _alpha_type = copy._alpha_type;
82 _got_num_channels = copy._got_num_channels;
83 _num_channels = copy._num_channels;
84 _effective_num_channels = copy._effective_num_channels;
85 _format = copy._format;
95 _format = EggTexture::F_unspecified;
98 _minfilter = EggTexture::FT_unspecified;
99 _magfilter = EggTexture::FT_unspecified;
100 _quality_level = EggTexture::QL_unspecified;
101 _anisotropic_degree = 0;
109 return _got_num_channels;
118 nassertr(_got_num_channels, 0);
119 return _effective_num_channels;
128 _num_channels = num_channels;
129 _effective_num_channels = num_channels;
130 _got_num_channels =
true;
139 nassertv(_got_num_channels && _num_channels >= 3);
141 _effective_num_channels = _num_channels;
151 nassertv(_got_num_channels && (_num_channels == 2 || _num_channels == 4));
153 _effective_num_channels = _num_channels;
162 case EggTexture::F_rgba:
163 case EggTexture::F_rgbm:
164 case EggTexture::F_rgba12:
165 case EggTexture::F_rgba8:
166 case EggTexture::F_rgba4:
167 case EggTexture::F_rgba5:
168 case EggTexture::F_alpha:
169 case EggTexture::F_luminance_alpha:
170 case EggTexture::F_luminance_alphamask:
187 if (_got_num_channels) {
188 std::ostringstream num;
189 num << _effective_num_channels;
193 result += get_format_string(_format);
194 result += get_filter_string(_minfilter);
195 result += get_filter_string(_magfilter);
196 result += get_anisotropic_degree_string(_anisotropic_degree);
197 result += get_type_string(_color_type, _alpha_type);
198 result += get_quality_level_string(_quality_level);
208 if (!_got_num_channels) {
209 _got_num_channels = other._got_num_channels;
210 _num_channels = other._num_channels;
211 _effective_num_channels = _num_channels;
215 }
else if (other._force_format) {
216 _format = other._format;
218 _format = union_format(_format, other._format);
221 _minfilter = union_filter(_minfilter, other._minfilter);
222 _magfilter = union_filter(_magfilter, other._magfilter);
223 _quality_level = union_quality_level(_quality_level, other._quality_level);
225 _anisotropic_degree = other._anisotropic_degree;
227 if (_color_type ==
nullptr) {
228 _color_type = other._color_type;
229 _alpha_type = other._alpha_type;
239 if (!_got_num_channels || _force_format) {
241 case EggTexture::F_rgba:
242 case EggTexture::F_rgbm:
243 case EggTexture::F_rgba12:
244 case EggTexture::F_rgba8:
245 case EggTexture::F_rgba4:
246 case EggTexture::F_rgba5:
250 case EggTexture::F_unspecified:
251 case EggTexture::F_rgb:
252 case EggTexture::F_rgb12:
253 case EggTexture::F_rgb8:
254 case EggTexture::F_rgb5:
255 case EggTexture::F_rgb332:
259 case EggTexture::F_luminance_alpha:
260 case EggTexture::F_luminance_alphamask:
264 case EggTexture::F_red:
265 case EggTexture::F_green:
266 case EggTexture::F_blue:
267 case EggTexture::F_alpha:
268 case EggTexture::F_luminance:
272 _got_num_channels =
true;
275 _effective_num_channels = _num_channels;
280 if (_generic_format) {
282 case EggTexture::F_unspecified:
283 case EggTexture::F_rgba:
284 case EggTexture::F_rgbm:
285 case EggTexture::F_rgb:
286 case EggTexture::F_red:
287 case EggTexture::F_green:
288 case EggTexture::F_blue:
289 case EggTexture::F_alpha:
290 case EggTexture::F_luminance:
291 case EggTexture::F_luminance_alpha:
292 case EggTexture::F_luminance_alphamask:
295 case EggTexture::F_rgba12:
296 case EggTexture::F_rgba8:
297 case EggTexture::F_rgba4:
298 case EggTexture::F_rgba5:
299 _format = EggTexture::F_rgba;
302 case EggTexture::F_rgb12:
303 case EggTexture::F_rgb8:
304 case EggTexture::F_rgb5:
305 case EggTexture::F_rgb332:
306 _format = EggTexture::F_rgb;
313 if (!_force_format && !_keep_format) {
314 switch (_num_channels) {
317 case EggTexture::F_red:
318 case EggTexture::F_green:
319 case EggTexture::F_blue:
320 case EggTexture::F_alpha:
321 case EggTexture::F_luminance:
326 case EggTexture::F_luminance_alpha:
327 case EggTexture::F_luminance_alphamask:
328 _format = EggTexture::F_luminance;
332 _format = EggTexture::F_luminance;
338 case EggTexture::F_luminance_alpha:
339 case EggTexture::F_luminance_alphamask:
343 case EggTexture::F_red:
344 case EggTexture::F_green:
345 case EggTexture::F_blue:
346 case EggTexture::F_alpha:
347 case EggTexture::F_luminance:
351 _format = EggTexture::F_luminance_alpha;
357 case EggTexture::F_rgb:
358 case EggTexture::F_rgb12:
359 case EggTexture::F_rgb8:
360 case EggTexture::F_rgb5:
361 case EggTexture::F_rgb332:
366 case EggTexture::F_rgba8:
367 _format = EggTexture::F_rgb8;
370 case EggTexture::F_rgba5:
371 case EggTexture::F_rgba4:
372 _format = EggTexture::F_rgb5;
376 case EggTexture::F_red:
377 case EggTexture::F_green:
378 case EggTexture::F_blue:
379 case EggTexture::F_alpha:
380 case EggTexture::F_luminance:
384 _format = EggTexture::F_rgb;
390 case EggTexture::F_rgba:
391 case EggTexture::F_rgbm:
392 case EggTexture::F_rgba12:
393 case EggTexture::F_rgba8:
394 case EggTexture::F_rgba4:
395 case EggTexture::F_rgba5:
399 case EggTexture::F_rgb:
400 case EggTexture::F_rgb12:
401 case EggTexture::F_rgb8:
402 case EggTexture::F_rgb5:
403 case EggTexture::F_rgb332:
404 _effective_num_channels = 3;
408 case EggTexture::F_luminance_alpha:
409 case EggTexture::F_luminance_alphamask:
410 _effective_num_channels = 2;
414 case EggTexture::F_red:
415 case EggTexture::F_green:
416 case EggTexture::F_blue:
417 case EggTexture::F_alpha:
418 case EggTexture::F_luminance:
419 _effective_num_channels = 1;
423 _format = EggTexture::F_rgba;
428 switch (_minfilter) {
429 case EggTexture::FT_unspecified:
430 _minfilter = EggTexture::FT_linear;
437 switch (_magfilter) {
438 case EggTexture::FT_unspecified:
439 case EggTexture::FT_nearest_mipmap_nearest:
440 case EggTexture::FT_linear_mipmap_nearest:
441 case EggTexture::FT_nearest_mipmap_linear:
442 case EggTexture::FT_linear_mipmap_linear:
443 _magfilter = EggTexture::FT_linear;
450 if (_color_type ==
nullptr) {
451 _color_type = pal->_color_type;
452 _alpha_type = pal->_alpha_type;
462 egg_tex->set_format(_format);
463 egg_tex->set_minfilter(_minfilter);
464 egg_tex->set_magfilter(_minfilter);
465 egg_tex->set_quality_level(_quality_level);
476 return (_format == other._format &&
477 _minfilter == other._minfilter &&
478 _magfilter == other._magfilter &&
479 _quality_level == other._quality_level &&
480 _anisotropic_degree == other._anisotropic_degree);
486 bool TextureProperties::
488 if (_format != other._format) {
489 return (
int)_format < (int)other._format;
491 if (_minfilter != other._minfilter) {
492 return (
int)_minfilter < (int)other._minfilter;
494 if (_magfilter != other._magfilter) {
495 return (
int)_magfilter < (int)other._magfilter;
497 if (_quality_level != other._quality_level) {
498 return (
int)_quality_level < (int)other._quality_level;
500 if (_anisotropic_degree != other._anisotropic_degree) {
501 return _anisotropic_degree < other._anisotropic_degree;
503 if (_color_type != other._color_type) {
504 return _color_type < other._color_type;
506 if (_color_type !=
nullptr) {
507 if (_alpha_type != other._alpha_type) {
508 return _alpha_type < other._alpha_type;
517 bool TextureProperties::
519 return (_format == other._format &&
520 _minfilter == other._minfilter &&
521 _magfilter == other._magfilter &&
522 _quality_level == other._quality_level &&
523 _anisotropic_degree == other._anisotropic_degree &&
524 _color_type == other._color_type &&
525 (_color_type ==
nullptr ||
526 _alpha_type == other._alpha_type));
532 bool TextureProperties::
534 return !operator == (other);
540 string TextureProperties::
541 get_format_string(EggTexture::Format format) {
543 case EggTexture::F_unspecified:
546 case EggTexture::F_rgba:
549 case EggTexture::F_rgbm:
552 case EggTexture::F_rgba12:
555 case EggTexture::F_rgba8:
558 case EggTexture::F_rgba4:
561 case EggTexture::F_rgba5:
564 case EggTexture::F_rgb:
567 case EggTexture::F_rgb12:
570 case EggTexture::F_rgb8:
573 case EggTexture::F_rgb5:
576 case EggTexture::F_rgb332:
579 case EggTexture::F_luminance_alpha:
582 case EggTexture::F_luminance_alphamask:
585 case EggTexture::F_red:
588 case EggTexture::F_green:
591 case EggTexture::F_blue:
594 case EggTexture::F_alpha:
597 case EggTexture::F_luminance:
607 string TextureProperties::
608 get_filter_string(EggTexture::FilterType filter_type) {
609 switch (filter_type) {
610 case EggTexture::FT_unspecified:
613 case EggTexture::FT_nearest:
616 case EggTexture::FT_linear:
619 case EggTexture::FT_nearest_mipmap_nearest:
622 case EggTexture::FT_linear_mipmap_nearest:
625 case EggTexture::FT_nearest_mipmap_linear:
628 case EggTexture::FT_linear_mipmap_linear:
638 string TextureProperties::
639 get_anisotropic_degree_string(
int aniso_degree) {
640 if (aniso_degree <= 1) {
643 return string(
"an") + format_string(aniso_degree);
650 string TextureProperties::
651 get_quality_level_string(EggTexture::QualityLevel quality_level) {
652 switch (quality_level) {
653 case EggTexture::QL_unspecified:
654 case EggTexture::QL_default:
657 case EggTexture::QL_fastest:
660 case EggTexture::QL_normal:
663 case EggTexture::QL_best:
673 string TextureProperties::
675 if (color_type ==
nullptr) {
678 if (alpha_type ==
nullptr) {
687 EggTexture::Format TextureProperties::
688 union_format(EggTexture::Format a, EggTexture::Format b) {
690 case EggTexture::F_unspecified:
693 case EggTexture::F_rgba:
695 case EggTexture::F_rgbm:
696 case EggTexture::F_rgba12:
697 case EggTexture::F_rgba8:
698 case EggTexture::F_rgba4:
699 case EggTexture::F_rgba5:
700 case EggTexture::F_red:
701 case EggTexture::F_green:
702 case EggTexture::F_blue:
703 case EggTexture::F_alpha:
710 case EggTexture::F_rgb:
711 if (b != EggTexture::F_unspecified) {
724 EggTexture::FilterType TextureProperties::
725 union_filter(EggTexture::FilterType a, EggTexture::FilterType b) {
726 if ((
int)a < (
int)b) {
736 EggTexture::QualityLevel TextureProperties::
737 union_quality_level(EggTexture::QualityLevel a, EggTexture::QualityLevel b) {
738 if ((
int)a < (
int)b) {
751 register_factory(get_class_type(), make_TextureProperties);
761 datagram.
add_bool(_got_num_channels);
763 datagram.
add_int32(_effective_num_channels);
786 if (p_list[index] !=
nullptr) {
787 DCAST_INTO_R(_color_type, p_list[index], index);
791 if (p_list[index] !=
nullptr) {
792 DCAST_INTO_R(_alpha_type, p_list[index], index);
811 me->
fillin(scan, manager);
822 _got_num_channels = scan.
get_bool();
824 _effective_num_channels = _num_channels;
825 if (Palettizer::_read_pi_version >= 9) {
826 _effective_num_channels = scan.
get_int32();
828 _format = (EggTexture::Format)scan.
get_int32();
830 _generic_format =
false;
831 if (Palettizer::_read_pi_version >= 9) {
834 _keep_format =
false;
835 if (Palettizer::_read_pi_version >= 13) {
838 _minfilter = (EggTexture::FilterType)scan.
get_int32();
839 _magfilter = (EggTexture::FilterType)scan.
get_int32();
840 if (Palettizer::_read_pi_version >= 18) {
841 _quality_level = (EggTexture::QualityLevel)scan.
get_int32();
void set_num_channels(int num_channels)
Sets the number of channels (1 through 4) associated with the image, presumably after reading this in...
int get_num_channels() const
Returns the number of channels (1 through 4) associated with the image.
bool get_bool()
Extracts a boolean value.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Defines a texture map that may be applied to geometry.
Base class for objects that can be written to and read from Bam files.
This is the base class of a family of classes that represent particular image file types that PNMImag...
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Called after the object is otherwise completely read from a Bam file, this function's job is to store...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
set_anisotropic_degree
Sets the degree of anisotropic filtering for this texture.
int32_t get_int32()
Extracts a signed 32-bit integer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
void update_egg_tex(EggTexture *egg_tex) const
Adjusts the texture properties of the indicated egg reference to match these properties.
std::string get_string() const
Returns a string corresponding to the TextureProperties object.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
void add_bool(bool value)
Adds a boolean value to the datagram.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
An instance of this class is passed to the Factory when requesting it to do its business and construc...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void force_nonalpha()
Sets the actual number of channels to indicate an image with no alpha channel, presumably after disco...
bool uses_alpha() const
Returns true if the texture uses an alpha channel, false otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool has_num_channels() const
Returns true if the number of channels is known.
void fillin(DatagramIterator &scan, BamReader *manager)
Reads the binary data from the given datagram iterator, which was written by a previous call to write...
void force_grayscale()
Sets the actual number of channels to indicate a grayscale image, presumably after discovering that t...
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
bool egg_properties_match(const TextureProperties &other) const
Returns true if all of the properties that are reflected directly in an egg file match between this T...
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
void clear_basic()
Resets only the properties that might be changed by update_properties() to a neutral state.
A class to retrieve the individual data elements previously stored in a Datagram.
void update_properties(const TextureProperties &other)
If the indicate TextureProperties structure is more specific than this one, updates this one.
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void fully_define()
If any properties remain unspecified, specify them now.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
This is the set of characteristics of a texture that, if different from another texture,...