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 LMatrix4 &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 LMatrix4 &get_mat() const; 00058 const LMatrix4 &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 size_t get_hash_impl() const; 00071 virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const; 00072 virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const; 00073 virtual CPT(RenderAttrib) get_auto_shader_attrib_impl(const RenderState *state) const; 00074 00075 private: 00076 INLINE void check_stage_list() const; 00077 void rebuild_stage_list(); 00078 00079 private: 00080 class StageNode { 00081 public: 00082 INLINE StageNode(const TextureStage *stage); 00083 00084 INLINE bool operator < (const StageNode &other) const; 00085 00086 PT(TextureStage) _stage; 00087 CPT(TransformState) _transform; 00088 int _override; 00089 }; 00090 00091 class CompareTextureStagePointer { 00092 public: 00093 INLINE bool operator () (const TexMatrixAttrib::StageNode &a, const TexMatrixAttrib::StageNode &b) const; 00094 }; 00095 00096 typedef ov_set<StageNode, CompareTextureStagePointer> Stages; 00097 Stages _stages; 00098 00099 static CPT(RenderAttrib) _empty_attrib; 00100 00101 PUBLISHED: 00102 static int get_class_slot() { 00103 return _attrib_slot; 00104 } 00105 virtual int get_slot() const { 00106 return get_class_slot(); 00107 } 00108 00109 public: 00110 static void register_with_read_factory(); 00111 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00112 virtual int complete_pointers(TypedWritable **plist, BamReader *manager); 00113 00114 protected: 00115 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00116 void fillin(DatagramIterator &scan, BamReader *manager); 00117 00118 public: 00119 static TypeHandle get_class_type() { 00120 return _type_handle; 00121 } 00122 static void init_type() { 00123 RenderAttrib::init_type(); 00124 register_type(_type_handle, "TexMatrixAttrib", 00125 RenderAttrib::get_class_type()); 00126 _attrib_slot = register_slot(_type_handle, 100, make_default); 00127 } 00128 virtual TypeHandle get_type() const { 00129 return get_class_type(); 00130 } 00131 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00132 00133 private: 00134 static TypeHandle _type_handle; 00135 static int _attrib_slot; 00136 }; 00137 00138 #include "texMatrixAttrib.I" 00139 00140 #endif 00141