2002-04-04 01:42:12 +08:00
|
|
|
#include <stdio.h>
|
2001-09-22 10:42:08 +08:00
|
|
|
#include <osg/Notify>
|
2002-07-18 22:20:01 +08:00
|
|
|
#include <osg/Statistics>
|
2001-09-22 10:42:08 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
#include <osgUtil/RenderStage>
|
|
|
|
|
2002-07-18 22:20:01 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
using namespace osg;
|
|
|
|
using namespace osgUtil;
|
|
|
|
|
|
|
|
// register a RenderStage prototype with the RenderBin prototype list.
|
|
|
|
//RegisterRenderBinProxy<RenderStage> s_registerRenderStageProxy;
|
|
|
|
|
2002-09-17 23:47:23 +08:00
|
|
|
RenderStage::RenderStage(SortMode mode):
|
|
|
|
RenderBin(mode)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
// point RenderBin's _stage to this to ensure that references to
|
|
|
|
// stage don't go tempted away to any other stage.
|
|
|
|
_stage = this;
|
|
|
|
_stageDrawnThisFrame = false;
|
|
|
|
|
|
|
|
_clearMask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
|
|
|
|
_clearColor.set(0.0f,0.0f,0.0f,0.0f);
|
|
|
|
_clearAccum.set(0.0f,0.0f,0.0f,0.0f);
|
|
|
|
_clearDepth = 1.0;
|
|
|
|
_clearStencil = 0;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-09-17 23:47:23 +08:00
|
|
|
RenderStage::RenderStage(const RenderStage& rhs,const osg::CopyOp& copyop):
|
|
|
|
RenderBin(rhs,copyop),
|
|
|
|
_stageDrawnThisFrame(false),
|
|
|
|
_dependencyList(rhs._dependencyList),
|
|
|
|
_viewport(rhs._viewport),
|
|
|
|
_clearMask(rhs._clearMask),
|
|
|
|
_colorMask(rhs._colorMask),
|
|
|
|
_clearColor(rhs._clearColor),
|
|
|
|
_clearAccum(rhs._clearAccum),
|
|
|
|
_clearDepth(rhs._clearDepth),
|
|
|
|
_clearStencil(rhs._clearStencil),
|
|
|
|
_renderStageLighting(rhs._renderStageLighting)
|
|
|
|
|
|
|
|
{
|
2002-09-19 17:05:50 +08:00
|
|
|
_stage = this;
|
2002-09-17 23:47:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
RenderStage::~RenderStage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderStage::reset()
|
|
|
|
{
|
|
|
|
_dependencyList.clear();
|
|
|
|
_stageDrawnThisFrame = false;
|
|
|
|
|
|
|
|
if (_renderStageLighting.valid()) _renderStageLighting->reset();
|
|
|
|
|
|
|
|
RenderBin::reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderStage::addToDependencyList(RenderStage* rs)
|
|
|
|
{
|
|
|
|
if (rs) _dependencyList.push_back(rs);
|
|
|
|
}
|
2002-04-22 17:37:17 +08:00
|
|
|
|
2002-09-19 17:52:50 +08:00
|
|
|
void RenderStage::drawPreRenderStages(osg::State& state,RenderLeaf*& previous)
|
|
|
|
{
|
|
|
|
for(DependencyList::iterator itr=_dependencyList.begin();
|
|
|
|
itr!=_dependencyList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
(*itr)->draw(state,previous);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
void RenderStage::draw(osg::State& state,RenderLeaf*& previous)
|
2002-10-17 21:48:46 +08:00
|
|
|
{
|
|
|
|
drawPreRenderStages(state,previous);
|
|
|
|
RenderBin::draw(state,previous);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderStage::drawImplementation(osg::State& state,RenderLeaf*& previous)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
if (_stageDrawnThisFrame) return;
|
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
if (!_viewport)
|
|
|
|
{
|
2002-04-19 23:02:34 +08:00
|
|
|
notify(FATAL) << "Error: cannot draw stage due to undefined viewport."<< std::endl;
|
2001-09-22 10:42:08 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
_stageDrawnThisFrame = true;
|
|
|
|
|
|
|
|
// set up the back buffer.
|
2002-04-22 17:37:17 +08:00
|
|
|
state.applyAttribute(_viewport.get());
|
2002-04-16 23:31:46 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
#define USE_SISSOR_TEST
|
|
|
|
#ifdef USE_SISSOR_TEST
|
2001-09-22 10:42:08 +08:00
|
|
|
glScissor( _viewport->x(), _viewport->y(), _viewport->width(), _viewport->height() );
|
2001-09-20 05:19:47 +08:00
|
|
|
glEnable( GL_SCISSOR_TEST );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// glEnable( GL_DEPTH_TEST );
|
|
|
|
|
2001-12-03 06:20:46 +08:00
|
|
|
// set which color planes to operate on.
|
|
|
|
if (_colorMask.valid()) _colorMask->apply(state);
|
|
|
|
else glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
if (_clearMask & GL_COLOR_BUFFER_BIT)
|
|
|
|
glClearColor( _clearColor[0], _clearColor[1], _clearColor[2], _clearColor[3]);
|
|
|
|
|
|
|
|
if (_clearMask & GL_DEPTH_BUFFER_BIT)
|
|
|
|
glClearDepth( _clearDepth);
|
|
|
|
|
|
|
|
if (_clearMask & GL_STENCIL_BUFFER_BIT)
|
|
|
|
glClearStencil( _clearStencil);
|
|
|
|
|
|
|
|
if (_clearMask & GL_ACCUM_BUFFER_BIT)
|
|
|
|
glClearAccum( _clearAccum[0], _clearAccum[1], _clearAccum[2], _clearAccum[3]);
|
|
|
|
|
|
|
|
|
|
|
|
glClear( _clearMask );
|
|
|
|
|
|
|
|
#ifdef USE_SISSOR_TEST
|
|
|
|
glDisable( GL_SCISSOR_TEST );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
glMatrixMode( GL_MODELVIEW );
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
// apply the lights.
|
|
|
|
if (_renderStageLighting.valid()) _renderStageLighting->draw(state,previous);
|
|
|
|
|
|
|
|
// draw the children and local.
|
2002-10-17 21:48:46 +08:00
|
|
|
RenderBin::drawImplementation(state,previous);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
// now reset the state so its back in its default state.
|
|
|
|
if (previous)
|
|
|
|
{
|
|
|
|
RenderGraph::moveToRootRenderGraph(state,previous->_parent);
|
|
|
|
state.apply();
|
|
|
|
previous = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// Statistics features
|
2001-11-05 03:29:20 +08:00
|
|
|
bool RenderStage::getStats(Statistics* primStats)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
2002-05-02 08:14:40 +08:00
|
|
|
if (_renderStageLighting.valid())
|
|
|
|
{
|
|
|
|
// need to re-implement by checking for lights in the scene
|
|
|
|
// by downcasting the positioned attribute list. RO. May 2002.
|
|
|
|
//primStats->addLight(_renderStageLighting->_lightList.size());
|
|
|
|
}
|
2001-11-05 03:29:20 +08:00
|
|
|
return RenderBin::getStats(primStats);
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|