Fixes to the Impostor implementation.

This commit is contained in:
Robert Osfield 2003-04-09 21:53:09 +00:00
parent 3dc180f3fd
commit 2166f9b701
4 changed files with 31 additions and 7 deletions

View File

@ -198,7 +198,10 @@ class SG_EXPORT ImpostorSpriteManager : public Referenced
void remove(ImpostorSprite* is);
ImpostorSprite* createOrReuseImpostorSprite(int s,int t,int frameNumber);
StateSet* createOrReuseStateSet();
void reset();
protected:
@ -210,6 +213,10 @@ class SG_EXPORT ImpostorSpriteManager : public Referenced
ImpostorSprite* _first;
ImpostorSprite* _last;
typedef std::vector< ref_ptr<StateSet> > StateSetList;
StateSetList _stateSetList;
unsigned int _reuseStateSetIndex;
};

View File

@ -244,8 +244,6 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
osg::ref_ptr<RenderStage> _rootRenderStage;
RenderBin* _currentRenderBin;
osg::ref_ptr<osg::StateSet> _localPreRenderState;
ComputeNearFarMode _computeNearFar;
float _computed_znear;
float _computed_zfar;

View File

@ -163,6 +163,8 @@ ImpostorSpriteManager::ImpostorSpriteManager():
_alphafunc = new osg::AlphaFunc;
_alphafunc->setFunction( AlphaFunc::GREATER, 0.000f );
_reuseStateSetIndex = 0;
}
@ -305,3 +307,18 @@ ImpostorSprite* ImpostorSpriteManager::createOrReuseImpostorSprite(int s,int t,i
}
StateSet* ImpostorSpriteManager::createOrReuseStateSet()
{
if (_reuseStateSetIndex<_stateSetList.size())
{
return _stateSetList[_reuseStateSetIndex++].get();
}
_stateSetList.push_back(new StateSet);
_reuseStateSetIndex=_stateSetList.size();
return _stateSetList.back().get();
}
void ImpostorSpriteManager::reset()
{
_reuseStateSetIndex = 0;
}

View File

@ -142,6 +142,8 @@ void CullVisitor::reset()
(*itr)->reset();
}
if (_impostorSpriteManager.valid()) _impostorSpriteManager->reset();
}
float CullVisitor::getDistanceToEyePoint(const Vec3& pos, bool withLODScale) const
@ -802,9 +804,9 @@ ImpostorSprite* CullVisitor::createImpostorSprite(Impostor& node)
// into account the new camera orientation.
pushModelViewMatrix(rotate_matrix);
if (!_localPreRenderState) _localPreRenderState = new StateSet;
StateSet* localPreRenderState = _impostorSpriteManager->createOrReuseStateSet();
pushStateSet(_localPreRenderState.get());
pushStateSet(localPreRenderState);
{
@ -888,7 +890,7 @@ ImpostorSprite* CullVisitor::createImpostorSprite(Impostor& node)
new_viewport->setViewport(center_x-new_s/2,center_y-new_t/2,new_s,new_t);
rtts->setViewport(new_viewport);
_localPreRenderState->setAttribute(new_viewport);
localPreRenderState->setAttribute(new_viewport);
// create the impostor sprite.
ImpostorSprite* impostorSprite =
@ -912,7 +914,7 @@ ImpostorSprite* CullVisitor::createImpostorSprite(Impostor& node)
// the depth sort bin should probably be user definable,
// will look into this later. RO July 2001.
StateSet* stateset = impostorSprite->getStateSet();
stateset->setRenderBinDetails(1,"DepthSortedBin");
stateset->setRenderBinDetails(10,"DepthSortedBin");
}
Texture2D* texture = impostorSprite->getTexture();