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:
@@ -259,7 +259,7 @@ void CullVisitor::apply(Geode& node)
|
||||
StateSet* node_state = node.getStateSet();
|
||||
if (node_state) pushStateSet(node_state);
|
||||
|
||||
Matrix& matrix = getModelViewMatrix();
|
||||
RefMatrix& matrix = getModelViewMatrix();
|
||||
for(unsigned int i=0;i<node.getNumDrawables();++i)
|
||||
{
|
||||
Drawable* drawable = node.getDrawable(i);
|
||||
@@ -304,7 +304,7 @@ void CullVisitor::apply(Billboard& node)
|
||||
if (node_state) pushStateSet(node_state);
|
||||
|
||||
const Vec3& eye_local = getEyeLocal();
|
||||
const Matrix& modelview = getModelViewMatrix();
|
||||
const RefMatrix& modelview = getModelViewMatrix();
|
||||
|
||||
for(unsigned int i=0;i<node.getNumDrawables();++i)
|
||||
{
|
||||
@@ -314,7 +314,7 @@ void CullVisitor::apply(Billboard& node)
|
||||
// need to modify isCulled to handle the billboard offset.
|
||||
// if (isCulled(drawable->getBound())) continue;
|
||||
|
||||
Matrix* billboard_matrix = createOrReuseMatrix(modelview);
|
||||
RefMatrix* billboard_matrix = createOrReuseMatrix(modelview);
|
||||
|
||||
node.getMatrix(*billboard_matrix,eye_local,pos);
|
||||
|
||||
@@ -347,7 +347,7 @@ void CullVisitor::apply(LightSource& node)
|
||||
StateSet* node_state = node.getStateSet();
|
||||
if (node_state) pushStateSet(node_state);
|
||||
|
||||
Matrix& matrix = getModelViewMatrix();
|
||||
RefMatrix& matrix = getModelViewMatrix();
|
||||
StateAttribute* light = node.getLight();
|
||||
if (light)
|
||||
{
|
||||
@@ -366,7 +366,7 @@ void CullVisitor::apply(ClipNode& node)
|
||||
StateSet* node_state = node.getStateSet();
|
||||
if (node_state) pushStateSet(node_state);
|
||||
|
||||
Matrix& matrix = getModelViewMatrix();
|
||||
RefMatrix& matrix = getModelViewMatrix();
|
||||
|
||||
const ClipNode::ClipPlaneList& planes = node.getClipPlaneList();
|
||||
for(ClipNode::ClipPlaneList::const_iterator itr=planes.begin();
|
||||
@@ -413,7 +413,7 @@ void CullVisitor::apply(Transform& node)
|
||||
StateSet* node_state = node.getStateSet();
|
||||
if (node_state) pushStateSet(node_state);
|
||||
|
||||
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(getModelViewMatrix());
|
||||
ref_ptr<RefMatrix> matrix = createOrReuseMatrix(getModelViewMatrix());
|
||||
node.getLocalToWorldMatrix(*matrix,this);
|
||||
pushModelViewMatrix(matrix.get());
|
||||
|
||||
@@ -447,7 +447,7 @@ void CullVisitor::apply(Projection& node)
|
||||
_computed_znear = FLT_MAX;
|
||||
_computed_zfar = -FLT_MAX;
|
||||
|
||||
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);
|
||||
@@ -580,7 +580,7 @@ void CullVisitor::apply(Impostor& node)
|
||||
// within the impostor distance threshold therefore attempt
|
||||
// to use impostor instead.
|
||||
|
||||
Matrix& matrix = getModelViewMatrix();
|
||||
RefMatrix& matrix = getModelViewMatrix();
|
||||
|
||||
// search for the best fit ImpostorSprite;
|
||||
ImpostorSprite* impostorSprite = node.findBestImpostorSprite(eyeLocal);
|
||||
@@ -748,7 +748,7 @@ ImpostorSprite* CullVisitor::createImpostorSprite(Impostor& node)
|
||||
zfar *= 1.1f;
|
||||
|
||||
// set up projection.
|
||||
osg::Matrix* projection = new osg::Matrix;
|
||||
osg::RefMatrix* projection = new osg::RefMatrix;
|
||||
if (isPerspectiveProjection)
|
||||
{
|
||||
// deal with projection issue move the top and right points
|
||||
@@ -768,7 +768,7 @@ ImpostorSprite* CullVisitor::createImpostorSprite(Impostor& node)
|
||||
Vec3 rotate_from = bs.center()-eye_local;
|
||||
Vec3 rotate_to = getLookVectorLocal();
|
||||
|
||||
osg::Matrix* rotate_matrix = new osg::Matrix(
|
||||
osg::RefMatrix* rotate_matrix = new osg::RefMatrix(
|
||||
osg::Matrix::translate(-eye_local)*
|
||||
osg::Matrix::rotate(rotate_from,rotate_to)*
|
||||
osg::Matrix::translate(eye_local)*
|
||||
|
||||
@@ -215,15 +215,15 @@ void IntersectVisitor::pushMatrix(const Matrix& matrix)
|
||||
|
||||
if (cis->_matrix.valid())
|
||||
{
|
||||
nis->_matrix = new Matrix;
|
||||
nis->_matrix = new RefMatrix;
|
||||
nis->_matrix->mult(matrix,*(cis->_matrix));
|
||||
}
|
||||
else
|
||||
{
|
||||
nis->_matrix = new Matrix(matrix);
|
||||
nis->_matrix = new RefMatrix(matrix);
|
||||
}
|
||||
|
||||
Matrix* inverse_world = new Matrix;
|
||||
RefMatrix* inverse_world = new RefMatrix;
|
||||
inverse_world->invert(*(nis->_matrix));
|
||||
nis->_inverse = inverse_world;
|
||||
|
||||
@@ -527,7 +527,7 @@ void IntersectVisitor::apply(Transform& node)
|
||||
{
|
||||
if (!enterNode(node)) return;
|
||||
|
||||
osg::ref_ptr<Matrix> matrix = new Matrix;
|
||||
osg::ref_ptr<RefMatrix> matrix = new RefMatrix;
|
||||
node.getLocalToWorldMatrix(*matrix,this);
|
||||
|
||||
pushMatrix(*matrix);
|
||||
|
||||
@@ -206,8 +206,8 @@ void SceneView::cull()
|
||||
_state->setDisplaySettings(_displaySettings.get());
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Matrix> projection = _projectionMatrix.get();
|
||||
osg::ref_ptr<osg::Matrix> modelview = _modelviewMatrix.get();
|
||||
osg::ref_ptr<osg::RefMatrix> projection = _projectionMatrix.get();
|
||||
osg::ref_ptr<osg::RefMatrix> modelview = _modelviewMatrix.get();
|
||||
|
||||
if (_camera.valid())
|
||||
{
|
||||
@@ -235,15 +235,15 @@ void SceneView::cull()
|
||||
if (_displaySettings.valid())
|
||||
_camera->setScreenDistance(_displaySettings->getScreenDistance());
|
||||
|
||||
if (!projection) projection = new osg::Matrix(_camera->getProjectionMatrix());
|
||||
if (!modelview) modelview = new osg::Matrix(_camera->getModelViewMatrix());
|
||||
if (!projection) projection = new osg::RefMatrix(_camera->getProjectionMatrix());
|
||||
if (!modelview) modelview = new osg::RefMatrix(_camera->getModelViewMatrix());
|
||||
|
||||
//cout <<"fovx="<<_camera->calc_fovx()<<endl;
|
||||
|
||||
}
|
||||
|
||||
if (!projection) projection = new osg::Matrix();
|
||||
if (!modelview) modelview = new osg::Matrix();
|
||||
if (!projection) projection = new osg::RefMatrix();
|
||||
if (!modelview) modelview = new osg::RefMatrix();
|
||||
|
||||
if (!_cullVisitor)
|
||||
{
|
||||
@@ -288,18 +288,18 @@ void SceneView::cull()
|
||||
if (_displaySettings->getStereoMode()==osg::DisplaySettings::LEFT_EYE)
|
||||
{
|
||||
// set up the left eye.
|
||||
osg::ref_ptr<osg::Matrix> projectionLeft = new osg::Matrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
iod/(2.0f*sd),0.0f,1.0f,0.0f,
|
||||
0.0f,0.0f,0.0f,1.0f)*
|
||||
(*projection));
|
||||
osg::ref_ptr<osg::RefMatrix> projectionLeft = new osg::RefMatrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
iod/(2.0f*sd),0.0f,1.0f,0.0f,
|
||||
0.0f,0.0f,0.0f,1.0f)*
|
||||
(*projection));
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Matrix> modelviewLeft = new osg::Matrix( (*modelview) *
|
||||
osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
0.0f,0.0f,1.0f,0.0f,
|
||||
es,0.0f,0.0f,1.0f));
|
||||
osg::ref_ptr<osg::RefMatrix> modelviewLeft = new osg::RefMatrix( (*modelview) *
|
||||
osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
0.0f,0.0f,1.0f,0.0f,
|
||||
es,0.0f,0.0f,1.0f));
|
||||
|
||||
_cullVisitor->setTraversalMask(_cullMaskLeft);
|
||||
cullStage(projectionLeft.get(),modelviewLeft.get(),_cullVisitor.get(),_rendergraph.get(),_renderStage.get());
|
||||
@@ -313,17 +313,17 @@ void SceneView::cull()
|
||||
else if (_displaySettings->getStereoMode()==osg::DisplaySettings::RIGHT_EYE)
|
||||
{
|
||||
// set up the right eye.
|
||||
osg::ref_ptr<osg::Matrix> projectionRight = new osg::Matrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
-iod/(2.0f*sd),0.0f,1.0f,0.0f,
|
||||
0.0f,0.0f,0.0f,1.0f)*
|
||||
(*projection));
|
||||
osg::ref_ptr<osg::RefMatrix> projectionRight = new osg::RefMatrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
-iod/(2.0f*sd),0.0f,1.0f,0.0f,
|
||||
0.0f,0.0f,0.0f,1.0f)*
|
||||
(*projection));
|
||||
|
||||
osg::ref_ptr<osg::Matrix> modelviewRight = new osg::Matrix( (*modelview) *
|
||||
osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
0.0f,0.0f,1.0f,0.0f,
|
||||
-es,0.0f,0.0f,1.0f));
|
||||
osg::ref_ptr<osg::RefMatrix> modelviewRight = new osg::RefMatrix( (*modelview) *
|
||||
osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
0.0f,0.0f,1.0f,0.0f,
|
||||
-es,0.0f,0.0f,1.0f));
|
||||
|
||||
_cullVisitor->setTraversalMask(_cullMaskRight);
|
||||
cullStage(projectionRight.get(),modelviewRight.get(),_cullVisitor.get(),_rendergraph.get(),_renderStage.get());
|
||||
@@ -348,14 +348,14 @@ void SceneView::cull()
|
||||
|
||||
|
||||
// set up the left eye.
|
||||
osg::ref_ptr<osg::Matrix> projectionLeft = new osg::Matrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
iod/(2.0f*sd),0.0f,1.0f,0.0f,
|
||||
0.0f,0.0f,0.0f,1.0f)*
|
||||
(*projection));
|
||||
osg::ref_ptr<osg::RefMatrix> projectionLeft = new osg::RefMatrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
iod/(2.0f*sd),0.0f,1.0f,0.0f,
|
||||
0.0f,0.0f,0.0f,1.0f)*
|
||||
(*projection));
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Matrix> modelviewLeft = new osg::Matrix( (*modelview) *
|
||||
osg::ref_ptr<osg::RefMatrix> modelviewLeft = new osg::RefMatrix( (*modelview) *
|
||||
osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
0.0f,0.0f,1.0f,0.0f,
|
||||
@@ -366,17 +366,17 @@ void SceneView::cull()
|
||||
|
||||
|
||||
// set up the right eye.
|
||||
osg::ref_ptr<osg::Matrix> projectionRight = new osg::Matrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
-iod/(2.0f*sd),0.0f,1.0f,0.0f,
|
||||
0.0f,0.0f,0.0f,1.0f)*
|
||||
(*projection));
|
||||
osg::ref_ptr<osg::RefMatrix> projectionRight = new osg::RefMatrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
-iod/(2.0f*sd),0.0f,1.0f,0.0f,
|
||||
0.0f,0.0f,0.0f,1.0f)*
|
||||
(*projection));
|
||||
|
||||
osg::ref_ptr<osg::Matrix> modelviewRight = new osg::Matrix( (*modelview) *
|
||||
osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
0.0f,0.0f,1.0f,0.0f,
|
||||
-es,0.0f,0.0f,1.0f));
|
||||
osg::ref_ptr<osg::RefMatrix> modelviewRight = new osg::RefMatrix( (*modelview) *
|
||||
osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
0.0f,0.0f,1.0f,0.0f,
|
||||
-es,0.0f,0.0f,1.0f));
|
||||
|
||||
_cullVisitorRight->setTraversalMask(_cullMaskRight);
|
||||
cullStage(projectionRight.get(),modelviewRight.get(),_cullVisitorRight.get(),_rendergraphRight.get(),_renderStageRight.get());
|
||||
@@ -407,7 +407,7 @@ void SceneView::cull()
|
||||
|
||||
}
|
||||
|
||||
void SceneView::cullStage(osg::Matrix* projection,osg::Matrix* modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::RenderGraph* rendergraph, osgUtil::RenderStage* renderStage)
|
||||
void SceneView::cullStage(osg::RefMatrix* projection,osg::RefMatrix* modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::RenderGraph* rendergraph, osgUtil::RenderStage* renderStage)
|
||||
{
|
||||
|
||||
if (!_sceneData || !_viewport->valid()) return;
|
||||
|
||||
Reference in New Issue
Block a user