Updated TODO list.

Converted AnimationPath so it is now subclassed from osg::Transform::ComputeTransfromCallback()
so that it can be directly attached to the scene to move objects about.

Changed the osg::SateSet::setGlobalDefaults() so that is sets GL_DEPTH_TEST
to ON.

Added guards and creation of default helper classes in osgGLUT::Viewer and
osgUtil::SceneView so that sensible defaults are used when no settings
are used of osg::State/StateSet,osgUtil::RenderStage/RenderGraph/CullVisitor.
This commit is contained in:
Robert Osfield
2002-04-21 22:05:26 +00:00
parent a0cb66ed78
commit 9574ce97d2
7 changed files with 131 additions and 51 deletions

View File

@@ -1,4 +1,5 @@
#include <osg/AnimationPath>
#include <osg/NodeVisitor>
using namespace osg;
@@ -7,18 +8,18 @@ void AnimationPath::insert(double time,const Key& key)
_timeKeyMap[time] = key;
}
bool AnimationPath::getMatrix(double time,Matrix& matrix)
bool AnimationPath::getMatrix(double time,Matrix& matrix) const
{
if (_timeKeyMap.empty()) return false;
TimeKeyMap::iterator second = _timeKeyMap.lower_bound(time);
TimeKeyMap::const_iterator second = _timeKeyMap.lower_bound(time);
if (second==_timeKeyMap.begin())
{
second->second.getMatrix(matrix);
}
else if (second!=_timeKeyMap.end())
{
TimeKeyMap::iterator first = second;
TimeKeyMap::const_iterator first = second;
--first;
// we have both a lower bound and the next item.
@@ -44,18 +45,18 @@ bool AnimationPath::getMatrix(double time,Matrix& matrix)
return true;
}
bool AnimationPath::getInverse(double time,Matrix& matrix)
bool AnimationPath::getInverse(double time,Matrix& matrix) const
{
if (_timeKeyMap.empty()) return false;
TimeKeyMap::iterator second = _timeKeyMap.lower_bound(time);
TimeKeyMap::const_iterator second = _timeKeyMap.lower_bound(time);
if (second==_timeKeyMap.begin())
{
second->second.getInverse(matrix);
}
else if (second!=_timeKeyMap.end())
{
TimeKeyMap::iterator first = second;
TimeKeyMap::const_iterator first = second;
--first;
// we have both a lower bound and the next item.
@@ -80,3 +81,36 @@ bool AnimationPath::getInverse(double time,Matrix& matrix)
}
return true;
}
const bool AnimationPath::computeLocalToWorldMatrix(Matrix& matrix,const Transform*, NodeVisitor* nv) const
{
if (nv)
{
const osg::FrameStamp* fs = nv->getFrameStamp();
if (fs)
{
osg::Matrix localMatrix;
getMatrix(fs->getReferenceTime(),localMatrix);
matrix.preMult(localMatrix);
return true;
}
}
return false;
}
/** Get the transformation matrix which moves from world coords to local coords.*/
const bool AnimationPath::computeWorldToLocalMatrix(Matrix& matrix,const Transform* , NodeVisitor* nv) const
{
if (nv)
{
const osg::FrameStamp* fs = nv->getFrameStamp();
if (fs)
{
osg::Matrix localInverse;
getInverse(fs->getReferenceTime(),localInverse);
matrix.postMult(localInverse);
return true;
}
}
return false;
}

View File

@@ -33,7 +33,8 @@ void State::reset()
_modeMap.clear();
_modeMap[GL_DEPTH_TEST].global_default_value = true;
_modeMap[GL_DEPTH_TEST].changed = true;
// go through all active StateAttribute's, applying where appropriate.
for(AttributeMap::iterator aitr=_attributeMap.begin();
aitr!=_attributeMap.end();

View File

@@ -130,6 +130,7 @@ void StateSet::setGlobalDefaults()
setRendingBinToInherit();
setMode(GL_DEPTH_TEST,StateAttribute::ON);
setAttributeAndModes(osgNew AlphaFunc,StateAttribute::OFF);
setAttributeAndModes(osgNew Transparency,StateAttribute::OFF);

View File

@@ -243,7 +243,7 @@ bool Viewer::open()
++itr)
{
osgUtil::RenderStage *stage = itr->sceneView->getRenderStage();
stage->setClearMask(clear_mask);
if (stage) stage->setClearMask(clear_mask);
}
@@ -767,6 +767,7 @@ void Viewer::mouse(int button, int state, int x, int y)
}
void Viewer::keyboard(unsigned char key, int x, int y)
{
osg::ref_ptr<GLUTEventAdapter> ea = osgNew GLUTEventAdapter;
@@ -775,6 +776,8 @@ void Viewer::keyboard(unsigned char key, int x, int y)
if (_viewportList[_focusedViewport]._cameraManipulator->handle(*ea,*this))
return;
if (key>='1' && key<='3')
{
int pos = key-'1';
@@ -782,6 +785,12 @@ void Viewer::keyboard(unsigned char key, int x, int y)
}
osgUtil::SceneView* sceneView = getViewportSceneView(_focusedViewport);
osg::StateSet* globalStateSet = sceneView->getGlobalStateSet();
if (!globalStateSet)
{
globalStateSet = osgNew osg::StateSet;
sceneView->setGlobalStateSet(globalStateSet);
}
switch( key )
{
@@ -881,7 +890,7 @@ void Viewer::keyboard(unsigned char key, int x, int y)
case 's' :
{
flat_shade = 1 - flat_shade ;
osg::StateSet* stateset = sceneView->getGlobalStateSet();
osg::StateSet* stateset = globalStateSet;
osg::ShadeModel* shademodel = dynamic_cast<osg::ShadeModel*>(stateset->getAttribute(osg::StateAttribute::SHADEMODEL));
if (!shademodel)
{
@@ -920,18 +929,18 @@ void Viewer::keyboard(unsigned char key, int x, int y)
backface = 1 - backface;
if( backface )
sceneView->getGlobalStateSet()->setMode(GL_CULL_FACE,osg::StateAttribute::ON);
globalStateSet->setMode(GL_CULL_FACE,osg::StateAttribute::ON);
else
sceneView->getGlobalStateSet()->setMode(GL_CULL_FACE,osg::StateAttribute::OVERRIDE_OFF);
globalStateSet->setMode(GL_CULL_FACE,osg::StateAttribute::OVERRIDE_OFF);
break;
case 'l' :
lighting = 1 - lighting ;
if( lighting )
sceneView->getGlobalStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE_ON);
globalStateSet->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE_ON);
else
sceneView->getGlobalStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE_OFF);
globalStateSet->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE_OFF);
break;
case 'L' :
@@ -950,8 +959,8 @@ void Viewer::keyboard(unsigned char key, int x, int y)
texture = 1 - texture;
if (texture)
{
sceneView->getGlobalStateSet()->setModeToInherit(GL_TEXTURE_2D);
// sceneView->getGlobalStateSet()->setAttributeToInherit(osg::StateAttribute::TEXTURE);
globalStateSet->setModeToInherit(GL_TEXTURE_2D);
// globalStateSet->setAttributeToInherit(osg::StateAttribute::TEXTURE);
}
else
{
@@ -959,18 +968,18 @@ void Viewer::keyboard(unsigned char key, int x, int y)
// thus causing them to all use the same texture attribute, hence
// preventing a state attribute change due to unused textures.
static osg::ref_ptr<osg::Texture> blank_texture = osgNew osg::Texture;
sceneView->getGlobalStateSet()->setMode(GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE_OFF);
// sceneView->getGlobalStateSet()->setAttribute(blank_texture.get(),true);
globalStateSet->setMode(GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE_OFF);
// globalStateSet->setAttribute(blank_texture.get(),true);
}
break;
case 'T' :
{
osg::LightModel* lightmodel = dynamic_cast<LightModel*>(sceneView->getGlobalStateSet()->getAttribute(osg::StateAttribute::LIGHTMODEL));
osg::LightModel* lightmodel = dynamic_cast<LightModel*>(globalStateSet->getAttribute(osg::StateAttribute::LIGHTMODEL));
if (lightmodel)
{
lightmodel = osgNew osg::LightModel;
sceneView->getGlobalStateSet()->setAttribute(lightmodel);
globalStateSet->setAttribute(lightmodel);
}
lightmodel->setTwoSided(!lightmodel->getTwoSided());
}
@@ -981,7 +990,7 @@ void Viewer::keyboard(unsigned char key, int x, int y)
polymode = (polymode+1)%3;
osg::PolygonMode* polyModeObj = osgNew osg::PolygonMode;
polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,polymodes[polymode]);
sceneView->getGlobalStateSet()->setAttribute(polyModeObj);
globalStateSet->setAttribute(polyModeObj);
}
break;

View File

@@ -158,8 +158,30 @@ void SceneView::app()
void SceneView::cull()
{
if (!_state)
{
osg::notify(osg::INFO) << "Warning: no valid osgUtil::SceneView::_state attached, creating a default state automatically."<< std::endl;
// note the constructor for osg::State will set ContextID to 0 which will be fine to single context graphics
// applications which is ok for most apps, but not multiple context/pipe applications.
_state = osgNew osg::State;
}
if (!_globalState)
{
osg::notify(osg::INFO) << "Warning: no valid osgUtil::SceneView::_globalState attached, creating a default global stateset automatically."<< std::endl;
_globalState = osgNew osg::StateSet;
_globalState->setGlobalDefaults();
}
// we in theory should be able to be able to bypass reset, but we'll call it just incase.
_state->reset();
_state->setFrameStamp(_frameStamp.get());
_state->setDisplaySettings(_displaySettings.get());
osg::ref_ptr<osg::Matrix> projection = _projectionMatrix.get();
osg::ref_ptr<osg::Matrix> modelview = _modelviewMatrix.get();
@@ -238,6 +260,22 @@ void SceneView::cull()
}
else
{
if (!_cullVisitor)
{
osg::notify(osg::INFO) << "Warning: no valid osgUtil::SceneView:: attached, creating a default CullVisitor automatically."<< std::endl;
_cullVisitor = osgNew CullVisitor;
}
if (!_rendergraph)
{
osg::notify(osg::INFO) << "Warning: no valid osgUtil::SceneView:: attached, creating a global default RenderGraph automatically."<< std::endl;
_rendergraph = osgNew RenderGraph;
}
if (!_renderStage)
{
osg::notify(osg::INFO) << "Warning: no valid osgUtil::SceneView::_renderStage attached, creating a default RenderStage automatically."<< std::endl;
_renderStage = osgNew RenderStage;
}
_cullVisitor->setTraversalMask(_cullMask);
cullStage(projection.get(),modelview.get(),_cullVisitor.get(),_rendergraph.get(),_renderStage.get());
}
@@ -256,20 +294,6 @@ void SceneView::cullStage(osg::Matrix* projection,osg::Matrix* modelview,osgUtil
if (!_initCalled) init();
if (!_state)
{
osg::notify(osg::WARN) << "Warning: no valid osgUtil::SceneView::_state"<< std::endl;
osg::notify(osg::WARN) << " creating a state automatically."<< std::endl;
// note the constructor for osg::State will set ContextID to 0.
_state = osgNew osg::State;
}
// we in theory should be able to be able to bypass reset, but we'll call it just incase.
_state->reset();
_state->setFrameStamp(_frameStamp.get());
_state->setDisplaySettings(_displaySettings.get());