Integrated various changes worked on at the Glasgow Science Center. Changes

include change the CameraManipulators so they work with double for time
instead of float.  Also added support for DataType to osg::StateAttribute
and StateSet so that they can be set to either STATIC or DYNAMIC, this
allows the optimizer to know whether that an attribute can be optimized
or not.
This commit is contained in:
Robert Osfield
2002-03-14 17:34:08 +00:00
parent 9e92b9b899
commit c49c62ee15
15 changed files with 105 additions and 27 deletions

View File

@@ -150,6 +150,17 @@ void Image::ensureDimensionsArePowerOfTwo()
float rounded_tp2 = floorf(tp2+0.5f);
int new_t = (int)(powf(2.0f,rounded_tp2));
static int max_size=256;
static bool init = true;
if (init)
{
init = false;
glGetIntegerv(GL_MAX_TEXTURE_SIZE,&max_size);
std::cout<<"Max texture size "<<max_size<<std::endl;
}
if (new_s>max_size) new_s = max_size;
if (new_t>max_size) new_t = max_size;
if (new_s!=_s || new_t!=_t)
{

View File

@@ -17,6 +17,7 @@ using namespace osg;
StateSet::StateSet()
{
_renderingHint = DEFAULT_BIN;
_datatype = osg::StateAttribute::STATIC;
setRendingBinToInherit();
}
@@ -40,6 +41,7 @@ StateSet::StateSet(const StateSet& rhs,const CopyOp& copyop):Object(rhs,copyop)
_binMode = rhs._binMode;
_binNum = rhs._binNum;
_binName = rhs._binName;
_datatype = rhs._datatype;
}
StateSet::~StateSet()

View File

@@ -57,7 +57,7 @@ void GLUTEventAdapter::setButtonMask(unsigned int buttonMask)
}
void GLUTEventAdapter::adaptResize(float time, int Xmin, int Ymin, int Xmax, int Ymax)
void GLUTEventAdapter::adaptResize(double time, int Xmin, int Ymin, int Xmax, int Ymax)
{
setWindowSize(Xmin,Ymin,Xmax,Ymax);
_eventType = RESIZE;
@@ -67,7 +67,7 @@ void GLUTEventAdapter::adaptResize(float time, int Xmin, int Ymin, int Xmax, int
/** method for adapting mouse motion events whilst mouse buttons are pressed.*/
void GLUTEventAdapter::adaptMouseMotion(float time, int x, int y)
void GLUTEventAdapter::adaptMouseMotion(double time, int x, int y)
{
_eventType = DRAG;
_time = time;
@@ -78,7 +78,7 @@ void GLUTEventAdapter::adaptMouseMotion(float time, int x, int y)
/** method for adapting mouse motion events whilst no mouse button are pressed.*/
void GLUTEventAdapter::adaptMousePassiveMotion(float time, int x, int y)
void GLUTEventAdapter::adaptMousePassiveMotion(double time, int x, int y)
{
_eventType = MOVE;
_time = time;
@@ -89,7 +89,7 @@ void GLUTEventAdapter::adaptMousePassiveMotion(float time, int x, int y)
/** method for adapting mouse button pressed/released events.*/
void GLUTEventAdapter::adaptMouse(float time, int button, int state, int x, int y)
void GLUTEventAdapter::adaptMouse(double time, int button, int state, int x, int y)
{
_time = time;
@@ -154,7 +154,7 @@ void GLUTEventAdapter::adaptMouse(float time, int button, int state, int x, int
/** method for adapting keyboard events.*/
void GLUTEventAdapter::adaptKeyboard(float time, unsigned char key, int x, int y )
void GLUTEventAdapter::adaptKeyboard(double time, unsigned char key, int x, int y )
{
_eventType = KEYBOARD;
_time = time;
@@ -167,7 +167,7 @@ void GLUTEventAdapter::adaptKeyboard(float time, unsigned char key, int x, int y
/** method for adapting frame events, i.e. iddle/display callback.*/
void GLUTEventAdapter::adaptFrame(float time)
void GLUTEventAdapter::adaptFrame(double time)
{
_eventType = FRAME;
_time = time;

View File

@@ -776,6 +776,21 @@ void Viewer::keyboard(unsigned char key, int x, int y)
switch( key )
{
case '>' :
{
osg::DisplaySettings* ds = const_cast<osg::DisplaySettings*>(sceneView->getDisplaySettings());
if (ds) ds->setEyeSeperation(ds->getEyeSeperation()*1.5f);
}
break;
case '<' :
{
osg::DisplaySettings* ds = const_cast<osg::DisplaySettings*>(sceneView->getDisplaySettings());
if (ds) ds->setEyeSeperation(ds->getEyeSeperation()/1.5f);
}
break;
case '7' :
sceneView->setBackgroundColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
break;

View File

@@ -7,6 +7,10 @@ using namespace osgUtil;
CameraManipulator::CameraManipulator(): _camera(NULL)
{
_homeToUseNode = true;
_eyeHome.set(0.0,0.0,0.0);
_centerHome.set(0.0,0.0,-1.0);
_upHome.set(0.0,1.0,0.0);
}

View File

@@ -370,7 +370,7 @@ bool DriveManipulator::calcMovement()
// return if less then two events have been added.
if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;
float dt = _ga_t0->time()-_ga_t1->time();
double dt = _ga_t0->time()-_ga_t1->time();
if (dt<0.0f)
{

View File

@@ -175,7 +175,7 @@ bool FlightManipulator::calcMovement()
if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;
float dt = _ga_t0->time()-_ga_t1->time();
double dt = _ga_t0->time()-_ga_t1->time();
if (dt<0.0f)
{

View File

@@ -129,7 +129,7 @@ void Optimizer::StateVisitor::addStateSet(osg::StateSet* stateset,osg::Object* o
void Optimizer::StateVisitor::apply(osg::Node& node)
{
osg::StateSet* ss = node.getStateSet();
if (ss) addStateSet(ss,&node);
if (ss && ss->getDataType()==osg::StateAttribute::STATIC) addStateSet(ss,&node);
traverse(node);
}
@@ -137,14 +137,14 @@ void Optimizer::StateVisitor::apply(osg::Node& node)
void Optimizer::StateVisitor::apply(osg::Geode& geode)
{
osg::StateSet* ss = geode.getStateSet();
if (ss) addStateSet(ss,&geode);
if (ss && ss->getDataType()==osg::StateAttribute::STATIC) addStateSet(ss,&geode);
for(int i=0;i<geode.getNumDrawables();++i)
{
osg::Drawable* drawable = geode.getDrawable(i);
if (drawable)
{
ss = drawable->getStateSet();
if (ss) addStateSet(ss,drawable);
if (ss && ss->getDataType()==osg::StateAttribute::STATIC) addStateSet(ss,drawable);
}
}
}
@@ -172,7 +172,10 @@ void Optimizer::StateVisitor::optimize()
aitr!=attributes.end();
++aitr)
{
_attributeToStateSetMap[aitr->second.first.get()].insert(sitr->first);
if (aitr->second.first->getDataType()==osg::StateAttribute::STATIC)
{
_attributeToStateSetMap[aitr->second.first.get()].insert(sitr->first);
}
}
}
@@ -559,7 +562,8 @@ void Optimizer::RemoveRedundentNodesVisitor::apply(osg::Group& group)
{
if (!group.getUserData() &&
!group.getAppCallback() &&
!group.getStateSet())
!group.getStateSet() &&
group.getNodeMask()!=0xffffffff)
{
_redundentNodeList.insert(&group);
}

View File

@@ -66,15 +66,16 @@ void SceneView::setDefaults()
_renderStage = new RenderStage;
#ifndef __sgi
//#ifndef __sgi
// sgi's IR graphics has a problem with lighting and display lists, as it seems to store
// lighting state with the display list, and the display list visitor doesn't currently apply
// state before creating display lists. So will disable the init visitor default, this won't
// affect functionality since the display lists will be created as and when needed.
DisplayListVisitor* dlv = new DisplayListVisitor();
dlv->setState(_state.get());
dlv->setNodeMaskOverride(0xffffffff);
_initVisitor = dlv;
#endif
//#endif
_appVisitor = new AppVisitor;