00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef EGGTEXTURE_H
00020 #define EGGTEXTURE_H
00021
00022 #include <pandabase.h>
00023
00024 #include "eggRenderMode.h"
00025 #include "eggFilenameNode.h"
00026
00027 #include <luse.h>
00028
00029
00030
00031
00032
00033
00034
00035 class EXPCL_PANDAEGG EggTexture : public EggFilenameNode, public EggRenderMode {
00036 public:
00037 EggTexture(const string &tref_name, const string &filename);
00038 EggTexture(const EggTexture ©);
00039 EggTexture &operator = (const EggTexture ©);
00040
00041 virtual void write(ostream &out, int indent_level) const;
00042
00043 enum Equivalence {
00044 E_basename = 0x001,
00045 E_extension = 0x002,
00046 E_dirname = 0x004,
00047 E_complete_filename = 0x007,
00048 E_transform = 0x008,
00049 E_attributes = 0x010,
00050 E_tref_name = 0x020,
00051 };
00052
00053 bool is_equivalent_to(const EggTexture &other, int eq) const;
00054 bool sorts_less_than(const EggTexture &other, int eq) const;
00055
00056 bool has_alpha_channel(int num_components) const;
00057
00058 enum Format {
00059 F_unspecified,
00060 F_rgba, F_rgbm, F_rgba12, F_rgba8, F_rgba4, F_rgba5,
00061 F_rgb, F_rgb12, F_rgb8, F_rgb5, F_rgb332,
00062 F_red, F_green, F_blue, F_alpha, F_luminance,
00063 F_luminance_alpha, F_luminance_alphamask
00064 };
00065 enum WrapMode {
00066 WM_unspecified, WM_repeat, WM_clamp
00067 };
00068 enum FilterType {
00069
00070
00071
00072
00073 FT_unspecified,
00074
00075
00076 FT_nearest,
00077 FT_linear,
00078
00079
00080 FT_nearest_mipmap_nearest,
00081 FT_linear_mipmap_nearest,
00082 FT_nearest_mipmap_linear,
00083 FT_linear_mipmap_linear,
00084 };
00085 enum EnvType {
00086 ET_unspecified, ET_modulate, ET_decal
00087 };
00088
00089 INLINE void set_format(Format format);
00090 INLINE Format get_format() const;
00091
00092 INLINE void set_wrap_mode(WrapMode mode);
00093 INLINE WrapMode get_wrap_mode() const;
00094
00095 INLINE void set_wrap_u(WrapMode mode);
00096 INLINE WrapMode get_wrap_u() const;
00097 INLINE WrapMode determine_wrap_u() const;
00098
00099 INLINE void set_wrap_v(WrapMode mode);
00100 INLINE WrapMode get_wrap_v() const;
00101 INLINE WrapMode determine_wrap_v() const;
00102
00103 INLINE void set_minfilter(FilterType type);
00104 INLINE FilterType get_minfilter() const;
00105
00106 INLINE void set_magfilter(FilterType type);
00107 INLINE FilterType get_magfilter() const;
00108
00109 INLINE void set_anisotropic_degree(int anisotropic_degree);
00110 INLINE void clear_anisotropic_degree();
00111 INLINE bool has_anisotropic_degree() const;
00112 INLINE int get_anisotropic_degree() const;
00113
00114 INLINE void set_env_type(EnvType type);
00115 INLINE EnvType get_env_type() const;
00116
00117 INLINE void set_transform(const LMatrix3d &transform);
00118 INLINE void clear_transform();
00119 INLINE bool has_transform() const;
00120 INLINE const LMatrix3d &get_transform() const;
00121 INLINE bool transform_is_identity() const;
00122
00123 INLINE void set_alpha_filename(const Filename &filename);
00124 INLINE void clear_alpha_filename();
00125 INLINE bool has_alpha_filename() const;
00126 INLINE const Filename &get_alpha_filename() const;
00127
00128 INLINE void set_alpha_fullpath(const Filename &fullpath);
00129 INLINE const Filename &get_alpha_fullpath() const;
00130
00131 INLINE void set_alpha_file_channel(int alpha_file_channel);
00132 INLINE void clear_alpha_file_channel();
00133 INLINE bool has_alpha_file_channel() const;
00134 INLINE int get_alpha_file_channel() const;
00135
00136 static Format string_format(const string &string);
00137 static WrapMode string_wrap_mode(const string &string);
00138 static FilterType string_filter_type(const string &string);
00139 static EnvType string_env_type(const string &string);
00140
00141 protected:
00142 virtual bool egg_start_parse_body();
00143
00144 private:
00145 enum Flags {
00146 F_has_transform = 0x0001,
00147 F_has_alpha_filename = 0x0002,
00148 F_has_anisotropic_degree = 0x0004,
00149 F_has_alpha_file_channel = 0x0008,
00150 };
00151
00152 Format _format;
00153 WrapMode _wrap_mode, _wrap_u, _wrap_v;
00154 FilterType _minfilter, _magfilter;
00155 int _anisotropic_degree;
00156 EnvType _env_type;
00157 int _flags;
00158 LMatrix3d _transform;
00159 Filename _alpha_filename;
00160 Filename _alpha_fullpath;
00161 int _alpha_file_channel;
00162
00163
00164 public:
00165 static TypeHandle get_class_type() {
00166 return _type_handle;
00167 }
00168 static void init_type() {
00169 EggFilenameNode::init_type();
00170 EggRenderMode::init_type();
00171 register_type(_type_handle, "EggTexture",
00172 EggFilenameNode::get_class_type(),
00173 EggRenderMode::get_class_type());
00174 }
00175 virtual TypeHandle get_type() const {
00176 return get_class_type();
00177 }
00178 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00179
00180 private:
00181 static TypeHandle _type_handle;
00182 };
00183
00184
00185
00186
00187
00188
00189
00190
00191 class EXPCL_PANDAEGG UniqueEggTextures {
00192 public:
00193 INLINE UniqueEggTextures(int eq = ~0);
00194 INLINE bool operator ()(const EggTexture *t1, const EggTexture *t2) const;
00195
00196 int _eq;
00197 };
00198
00199 INLINE ostream &operator << (ostream &out, const EggTexture &n) {
00200 return out << n.get_filename();
00201 }
00202
00203 ostream EXPCL_PANDAEGG &operator << (ostream &out, EggTexture::Format format);
00204 ostream EXPCL_PANDAEGG &operator << (ostream &out, EggTexture::WrapMode mode);
00205 ostream EXPCL_PANDAEGG &operator << (ostream &out, EggTexture::FilterType type);
00206 ostream EXPCL_PANDAEGG &operator << (ostream &out, EggTexture::EnvType type);
00207
00208 #include "eggTexture.I"
00209
00210 #endif