Panda3D
|
00001 // Filename: textureAttrib.h 00002 // Created by: drose (21Feb02) 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 TEXTUREATTRIB_H 00016 #define TEXTUREATTRIB_H 00017 00018 #include "pandabase.h" 00019 00020 #include "renderAttrib.h" 00021 #include "texture.h" 00022 #include "textureStage.h" 00023 #include "updateSeq.h" 00024 #include "ordered_vector.h" 00025 #include "vector_int.h" 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Class : TextureAttrib 00029 // Description : Indicates the set of TextureStages and their 00030 // associated Textures that should be applied to (or 00031 // removed from) a node. 00032 //////////////////////////////////////////////////////////////////// 00033 class EXPCL_PANDA_PGRAPH TextureAttrib : public RenderAttrib { 00034 protected: 00035 INLINE TextureAttrib(); 00036 INLINE TextureAttrib(const TextureAttrib ©); 00037 00038 PUBLISHED: 00039 // These methods are used to create a simple, single-textured layer. 00040 // For multitexture, use the multitexture interfaces, further below. 00041 static CPT(RenderAttrib) make(Texture *tex); 00042 static CPT(RenderAttrib) make_off(); 00043 static CPT(RenderAttrib) make_default(); 00044 00045 INLINE bool is_off() const; 00046 INLINE Texture *get_texture() const; 00047 00048 // The following methods define the new multitexture mode for 00049 // TextureAttrib. Each TextureAttrib can add or remove individual 00050 // texture stages from the complete set of textures that are to be 00051 // applied; this is similar to the mechanism of LightAttrib. 00052 static CPT(RenderAttrib) make(); 00053 static CPT(RenderAttrib) make_all_off(); 00054 00055 INLINE int get_num_on_stages() const; 00056 INLINE TextureStage *get_on_stage(int n) const; 00057 MAKE_SEQ(get_on_stages, get_num_on_stages, get_on_stage); 00058 INLINE int get_num_on_ff_stages() const; 00059 INLINE TextureStage *get_on_ff_stage(int n) const; 00060 MAKE_SEQ(get_on_ff_stages, get_num_on_ff_stages, get_on_ff_stage); 00061 INLINE int get_ff_tc_index(int n) const; 00062 INLINE bool has_on_stage(TextureStage *stage) const; 00063 INLINE Texture *get_on_texture(TextureStage *stage) const; 00064 INLINE int get_on_stage_override(TextureStage *stage) const; 00065 00066 int find_on_stage(const TextureStage *stage) const; 00067 00068 INLINE int get_num_off_stages() const; 00069 INLINE TextureStage *get_off_stage(int n) const; 00070 MAKE_SEQ(get_off_stages, get_num_off_stages, get_off_stage); 00071 INLINE bool has_off_stage(TextureStage *stage) const; 00072 INLINE bool has_all_off() const; 00073 00074 INLINE bool is_identity() const; 00075 00076 CPT(RenderAttrib) add_on_stage(TextureStage *stage, Texture *tex, int override = 0) const; 00077 CPT(RenderAttrib) remove_on_stage(TextureStage *stage) const; 00078 CPT(RenderAttrib) add_off_stage(TextureStage *stage, int override = 0) const; 00079 CPT(RenderAttrib) remove_off_stage(TextureStage *stage) const; 00080 CPT(RenderAttrib) unify_texture_stages(TextureStage *stage) const; 00081 00082 public: 00083 CPT(TextureAttrib) filter_to_max(int max_texture_stages) const; 00084 00085 virtual bool lower_attrib_can_override() const; 00086 virtual void output(ostream &out) const; 00087 00088 virtual bool has_cull_callback() const; 00089 virtual bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const; 00090 00091 protected: 00092 virtual int compare_to_impl(const RenderAttrib *other) const; 00093 virtual size_t get_hash_impl() const; 00094 virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const; 00095 virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const; 00096 virtual CPT(RenderAttrib) get_auto_shader_attrib_impl(const RenderState *state) const; 00097 00098 private: 00099 INLINE void check_sorted() const; 00100 void sort_on_stages(); 00101 00102 private: 00103 class StageNode { 00104 public: 00105 INLINE StageNode(const TextureStage *stage, 00106 unsigned int implicit_sort = 0, 00107 int override = 0); 00108 00109 PT(TextureStage) _stage; 00110 PT(Texture) _texture; 00111 int _ff_tc_index; 00112 unsigned int _implicit_sort; 00113 int _override; 00114 }; 00115 00116 class CompareTextureStagePriorities { 00117 public: 00118 INLINE bool operator () (const TextureAttrib::StageNode *a, const TextureAttrib::StageNode *b) const; 00119 }; 00120 00121 class CompareTextureStageSort { 00122 public: 00123 INLINE bool operator () (const TextureAttrib::StageNode *a, const TextureAttrib::StageNode *b) const; 00124 }; 00125 00126 class CompareTextureStagePointer { 00127 public: 00128 INLINE bool operator () (const TextureAttrib::StageNode &a, const TextureAttrib::StageNode &b) const; 00129 }; 00130 00131 typedef ov_set<StageNode, CompareTextureStagePointer> Stages; 00132 Stages _on_stages; // set of all "on" stages, indexed by pointer. 00133 00134 typedef pvector<StageNode *> RenderStages; 00135 RenderStages _render_stages; // all "on" stages, sorted in render order. 00136 RenderStages _render_ff_stages; // fixed-function stages only, in render order. 00137 unsigned int _next_implicit_sort; 00138 00139 Stages _off_stages; 00140 bool _off_all_stages; 00141 00142 typedef pmap< int, CPT(TextureAttrib) > Filtered; 00143 Filtered _filtered; 00144 00145 UpdateSeq _sort_seq; 00146 UpdateSeq _filtered_seq; 00147 00148 static CPT(RenderAttrib) _empty_attrib; 00149 static CPT(RenderAttrib) _all_off_attrib; 00150 00151 PUBLISHED: 00152 static int get_class_slot() { 00153 return _attrib_slot; 00154 } 00155 virtual int get_slot() const { 00156 return get_class_slot(); 00157 } 00158 00159 public: 00160 static void register_with_read_factory(); 00161 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00162 virtual int complete_pointers(TypedWritable **plist, BamReader *manager); 00163 00164 protected: 00165 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00166 void fillin(DatagramIterator &scan, BamReader *manager); 00167 00168 public: 00169 static TypeHandle get_class_type() { 00170 return _type_handle; 00171 } 00172 static void init_type() { 00173 RenderAttrib::init_type(); 00174 register_type(_type_handle, "TextureAttrib", 00175 RenderAttrib::get_class_type()); 00176 _attrib_slot = register_slot(_type_handle, 30, make_default); 00177 } 00178 virtual TypeHandle get_type() const { 00179 return get_class_type(); 00180 } 00181 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00182 00183 private: 00184 static TypeHandle _type_handle; 00185 static int _attrib_slot; 00186 }; 00187 00188 #include "textureAttrib.I" 00189 00190 #endif 00191