Cleand up the root Makefile.

Moved CullVisitor/RenderStage/RenderStageLighting across to managing lights
entirely within RenderStageLighting, and changed the management of modelview
matrices so that RenderLeaf now stores the absolute modelview matrix, rather
than a model matrix as done previously. The later allows RenderLeaf's to do
a glLoadMatrix rather than a glPushMatrix/glMultMatrix/glPopMatrix.
This commit is contained in:
Robert Osfield
2002-02-11 19:51:24 +00:00
parent aeaa31bd2a
commit 386b87d4a0
7 changed files with 37 additions and 64 deletions

View File

@@ -163,7 +163,6 @@ stats :
cat include/osgUtil/* src/osgUtil/*.cpp | wc -l
cat include/osgDB/* src/osgDB/*.cpp | wc -l
cat include/osgGLUT/* src/osgGLUT/*.cpp | wc -l
cat include/osgWX/* src/osgWX/*.cpp | wc -l
cat include/osgText/* src/osgText/*.cpp | wc -l
cat include/*/* src/*/*.cpp | wc -l
cat src/Demos/*/*.cpp | wc -l

View File

@@ -106,13 +106,6 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin
return _renderStageLighting.get();
}
void setLightingMode(RenderStageLighting::Mode mode) { getRenderStageLighting()->setLightingMode(mode); }
RenderStageLighting::Mode getLightingMode() const { return getRenderStageLighting()->getLightingMode(); }
void setLight(osg::Light* light) { getRenderStageLighting()->setLight(light); }
osg::Light* getLight() { return getRenderStageLighting()->getLight(); }
const osg::Light* getLight() const { return getRenderStageLighting()->getLight(); }
virtual void addLight(osg::Light* light,osg::Matrix* matrix)
{
getRenderStageLighting()->addLight(light,matrix);

View File

@@ -30,19 +30,6 @@ class OSGUTIL_EXPORT RenderStageLighting : public osg::Object
virtual void reset();
enum Mode {
HEADLIGHT, // default
SKY_LIGHT,
NO_SCENEVIEW_LIGHT
};
void setLightingMode(Mode mode) { _lightingMode=mode; }
Mode getLightingMode() const { return _lightingMode; }
void setLight(osg::Light* light) { _light = light; }
osg::Light* getLight() { return _light.get(); }
const osg::Light* getLight() const { return _light.get(); }
typedef std::pair< osg::Light*, osg::ref_ptr<osg::Matrix> > LightMatrixPair;
typedef std::vector< LightMatrixPair > LightList;
@@ -55,10 +42,7 @@ class OSGUTIL_EXPORT RenderStageLighting : public osg::Object
public:
Mode _lightingMode;
osg::ref_ptr<osg::Light> _light;
LightList _lightList;
protected:

View File

@@ -33,12 +33,14 @@ void RenderLeaf::render(State& state,RenderLeaf* previous)
Matrix* prev_matrix = previous->_matrix.get();
if (_matrix != prev_matrix)
{
if (prev_matrix) glPopMatrix();
if (_matrix.valid())
{
glPushMatrix();
glMultMatrixf(_matrix->ptr());
glLoadMatrixf(_matrix->ptr());
}
else
{
glLoadIdentity();
}
}
@@ -54,8 +56,11 @@ void RenderLeaf::render(State& state,RenderLeaf* previous)
if (_matrix.valid())
{
glPushMatrix();
glMultMatrixf(_matrix->ptr());
glLoadMatrixf(_matrix->ptr());
}
else
{
glLoadIdentity();
}
_drawable->draw(state);

View File

@@ -108,22 +108,6 @@ void RenderStage::draw(osg::State& state,RenderLeaf*& previous)
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
Light* light = getLight();
if (getLightingMode()==RenderStageLighting::HEADLIGHT && light)
{
light->apply(state);
}
// set up camera modelview.
const Matrix& modelView = _camera->getModelViewMatrix();
glLoadMatrixf(modelView.ptr());
if (getLightingMode()==RenderStageLighting::SKY_LIGHT && light)
{
light->apply(state);
}
// apply the lights.
if (_renderStageLighting.valid()) _renderStageLighting->draw(state,previous);
@@ -135,7 +119,6 @@ void RenderStage::draw(osg::State& state,RenderLeaf*& previous)
{
RenderGraph::moveToRootRenderGraph(state,previous->_parent);
state.apply();
if (previous->_matrix.valid()) glPopMatrix();
previous = NULL;
}

View File

@@ -26,7 +26,6 @@ void RenderStageLighting::draw(osg::State& state,RenderLeaf*& previous)
{
RenderGraph::moveToRootRenderGraph(state,previous->_parent);
state.apply();
if (previous->_matrix.valid()) glPopMatrix();
previous = NULL;
}
@@ -40,12 +39,13 @@ void RenderStageLighting::draw(osg::State& state,RenderLeaf*& previous)
Matrix* matrix = (*litr).second.get();
if (matrix != prev_matrix)
{
if (prev_matrix) glPopMatrix();
if (matrix)
{
glPushMatrix();
glMultMatrixf(matrix->ptr());
glLoadMatrixf(matrix->ptr());
}
else
{
glLoadIdentity();
}
prev_matrix = matrix;
@@ -55,7 +55,5 @@ void RenderStageLighting::draw(osg::State& state,RenderLeaf*& previous)
litr->first->apply(state);
}
// clean up matrix stack.
if (prev_matrix) glPopMatrix();
}

View File

@@ -152,6 +152,12 @@ void SceneView::cull()
_camera->adjustAspectRatio(_viewport->aspectRatio());
// comment out reset of rendergraph since clean is more efficient.
// _rendergraph->reset();
// use clean of the rendergraph rather than reset, as it is able to
// reuse the structure on the rendergraph in the next frame. This
// achieves a certain amount of frame cohereancy of memory allocation.
_rendergraph->clean();
_cullVisitor->reset();
@@ -164,15 +170,17 @@ void SceneView::cull()
_cullVisitor->setTraversalNumber(_frameStamp->getFrameNumber());
}
// comment out reset of rendergraph since clean is more efficient.
// _rendergraph->reset();
// get the camera's modelview
osg::Matrix* modelview = new osg::Matrix(_camera->getModelViewMatrix());
// take a copy of camera, and init it home
osg::Camera* camera = new Camera(*_camera);
camera->home();
// use clean of the rendergraph rather than reset, as it is able to
// reuse the structure on the rendergraph in the next frame. This
// achieves a certain amount of frame cohereancy of memory allocation.
_cullVisitor->setLODBias(_lodBias);
_cullVisitor->setCamera(*_camera);
_cullVisitor->setCamera(*camera);
_cullVisitor->setViewport(_viewport.get());
_cullVisitor->setEarthSky(NULL); // reset earth sky on each frame.
@@ -184,31 +192,34 @@ void SceneView::cull()
_renderStage->reset();
_renderStage->setViewport(_viewport.get());
_renderStage->setCamera(_camera.get());
_renderStage->setCamera(camera);
_renderStage->setClearColor(_backgroundColor);
_renderStage->setLight(_light.get());
switch(_lightingMode)
{
case(HEADLIGHT):
_renderStage->setLightingMode(RenderStageLighting::HEADLIGHT);
_renderStage->addLight(_light.get(),NULL);
break;
case(SKY_LIGHT):
_renderStage->setLightingMode(RenderStageLighting::SKY_LIGHT);
_renderStage->addLight(_light.get(),modelview);
break;
case(NO_SCENEVIEW_LIGHT):
_renderStage->setLightingMode(RenderStageLighting::NO_SCENEVIEW_LIGHT);
break;
}
if (_globalState.valid()) _cullVisitor->pushStateSet(_globalState.get());
_cullVisitor->pushCullViewState(modelview);
// traverse the scene graph to generate the rendergraph.
_sceneData->accept(*_cullVisitor);
if (_globalState.valid()) _cullVisitor->popStateSet();
_cullVisitor->popCullViewState();
// do any state sorting required.