Panda3D
|
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 ©); 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 TexCoord3f &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 TexCoord3f &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 CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const; 00080 virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const; 00081 00082 private: 00083 class ModeDef; 00084 void filled_stages(); 00085 void record_stage(TextureStage *stage, ModeDef &mode_def); 00086 00087 class ModeDef { 00088 public: 00089 INLINE ModeDef(); 00090 INLINE int compare_to(const ModeDef &other) const; 00091 Mode _mode; 00092 string _source_name; 00093 NodePath _light; 00094 TexCoord3f _constant_value; 00095 }; 00096 typedef pmap<PT(TextureStage), ModeDef> Stages; 00097 Stages _stages; 00098 00099 // This is a set of TextureStage pointers for which texture 00100 // coordinates will not be needed from the Geom. It's redundant; 00101 // it's almost the same set that is listed in _stages, above. It's 00102 // just here as an optimization during rendering. 00103 typedef pset<TextureStage *> NoTexCoordStages; 00104 NoTexCoordStages _no_texcoords; 00105 00106 // This is another optimization during rendering; it lists the 00107 // texture stages (if any) that use M_light_vector. 00108 LightVectors _light_vectors; 00109 00110 // This element is only used during reading from a bam file. It has 00111 // no meaningful value any other time. 00112 pvector<Mode> _read_modes; 00113 00114 int _num_point_sprites; 00115 int _num_light_vectors; 00116 00117 // _point_geom_rendering is the GeomRendering bits that are added by 00118 // the TexGenAttrib if there are any points in the Geom. 00119 // _geom_rendering is the GeomRendering bits that are added 00120 // regardless of the kind of Geom it is. 00121 int _point_geom_rendering; 00122 int _geom_rendering; 00123 00124 static CPT(RenderAttrib) _empty_attrib; 00125 00126 PUBLISHED: 00127 static int get_class_slot() { 00128 return _attrib_slot; 00129 } 00130 virtual int get_slot() const { 00131 return get_class_slot(); 00132 } 00133 00134 public: 00135 static void register_with_read_factory(); 00136 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00137 virtual int complete_pointers(TypedWritable **plist, BamReader *manager); 00138 00139 protected: 00140 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00141 void fillin(DatagramIterator &scan, BamReader *manager); 00142 00143 public: 00144 static TypeHandle get_class_type() { 00145 return _type_handle; 00146 } 00147 static void init_type() { 00148 RenderAttrib::init_type(); 00149 register_type(_type_handle, "TexGenAttrib", 00150 RenderAttrib::get_class_type()); 00151 _attrib_slot = register_slot(_type_handle, 100, make_default); 00152 } 00153 virtual TypeHandle get_type() const { 00154 return get_class_type(); 00155 } 00156 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00157 00158 private: 00159 static TypeHandle _type_handle; 00160 static int _attrib_slot; 00161 }; 00162 00163 #include "texGenAttrib.I" 00164 00165 #endif 00166