Work on the RenderToTexture usage of the new osg::CameraNode. Both osghud

and osgprerender now ported across to osg::CameraNode.
This commit is contained in:
Robert Osfield
2005-06-14 20:51:35 +00:00
parent 868d381528
commit 71122ff38f
9 changed files with 507 additions and 195 deletions

View File

@@ -1023,6 +1023,100 @@ void CullVisitor::apply(osg::ClearNode& node)
}
void CullVisitor::apply(osg::CameraNode& camera)
{
// push the node's state.
StateSet* node_state = camera.getStateSet();
if (node_state) pushStateSet(node_state);
// use render to texture stage.
{
// create the render to texture stage.
osg::ref_ptr<osgUtil::RenderToTextureStage> rtts = new osgUtil::RenderToTextureStage;
// set up lighting.
// currently ignore lights in the scene graph itself..
// will do later.
osgUtil::RenderStage* previous_stage = getCurrentRenderBin()->getStage();
// set up the background color and clear mask.
rtts->setClearColor(camera.getClearColor());
rtts->setClearMask(camera.getClearMask());
// set up the viewport.
rtts->setViewport( camera.getViewport()!=0 ? camera.getViewport() : previous_stage->getViewport());
// set up to charge the same RenderStageLighting is the parent previous stage.
rtts->setRenderStageLighting(previous_stage->getRenderStageLighting());
// record the render bin, to be restored after creation
// of the render to text
osgUtil::RenderBin* previousRenderBin = getCurrentRenderBin();
// set the current renderbin to be the newly created stage.
setCurrentRenderBin(rtts.get());
pushProjectionMatrix(new osg::RefMatrix(camera.getProjectionMatrix()));
pushModelViewMatrix(new osg::RefMatrix(camera.getViewMatrix()));
// traverse the subgraph
{
handle_cull_callbacks_and_traverse(camera);
}
// restore the previous model view matrix.
popModelViewMatrix();
// restore the previous model view matrix.
popProjectionMatrix();
// restore the previous renderbin.
setCurrentRenderBin(previousRenderBin);
if (rtts->getRenderGraphList().size()==0 && rtts->getRenderBinList().size()==0)
{
// getting to this point means that all the subgraph has been
// culled by small feature culling or is beyond LOD ranges.
}
// and the render to texture stage to the current stages
// dependancy list.
switch(camera.getRenderOrder())
{
case osg::CameraNode::PRE_RENDER :
getCurrentRenderBin()->getStage()->addPreRenderStage(rtts.get());
break;
case osg::CameraNode::NESTED_RENDER :
getCurrentRenderBin()->getStage()->addPostRenderStage(rtts.get());
break;
case osg::CameraNode::POST_RENDER :
getCurrentRenderBin()->getStage()->addPostRenderStage(rtts.get());
break;
}
osg::CameraNode::BufferAttachmentMap& bufferAttachements = camera.getBufferAttachmentMap();
for(osg::CameraNode::BufferAttachmentMap::iterator itr = bufferAttachements.begin();
itr != bufferAttachements.end();
++itr)
{
// if one exist attach texture to the RenderToTextureStage.
osg::Texture2D* texture2D = dynamic_cast<osg::Texture2D*>(itr->second._texture.get());
if (texture2D) rtts->setTexture(texture2D);
// if one exist attach image to the RenderToTextureStage.
if (itr->second._image.valid()) rtts->setImage(itr->second._image.get());
}
}
// pop the node's state off the render graph stack.
if (node_state) popStateSet();
}
void CullVisitor::apply(osg::OccluderNode& node)
{
// need to check if occlusion node is in the occluder

View File

@@ -322,7 +322,7 @@ RenderBin* RenderBin::find_or_insert(int binNum,const std::string& binName)
rs->_binNum = binNum;
rs->_parent = NULL;
rs->_stage = rs;
_stage->addToDependencyList(rs);
_stage->addPreRenderStage(rs);
}
else
{

View File

@@ -56,7 +56,8 @@ RenderStage::RenderStage(SortMode mode):
RenderStage::RenderStage(const RenderStage& rhs,const osg::CopyOp& copyop):
RenderBin(rhs,copyop),
_stageDrawnThisFrame(false),
_dependencyList(rhs._dependencyList),
_preRenderList(rhs._preRenderList),
_postRenderList(rhs._postRenderList),
_viewport(rhs._viewport),
_clearMask(rhs._clearMask),
_colorMask(rhs._colorMask),
@@ -77,7 +78,7 @@ RenderStage::~RenderStage()
void RenderStage::reset()
{
_dependencyList.clear();
_preRenderList.clear();
_stageDrawnThisFrame = false;
if (_renderStageLighting.valid()) _renderStageLighting->reset();
@@ -85,18 +86,23 @@ void RenderStage::reset()
RenderBin::reset();
}
void RenderStage::addToDependencyList(RenderStage* rs)
void RenderStage::addPreRenderStage(RenderStage* rs)
{
if (rs) _dependencyList.push_back(rs);
if (rs) _preRenderList.push_back(rs);
}
void RenderStage::addPostRenderStage(RenderStage* rs)
{
if (rs) _postRenderList.push_back(rs);
}
void RenderStage::drawPreRenderStages(osg::State& state,RenderLeaf*& previous)
{
if (_dependencyList.empty()) return;
if (_preRenderList.empty()) return;
//cout << "Drawing prerendering stages "<<this<< " "<<_viewport->x()<<","<< _viewport->y()<<","<< _viewport->width()<<","<< _viewport->height()<<std::endl;
for(DependencyList::iterator itr=_dependencyList.begin();
itr!=_dependencyList.end();
for(RenderStageList::iterator itr=_preRenderList.begin();
itr!=_preRenderList.end();
++itr)
{
(*itr)->draw(state,previous);
@@ -115,6 +121,10 @@ void RenderStage::draw(osg::State& state,RenderLeaf*& previous)
//drawPreRenderStages(state,previous);
RenderBin::draw(state,previous);
// place the post draw here temprorarily while we figure out how
// best to do SceneView.
drawPostRenderStages(state,previous);
}
void RenderStage::drawImplementation(osg::State& state,RenderLeaf*& previous)
@@ -182,6 +192,21 @@ void RenderStage::drawImplementation(osg::State& state,RenderLeaf*& previous)
}
}
void RenderStage::drawPostRenderStages(osg::State& state,RenderLeaf*& previous)
{
if (_postRenderList.empty()) return;
//cout << "Drawing prerendering stages "<<this<< " "<<_viewport->x()<<","<< _viewport->y()<<","<< _viewport->width()<<","<< _viewport->height()<<std::endl;
for(RenderStageList::iterator itr=_postRenderList.begin();
itr!=_postRenderList.end();
++itr)
{
(*itr)->draw(state,previous);
}
//cout << "Done Drawing prerendering stages "<<this<< " "<<_viewport->x()<<","<< _viewport->y()<<","<< _viewport->width()<<","<< _viewport->height()<<std::endl;
}
// Statistics features
bool RenderStage::getStats(Statistics* primStats)
{