Panda3D
|
00001 // Filename: texMatrixAttrib.h 00002 // Created by: drose (14Mar02) 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 TEXMATRIXATTRIB_H 00016 #define TEXMATRIXATTRIB_H 00017 00018 #include "pandabase.h" 00019 00020 #include "geom.h" 00021 #include "renderAttrib.h" 00022 #include "textureStage.h" 00023 #include "transformState.h" 00024 #include "pointerTo.h" 00025 00026 class FactoryParams; 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Class : TexMatrixAttrib 00030 // Description : Applies a transform matrix to UV's before they are 00031 // rendered. 00032 //////////////////////////////////////////////////////////////////// 00033 class EXPCL_PANDA_PGRAPH TexMatrixAttrib : public RenderAttrib { 00034 protected: 00035 INLINE TexMatrixAttrib(); 00036 INLINE TexMatrixAttrib(const TexMatrixAttrib ©); 00037 00038 public: 00039 virtual ~TexMatrixAttrib(); 00040 00041 PUBLISHED: 00042 static CPT(RenderAttrib) make(); 00043 static CPT(RenderAttrib) make(const LMatrix4f &mat); 00044 static CPT(RenderAttrib) make(TextureStage *stage, const TransformState *transform); 00045 static CPT(RenderAttrib) make_default(); 00046 00047 CPT(RenderAttrib) add_stage(TextureStage *stage, const TransformState *transform, int override = 0) const; 00048 CPT(RenderAttrib) remove_stage(TextureStage *stage) const; 00049 00050 bool is_empty() const; 00051 bool has_stage(TextureStage *stage) const; 00052 00053 int get_num_stages() const; 00054 TextureStage *get_stage(int n) const; 00055 MAKE_SEQ(get_stages, get_num_stages, get_stage); 00056 00057 const LMatrix4f &get_mat() const; 00058 const LMatrix4f &get_mat(TextureStage *stage) const; 00059 00060 CPT(TransformState) get_transform(TextureStage *stage) const; 00061 INLINE int get_override(TextureStage *stage) const; 00062 00063 INLINE int get_geom_rendering(int geom_rendering) const; 00064 00065 public: 00066 virtual void output(ostream &out) const; 00067 00068 protected: 00069 virtual int compare_to_impl(const RenderAttrib *other) const; 00070 virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const; 00071 virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const; 00072 00073 private: 00074 INLINE void check_stage_list() const; 00075 void rebuild_stage_list(); 00076 00077 private: 00078 class StageNode { 00079 public: 00080 INLINE StageNode(const TextureStage *stage); 00081 00082 INLINE bool operator < (const StageNode &other) const; 00083 00084 PT(TextureStage) _stage; 00085 CPT(TransformState) _transform; 00086 int _override; 00087 }; 00088 00089 class CompareTextureStagePointer { 00090 public: 00091 INLINE bool operator () (const TexMatrixAttrib::StageNode &a, const TexMatrixAttrib::StageNode &b) const; 00092 }; 00093 00094 typedef ov_set<StageNode, CompareTextureStagePointer> Stages; 00095 Stages _stages; 00096 00097 static CPT(RenderAttrib) _empty_attrib; 00098 00099 PUBLISHED: 00100 static int get_class_slot() { 00101 return _attrib_slot; 00102 } 00103 virtual int get_slot() const { 00104 return get_class_slot(); 00105 } 00106 00107 public: 00108 static void register_with_read_factory(); 00109 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00110 virtual int complete_pointers(TypedWritable **plist, BamReader *manager); 00111 00112 protected: 00113 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00114 void fillin(DatagramIterator &scan, BamReader *manager); 00115 00116 public: 00117 static TypeHandle get_class_type() { 00118 return _type_handle; 00119 } 00120 static void init_type() { 00121 RenderAttrib::init_type(); 00122 register_type(_type_handle, "TexMatrixAttrib", 00123 RenderAttrib::get_class_type()); 00124 _attrib_slot = register_slot(_type_handle, 100, make_default); 00125 } 00126 virtual TypeHandle get_type() const { 00127 return get_class_type(); 00128 } 00129 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00130 00131 private: 00132 static TypeHandle _type_handle; 00133 static int _attrib_slot; 00134 }; 00135 00136 #include "texMatrixAttrib.I" 00137 00138 #endif 00139