diff --git a/panda/src/pgraph/colorAttrib.I b/panda/src/pgraph/colorAttrib.I index 40a23ec066..2dfcde35b6 100644 --- a/panda/src/pgraph/colorAttrib.I +++ b/panda/src/pgraph/colorAttrib.I @@ -28,6 +28,7 @@ ColorAttrib(ColorAttrib::Type type, const Colorf &color) : _type(type), _color(color) { + quantize_color(); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pgraph/colorAttrib.cxx b/panda/src/pgraph/colorAttrib.cxx index 7100c668ae..b9d61ebdc7 100644 --- a/panda/src/pgraph/colorAttrib.cxx +++ b/panda/src/pgraph/colorAttrib.cxx @@ -145,6 +145,21 @@ make_default_impl() const { return new ColorAttrib; } +//////////////////////////////////////////////////////////////////// +// Function: ColorAttrib::quantize_color +// Access: Private +// Description: Quantizes the color color to the nearest multiple of +// 1000, just to prevent runaway accumulation of +// only slightly-different ColorAttribs. +//////////////////////////////////////////////////////////////////// +void ColorAttrib:: +quantize_color() { + _color[0] = cfloor(_color[0] * 1000.0f + 0.5f) * 0.001f; + _color[1] = cfloor(_color[1] * 1000.0f + 0.5f) * 0.001f; + _color[2] = cfloor(_color[2] * 1000.0f + 0.5f) * 0.001f; + _color[3] = cfloor(_color[3] * 1000.0f + 0.5f) * 0.001f; +} + //////////////////////////////////////////////////////////////////// // Function: ColorAttrib::register_with_read_factory // Access: Public, Static @@ -203,4 +218,5 @@ fillin(DatagramIterator &scan, BamReader *manager) { _type = (Type)scan.get_int8(); _color.read_datagram(scan); + quantize_color(); } diff --git a/panda/src/pgraph/colorAttrib.h b/panda/src/pgraph/colorAttrib.h index 8533f774d3..6f3286e4b6 100644 --- a/panda/src/pgraph/colorAttrib.h +++ b/panda/src/pgraph/colorAttrib.h @@ -57,6 +57,9 @@ protected: virtual int compare_to_impl(const RenderAttrib *other) const; virtual RenderAttrib *make_default_impl() const; +private: + void quantize_color(); + private: Type _type; Colorf _color; diff --git a/panda/src/pgraph/colorScaleAttrib.I b/panda/src/pgraph/colorScaleAttrib.I index 0f67e8e393..fe7fd02928 100644 --- a/panda/src/pgraph/colorScaleAttrib.I +++ b/panda/src/pgraph/colorScaleAttrib.I @@ -28,6 +28,7 @@ ColorScaleAttrib(bool off, const LVecBase4f &scale) : _off(off), _scale(scale) { + quantize_scale(); _has_scale = !_scale.almost_equal(LVecBase4f(1.0f, 1.0f, 1.0f, 1.0f)); } diff --git a/panda/src/pgraph/colorScaleAttrib.cxx b/panda/src/pgraph/colorScaleAttrib.cxx index a1f3cfb30c..d5829461c6 100644 --- a/panda/src/pgraph/colorScaleAttrib.cxx +++ b/panda/src/pgraph/colorScaleAttrib.cxx @@ -82,6 +82,7 @@ CPT(RenderAttrib) ColorScaleAttrib:: set_scale(const LVecBase4f &scale) const { ColorScaleAttrib *attrib = new ColorScaleAttrib(*this); attrib->_scale = scale; + attrib->quantize_scale(); attrib->_has_scale = !scale.almost_equal(LVecBase4f(1.0f, 1.0f, 1.0f, 1.0f)); return return_new(attrib); } @@ -234,6 +235,21 @@ make_default_impl() const { return new ColorScaleAttrib(false, LVecBase4f(1.0f, 1.0f, 1.0f, 1.0f)); } +//////////////////////////////////////////////////////////////////// +// Function: ColorScaleAttrib::quantize_scale +// Access: Private +// Description: Quantizes the color scale to the nearest multiple of +// 1000, just to prevent runaway accumulation of +// only slightly-different ColorScaleAttribs. +//////////////////////////////////////////////////////////////////// +void ColorScaleAttrib:: +quantize_scale() { + _scale[0] = cfloor(_scale[0] * 1000.0f + 0.5f) * 0.001f; + _scale[1] = cfloor(_scale[1] * 1000.0f + 0.5f) * 0.001f; + _scale[2] = cfloor(_scale[2] * 1000.0f + 0.5f) * 0.001f; + _scale[3] = cfloor(_scale[3] * 1000.0f + 0.5f) * 0.001f; +} + //////////////////////////////////////////////////////////////////// // Function: ColorScaleAttrib::register_with_read_factory // Access: Public, Static @@ -295,5 +311,6 @@ fillin(DatagramIterator &scan, BamReader *manager) { _off = scan.get_bool(); _scale.read_datagram(scan); + quantize_scale(); _has_scale = !_scale.almost_equal(LVecBase4f(1.0f, 1.0f, 1.0f, 1.0f)); } diff --git a/panda/src/pgraph/colorScaleAttrib.h b/panda/src/pgraph/colorScaleAttrib.h index 75cb2dea09..b86e22ae4d 100644 --- a/panda/src/pgraph/colorScaleAttrib.h +++ b/panda/src/pgraph/colorScaleAttrib.h @@ -57,6 +57,9 @@ protected: virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const; virtual RenderAttrib *make_default_impl() const; +private: + void quantize_scale(); + private: bool _off; bool _has_scale; diff --git a/panda/src/pgraph/stateMunger.cxx b/panda/src/pgraph/stateMunger.cxx index cf88e3a455..fcee72dfbd 100644 --- a/panda/src/pgraph/stateMunger.cxx +++ b/panda/src/pgraph/stateMunger.cxx @@ -20,6 +20,15 @@ TypeHandle StateMunger::_type_handle; +//////////////////////////////////////////////////////////////////// +// Function: StateMunger::Destructor +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +StateMunger:: +~StateMunger() { +} + //////////////////////////////////////////////////////////////////// // Function: StateMunger::munge_state // Access: Public @@ -27,14 +36,18 @@ TypeHandle StateMunger::_type_handle; //////////////////////////////////////////////////////////////////// CPT(RenderState) StateMunger:: munge_state(const RenderState *state) { - CPT(RenderState) ptstate = state; - StateMap::iterator mi = _state_map.find(ptstate); + WCPT(RenderState) pt_state = state; + + StateMap::iterator mi = _state_map.find(pt_state); if (mi != _state_map.end()) { - return (*mi).second; + if (!(*mi).first.was_deleted() && + !(*mi).second.was_deleted()) { + return (*mi).second.p(); + } } CPT(RenderState) result = munge_state_impl(state); - _state_map[ptstate] = result; + _state_map[pt_state] = result; return result; } diff --git a/panda/src/pgraph/stateMunger.h b/panda/src/pgraph/stateMunger.h index 452a6d9a12..fcf765fa34 100644 --- a/panda/src/pgraph/stateMunger.h +++ b/panda/src/pgraph/stateMunger.h @@ -22,6 +22,7 @@ #include "pandabase.h" #include "qpgeomMunger.h" #include "renderState.h" +#include "weakPointerTo.h" //////////////////////////////////////////////////////////////////// // Class : StateMunger @@ -34,12 +35,13 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA StateMunger : public qpGeomMunger { public: + virtual ~StateMunger(); CPT(RenderState) munge_state(const RenderState *state); protected: CPT(RenderState) munge_state_impl(const RenderState *state); - typedef pmap StateMap; + typedef pmap< WCPT(RenderState), WCPT(RenderState) > StateMap; StateMap _state_map; public: diff --git a/panda/src/pgraph/texGenAttrib.cxx b/panda/src/pgraph/texGenAttrib.cxx index c5641bab1d..fe41746373 100755 --- a/panda/src/pgraph/texGenAttrib.cxx +++ b/panda/src/pgraph/texGenAttrib.cxx @@ -261,7 +261,7 @@ compare_to_impl(const RenderAttrib *other) const { } } - if (bi != _stages.end()) { + if (bi != ta->_stages.end()) { // a ran out first; b was longer. return -1; }