| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- // Filename: renderEffects.h
- // Created by: drose (14Mar02)
- //
- ////////////////////////////////////////////////////////////////////
- //
- // PANDA 3D SOFTWARE
- // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
- //
- // All use of this software is subject to the terms of the Panda 3d
- // Software license. You should have received a copy of this license
- // along with this source code; you will also find a current copy of
- // the license at http://etc.cmu.edu/panda3d/docs/license/ .
- //
- // To contact the maintainers of this program write to
- // [email protected] .
- //
- ////////////////////////////////////////////////////////////////////
- #ifndef RENDEREFFECTS_H
- #define RENDEREFFECTS_H
- #include "pandabase.h"
- #include "transformState.h"
- #include "renderState.h"
- #include "renderEffect.h"
- #include "typedWritableReferenceCount.h"
- #include "pointerTo.h"
- #include "ordered_vector.h"
- #include "reMutex.h"
- #include "pmutex.h"
- class CullTraverser;
- class CullTraverserData;
- class FactoryParams;
- ////////////////////////////////////////////////////////////////////
- // Class : RenderEffects
- // Description : This represents a unique collection of RenderEffect
- // objects that correspond to a particular renderable
- // state.
- //
- // You should not attempt to create or modify a
- // RenderEffects object directly. Instead, call one of
- // the make() functions to create one for you. And
- // instead of modifying a RenderEffects object, create a
- // new one.
- ////////////////////////////////////////////////////////////////////
- class EXPCL_PANDA RenderEffects : public TypedWritableReferenceCount {
- protected:
- RenderEffects();
- private:
- RenderEffects(const RenderEffects ©);
- void operator = (const RenderEffects ©);
- public:
- virtual ~RenderEffects();
- bool safe_to_transform() const;
- virtual CPT(TransformState) prepare_flatten_transform(const TransformState *net_transform) const;
- bool safe_to_combine() const;
- CPT(RenderEffects) xform(const LMatrix4f &mat) const;
- PUBLISHED:
- bool operator < (const RenderEffects &other) const;
- INLINE bool is_empty() const;
- INLINE int get_num_effects() const;
- INLINE const RenderEffect *get_effect(int n) const;
- int find_effect(TypeHandle type) const;
- static CPT(RenderEffects) make_empty();
- static CPT(RenderEffects) make(const RenderEffect *effect);
- static CPT(RenderEffects) make(const RenderEffect *effect1,
- const RenderEffect *effect2);
- static CPT(RenderEffects) make(const RenderEffect *effect1,
- const RenderEffect *effect2,
- const RenderEffect *effect3);
- static CPT(RenderEffects) make(const RenderEffect *effect1,
- const RenderEffect *effect2,
- const RenderEffect *effect3,
- const RenderEffect *effect4);
- CPT(RenderEffects) add_effect(const RenderEffect *effect) const;
- CPT(RenderEffects) remove_effect(TypeHandle type) const;
- const RenderEffect *get_effect(TypeHandle type) const;
- void output(ostream &out) const;
- void write(ostream &out, int indent_level) const;
- static int get_num_states();
- static void list_states(ostream &out);
- static bool validate_states();
- public:
- INLINE bool has_decal() const;
- INLINE bool has_show_bounds() const;
- INLINE bool has_show_tight_bounds() const;
- INLINE bool has_cull_callback() const;
- void cull_callback(CullTraverser *trav, CullTraverserData &data,
- CPT(TransformState) &node_transform,
- CPT(RenderState) &node_state) const;
- INLINE bool has_adjust_transform() const;
- void adjust_transform(CPT(TransformState) &net_transform,
- CPT(TransformState) &node_transform,
- PandaNode *node) const;
- static void init_states();
- private:
- static CPT(RenderEffects) return_new(RenderEffects *state);
- void determine_decal();
- void determine_show_bounds();
- void determine_cull_callback();
- void determine_adjust_transform();
- private:
- // This mutex protects _states. It also protects any modification
- // to the cache, which is encoded in _composition_cache and
- // _invert_composition_cache.
- static ReMutex *_states_lock;
- typedef pset<const RenderEffects *, indirect_less<const RenderEffects *> > States;
- static States *_states;
- static CPT(RenderEffects) _empty_state;
- // This iterator records the entry corresponding to this RenderEffects
- // object in the above global set. We keep the iterator around so
- // we can remove it when the RenderEffects destructs.
- States::iterator _saved_entry;
- private:
- // This is the actual data within the RenderEffects: a set of
- // RenderEffects.
- class Effect {
- public:
- INLINE Effect(const RenderEffect *effect);
- INLINE Effect();
- INLINE Effect(TypeHandle type);
- INLINE Effect(const Effect ©);
- INLINE void operator = (const Effect ©);
- INLINE bool operator < (const Effect &other) const;
- INLINE int compare_to(const Effect &other) const;
- TypeHandle _type;
- CPT(RenderEffect) _effect;
- };
- typedef ov_set<Effect> Effects;
- Effects _effects;
- enum Flags {
- F_checked_decal = 0x0001,
- F_has_decal = 0x0002,
- F_checked_show_bounds = 0x0004,
- F_has_show_bounds = 0x0008,
- F_has_show_tight_bounds = 0x0010,
- F_checked_cull_callback = 0x0020,
- F_has_cull_callback = 0x0040,
- F_checked_adjust_transform = 0x0080,
- F_has_adjust_transform = 0x0100,
- };
- int _flags;
- // This mutex protects _flags, and all of the above computed values.
- Mutex _lock;
- public:
- static void register_with_read_factory();
- virtual void write_datagram(BamWriter *manager, Datagram &dg);
- virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
- static TypedWritable *change_this(TypedWritable *old_ptr, BamReader *manager);
- virtual void finalize(BamReader *manager);
- protected:
- static TypedWritable *make_from_bam(const FactoryParams ¶ms);
- void fillin(DatagramIterator &scan, BamReader *manager);
-
- public:
- static TypeHandle get_class_type() {
- return _type_handle;
- }
- static void init_type() {
- TypedWritableReferenceCount::init_type();
- register_type(_type_handle, "RenderEffects",
- TypedWritableReferenceCount::get_class_type());
- }
- virtual TypeHandle get_type() const {
- return get_class_type();
- }
- virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
- private:
- static TypeHandle _type_handle;
- };
- INLINE ostream &operator << (ostream &out, const RenderEffects &state) {
- state.output(out);
- return out;
- }
- #include "renderEffects.I"
- #endif
|