Panda3D
 All Classes Functions Variables Enumerations
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     ET_normal_gloss,
00110   };
00111   enum CombineMode {
00112     CM_unspecified,
00113     CM_replace,
00114     CM_modulate,
00115     CM_add,
00116     CM_add_signed,
00117     CM_interpolate,
00118     CM_subtract,
00119     CM_dot3_rgb,
00120     CM_dot3_rgba,
00121   };
00122   enum CombineChannel {
00123     CC_rgb = 0,
00124     CC_alpha = 1,
00125     CC_num_channels = 2,
00126   };
00127   enum CombineIndex {
00128     CI_num_indices = 3
00129   };
00130   enum CombineSource {
00131     CS_unspecified,
00132     CS_texture,
00133     CS_constant,
00134     CS_primary_color,
00135     CS_previous,
00136     CS_constant_color_scale,
00137     CS_last_saved_result,
00138   };
00139   enum CombineOperand {
00140     CO_unspecified,
00141     CO_src_color,
00142     CO_one_minus_src_color,
00143     CO_src_alpha,
00144     CO_one_minus_src_alpha,
00145   };
00146   enum TexGen {
00147     TG_unspecified,
00148 
00149     TG_eye_sphere_map,
00150 
00151     TG_world_cube_map,
00152     TG_eye_cube_map,
00153 
00154     TG_world_normal,
00155     TG_eye_normal,
00156 
00157     TG_world_position,
00158     TG_eye_position,
00159 
00160     TG_point_sprite,
00161   };
00162   enum QualityLevel {
00163     QL_unspecified,
00164     QL_default,
00165     QL_fastest,
00166     QL_normal,
00167     QL_best,
00168   };
00169 
00170   INLINE void set_texture_type(TextureType texture_type);
00171   INLINE TextureType get_texture_type() const;
00172 
00173   INLINE void set_format(Format format);
00174   INLINE Format get_format() const;
00175 
00176   INLINE void set_compression_mode(CompressionMode mode);
00177   INLINE CompressionMode get_compression_mode() const;
00178 
00179   INLINE void set_wrap_mode(WrapMode mode);
00180   INLINE WrapMode get_wrap_mode() const;
00181 
00182   INLINE void set_wrap_u(WrapMode mode);
00183   INLINE WrapMode get_wrap_u() const;
00184   INLINE WrapMode determine_wrap_u() const;
00185 
00186   INLINE void set_wrap_v(WrapMode mode);
00187   INLINE WrapMode get_wrap_v() const;
00188   INLINE WrapMode determine_wrap_v() const;
00189 
00190   INLINE void set_wrap_w(WrapMode mode);
00191   INLINE WrapMode get_wrap_w() const;
00192   INLINE WrapMode determine_wrap_w() const;
00193 
00194   INLINE void set_minfilter(FilterType type);
00195   INLINE FilterType get_minfilter() const;
00196 
00197   INLINE void set_magfilter(FilterType type);
00198   INLINE FilterType get_magfilter() const;
00199 
00200   INLINE void set_anisotropic_degree(int anisotropic_degree);
00201   INLINE void clear_anisotropic_degree();
00202   INLINE bool has_anisotropic_degree() const;
00203   INLINE int get_anisotropic_degree() const;
00204 
00205   INLINE void set_env_type(EnvType type);
00206   INLINE EnvType get_env_type() const;
00207   bool affects_polygon_alpha() const;
00208 
00209   INLINE void set_combine_mode(CombineChannel channel, CombineMode cm);
00210   INLINE CombineMode get_combine_mode(CombineChannel channel) const;
00211   INLINE void set_combine_source(CombineChannel channel, int n, CombineSource cs);
00212   INLINE CombineSource get_combine_source(CombineChannel channel, int n) const;
00213   INLINE void set_combine_operand(CombineChannel channel, int n, CombineOperand co);
00214   INLINE CombineOperand get_combine_operand(CombineChannel channel, int n) const;
00215 
00216   INLINE void set_saved_result(bool saved_result);
00217   INLINE bool get_saved_result() const;
00218 
00219   INLINE void set_tex_gen(TexGen tex_gen);
00220   INLINE TexGen get_tex_gen() const;
00221 
00222   INLINE void set_quality_level(QualityLevel quality_level);
00223   INLINE QualityLevel get_quality_level() const;
00224 
00225   INLINE void set_stage_name(const string &stage_name);
00226   INLINE void clear_stage_name();
00227   INLINE bool has_stage_name() const;
00228   INLINE const string &get_stage_name() const;
00229 
00230   INLINE void set_priority(int priority);
00231   INLINE void clear_priority();
00232   INLINE bool has_priority() const;
00233   INLINE int get_priority() const;
00234 
00235   INLINE void set_color(const LColor &color);
00236   INLINE void clear_color();
00237   INLINE bool has_color() const;
00238   INLINE const LColor &get_color() const;
00239 
00240   INLINE void set_border_color(const LColor &border_color);
00241   INLINE void clear_border_color();
00242   INLINE bool has_border_color() const;
00243   INLINE const LColor &get_border_color() const;
00244 
00245   INLINE void set_uv_name(const string &uv_name);
00246   INLINE void clear_uv_name();
00247   INLINE bool has_uv_name() const;
00248   INLINE const string &get_uv_name() const;
00249 
00250   INLINE void set_rgb_scale(int rgb_scale);
00251   INLINE void clear_rgb_scale();
00252   INLINE bool has_rgb_scale() const;
00253   INLINE int get_rgb_scale() const;
00254 
00255   INLINE void set_alpha_scale(int alpha_scale);
00256   INLINE void clear_alpha_scale();
00257   INLINE bool has_alpha_scale() const;
00258   INLINE int get_alpha_scale() const;
00259 
00260   INLINE void set_alpha_filename(const Filename &filename);
00261   INLINE void clear_alpha_filename();
00262   INLINE bool has_alpha_filename() const;
00263   INLINE const Filename &get_alpha_filename() const;
00264 
00265   INLINE void set_alpha_fullpath(const Filename &fullpath);
00266   INLINE const Filename &get_alpha_fullpath() const;
00267 
00268   INLINE void set_alpha_file_channel(int alpha_file_channel);
00269   INLINE void clear_alpha_file_channel();
00270   INLINE bool has_alpha_file_channel() const;
00271   INLINE int get_alpha_file_channel() const;
00272 
00273   INLINE void set_multiview(bool multiview);
00274   INLINE bool get_multiview() const;
00275 
00276   INLINE void set_num_views(int num_views);
00277   INLINE void clear_num_views();
00278   INLINE bool has_num_views() const;
00279   INLINE int get_num_views() const;
00280 
00281   INLINE void set_read_mipmaps(bool read_mipmaps);
00282   INLINE bool get_read_mipmaps() const;
00283 
00284 
00285   void clear_multitexture();
00286   bool multitexture_over(EggTexture *other);
00287   INLINE int get_multitexture_sort() const;
00288 
00289   static TextureType string_texture_type(const string &string);
00290   static Format string_format(const string &string);
00291   static CompressionMode string_compression_mode(const string &string);
00292   static WrapMode string_wrap_mode(const string &string);
00293   static FilterType string_filter_type(const string &string);
00294   static EnvType string_env_type(const string &string);
00295   static CombineMode string_combine_mode(const string &string);
00296   static CombineSource string_combine_source(const string &string);
00297   static CombineOperand string_combine_operand(const string &string);
00298   static TexGen string_tex_gen(const string &string);
00299   static QualityLevel string_quality_level(const string &string);
00300 
00301 public:
00302   virtual EggTransform *as_transform();
00303 
00304 protected:
00305   virtual bool egg_start_parse_body();
00306 
00307 private:
00308   typedef pset<EggTexture *> MultiTextures;
00309   bool r_min_multitexture_sort(int sort, MultiTextures &cycle_detector);
00310 
00311   enum Flags {
00312     F_has_alpha_filename     = 0x0002,
00313     F_has_anisotropic_degree = 0x0004,
00314     F_has_alpha_file_channel = 0x0008,
00315     F_has_stage_name         = 0x0010,
00316     F_has_uv_name            = 0x0020,
00317     F_has_priority           = 0x0040,
00318     F_has_color              = 0x0080,
00319     F_has_rgb_scale          = 0x0100,
00320     F_has_alpha_scale        = 0x0200,
00321     F_has_border_color       = 0x0400,
00322     F_has_num_views          = 0x0800,
00323   };
00324 
00325   TextureType _texture_type;
00326   Format _format;
00327   CompressionMode _compression_mode;
00328   WrapMode _wrap_mode, _wrap_u, _wrap_v, _wrap_w;
00329   FilterType _minfilter, _magfilter;
00330   int _anisotropic_degree;
00331   EnvType _env_type;
00332   bool _saved_result;
00333   bool _multiview;
00334   int _num_views;
00335   TexGen _tex_gen;
00336   QualityLevel _quality_level;
00337   string _stage_name;
00338   int _priority;
00339   LColor _color;
00340   LColor _border_color;
00341   string _uv_name;
00342   int _rgb_scale;
00343   int _alpha_scale;
00344   int _flags;
00345   Filename _alpha_filename;
00346   Filename _alpha_fullpath;
00347   int _alpha_file_channel;
00348   bool _read_mipmaps;
00349   int _multitexture_sort;
00350 
00351   class SourceAndOperand {
00352   public:
00353     INLINE SourceAndOperand();
00354     CombineSource _source;
00355     CombineOperand _operand;
00356   };
00357 
00358   class Combiner {
00359   public:
00360     INLINE Combiner();
00361     CombineMode _mode;
00362     SourceAndOperand _ops[CI_num_indices];
00363   };
00364 
00365   Combiner _combiner[CC_num_channels];
00366 
00367   // This is the set of all of the textures that are multitextured on
00368   // top of (and under) this one.  This is filled in by
00369   // multitexture_over().
00370   MultiTextures _over_textures, _under_textures;
00371 
00372 public:
00373   static TypeHandle get_class_type() {
00374     return _type_handle;
00375   }
00376   static void init_type() {
00377     EggFilenameNode::init_type();
00378     EggRenderMode::init_type();
00379     register_type(_type_handle, "EggTexture",
00380                   EggFilenameNode::get_class_type(),
00381           EggRenderMode::get_class_type());
00382   }
00383   virtual TypeHandle get_type() const {
00384     return get_class_type();
00385   }
00386   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00387 
00388 private:
00389   static TypeHandle _type_handle;
00390 };
00391 
00392 ////////////////////////////////////////////////////////////////////
00393 //       Class : UniqueEggTextures
00394 // Description : An STL function object for sorting textures into
00395 //               order by properties.  Returns true if the two
00396 //               referenced EggTexture pointers are in sorted order,
00397 //               false otherwise.
00398 ////////////////////////////////////////////////////////////////////
00399 class EXPCL_PANDAEGG UniqueEggTextures {
00400 public:
00401   INLINE UniqueEggTextures(int eq = ~0);
00402   INLINE bool operator ()(const EggTexture *t1, const EggTexture *t2) const;
00403 
00404   int _eq;
00405 };
00406 
00407 INLINE ostream &operator << (ostream &out, const EggTexture &n) {
00408   return out << n.get_filename();
00409 }
00410 
00411 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::TextureType texture_type);
00412 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::Format format);
00413 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::CompressionMode mode);
00414 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::WrapMode mode);
00415 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::FilterType type);
00416 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::EnvType type);
00417 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::CombineMode cm);
00418 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::CombineChannel cc);
00419 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::CombineSource cs);
00420 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::CombineOperand co);
00421 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::TexGen tex_gen);
00422 EXPCL_PANDAEGG ostream &operator << (ostream &out, EggTexture::QualityLevel quality_level);
00423 
00424 #include "eggTexture.I"
00425 
00426 #endif
 All Classes Functions Variables Enumerations