mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
fix RenderState memory leak
This commit is contained in:
parent
b3ff57023c
commit
dab9fd6d27
@ -28,6 +28,7 @@ ColorAttrib(ColorAttrib::Type type, const Colorf &color) :
|
|||||||
_type(type),
|
_type(type),
|
||||||
_color(color)
|
_color(color)
|
||||||
{
|
{
|
||||||
|
quantize_color();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -145,6 +145,21 @@ make_default_impl() const {
|
|||||||
return new ColorAttrib;
|
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
|
// Function: ColorAttrib::register_with_read_factory
|
||||||
// Access: Public, Static
|
// Access: Public, Static
|
||||||
@ -203,4 +218,5 @@ fillin(DatagramIterator &scan, BamReader *manager) {
|
|||||||
|
|
||||||
_type = (Type)scan.get_int8();
|
_type = (Type)scan.get_int8();
|
||||||
_color.read_datagram(scan);
|
_color.read_datagram(scan);
|
||||||
|
quantize_color();
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,9 @@ protected:
|
|||||||
virtual int compare_to_impl(const RenderAttrib *other) const;
|
virtual int compare_to_impl(const RenderAttrib *other) const;
|
||||||
virtual RenderAttrib *make_default_impl() const;
|
virtual RenderAttrib *make_default_impl() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void quantize_color();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type _type;
|
Type _type;
|
||||||
Colorf _color;
|
Colorf _color;
|
||||||
|
@ -28,6 +28,7 @@ ColorScaleAttrib(bool off, const LVecBase4f &scale) :
|
|||||||
_off(off),
|
_off(off),
|
||||||
_scale(scale)
|
_scale(scale)
|
||||||
{
|
{
|
||||||
|
quantize_scale();
|
||||||
_has_scale = !_scale.almost_equal(LVecBase4f(1.0f, 1.0f, 1.0f, 1.0f));
|
_has_scale = !_scale.almost_equal(LVecBase4f(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +82,7 @@ CPT(RenderAttrib) ColorScaleAttrib::
|
|||||||
set_scale(const LVecBase4f &scale) const {
|
set_scale(const LVecBase4f &scale) const {
|
||||||
ColorScaleAttrib *attrib = new ColorScaleAttrib(*this);
|
ColorScaleAttrib *attrib = new ColorScaleAttrib(*this);
|
||||||
attrib->_scale = scale;
|
attrib->_scale = scale;
|
||||||
|
attrib->quantize_scale();
|
||||||
attrib->_has_scale = !scale.almost_equal(LVecBase4f(1.0f, 1.0f, 1.0f, 1.0f));
|
attrib->_has_scale = !scale.almost_equal(LVecBase4f(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
return return_new(attrib);
|
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));
|
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
|
// Function: ColorScaleAttrib::register_with_read_factory
|
||||||
// Access: Public, Static
|
// Access: Public, Static
|
||||||
@ -295,5 +311,6 @@ fillin(DatagramIterator &scan, BamReader *manager) {
|
|||||||
|
|
||||||
_off = scan.get_bool();
|
_off = scan.get_bool();
|
||||||
_scale.read_datagram(scan);
|
_scale.read_datagram(scan);
|
||||||
|
quantize_scale();
|
||||||
_has_scale = !_scale.almost_equal(LVecBase4f(1.0f, 1.0f, 1.0f, 1.0f));
|
_has_scale = !_scale.almost_equal(LVecBase4f(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,9 @@ protected:
|
|||||||
virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
|
virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
|
||||||
virtual RenderAttrib *make_default_impl() const;
|
virtual RenderAttrib *make_default_impl() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void quantize_scale();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _off;
|
bool _off;
|
||||||
bool _has_scale;
|
bool _has_scale;
|
||||||
|
@ -20,6 +20,15 @@
|
|||||||
|
|
||||||
TypeHandle StateMunger::_type_handle;
|
TypeHandle StateMunger::_type_handle;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: StateMunger::Destructor
|
||||||
|
// Access: Public, Virtual
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
StateMunger::
|
||||||
|
~StateMunger() {
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: StateMunger::munge_state
|
// Function: StateMunger::munge_state
|
||||||
// Access: Public
|
// Access: Public
|
||||||
@ -27,14 +36,18 @@ TypeHandle StateMunger::_type_handle;
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
CPT(RenderState) StateMunger::
|
CPT(RenderState) StateMunger::
|
||||||
munge_state(const RenderState *state) {
|
munge_state(const RenderState *state) {
|
||||||
CPT(RenderState) ptstate = state;
|
WCPT(RenderState) pt_state = state;
|
||||||
StateMap::iterator mi = _state_map.find(ptstate);
|
|
||||||
|
StateMap::iterator mi = _state_map.find(pt_state);
|
||||||
if (mi != _state_map.end()) {
|
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);
|
CPT(RenderState) result = munge_state_impl(state);
|
||||||
_state_map[ptstate] = result;
|
_state_map[pt_state] = result;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "pandabase.h"
|
#include "pandabase.h"
|
||||||
#include "qpgeomMunger.h"
|
#include "qpgeomMunger.h"
|
||||||
#include "renderState.h"
|
#include "renderState.h"
|
||||||
|
#include "weakPointerTo.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Class : StateMunger
|
// Class : StateMunger
|
||||||
@ -34,12 +35,13 @@
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
class EXPCL_PANDA StateMunger : public qpGeomMunger {
|
class EXPCL_PANDA StateMunger : public qpGeomMunger {
|
||||||
public:
|
public:
|
||||||
|
virtual ~StateMunger();
|
||||||
CPT(RenderState) munge_state(const RenderState *state);
|
CPT(RenderState) munge_state(const RenderState *state);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CPT(RenderState) munge_state_impl(const RenderState *state);
|
CPT(RenderState) munge_state_impl(const RenderState *state);
|
||||||
|
|
||||||
typedef pmap<CPT(RenderState), CPT(RenderState) > StateMap;
|
typedef pmap< WCPT(RenderState), WCPT(RenderState) > StateMap;
|
||||||
StateMap _state_map;
|
StateMap _state_map;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -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.
|
// a ran out first; b was longer.
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user