diff --git a/include/osg/StateAttribute b/include/osg/StateAttribute index 274b62730..0b9a09c6a 100644 --- a/include/osg/StateAttribute +++ b/include/osg/StateAttribute @@ -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; + }; } diff --git a/include/osg/StateSet b/include/osg/StateSet index 8ab3e476f..c8366454a 100644 --- a/include/osg/StateSet +++ b/include/osg/StateSet @@ -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; + }; } diff --git a/include/osgGLUT/GLUTEventAdapter b/include/osgGLUT/GLUTEventAdapter index 2493dc32b..8ba1dec0b 100644 --- a/include/osgGLUT/GLUTEventAdapter +++ b/include/osgGLUT/GLUTEventAdapter @@ -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 diff --git a/include/osgGLUT/Viewer b/include/osgGLUT/Viewer index 2cc10b9b2..297b0adb3 100644 --- a/include/osgGLUT/Viewer +++ b/include/osgGLUT/Viewer @@ -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& 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(); diff --git a/include/osgUtil/CameraManipulator b/include/osgUtil/CameraManipulator index aadc6ce65..d98322e7f 100644 --- a/include/osgUtil/CameraManipulator +++ b/include/osgUtil/CameraManipulator @@ -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 _camera; + bool _homeToUseNode; + osg::Vec3 _eyeHome; + osg::Vec3 _centerHome; + osg::Vec3 _upHome; + }; } diff --git a/include/osgUtil/GUIEventAdapter b/include/osgUtil/GUIEventAdapter index a2c6384f7..f0c998599 100644 --- a/include/osgUtil/GUIEventAdapter +++ b/include/osgUtil/GUIEventAdapter @@ -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: diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index a126591fc..abae68a2c 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -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) new_s = max_size; + if (new_t>max_size) new_t = max_size; if (new_s!=_s || new_t!=_t) { diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index 8c21fcef8..367a070a4 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -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() diff --git a/src/osgGLUT/GLUTEventAdapter.cpp b/src/osgGLUT/GLUTEventAdapter.cpp index f5d572d65..0894ec837 100644 --- a/src/osgGLUT/GLUTEventAdapter.cpp +++ b/src/osgGLUT/GLUTEventAdapter.cpp @@ -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; diff --git a/src/osgGLUT/Viewer.cpp b/src/osgGLUT/Viewer.cpp index 7b8685539..aa599d73a 100644 --- a/src/osgGLUT/Viewer.cpp +++ b/src/osgGLUT/Viewer.cpp @@ -776,6 +776,21 @@ void Viewer::keyboard(unsigned char key, int x, int y) switch( key ) { + case '>' : + { + osg::DisplaySettings* ds = const_cast(sceneView->getDisplaySettings()); + if (ds) ds->setEyeSeperation(ds->getEyeSeperation()*1.5f); + } + break; + + case '<' : + { + osg::DisplaySettings* ds = const_cast(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; diff --git a/src/osgUtil/CameraManipulator.cpp b/src/osgUtil/CameraManipulator.cpp index 622a71ceb..e763b1042 100644 --- a/src/osgUtil/CameraManipulator.cpp +++ b/src/osgUtil/CameraManipulator.cpp @@ -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); } diff --git a/src/osgUtil/DriveManipulator.cpp b/src/osgUtil/DriveManipulator.cpp index ec0fc6ba6..1c15f4b62 100644 --- a/src/osgUtil/DriveManipulator.cpp +++ b/src/osgUtil/DriveManipulator.cpp @@ -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) { diff --git a/src/osgUtil/FlightManipulator.cpp b/src/osgUtil/FlightManipulator.cpp index c93c3a972..2af65bd4f 100644 --- a/src/osgUtil/FlightManipulator.cpp +++ b/src/osgUtil/FlightManipulator.cpp @@ -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) { diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index bf0144c1f..3fb96e6fc 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -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;igetStateSet(); - 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); } diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index b4a9ca0cf..27761847a 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -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;