00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef RENDERSTATE_H
00020 #define RENDERSTATE_H
00021
00022 #include "pandabase.h"
00023
00024 #include "renderAttrib.h"
00025 #include "typedWritableReferenceCount.h"
00026 #include "pointerTo.h"
00027 #include "indirectLess.h"
00028 #include "ordered_vector.h"
00029
00030 class GraphicsStateGuardianBase;
00031 class FogAttrib;
00032 class CullBinAttrib;
00033 class TransparencyAttrib;
00034 class FactoryParams;
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 class EXPCL_PANDA RenderState : public TypedWritableReferenceCount {
00049 protected:
00050 RenderState();
00051
00052 private:
00053 RenderState(const RenderState ©);
00054 void operator = (const RenderState ©);
00055
00056 public:
00057 virtual ~RenderState();
00058
00059 bool operator < (const RenderState &other) const;
00060
00061 PUBLISHED:
00062 INLINE bool is_empty() const;
00063 INLINE int get_num_attribs() const;
00064 INLINE const RenderAttrib *get_attrib(int n) const;
00065 INLINE int get_override(int n) const;
00066
00067 int find_attrib(TypeHandle type) const;
00068
00069 static CPT(RenderState) make_empty();
00070 static CPT(RenderState) make(const RenderAttrib *attrib, int override = 0);
00071 static CPT(RenderState) make(const RenderAttrib *attrib1,
00072 const RenderAttrib *attrib2, int override = 0);
00073 static CPT(RenderState) make(const RenderAttrib *attrib1,
00074 const RenderAttrib *attrib2,
00075 const RenderAttrib *attrib3, int override = 0);
00076 static CPT(RenderState) make(const RenderAttrib *attrib1,
00077 const RenderAttrib *attrib2,
00078 const RenderAttrib *attrib3,
00079 const RenderAttrib *attrib4, int override = 0);
00080 static CPT(RenderState) make(const RenderAttrib * const *attrib,
00081 int num_attribs, int override = 0);
00082
00083 CPT(RenderState) compose(const RenderState *other) const;
00084 CPT(RenderState) invert_compose(const RenderState *other) const;
00085
00086 CPT(RenderState) add_attrib(const RenderAttrib *attrib, int override = 0) const;
00087 CPT(RenderState) remove_attrib(TypeHandle type) const;
00088
00089 CPT(RenderState) adjust_all_priorities(int adjustment) const;
00090
00091 const RenderAttrib *get_attrib(TypeHandle type) const;
00092
00093 void output(ostream &out) const;
00094 void write(ostream &out, int indent_level) const;
00095
00096 static int get_max_priority();
00097
00098 static int get_num_states();
00099 static int get_num_unused_states();
00100 static int clear_cache();
00101
00102 public:
00103 INLINE int get_bin_index() const;
00104 INLINE int get_draw_order() const;
00105 INLINE const FogAttrib *get_fog() const;
00106 INLINE const CullBinAttrib *get_bin() const;
00107 INLINE const TransparencyAttrib *get_transparency() const;
00108
00109 CPT(RenderState) issue_delta_modify(const RenderState *other,
00110 GraphicsStateGuardianBase *gsg) const;
00111 CPT(RenderState) issue_delta_set(const RenderState *other,
00112 GraphicsStateGuardianBase *gsg) const;
00113
00114 static void bin_removed(int bin_index);
00115
00116 private:
00117 static CPT(RenderState) return_new(RenderState *state);
00118 CPT(RenderState) do_compose(const RenderState *other) const;
00119 CPT(RenderState) do_invert_compose(const RenderState *other) const;
00120 void determine_bin_index();
00121 void determine_fog();
00122 void determine_bin();
00123 void determine_transparency();
00124
00125 INLINE void set_destructing();
00126 INLINE bool is_destructing() const;
00127
00128 private:
00129 typedef pset<const RenderState *, IndirectLess<RenderState> > States;
00130 static States *_states;
00131 static CPT(RenderState) _empty_state;
00132
00133
00134
00135
00136 States::iterator _saved_entry;
00137
00138
00139
00140
00141
00142
00143 class Composition {
00144 public:
00145 INLINE Composition();
00146 INLINE Composition(const Composition ©);
00147
00148 CPT(RenderState) _result;
00149 };
00150
00151 typedef pmap<const RenderState *, Composition> CompositionCache;
00152 CompositionCache _composition_cache;
00153 CompositionCache _invert_composition_cache;
00154
00155
00156
00157
00158
00159
00160
00161 const RenderState *_self_compose;
00162
00163 private:
00164
00165
00166 class Attribute {
00167 public:
00168 INLINE Attribute(const RenderAttrib *attrib, int override);
00169 INLINE Attribute(int override);
00170 INLINE Attribute(TypeHandle type);
00171 INLINE Attribute(const Attribute ©);
00172 INLINE void operator = (const Attribute ©);
00173 INLINE bool operator < (const Attribute &other) const;
00174 INLINE int compare_to(const Attribute &other) const;
00175
00176 TypeHandle _type;
00177 CPT(RenderAttrib) _attrib;
00178 int _override;
00179 };
00180 typedef ov_set<Attribute> Attributes;
00181 Attributes _attributes;
00182
00183
00184
00185 int _bin_index;
00186 int _draw_order;
00187
00188
00189
00190 const FogAttrib *_fog;
00191 const CullBinAttrib *_bin;
00192 const TransparencyAttrib *_transparency;
00193
00194 enum Flags {
00195 F_checked_bin_index = 0x0001,
00196 F_checked_fog = 0x0002,
00197 F_checked_bin = 0x0004,
00198 F_checked_transparency = 0x0008,
00199 F_is_destructing = 0x8000,
00200 };
00201 unsigned short _flags;
00202
00203 public:
00204 static void register_with_read_factory();
00205 virtual void write_datagram(BamWriter *manager, Datagram &dg);
00206 virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
00207 static TypedWritable *change_this(TypedWritable *old_ptr, BamReader *manager);
00208 virtual void finalize();
00209
00210 protected:
00211 static TypedWritable *make_from_bam(const FactoryParams ¶ms);
00212 void fillin(DatagramIterator &scan, BamReader *manager);
00213
00214 public:
00215 static TypeHandle get_class_type() {
00216 return _type_handle;
00217 }
00218 static void init_type() {
00219 TypedWritableReferenceCount::init_type();
00220 register_type(_type_handle, "RenderState",
00221 TypedWritableReferenceCount::get_class_type());
00222 }
00223 virtual TypeHandle get_type() const {
00224 return get_class_type();
00225 }
00226 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00227
00228 private:
00229 static TypeHandle _type_handle;
00230 };
00231
00232 INLINE ostream &operator << (ostream &out, const RenderState &state) {
00233 state.output(out);
00234 return out;
00235 }
00236
00237 #include "renderState.I"
00238
00239 #endif
00240