00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef RENDERATTRIB_H
00016 #define RENDERATTRIB_H
00017
00018 #include "pandabase.h"
00019
00020 #include "typedWritableReferenceCount.h"
00021 #include "renderAttribRegistry.h"
00022 #include "pointerTo.h"
00023 #include "simpleHashMap.h"
00024 #include "lightReMutex.h"
00025 #include "pStatCollector.h"
00026
00027 class AttribSlots;
00028 class GraphicsStateGuardianBase;
00029 class CullTraverser;
00030 class CullTraverserData;
00031 class RenderState;
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 class EXPCL_PANDA_PGRAPH RenderAttrib : public TypedWritableReferenceCount {
00061 protected:
00062 RenderAttrib();
00063 private:
00064 RenderAttrib(const RenderAttrib ©);
00065 void operator = (const RenderAttrib ©);
00066
00067 public:
00068 virtual ~RenderAttrib();
00069
00070 PUBLISHED:
00071 INLINE CPT(RenderAttrib) compose(const RenderAttrib *other) const;
00072 INLINE CPT(RenderAttrib) invert_compose(const RenderAttrib *other) const;
00073 virtual bool lower_attrib_can_override() const;
00074
00075 public:
00076 INLINE bool always_reissue() const;
00077
00078 virtual bool has_cull_callback() const;
00079 virtual bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const;
00080
00081 PUBLISHED:
00082 INLINE int compare_to(const RenderAttrib &other) const;
00083 INLINE size_t get_hash() const;
00084 INLINE CPT(RenderAttrib) get_unique() const;
00085 INLINE CPT(RenderAttrib) get_auto_shader_attrib(const RenderState *state) const;
00086
00087 virtual bool unref() const;
00088
00089 virtual void output(ostream &out) const;
00090 virtual void write(ostream &out, int indent_level) const;
00091
00092 static int get_num_attribs();
00093 static void list_attribs(ostream &out);
00094 static int garbage_collect();
00095 static bool validate_attribs();
00096
00097 virtual int get_slot() const=0;
00098
00099 enum PandaCompareFunc {
00100 M_none=0,
00101 M_never,
00102 M_less,
00103 M_equal,
00104 M_less_equal,
00105 M_greater,
00106 M_not_equal,
00107 M_greater_equal,
00108 M_always
00109 };
00110
00111
00112
00113
00114 enum TexGenMode {
00115 M_off,
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 M_eye_sphere_map,
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 M_world_cube_map,
00137 M_eye_cube_map,
00138
00139
00140
00141 M_world_normal,
00142 M_eye_normal,
00143
00144
00145
00146
00147 M_world_position,
00148 M_unused,
00149 M_eye_position,
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 M_point_sprite,
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 M_light_vector,
00176
00177
00178
00179
00180 M_constant,
00181 };
00182
00183 protected:
00184 static CPT(RenderAttrib) return_new(RenderAttrib *attrib);
00185 static CPT(RenderAttrib) return_unique(RenderAttrib *attrib);
00186 virtual int compare_to_impl(const RenderAttrib *other) const;
00187 virtual size_t get_hash_impl() const;
00188 virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
00189 virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
00190 virtual CPT(RenderAttrib) get_auto_shader_attrib_impl(const RenderState *state) const;
00191 void output_comparefunc(ostream &out, PandaCompareFunc fn) const;
00192
00193 public:
00194 INLINE static int register_slot(TypeHandle type_handle, int sort,
00195 RenderAttribRegistry::MakeDefaultFunc *make_default_func);
00196
00197 private:
00198 void release_new();
00199
00200 protected:
00201 bool _always_reissue;
00202
00203 public:
00204 static void init_attribs();
00205
00206 private:
00207
00208 static LightReMutex *_attribs_lock;
00209 class Empty {
00210 };
00211 typedef SimpleHashMap<const RenderAttrib *, Empty, indirect_compare_to_hash<const RenderAttrib *> > Attribs;
00212 static Attribs *_attribs;
00213
00214 int _saved_entry;
00215
00216
00217
00218 static int _garbage_index;
00219
00220 static PStatCollector _garbage_collect_pcollector;
00221
00222 public:
00223 virtual void write_datagram(BamWriter *manager, Datagram &dg);
00224 static TypedWritable *change_this(TypedWritable *old_ptr, BamReader *manager);
00225 virtual void finalize(BamReader *manager);
00226
00227 protected:
00228 static TypedWritable *new_from_bam(RenderAttrib *attrib, BamReader *manager);
00229 void fillin(DatagramIterator &scan, BamReader *manager);
00230
00231 public:
00232 static TypeHandle get_class_type() {
00233 return _type_handle;
00234 }
00235 static void init_type() {
00236 TypedWritableReferenceCount::init_type();
00237 register_type(_type_handle, "RenderAttrib",
00238 TypedWritableReferenceCount::get_class_type());
00239 }
00240 virtual TypeHandle get_type() const {
00241 return get_class_type();
00242 }
00243 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00244
00245 private:
00246 static TypeHandle _type_handle;
00247 };
00248
00249 INLINE ostream &operator << (ostream &out, const RenderAttrib &attrib) {
00250 attrib.output(out);
00251 return out;
00252 }
00253
00254 #include "renderAttrib.I"
00255
00256 #endif
00257