Panda3D
 All Classes Functions Variables Enumerations
textureProperties.h
1 // Filename: textureProperties.h
2 // Created by: drose (28Nov00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef TEXTUREPROPERTIES_H
16 #define TEXTUREPROPERTIES_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "eggTexture.h"
21 #include "typedWritable.h"
22 
23 class PNMFileType;
24 class FactoryParams;
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : TextureProperties
28 // Description : This is the set of characteristics of a texture that,
29 // if different from another texture, prevent the two
30 // textures from sharing a PaletteImage. It includes
31 // properties such as mipmapping, number of channels,
32 // etc.
33 ////////////////////////////////////////////////////////////////////
35 public:
38  void operator = (const TextureProperties &copy);
39 
40  void clear_basic();
41 
42  bool has_num_channels() const;
43  int get_num_channels() const;
44  void set_num_channels(int num_channels);
45  void force_grayscale();
46  void force_nonalpha();
47  bool uses_alpha() const;
48 
49  string get_string() const;
50  void update_properties(const TextureProperties &other);
51  void fully_define();
52 
53  void update_egg_tex(EggTexture *egg_tex) const;
54  bool egg_properties_match(const TextureProperties &other) const;
55 
56  bool operator < (const TextureProperties &other) const;
57  bool operator == (const TextureProperties &other) const;
58  bool operator != (const TextureProperties &other) const;
59 
60  EggTexture::Format _format;
61  bool _force_format; // true when format has been explicitly specified
62  bool _generic_format; // true if 'generic' keyword, meaning rgba8 -> rgba.
63  bool _keep_format; // true if 'keep-format' keyword.
64  EggTexture::FilterType _minfilter, _magfilter;
65  EggTexture::QualityLevel _quality_level;
66  int _anisotropic_degree;
67  PNMFileType *_color_type;
68  PNMFileType *_alpha_type;
69 
70 private:
71  static string get_format_string(EggTexture::Format format);
72  static string get_filter_string(EggTexture::FilterType filter_type);
73  static string get_anisotropic_degree_string(int aniso_degree);
74  static string get_quality_level_string(EggTexture::QualityLevel quality_level);
75  static string get_type_string(PNMFileType *color_type,
76  PNMFileType *alpha_type);
77 
78  static EggTexture::Format union_format(EggTexture::Format a,
79  EggTexture::Format b);
80 
81  static EggTexture::FilterType union_filter(EggTexture::FilterType a,
82  EggTexture::FilterType b);
83  static EggTexture::QualityLevel union_quality_level(EggTexture::QualityLevel a,
84  EggTexture::QualityLevel b);
85 
86  bool _got_num_channels;
87  int _num_channels;
88  int _effective_num_channels;
89 
90  // The TypedWritable interface follows.
91 public:
92  static void register_with_read_factory();
93  virtual void write_datagram(BamWriter *writer, Datagram &datagram);
94  virtual int complete_pointers(TypedWritable **p_list,
95  BamReader *manager);
96 
97 protected:
98  static TypedWritable *make_TextureProperties(const FactoryParams &params);
99 
100 public:
101  void fillin(DatagramIterator &scan, BamReader *manager);
102 
103 public:
104  static TypeHandle get_class_type() {
105  return _type_handle;
106  }
107  static void init_type() {
108  TypedWritable::init_type();
109  register_type(_type_handle, "TextureProperties",
110  TypedWritable::get_class_type());
111  }
112  virtual TypeHandle get_type() const {
113  return get_class_type();
114  }
115 
116 private:
117  static TypeHandle _type_handle;
118 };
119 
120 #endif
121 
void set_num_channels(int num_channels)
Sets the number of channels (1 through 4) associated with the image, presumably after reading this in...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:33
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the base class of a family of classes that represent particular image file types that PNMImag...
Definition: pnmFileType.h:35
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Called after the object is otherwise completely read from a Bam file, this function&#39;s job is to store...
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
int get_num_channels() const
Returns the number of channels (1 through 4) associated with the image.
void update_egg_tex(EggTexture *egg_tex) const
Adjusts the texture properties of the indicated egg reference to match these properties.
bool uses_alpha() const
Returns true if the texture uses an alpha channel, false otherwise.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
void force_nonalpha()
Sets the actual number of channels to indicate an image with no alpha channel, presumably after disco...
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...
void fillin(DatagramIterator &scan, BamReader *manager)
Reads the binary data from the given datagram iterator, which was written by a previous call to write...
bool has_num_channels() const
Returns true if the number of channels is known.
string get_string() const
Returns a string corresponding to the TextureProperties object.
void force_grayscale()
Sets the actual number of channels to indicate a grayscale image, presumably after discovering that t...
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.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
void fully_define()
If any properties remain unspecified, specify them now.
This is the set of characteristics of a texture that, if different from another texture, prevent the two textures from sharing a PaletteImage.