Panda3D

texGenAttrib.h

00001 // Filename: texGenAttrib.h
00002 // Created by:  masad (21Jun04)
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 TEXGENATTRIB_H
00016 #define TEXGENATTRIB_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "geom.h"
00021 #include "renderAttrib.h"
00022 #include "textureStage.h"
00023 #include "texture.h"
00024 #include "pointerTo.h"
00025 #include "nodePath.h"
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : TexGenAttrib
00029 // Description : Computes texture coordinates for geometry
00030 //               automatically based on vertex position and/or normal.
00031 //               This can be used to implement reflection and/or
00032 //               refraction maps, for instance to make shiny surfaces,
00033 //               as well as other special effects such as projective
00034 //               texturing.
00035 ////////////////////////////////////////////////////////////////////
00036 class EXPCL_PANDA_PGRAPH TexGenAttrib : public RenderAttrib {
00037 PUBLISHED:
00038   // We inherit the definition of our Mode enumerated type from
00039   // RenderAttrib.  Normally, Mode would be defined here, but we
00040   // define it in the base class instead as a hack to avoid a problem
00041   // with circular includes.
00042   typedef RenderAttrib::TexGenMode Mode;
00043 
00044 protected:
00045   INLINE TexGenAttrib();
00046   INLINE TexGenAttrib(const TexGenAttrib &copy);
00047 
00048 public:
00049   virtual ~TexGenAttrib();
00050 
00051 PUBLISHED:
00052   static CPT(RenderAttrib) make();
00053   static CPT(RenderAttrib) make(TextureStage *stage, Mode mode);
00054   static CPT(RenderAttrib) make_default();
00055 
00056   CPT(RenderAttrib) add_stage(TextureStage *stage, Mode mode) const;
00057   CPT(RenderAttrib) add_stage(TextureStage *stage, Mode mode, const string &source_name, const NodePath &light) const;
00058   CPT(RenderAttrib) add_stage(TextureStage *stage, Mode mode, const LTexCoord3 &constant_value) const;
00059   CPT(RenderAttrib) remove_stage(TextureStage *stage) const;
00060 
00061   bool is_empty() const;
00062   bool has_stage(TextureStage *stage) const;
00063   Mode get_mode(TextureStage *stage) const;
00064   bool has_gen_texcoord_stage(TextureStage *stage) const;
00065   string get_source_name(TextureStage *stage) const;
00066   NodePath get_light(TextureStage *stage) const;
00067   const LTexCoord3 &get_constant_value(TextureStage *stage) const;
00068 
00069   INLINE int get_geom_rendering(int geom_rendering) const;
00070 
00071 public:
00072   typedef pset<TextureStage *> LightVectors;
00073   INLINE const LightVectors &get_light_vectors() const;
00074 
00075   virtual void output(ostream &out) const;
00076 
00077 protected:
00078   virtual int compare_to_impl(const RenderAttrib *other) const;
00079   virtual size_t get_hash_impl() const;
00080   virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
00081   virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
00082   virtual CPT(RenderAttrib) get_auto_shader_attrib_impl(const RenderState *state) const;
00083 
00084 private:
00085   class ModeDef;
00086   void filled_stages();
00087   void record_stage(TextureStage *stage, ModeDef &mode_def);
00088 
00089   class ModeDef {
00090   public:
00091     INLINE ModeDef();
00092     INLINE int compare_to(const ModeDef &other) const;
00093     Mode _mode;
00094     string _source_name;
00095     NodePath _light;
00096     LTexCoord3 _constant_value;
00097   };
00098   typedef pmap<PT(TextureStage), ModeDef> Stages;
00099   Stages _stages;
00100 
00101   // This is a set of TextureStage pointers for which texture
00102   // coordinates will not be needed from the Geom.  It's redundant;
00103   // it's almost the same set that is listed in _stages, above.  It's
00104   // just here as an optimization during rendering.
00105   typedef pset<TextureStage *> NoTexCoordStages;
00106   NoTexCoordStages _no_texcoords;
00107 
00108   // This is another optimization during rendering; it lists the
00109   // texture stages (if any) that use M_light_vector.
00110   LightVectors _light_vectors;
00111 
00112   // This element is only used during reading from a bam file.  It has
00113   // no meaningful value any other time.
00114   pvector<Mode> _read_modes;
00115 
00116   int _num_point_sprites;
00117   int _num_light_vectors;
00118 
00119   // _point_geom_rendering is the GeomRendering bits that are added by
00120   // the TexGenAttrib if there are any points in the Geom.
00121   // _geom_rendering is the GeomRendering bits that are added
00122   // regardless of the kind of Geom it is.
00123   int _point_geom_rendering;
00124   int _geom_rendering;
00125   
00126   static CPT(RenderAttrib) _empty_attrib;
00127 
00128 PUBLISHED:
00129   static int get_class_slot() {
00130     return _attrib_slot;
00131   }
00132   virtual int get_slot() const {
00133     return get_class_slot();
00134   }
00135 
00136 public:
00137   static void register_with_read_factory();
00138   virtual void write_datagram(BamWriter *manager, Datagram &dg);
00139   virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
00140 
00141 protected:
00142   static TypedWritable *make_from_bam(const FactoryParams &params);
00143   void fillin(DatagramIterator &scan, BamReader *manager);
00144   
00145 public:
00146   static TypeHandle get_class_type() {
00147     return _type_handle;
00148   }
00149   static void init_type() {
00150     RenderAttrib::init_type();
00151     register_type(_type_handle, "TexGenAttrib",
00152                   RenderAttrib::get_class_type());
00153     _attrib_slot = register_slot(_type_handle, 100, make_default);
00154   }
00155   virtual TypeHandle get_type() const {
00156     return get_class_type();
00157   }
00158   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00159 
00160 private:
00161   static TypeHandle _type_handle;
00162   static int _attrib_slot;
00163 };
00164 
00165 #include "texGenAttrib.I"
00166 
00167 #endif
00168 
 All Classes Functions Variables Enumerations