Panda3D
textureProperties.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file textureProperties.h
10  * @author drose
11  * @date 2000-11-28
12  */
13 
14 #ifndef TEXTUREPROPERTIES_H
15 #define TEXTUREPROPERTIES_H
16 
17 #include "pandatoolbase.h"
18 
19 #include "eggTexture.h"
20 #include "typedWritable.h"
21 
22 class PNMFileType;
23 class FactoryParams;
24 
25 /**
26  * This is the set of characteristics of a texture that, if different from
27  * another texture, prevent the two textures from sharing a PaletteImage. It
28  * includes properties such as mipmapping, number of channels, etc.
29  */
31 public:
34  void operator = (const TextureProperties &copy);
35 
36  void clear_basic();
37 
38  bool has_num_channels() const;
39  int get_num_channels() const;
40  void set_num_channels(int num_channels);
41  void force_grayscale();
42  void force_nonalpha();
43  bool uses_alpha() const;
44 
45  std::string get_string() const;
46  void update_properties(const TextureProperties &other);
47  void fully_define();
48 
49  void update_egg_tex(EggTexture *egg_tex) const;
50  bool egg_properties_match(const TextureProperties &other) const;
51 
52  bool operator < (const TextureProperties &other) const;
53  bool operator == (const TextureProperties &other) const;
54  bool operator != (const TextureProperties &other) const;
55 
56  EggTexture::Format _format;
57  bool _force_format; // true when format has been explicitly specified
58  bool _generic_format; // true if 'generic' keyword, meaning rgba8 -> rgba.
59  bool _keep_format; // true if 'keep-format' keyword.
60  EggTexture::FilterType _minfilter, _magfilter;
61  EggTexture::QualityLevel _quality_level;
62  int _anisotropic_degree;
63  PNMFileType *_color_type;
64  PNMFileType *_alpha_type;
65 
66 private:
67  static std::string get_format_string(EggTexture::Format format);
68  static std::string get_filter_string(EggTexture::FilterType filter_type);
69  static std::string get_anisotropic_degree_string(int aniso_degree);
70  static std::string get_quality_level_string(EggTexture::QualityLevel quality_level);
71  static std::string get_type_string(PNMFileType *color_type,
72  PNMFileType *alpha_type);
73 
74  static EggTexture::Format union_format(EggTexture::Format a,
75  EggTexture::Format b);
76 
77  static EggTexture::FilterType union_filter(EggTexture::FilterType a,
78  EggTexture::FilterType b);
79  static EggTexture::QualityLevel union_quality_level(EggTexture::QualityLevel a,
80  EggTexture::QualityLevel b);
81 
82  bool _got_num_channels;
83  int _num_channels;
84  int _effective_num_channels;
85 
86  // The TypedWritable interface follows.
87 public:
88  static void register_with_read_factory();
89  virtual void write_datagram(BamWriter *writer, Datagram &datagram);
90  virtual int complete_pointers(TypedWritable **p_list,
91  BamReader *manager);
92 
93 protected:
94  static TypedWritable *make_TextureProperties(const FactoryParams &params);
95 
96 public:
97  void fillin(DatagramIterator &scan, BamReader *manager);
98 
99 public:
100  static TypeHandle get_class_type() {
101  return _type_handle;
102  }
103  static void init_type() {
104  TypedWritable::init_type();
105  register_type(_type_handle, "TextureProperties",
106  TypedWritable::get_class_type());
107  }
108  virtual TypeHandle get_type() const {
109  return get_class_type();
110  }
111 
112 private:
113  static TypeHandle _type_handle;
114 };
115 
116 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
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...
Definition: bamReader.h:110
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:30
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
This is the base class of a family of classes that represent particular image file types that PNMImag...
Definition: pnmFileType.h:32
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...
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 ...
Definition: bamWriter.h:63
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.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
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.
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...
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...
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:81
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
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,...