Made the more of the OSG's referenced object desctructors protected to ensure

that they arn't created on the stack inappropriately.

Split the implemention of Matrix up so that it is a simple no referenced counted
class and can be safefly created on the stack.  To support referenced counting a
seperate subclass now exists, this is RefMatrix which inherits from both Matrix and
Object.
This commit is contained in:
Robert Osfield
2003-01-10 09:25:42 +00:00
parent f948a3de7c
commit f36bc69c58
53 changed files with 446 additions and 441 deletions

View File

@@ -359,7 +359,7 @@ Vec3 Camera::getSideVector() const
}
void Camera::attachTransform(TransformMode mode, Matrix* matrix)
void Camera::attachTransform(TransformMode mode, RefMatrix* matrix)
{
switch(mode)
{
@@ -369,7 +369,7 @@ void Camera::attachTransform(TransformMode mode, Matrix* matrix)
if (_eyeToModelTransform.valid())
{
_attachedTransformMode = mode;
if (!_modelToEyeTransform.valid()) _modelToEyeTransform = new Matrix;
if (!_modelToEyeTransform.valid()) _modelToEyeTransform = new RefMatrix;
if (!_modelToEyeTransform->invert(*_eyeToModelTransform))
{
notify(WARN)<<"Warning: Camera::attachTransform() failed to invert _modelToEyeTransform"<<std::endl;
@@ -388,7 +388,7 @@ void Camera::attachTransform(TransformMode mode, Matrix* matrix)
if (_modelToEyeTransform.valid())
{
_attachedTransformMode = mode;
if (!_eyeToModelTransform.valid()) _eyeToModelTransform = new Matrix;
if (!_eyeToModelTransform.valid()) _eyeToModelTransform = new RefMatrix;
if (!_eyeToModelTransform->invert(*_modelToEyeTransform))
{
notify(WARN)<<"Warning: Camera::attachTransform() failed to invert _modelToEyeTransform"<<std::endl;

View File

@@ -67,7 +67,7 @@ void CollectOccludersVisitor::apply(osg::Transform& node)
// push the culling mode.
pushCurrentMask();
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(getModelViewMatrix());
ref_ptr<osg::RefMatrix> matrix = createOrReuseMatrix(getModelViewMatrix());
node.getLocalToWorldMatrix(*matrix,this);
pushModelViewMatrix(matrix.get());
@@ -86,7 +86,7 @@ void CollectOccludersVisitor::apply(osg::Projection& node)
// push the culling mode.
pushCurrentMask();
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(node.getMatrix());
ref_ptr<osg::RefMatrix> matrix = createOrReuseMatrix(node.getMatrix());
pushProjectionMatrix(matrix.get());
handle_cull_callbacks_and_traverse(node);

View File

@@ -10,7 +10,8 @@ CullStack::CullStack()
_frustumVolume=-1.0f;
_bbCornerNear = 0;
_bbCornerFar = 7;
_currentReuseMatrixIndex=0;
_currentReuseMatrixIndex=0;
_identity = new RefMatrix();
}
@@ -126,7 +127,7 @@ void CullStack::popViewport()
_MVPW_Stack.pop_back();
}
void CullStack::pushProjectionMatrix(Matrix* matrix)
void CullStack::pushProjectionMatrix(RefMatrix* matrix)
{
_projectionStack.push_back(matrix);
@@ -181,7 +182,7 @@ void CullStack::popProjectionMatrix()
popCullingSet();
}
void CullStack::pushModelViewMatrix(Matrix* matrix)
void CullStack::pushModelViewMatrix(RefMatrix* matrix)
{
_modelviewStack.push_back(matrix);

View File

@@ -1,30 +1,17 @@
#include <osg/DisplaySettings>
#include <osg/ref_ptr>
#include <algorithm>
using namespace osg;
using namespace std;
class DisplaySettingsPtr
{
public:
DisplaySettingsPtr() : _ptr(0L) {}
DisplaySettingsPtr(DisplaySettings* t): _ptr(t) {}
DisplaySettingsPtr(const DisplaySettingsPtr& rp):_ptr(rp._ptr) { }
~DisplaySettingsPtr() { if (_ptr) delete _ptr; _ptr=0L; }
inline DisplaySettings* get() { return _ptr; }
DisplaySettings* _ptr;
};
DisplaySettings* DisplaySettings::instance()
{
static DisplaySettingsPtr s_displaySettings = new DisplaySettings;
static ref_ptr<DisplaySettings> s_displaySettings = new DisplaySettings;
return s_displaySettings.get();
}
DisplaySettings::DisplaySettings(const DisplaySettings& vs):Referenced()
{
copy(vs);

View File

@@ -24,12 +24,12 @@ using namespace osg;
Matrix::Matrix() : Object()
Matrix::Matrix()
{
makeIdentity();
}
Matrix::Matrix( const Matrix& other) : Object()
Matrix::Matrix( const Matrix& other)
{
set( (const float *) other._mat );
}

View File

@@ -5,14 +5,12 @@ using namespace osg;
MatrixTransform::MatrixTransform():
_inverseDirty(false)
{
_matrix = new Matrix;
_inverse = new Matrix;
}
MatrixTransform::MatrixTransform(const MatrixTransform& transform,const CopyOp& copyop):
Transform(transform,copyop),
_matrix(new Matrix(*transform._matrix)),
_inverse(new Matrix(*transform._inverse)),
_matrix(transform._matrix),
_inverse(transform._inverse),
_inverseDirty(transform._inverseDirty)
{
}
@@ -21,8 +19,7 @@ MatrixTransform::MatrixTransform(const Matrix& mat )
{
_referenceFrame = RELATIVE_TO_PARENTS;
_matrix = new Matrix(mat);
_inverse = new Matrix();
_matrix = mat;
_inverseDirty = false;
}
@@ -35,11 +32,11 @@ bool MatrixTransform::computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) con
{
if (_referenceFrame==RELATIVE_TO_PARENTS)
{
matrix.preMult(*_matrix);
matrix.preMult(_matrix);
}
else // absolute
{
matrix = *_matrix;
matrix = _matrix;
}
return true;
}

View File

@@ -4,18 +4,17 @@ using namespace osg;
Projection::Projection()
{
_matrix = new Matrix;
}
Projection::Projection(const Projection& projection,const CopyOp& copyop):
Group(projection,copyop),
_matrix(new Matrix(*projection._matrix))
_matrix(projection._matrix)
{
}
Projection::Projection(const Matrix& mat )
{
_matrix = new Matrix(mat);
_matrix = mat;
}

View File

@@ -170,8 +170,8 @@ bool ShadowVolumeOccluder::computeOccluder(const NodePath& nodePath,const Convex
CullingSet& cullingset = cullStack.getCurrentCullingSet();
const Matrix& MV = cullStack.getModelViewMatrix();
const Matrix& P = cullStack.getProjectionMatrix();
const RefMatrix& MV = cullStack.getModelViewMatrix();
const RefMatrix& P = cullStack.getProjectionMatrix();
// take a reference to the NodePath to this occluder.
_nodePath = nodePath;

View File

@@ -10,7 +10,7 @@ using namespace osg;
State::State()
{
_contextID = 0;
_identity = new osg::Matrix(); // default Matrix constructs to identity.
_identity = new osg::RefMatrix(); // default RefMatrix constructs to identity.
_projection = _identity;
_modelView = _identity;

View File

@@ -91,7 +91,7 @@ void VertexProgram::apply(State& state) const
++itr)
{
::glMatrixMode((*itr).first);
::glLoadMatrixf((*itr).second->ptr());
::glLoadMatrixf((*itr).second.ptr());
}
::glMatrixMode(GL_MODELVIEW); // restore matrix mode
}