diff --git a/include/osg/Drawable b/include/osg/Drawable index c06d9fc1c..adec13f33 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -10,10 +10,7 @@ #include #include #include - -#include -#include -#include +#include namespace osg { @@ -381,18 +378,13 @@ class SG_EXPORT Drawable : public Object bool _supportsDisplayList; bool _useDisplayList; - typedef std::vector GLObjectList; + typedef osg::buffered_value GLObjectList; mutable GLObjectList _globjList; ref_ptr _appCallback; ref_ptr _drawCallback; ref_ptr _cullCallback; - // static cache of deleted display lists which can only - // by completely deleted once the appropriate OpenGL context - // is set. - typedef std::map > DeletedDisplayListCache; - static DeletedDisplayListCache s_deletedDisplayListCache; }; @@ -405,9 +397,6 @@ inline void Drawable::draw(State& state) // current OpenGL context. uint contextID = state.getContextID(); - // fill in array if required. - while (_globjList.size()<=contextID) _globjList.push_back(0); - // get the globj for the current contextID. uint& globj = _globjList[contextID]; diff --git a/include/osg/Group b/include/osg/Group index 4fd44a4df..164746e3a 100644 --- a/include/osg/Group +++ b/include/osg/Group @@ -50,23 +50,29 @@ class SG_EXPORT Group : public Node virtual bool removeChild( Node *child ); /** Replace specified Node with another Node. - * Decrement the reference count origNode and increments the + * Equivalent to setChild(findChildNum(orignChild),node), + * see docs for setChild for futher details on implementation.*/ + virtual bool replaceChild( Node *origChild, Node* newChild ); + + /** return the number of chilren nodes.*/ + inline unsigned int getNumChildren() const { return _children.size(); } + + /** set child node at position i. + * return true if set correctly, false on failure (if node==NULL || i is out of range). + * When set can be successful applied, the algorithm is : decrement the reference count origNode and increments the * reference count of newNode, and dirty the bounding sphere * to force it to recompute on next getBound() and returns true. * If origNode is not found then return false and do not * add newNode. If newNode is NULL then return false and do * not remove origNode. Also returns false if newChild is a Scene node. */ - virtual bool replaceChild( Node *origChild, Node* newChild ); - - /** return the number of chilren nodes.*/ - inline unsigned int getNumChildren() const { return _children.size(); } + virtual bool setChild( unsigned int i, Node* node ); /** return child node at position i.*/ - inline Node *getChild( unsigned int i ) { return _children[i].get(); } + inline Node* getChild( unsigned int i ) { return _children[i].get(); } /** return child node at position i.*/ - inline const Node *getChild( unsigned int i ) const { return _children[i].get(); } + inline const Node* getChild( unsigned int i ) const { return _children[i].get(); } /** return true if node is contained within Group.*/ inline bool containsNode( const Node* node ) const @@ -113,11 +119,11 @@ class SG_EXPORT Group : public Node /** Find the index number of child, return a value between * 0 and _children.size()-1 if found, if not found then * return _children.size().*/ - inline unsigned int findChildNo( const Node* node ) const + inline unsigned int findChildNum( const Node* node ) const { - for (unsigned int childNo=0;childNo<_children.size();++childNo) + for (unsigned int childNum=0;childNum<_children.size();++childNum) { - if (_children[childNo]==node) return childNo; + if (_children[childNum]==node) return childNum; } return _children.size(); // node not found. } diff --git a/include/osg/State b/include/osg/State index f727225c9..282d6c34b 100644 --- a/include/osg/State +++ b/include/osg/State @@ -221,6 +221,13 @@ class SG_EXPORT State : public Referenced /** dirty the vertex, normal, color, tex coords, secenday color, fog coord and index arrays.*/ void dirtyAllVertexArrays(); + + /** Wrapper around glInterleavedArrays(..). + * also resets the internal array points and modes within osg::State to keep the other + * vertex array operations consistent. */ + void setInterleavedArrays( GLenum format, GLsizei stride, void* pointer); + + /** wrapper around glEnableClientState(GL_VERTEX_ARRAY);glVertexPointer(..); * note, only updates values that change.*/ inline void setVertexPointer( GLint size, GLenum type, diff --git a/include/osg/Texture b/include/osg/Texture index 7bcdca8a3..912c4968a 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -176,39 +176,6 @@ class SG_EXPORT Texture : public osg::StateAttribute bool isCompressedInternalFormat() const; - -// /** Get the handle to the texture object for the current context.*/ -// /** return the OpenGL texture object for specified context.*/ -// inline GLuint& getTextureObject(uint contextID) const -// { -// // pad out handle list if required. -// if (_handleList.size()<=contextID) -// _handleList.resize(contextID+1,0); -// -// // get the globj for the current contextID. -// return _handleList[contextID]; -// } -// -// inline uint& getModifiedTag(uint contextID) const -// { -// // pad out handle list if required. -// if (_modifiedTag.size()<=contextID) -// _modifiedTag.resize(contextID+1,0); -// -// // get the modified tag for the current contextID. -// return _modifiedTag[contextID]; -// } -// -// inline uint& getTextureParameterDirty(uint contextID) const -// { -// // pad out handle list if required. -// if (_texParametersDirtyList.size()<=contextID) -// _texParametersDirtyList.resize(contextID+1,0); -// -// // get the dirty flag for the current contextID. -// return _texParametersDirtyList[contextID]; -// } - /** Get the handle to the texture object for the current context.*/ /** return the OpenGL texture object for specified context.*/ @@ -330,15 +297,12 @@ class SG_EXPORT Texture : public osg::StateAttribute /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ int compareTexture(const Texture& rhs) const; -// typedef std::vector TextureNameList; typedef buffered_value TextureNameList; mutable TextureNameList _handleList; -// typedef std::vector ImageModifiedTag; typedef buffered_value ImageModifiedTag; mutable ImageModifiedTag _modifiedTag; -// typedef std::vector TexParameterDirtyList; typedef buffered_value TexParameterDirtyList; mutable TexParameterDirtyList _texParametersDirtyList; diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index eb6661063..708ed51d8 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -8,15 +8,19 @@ #include #include +#include +#include using namespace osg; -Drawable::DeletedDisplayListCache Drawable::s_deletedDisplayListCache; +// static cache of deleted display lists which can only +// by completely deleted once the appropriate OpenGL context +// is set. Used osg::Drawable::deleteDisplayList(..) and flushDeletedDisplayLists(..) below. +typedef std::map > DeletedDisplayListCache; +static DeletedDisplayListCache s_deletedDisplayListCache; Drawable::Drawable() { - _globjList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0); - _bbox_computed = false; // Note, if your are defining a subclass from drawable which is @@ -26,7 +30,6 @@ Drawable::Drawable() // dynamic updating of data. _supportsDisplayList = true; _useDisplayList = true; - } Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop): @@ -38,10 +41,10 @@ Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop): _shape(copyop(drawable._shape.get())), _supportsDisplayList(drawable._supportsDisplayList), _useDisplayList(drawable._useDisplayList), - _globjList(drawable._globjList), _drawCallback(drawable._drawCallback), _cullCallback(drawable._cullCallback) -{} +{ +} Drawable::~Drawable() { @@ -90,9 +93,6 @@ void Drawable::compile(State& state) // current OpenGL context. uint contextID = state.getContextID(); - // fill in array if required. - while (_globjList.size()<=contextID) _globjList.push_back(0); - // get the globj for the current contextID. uint& globj = _globjList[contextID]; diff --git a/src/osg/GeoSet.cpp b/src/osg/GeoSet.cpp index f52ffda40..ef3746913 100644 --- a/src/osg/GeoSet.cpp +++ b/src/osg/GeoSet.cpp @@ -11,6 +11,8 @@ #include #include +#include + using namespace osg; GeoSet::GeoSet() diff --git a/src/osg/Group.cpp b/src/osg/Group.cpp index e6040c1d1..ed9f0bd17 100644 --- a/src/osg/Group.cpp +++ b/src/osg/Group.cpp @@ -146,15 +146,28 @@ bool Group::replaceChild( Node *origNode, Node *newNode ) { if (newNode==NULL || origNode==newNode) return false; - ChildList::iterator itr = findNode(origNode); - if (itr!=_children.end()) + unsigned int pos = findChildNum(origNode); + if (pos<_children.size()) { + return setChild(pos,newNode); + } + return false; +} + + +bool Group::setChild( unsigned int i, Node* newNode ) +{ + if (i<_children.size() && newNode) + { + + Node* origNode = _children[i].get(); + // first remove for origNode's parent list. origNode->removeParent(this); // note ref_ptr<> automatically handles decrementing origNode's reference count, // and inccrementing newNode's reference count. - *itr = newNode; + _children[i] = newNode; // register as parent of child. newNode->addParent(this); diff --git a/src/osg/LOD.cpp b/src/osg/LOD.cpp index ee21b2680..0d7cd8a0d 100644 --- a/src/osg/LOD.cpp +++ b/src/osg/LOD.cpp @@ -69,7 +69,7 @@ bool LOD::addChild(Node *child, float min, float max) bool LOD::removeChild( Node *child ) { // find the child's position. - unsigned int pos=findChildNo(child); + unsigned int pos=findChildNum(child); if (pos==_children.size()) return false; _rangeList.erase(_rangeList.begin()+pos); diff --git a/src/osg/State.cpp b/src/osg/State.cpp index 9ea6bfc93..43fc8ae8f 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -427,6 +427,17 @@ void State::dirtyAllVertexArrays() dirtySecondaryColorPointer(); } +void State::setInterleavedArrays( GLenum format, GLsizei stride, void* pointer) +{ + glInterleavedArrays( format, stride, pointer); + + // the crude way, assume that all arrays have been effected so dirty them and + // disable them... + dirtyAllVertexArrays(); + disableAllVertexArrays(); +} + + typedef void (APIENTRY * ActiveTextureProc) (GLenum texture); bool State::setClientActiveTextureUnit( unsigned int unit ) diff --git a/src/osg/Switch.cpp b/src/osg/Switch.cpp index 4c4621870..84fd1256a 100644 --- a/src/osg/Switch.cpp +++ b/src/osg/Switch.cpp @@ -61,7 +61,7 @@ bool Switch::addChild( Node *child, bool value ) bool Switch::removeChild( Node *child ) { // find the child's position. - unsigned int pos=findChildNo(child); + unsigned int pos=findChildNum(child); if (pos==_children.size()) return false; _values.erase(_values.begin()+pos); @@ -78,7 +78,7 @@ void Switch::setValue(unsigned int pos,bool value) void Switch::setValue(const Node* child,bool value) { // find the child's position. - unsigned int pos=findChildNo(child); + unsigned int pos=findChildNum(child); if (pos==_children.size()) return; _values[pos]=value; @@ -93,7 +93,7 @@ bool Switch::getValue(unsigned int pos) const bool Switch::getValue(const Node* child) const { // find the child's position. - unsigned int pos=findChildNo(child); + unsigned int pos=findChildNum(child); if (pos==_children.size()) return false; return _values[pos]; diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index dfbda2c3a..473c96af2 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -19,9 +19,6 @@ Texture::Texture(): _internalFormatMode(USE_IMAGE_DATA_FORMAT), _internalFormat(0) { -// _handleList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0); -// _modifiedTag.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0); -// _texParametersDirtyList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),true); } Texture::Texture(const Texture& text,const CopyOp& copyop): @@ -36,9 +33,6 @@ Texture::Texture(const Texture& text,const CopyOp& copyop): _internalFormatMode(text._internalFormatMode), _internalFormat(text._internalFormat) { -// _handleList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0); -// _modifiedTag.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0); -// _texParametersDirtyList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),true); } Texture::~Texture() @@ -134,7 +128,7 @@ void Texture::dirtyTextureParameters() { for(uint i=0;i<_texParametersDirtyList.size();++i) { - _texParametersDirtyList[i] = 0; + _texParametersDirtyList[i] = 1; } }