Panda3D

eggTexture.h

00001 // Filename: eggTexture.h
00002 // Created by:  drose (18Jan99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef EGGTEXTURE_H
00016 #define EGGTEXTURE_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "eggRenderMode.h"
00021 #include "eggFilenameNode.h"
00022 #include "eggTransform.h"
00023 
00024 #include "pset.h"
00025 #include "luse.h"
00026 
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //       Class : EggTexture
00030 // Description : Defines a texture map that may be applied to
00031 //               geometry.
00032 ////////////////////////////////////////////////////////////////////
00033 class EXPCL_PANDAEGG EggTexture : public EggFilenameNode, public EggRenderMode, public EggTransform {
00034 PUBLISHED:
00035   EggTexture(const string &tref_name, const Filename &filename);
00036   EggTexture(const EggTexture &copy);
00037   EggTexture &operator = (const EggTexture &copy);
00038   virtual ~EggTexture(); 
00039 
00040   virtual void write(ostream &out, int indent_level) const;
00041 
00042   enum Equivalence {
00043     E_basename             = 0x001,
00044     E_extension            = 0x002,
00045     E_dirname              = 0x004,
00046     E_complete_filename    = 0x007,
00047     E_transform            = 0x008,
00048     E_attributes           = 0x010,
00049     E_tref_name            = 0x020,
00050   };
00051 
00052   bool is_equivalent_to(const EggTexture &other, int eq) const;
00053   bool sorts_less_than(const EggTexture &other, int eq) const;
00054 
00055   bool has_alpha_channel(int num_components) const;
00056 
00057   enum TextureType {
00058     TT_unspecified, TT_1d_texture,
00059     TT_2d_texture, TT_3d_texture, TT_cube_map
00060   };
00061   enum Format {
00062     F_unspecified,
00063     F_rgba, F_rgbm, F_rgba12, F_rgba8, F_rgba4, F_rgba5,
00064     F_rgb, F_rgb12, F_rgb8, F_rgb5, F_rgb332,
00065     F_red, F_green, F_blue, F_alpha, F_luminance,
00066     F_luminance_alpha, F_luminance_alphamask
00067   };
00068   enum CompressionMode {
00069     CM_default, CM_off, CM_on,
00070     CM_fxt1, CM_dxt1, CM_dxt2, CM_dxt3, CM_dxt4, CM_dxt5,
00071   };
00072   enum WrapMode {
00073     WM_unspecified, WM_clamp, WM_repeat,
00074     WM_mirror, WM_mirror_once, WM_border_color
00075   };
00076   enum FilterType {
00077     // Note that these type values match up, name-for-name, with a
00078     // similar enumerated type in Panda's Texture object.  However,
00079     // they do *not* match up numerically.  You must convert between
00080     // them using a switch statement.
00081     FT_unspecified,
00082 
00083     // Mag Filter and Min Filter
00084     FT_nearest,
00085     FT_linear,
00086 
00087     // Min Filter Only
00088     FT_nearest_mipmap_nearest,   // "mipmap point"
00089     FT_linear_mipmap_nearest,    // "mipmap linear"
00090     FT_nearest_mipmap_linear,    // "mipmap bilinear"
00091     FT_linear_mipmap_linear,     // "mipmap trilinear"
00092   };
00093   enum EnvType {
00094     ET_unspecified, 
00095     ET_modulate, 
00096     ET_decal,
00097     ET_blend,
00098     ET_replace,
00099     ET_add,
00100     ET_blend_color_scale,
00101     ET_modulate_glow,
00102     ET_modulate_gloss,
00103     ET_normal,
00104     ET_normal_height,
00105     ET_glow,
00106     ET_gloss,
00107     ET_height,
00108     ET_selector,
00109   };
00110   enum CombineMode {
00111     CM_unspecified,
00112     CM_replace,
00113     CM_modulate,
00114     CM_add,
00115     CM_add_signed,
00116     CM_interpolate,
00117     CM_subtract,
00118     CM_dot3_rgb,
00119     CM_dot3_rgba,
00120   };
00121   enum CombineChannel {
00122     CC_rgb = 0,
00123     CC_alpha = 1,
00124     CC_num_channels = 2,
00125   };
00126   enum CombineIndex {
00127     CI_num_indices = 3
00128   };
00129   enum CombineSource {
00130     CS_unspecified,
00131     CS_texture,
00132     CS_constant,
00133     CS_primary_color,
00134     CS_previous,
00135     CS_constant_color_scale,
00136     CS_last_saved_result,
00137   };
00138   enum CombineOperand {
00139     CO_unspecified,
00140     CO_src_color,
00141     CO_one_minus_src_color,
00142     CO_src_alpha,
00143     CO_one_minus_src_alpha,
00144   };
00145   enum TexGen {
00146     TG_unspecified,
00147 
00148     TG_eye_sphere_map,
00149 
00150     TG_world_cube_map,
00151     TG_eye_cube_map,
00152 
00153     TG_world_normal,
00154     TG_eye_normal,
00155 
00156     TG_world_position,
00157     TG_eye_position,
00158 
00159     TG_point_sprite,
00160   };
00161   enum QualityLevel {
00162     QL_unspecified,
00163     QL_default,
00164     QL_fastest,
00165     QL_normal,
00166     QL_best,
00167   };
00168 
00169   INLINE void set_texture_type(TextureType texture_type);
00170   INLINE TextureType get_texture_type() const;
00171 
00172   INLINE void set_format(Format format);
00173   INLINE Format get_format() const;
00174 
00175   INLINE void set_compression_mode(CompressionMode mode);
00176   INLINE CompressionMode get_compression_mode() const;
00177 
00178   INLINE void set_wrap_mode(WrapMode mode);
00179   INLINE WrapMode get_wrap_mode() const;
00180 
00181   INLINE void set_wrap_u(WrapMode mode);
00182   INLINE WrapMode get_wrap_u() const;
00183   INLINE WrapMode determine_wrap_u() const;
00184 
00185   INLINE void set_wrap_v(WrapMode mode);
00186   INLINE WrapMode get_wrap_v() const;
00187   INLINE WrapMode determine_wrap_v() const;
00188 
00189   INLINE void set_wrap_w(WrapMode mode);
00190   INLINE WrapMode get_wrap_w() const;
00191   INLINE WrapMode determine_wrap_w() const;
00192 
00193   INLINE void set_minfilter(FilterType type);
00194   INLINE FilterType get_minfilter() const;
00195 
00196   INLINE void set_magfilter(FilterType type);
00197   INLINE FilterType get_magfilter() const;
00198 
00199   INLINE void set_anisotropic_degree(int anisotropic_degree);
00200   INLINE void clear_anisotropic_degree();
00201   INLINE bool has_anisotropic_degree() const;
00202   INLINE int get_anisotropic_degree() const;
00203 
00204   INLINE void set_env_type(EnvType type);
00205   INLINE EnvType get_env_type() const;
00206   bool affects_polygon_alpha() const;
00207 
00208   INLINE void set_combine_mode(CombineChannel channel, CombineMode cm);
00209   INLINE CombineMode get_combine_mode(CombineChannel channel) const;
00210   INLINE void set_combine_source(CombineChannel channel, int n, CombineSource cs);
00211   INLINE CombineSource get_combine_source(CombineChannel channel, int n) const;
00212   INLINE void set_combine_operand(CombineChannel channel, int n, CombineOperand co);
00213   INLINE CombineOperand get_combine_operand(CombineChannel channel, int n) const;
00214 
00215   INLINE void set_saved_result(bool saved_result);
00216   INLINE bool get_saved_result() const;
00217 
00218   INLINE void set_tex_gen(TexGen tex_gen);
00219   INLINE TexGen get_tex_gen() const;
00220 
00221   INLINE void set_quality_level(QualityLevel quality_level);
00222   INLINE QualityLevel get_quality_level() const;
00223 
00224   INLINE void set_stage_name(const string &stage_name);
00225   INLINE void clear_stage_name();
00226   INLINE bool has_stage_name() const;
00227   INLINE const string &get_stage_name() const;
00228 
00229   INLINE void set_priority(int priority);
00230   INLINE void clear_priority();
00231   INLINE bool has_priority() const;
00232   INLINE int get_priority() const;
00233 
00234   INLINE void set_color(const Colorf &color);
00235   INLINE void clear_color();
00236   INLINE bool has_color() const;
00237   INLINE const Colorf &get_color() const;
00238 
00239   INLINE void set_border_color(const Colorf &border_color);
00240   INLINE void clear_border_color();
00241   INLINE bool has_border_color() const;
00242   INLINE const Colorf &get_border_color() const;
00243 
00244   INLINE void set_uv_name(const string &uv_name);
00245   INLINE void clear_uv_name();
00246   INLINE bool has_uv_name() const;
00247   INLINE const string &get_uv_name() const;
00248 
00249   INLINE void set_rgb_scale(int rgb_scale);
00250   INLINE void clear_rgb_scale();
00251   INLINE bool has_rgb_scale() const;
00252   INLINE int get_rgb_scale() const;
00253 
00254   INLINE void set_alpha_scale(int alpha_scale);
00255   INLINE void clear_alpha_scale();
00256   INLINE bool has_alpha_scale() const;
00257   INLINE int get_alpha_scale() const;
00258 
00259   INLINE void set_alpha_filename(const Filename &filename);
00260   INLINE void clear_alpha_filename();
00261   INLINE bool has_alpha_filename() const;
00262   INLINE const Filename &get_alpha_filename() const;
00263 
00264   INLINE void set_alpha_fullpath(const Filename &fullpath);
00265   INLINE const Filename &get_alpha_fullpath() const;
00266 
00267   INLINE void set_alpha_file_channel(int alpha_file_channel);
00268   INLINE void clear_alpha_file_channel();
00269   INLINE bool has_alpha_file_channel() const;
00270   INLINE int get_alpha_file_channel() const;
00271 
00272   INLINE void set_read_mipmaps(bool read_mipmaps);
00273   INLINE bool get_read_mipmaps() const;
00274 
00275 
00276   void clear_multitexture();
00277   bool multitexture_over(EggTexture *other);
00278   INLINE int get_multitexture_sort() const;
00279 
00280   static TextureType string_texture_type(const string &string);
00281   static Format string_format(const string &string);
00282   static CompressionMode string_compression_mode(const string &string);
00283   static WrapMode string_wrap_mode(const string &string);
00284   static FilterType string_filter_type(const string &string);
00285   static EnvType string_env_type(const string &string);
00286   static CombineMode string_combine_mode(const string &string);
00287   static CombineSource string_combine_source(const string &string);
00288   static CombineOperand string_combine_operand(const string &string);
00289   static TexGen string_tex_gen(const string &string);
00290   static QualityLevel string_quality_level(const string &string);
00291 
00292 public:
00293   virtual EggTransform *as_transform();
00294 
00295 protected:
00296   virtual bool egg_start_parse_body();
00297 
00298 private:
00299   typedef pset<EggTexture *> MultiTextures;
00300   bool r_min_multitexture_sort(int sort, MultiTextures &cycle_detector);
00301 
00302   enum Flags {
00303     F_has_alpha_filename     = 0x0002,
00304     F_has_anisotropic_degree = 0x0004,
00305     F_has_alpha_file_channel = 0x0008,
00306     F_has_stage_name         = 0x0010,
00307     F_has_uv_name            = 0x0020,
00308     F_has_priority           = 0x0040,
00309     F_has_color              = 0x0080,
00310     F_has_rgb_scale          = 0x0100,
00311     F_has_alpha_scale        = 0x0200,
00312     F_has_border_color       = 0x0400,
00313   };
00314 
00315   TextureType _texture_type;
00316   Format _format;
00317   CompressionMode _compression_mode;
00318   WrapMode _wrap_mode, _wrap_u, _wrap_v, _wrap_w;
00319   FilterType _minfilter, _magfilter;
00320   int _anisotropic_degree;
00321   EnvType _env_type;
00322   bool _saved_result;
00323   TexGen _tex_gen;
00324   QualityLevel _quality_level;
00325   string _stage_name;
00326   int _priority;
00327   Colorf _color;
00328   Colorf _border_color;
00329   string _uv_name;
00330   int _rgb_scale;
00331   int _alpha_scale;
00332   int _flags;
00333   Filename _alpha_filename;
00334   Filename _alpha_fullpath;
00335   int _alpha_file_channel;
00336   bool _read_mipmaps;
00337   int _multitexture_sort;
00338 
00339   class SourceAndOperand {
00340   public:
00341     INLINE SourceAndOperand();
00342     CombineSource _source;
00343     CombineOperand _operand;
00344   };
00345 
00346   class Combiner {
00347   public:
00348     INLINE Combiner();
00349     CombineMode _mode;
00350     SourceAndOperand _ops[CI_num_indices];
00351   };
00352 
00353   Combiner _combiner[CC_num_channels];
00354 
00355   // This is the set of all of the textures that are multitextured on
00356   // top of (and under) this one.  This is filled in by
00357   // multitexture_over().
00358   MultiTextures _over_textures, _under_textures;
00359 
00360 public:
00361   static TypeHandle get_class_type() {
00362     return _type_handle;
00363   }
00364   static void init_type() {
00365     EggFilenameNode::init_type();
00366     EggRenderMode::init_type();
00367     register_type(_type_handle, "EggTexture",
00368                   EggFilenameNode::get_class_type(),
00369           EggRenderMode::get_class_type());
00370   }
00371   virtual TypeHandle get_type() const {
00372     return get_class_type();
00373   }
00374   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00375 
00376 private:
00377   static TypeHandle _type_handle;
00378 };
00379 
00380 ////////////////////////////////////////////////////////////////////
00381 //       Class : UniqueEggTextures
00382 // Description : An STL function object for sorting textures into
00383 //               order by properties.  Returns true if the two
00384 //               referenced EggTexture pointers are in sorted order,
00385 //               false otherwise.
00386 ////////////////////////////////////////////////////////////////////
00387 class EXPCL_PANDAEGG UniqueEggTextures {
00388 public:
00389   INLINE UniqueEggTextures(int eq = ~0);
00390   INLINE bool operator ()(const EggTexture *t1, const EggTexture *t2) const;
00391 
00392   int _eq;
00393 };
00394 
00395 INLINE ostream &operator << (ostream &out, const EggTexture &n) {
00396   return out << n.get_filename();
00397 }
00398 
00399 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::TextureType texture_type);
00400 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::Format format);
00401 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::CompressionMode mode);
00402 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::WrapMode mode);
00403 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::FilterType type);
00404 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::EnvType type);
00405 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::CombineMode cm);
00406 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::CombineChannel cc);
00407 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::CombineSource cs);
00408 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::CombineOperand co);
00409 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::TexGen tex_gen);
00410 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::QualityLevel quality_level);
00411 
00412 #include "eggTexture.I"
00413 
00414 #endif
 All Classes Functions Variables Enumerations