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:
@@ -149,10 +149,19 @@ class SG_EXPORT StateAttribute : public Object
|
||||
COLORMATRIX
|
||||
};
|
||||
|
||||
StateAttribute() {}
|
||||
/** Range of types that the StateAttribute can be.*/
|
||||
enum DataType
|
||||
{
|
||||
DYNAMIC,
|
||||
STATIC
|
||||
};
|
||||
|
||||
|
||||
|
||||
StateAttribute():_datatype(STATIC) {}
|
||||
|
||||
StateAttribute(const StateAttribute& sa,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Object(sa,copyop) {}
|
||||
Object(sa,copyop),_datatype(sa._datatype) {}
|
||||
|
||||
|
||||
/** Clone the type of an attribute, with Object* return type.
|
||||
@@ -172,6 +181,11 @@ class SG_EXPORT StateAttribute : public Object
|
||||
/** return the Type identifier of the attribute's class type.*/
|
||||
virtual const Type getType() const = 0;
|
||||
|
||||
|
||||
inline void setDataType(DataType type) { _datatype = type; }
|
||||
inline const DataType getDataType() const { return _datatype; }
|
||||
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& sa) const = 0;
|
||||
|
||||
@@ -199,6 +213,8 @@ class SG_EXPORT StateAttribute : public Object
|
||||
|
||||
virtual ~StateAttribute() {}
|
||||
|
||||
DataType _datatype;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,10 @@ class SG_EXPORT StateSet : public Object
|
||||
nodes which inherit all of their modes for the global state.*/
|
||||
void setAllToInherit();
|
||||
|
||||
/** merge this stateset with stateset rhs, this overrides
|
||||
inline void setDataType(osg::StateAttribute::DataType type) { _datatype = type; }
|
||||
inline const osg::StateAttribute::DataType getDataType() const { return _datatype; }
|
||||
|
||||
/** merge this stateset with stateset rhs, this overrides
|
||||
* the rhs if OVERRIDE is specified, otherwise rhs takes precedence.*/
|
||||
void merge(const StateSet& rhs);
|
||||
|
||||
@@ -169,6 +172,8 @@ class SG_EXPORT StateSet : public Object
|
||||
int _binNum;
|
||||
std::string _binName;
|
||||
|
||||
osg::StateAttribute::DataType _datatype;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class OSGGLUT_EXPORT GLUTEventAdapter : public osgUtil::GUIEventAdapter
|
||||
virtual unsigned int getButtonMask() const { return _buttonMask; }
|
||||
|
||||
/** time in seconds of event. */
|
||||
virtual float time() const { return _time; }
|
||||
virtual double time() const { return _time; }
|
||||
|
||||
|
||||
/** static method for setting window dimensions.*/
|
||||
@@ -60,22 +60,22 @@ class OSGGLUT_EXPORT GLUTEventAdapter : public osgUtil::GUIEventAdapter
|
||||
static void setButtonMask(unsigned int buttonMask);
|
||||
|
||||
/** method for adapting resize events. */
|
||||
void adaptResize(float t, int Xmin, int Ymin, int Xmax, int Ymax);
|
||||
void adaptResize(double t, int Xmin, int Ymin, int Xmax, int Ymax);
|
||||
|
||||
/** method for adapting mouse motion events whilst mouse buttons are pressed.*/
|
||||
void adaptMouseMotion(float t, int x, int y);
|
||||
void adaptMouseMotion(double t, int x, int y);
|
||||
|
||||
/** method for adapting mouse motion events whilst no mouse button are pressed.*/
|
||||
void adaptMousePassiveMotion(float t,int x, int y);
|
||||
void adaptMousePassiveMotion(double t,int x, int y);
|
||||
|
||||
/** method for adapting mouse button pressed/released events.*/
|
||||
void adaptMouse(float t,int button, int state, int x, int y);
|
||||
void adaptMouse(double t,int button, int state, int x, int y);
|
||||
|
||||
/** method for adapting keyboard events.*/
|
||||
void adaptKeyboard(float t,unsigned char key, int x, int y );
|
||||
void adaptKeyboard(double t,unsigned char key, int x, int y );
|
||||
|
||||
/** method for adapting frame events, i.e. idle/display callback.*/
|
||||
void adaptFrame(float t);
|
||||
void adaptFrame(double t);
|
||||
|
||||
void copyStaticVariables();
|
||||
|
||||
@@ -89,7 +89,7 @@ class OSGGLUT_EXPORT GLUTEventAdapter : public osgUtil::GUIEventAdapter
|
||||
int _mx;
|
||||
int _my;
|
||||
unsigned int _buttonMask;
|
||||
float _time;
|
||||
double _time;
|
||||
|
||||
// used to accumulate the button mask state, it represents
|
||||
// the current button mask state, which is modified by the
|
||||
|
||||
@@ -88,6 +88,11 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgUtil::GUIActionAdapter
|
||||
/** read the command line string list, removing any matched control sequences.*/
|
||||
void readCommandLine(std::vector<std::string>& commandLine);
|
||||
|
||||
void setDisplaySettings(osg::DisplaySettings* ds) { _displaySettings = ds; }
|
||||
osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); }
|
||||
const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual void display();
|
||||
|
||||
@@ -37,6 +37,16 @@ class OSGUTIL_EXPORT CameraManipulator : public GUIEventHandler
|
||||
/** Return node if attached.*/
|
||||
virtual const osg::Node* getNode() const { return NULL; }
|
||||
|
||||
|
||||
void setHomeToUseNode() { _homeToUseNode=true; }
|
||||
void setHome(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up)
|
||||
{
|
||||
_eyeHome = eye;
|
||||
_centerHome = center;
|
||||
_upHome = up;
|
||||
_homeToUseNode = false;
|
||||
}
|
||||
|
||||
/** Move the camera to the default position.
|
||||
May be ignored by manipulators if home functionality is not appropriate.*/
|
||||
virtual void home(const GUIEventAdapter& ,GUIActionAdapter&) {}
|
||||
@@ -53,6 +63,11 @@ class OSGUTIL_EXPORT CameraManipulator : public GUIEventHandler
|
||||
// Reference pointer to a camera
|
||||
osg::ref_ptr<osg::Camera> _camera;
|
||||
|
||||
bool _homeToUseNode;
|
||||
osg::Vec3 _eyeHome;
|
||||
osg::Vec3 _centerHome;
|
||||
osg::Vec3 _upHome;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ class GUIEventAdapter : public osg::Referenced
|
||||
virtual unsigned int getButtonMask() const = 0;
|
||||
|
||||
/** time in seconds of event. */
|
||||
virtual float time() const = 0;
|
||||
virtual double time() const = 0;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user