Introduced dedicated VertexArrayStateList class to wrap up the VertexArrayState container with convinience methods to help initialize them.
Using the new VertexArrayStateList class fixed bug associated with setting new setTexCoord() array when a VertexArrayState is already assigned.
This commit is contained in:
parent
d2bfde30f0
commit
5afd32b2d9
@ -321,8 +321,6 @@ class OSG_EXPORT Drawable : public Node
|
||||
/** Implementaion of Craeate tje VertexArrayState object.*/
|
||||
virtual VertexArrayState* createVertexArrayStateImplementation(RenderInfo& renderInfo) const;
|
||||
|
||||
typedef buffered_object< osg::ref_ptr<VertexArrayState> > VertexArrayStateList;
|
||||
|
||||
void setVertexArrayStateList(VertexArrayStateList& vasl) { _vertexArrayStateList = vasl; }
|
||||
|
||||
VertexArrayStateList& getVertexArrayStateList() { return _vertexArrayStateList; }
|
||||
|
@ -208,6 +208,59 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
class OSG_EXPORT VertexArrayStateList
|
||||
{
|
||||
public:
|
||||
|
||||
VertexArrayStateList();
|
||||
|
||||
VertexArrayStateList& operator = (const VertexArrayStateList& rhs);
|
||||
|
||||
inline void clear() { _array.clear(); }
|
||||
|
||||
inline bool empty() const { return _array.empty(); }
|
||||
|
||||
inline unsigned int size() const { return _array.size(); }
|
||||
|
||||
inline void resize(unsigned int newSize) { _array.resize(newSize); }
|
||||
|
||||
inline ref_ptr<VertexArrayState>& operator[] (unsigned int pos)
|
||||
{
|
||||
// automatically resize array.
|
||||
if (_array.size()<=pos)
|
||||
_array.resize(pos+1,0);
|
||||
|
||||
return _array[pos];
|
||||
}
|
||||
|
||||
inline const ref_ptr<VertexArrayState>& operator[] (unsigned int pos) const
|
||||
{
|
||||
// automatically resize array.
|
||||
if (_array.size()<=pos)
|
||||
_array.resize(pos+1,0);
|
||||
|
||||
return _array[pos];
|
||||
}
|
||||
|
||||
void assignAllDispatchers();
|
||||
|
||||
void assignVertexArrayDispatcher();
|
||||
void assignNormalArrayDispatcher();
|
||||
void assignColorArrayDispatcher();
|
||||
void assignSecondaryColorArrayDispatcher();
|
||||
void assignFogCoordArrayDispatcher();
|
||||
void assignTexCoordArrayDispatcher(unsigned int numUnits);
|
||||
void assignVertexAttribArrayDispatcher(unsigned int numUnits);
|
||||
|
||||
protected:
|
||||
|
||||
typedef std::vector< osg::ref_ptr<VertexArrayState> > Array;
|
||||
mutable Array _array;
|
||||
};
|
||||
|
||||
|
||||
|
||||
inline void VertexArrayState::lazyDisablingOfVertexAttributes()
|
||||
{
|
||||
_activeDispatchers.swap(_previous_activeDispatchers);
|
||||
|
@ -162,7 +162,12 @@ void Geometry::setVertexArray(Array* array)
|
||||
dirtyGLObjects();
|
||||
dirtyBound();
|
||||
|
||||
if (/*_useVertexBufferObjects && */array) addVertexBufferObjectIfRequired(array);
|
||||
if (/*_useVertexBufferObjects && */array)
|
||||
{
|
||||
_vertexArrayStateList.assignVertexArrayDispatcher();
|
||||
|
||||
addVertexBufferObjectIfRequired(array);
|
||||
}
|
||||
}
|
||||
|
||||
void Geometry::setNormalArray(Array* array, osg::Array::Binding binding)
|
||||
@ -173,7 +178,12 @@ void Geometry::setNormalArray(Array* array, osg::Array::Binding binding)
|
||||
|
||||
dirtyGLObjects();
|
||||
|
||||
if (/*_useVertexBufferObjects && */array) addVertexBufferObjectIfRequired(array);
|
||||
if (/*_useVertexBufferObjects && */array)
|
||||
{
|
||||
_vertexArrayStateList.assignNormalArrayDispatcher();
|
||||
|
||||
addVertexBufferObjectIfRequired(array);
|
||||
}
|
||||
}
|
||||
|
||||
void Geometry::setColorArray(Array* array, osg::Array::Binding binding)
|
||||
@ -184,7 +194,12 @@ void Geometry::setColorArray(Array* array, osg::Array::Binding binding)
|
||||
|
||||
dirtyGLObjects();
|
||||
|
||||
if (/*_useVertexBufferObjects && */array) addVertexBufferObjectIfRequired(array);
|
||||
if (/*_useVertexBufferObjects && */array)
|
||||
{
|
||||
_vertexArrayStateList.assignColorArrayDispatcher();
|
||||
|
||||
addVertexBufferObjectIfRequired(array);
|
||||
}
|
||||
}
|
||||
|
||||
void Geometry::setSecondaryColorArray(Array* array, osg::Array::Binding binding)
|
||||
@ -195,7 +210,12 @@ void Geometry::setSecondaryColorArray(Array* array, osg::Array::Binding binding)
|
||||
|
||||
dirtyGLObjects();
|
||||
|
||||
if (/*_useVertexBufferObjects && */array) addVertexBufferObjectIfRequired(array);
|
||||
if (/*_useVertexBufferObjects && */array)
|
||||
{
|
||||
_vertexArrayStateList.assignSecondaryColorArrayDispatcher();
|
||||
|
||||
addVertexBufferObjectIfRequired(array);
|
||||
}
|
||||
}
|
||||
|
||||
void Geometry::setFogCoordArray(Array* array, osg::Array::Binding binding)
|
||||
@ -206,7 +226,12 @@ void Geometry::setFogCoordArray(Array* array, osg::Array::Binding binding)
|
||||
|
||||
dirtyGLObjects();
|
||||
|
||||
if (/*_useVertexBufferObjects && */array) addVertexBufferObjectIfRequired(array);
|
||||
if (/*_useVertexBufferObjects && */array)
|
||||
{
|
||||
_vertexArrayStateList.assignFogCoordArrayDispatcher();
|
||||
|
||||
addVertexBufferObjectIfRequired(array);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -228,6 +253,8 @@ void Geometry::setTexCoordArray(unsigned int index,Array* array, osg::Array::Bin
|
||||
|
||||
if (/*_useVertexBufferObjects && */array)
|
||||
{
|
||||
_vertexArrayStateList.assignTexCoordArrayDispatcher(_texCoordList.size());
|
||||
|
||||
addVertexBufferObjectIfRequired(array);
|
||||
}
|
||||
}
|
||||
@ -250,8 +277,10 @@ void Geometry::setTexCoordArrayList(const ArrayList& arrayList)
|
||||
|
||||
dirtyGLObjects();
|
||||
|
||||
/*if (_useVertexBufferObjects)*/
|
||||
if (!_texCoordList.empty())
|
||||
{
|
||||
_vertexArrayStateList.assignTexCoordArrayDispatcher(_texCoordList.size());
|
||||
|
||||
for(ArrayList::iterator itr = _texCoordList.begin();
|
||||
itr != _texCoordList.end();
|
||||
++itr)
|
||||
@ -272,7 +301,12 @@ void Geometry::setVertexAttribArray(unsigned int index, Array* array, osg::Array
|
||||
|
||||
dirtyGLObjects();
|
||||
|
||||
if (/*_useVertexBufferObjects && */array) addVertexBufferObjectIfRequired(array);
|
||||
if (/*_useVertexBufferObjects && */array)
|
||||
{
|
||||
_vertexArrayStateList.assignVertexAttribArrayDispatcher(_vertexAttribList.size());
|
||||
|
||||
addVertexBufferObjectIfRequired(array);
|
||||
}
|
||||
}
|
||||
|
||||
Array *Geometry::getVertexAttribArray(unsigned int index)
|
||||
@ -293,8 +327,10 @@ void Geometry::setVertexAttribArrayList(const ArrayList& arrayList)
|
||||
|
||||
dirtyGLObjects();
|
||||
|
||||
/*if (_useVertexBufferObjects)*/
|
||||
if (!_vertexAttribList.empty())
|
||||
{
|
||||
_vertexArrayStateList.assignVertexAttribArrayDispatcher(_vertexAttribList.size());
|
||||
|
||||
for(ArrayList::iterator itr = _vertexAttribList.begin();
|
||||
itr != _vertexAttribList.end();
|
||||
++itr)
|
||||
|
@ -546,6 +546,8 @@ void VertexArrayState::deleteVertexArrayObject()
|
||||
|
||||
void VertexArrayState::assignVertexArrayDispatcher()
|
||||
{
|
||||
if (_vertexArray.valid()) return;
|
||||
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (!_state->getUseVertexAttributeAliasing())
|
||||
{
|
||||
@ -561,6 +563,8 @@ void VertexArrayState::assignVertexArrayDispatcher()
|
||||
|
||||
void VertexArrayState::assignNormalArrayDispatcher()
|
||||
{
|
||||
if (_normalArray.valid()) return;
|
||||
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (!_state->getUseVertexAttributeAliasing())
|
||||
{
|
||||
@ -576,6 +580,8 @@ void VertexArrayState::assignNormalArrayDispatcher()
|
||||
|
||||
void VertexArrayState::assignColorArrayDispatcher()
|
||||
{
|
||||
if (_colorArray.valid()) return;
|
||||
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (!_state->getUseVertexAttributeAliasing())
|
||||
{
|
||||
@ -591,6 +597,8 @@ void VertexArrayState::assignColorArrayDispatcher()
|
||||
|
||||
void VertexArrayState::assignSecondaryColorArrayDispatcher()
|
||||
{
|
||||
if (_secondaryColorArray.valid()) return;
|
||||
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (!_state->getUseVertexAttributeAliasing())
|
||||
{
|
||||
@ -605,6 +613,8 @@ void VertexArrayState::assignSecondaryColorArrayDispatcher()
|
||||
|
||||
void VertexArrayState::assignFogCoordArrayDispatcher()
|
||||
{
|
||||
if (_fogCoordArray.valid()) return;
|
||||
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (!_state->getUseVertexAttributeAliasing())
|
||||
{
|
||||
@ -622,8 +632,7 @@ void VertexArrayState::assignTexCoordArrayDispatcher(unsigned int numUnits)
|
||||
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
|
||||
if (!_state->getUseVertexAttributeAliasing())
|
||||
{
|
||||
_texCoordArrays.clear();
|
||||
for(unsigned int i=0; i<numUnits; ++i)
|
||||
for(unsigned int i=_texCoordArrays.size(); i<numUnits; ++i)
|
||||
{
|
||||
_texCoordArrays.push_back( new TexCoordArrayDispatch(i) );
|
||||
}
|
||||
@ -631,8 +640,7 @@ void VertexArrayState::assignTexCoordArrayDispatcher(unsigned int numUnits)
|
||||
else
|
||||
#endif
|
||||
{
|
||||
_texCoordArrays.clear();
|
||||
for(unsigned int i=0; i<numUnits; ++i)
|
||||
for(unsigned int i=_texCoordArrays.size(); i<numUnits; ++i)
|
||||
{
|
||||
VAS_NOTICE<<"VertexArrayState::VertexArrayState::assignTexCoordArrayDispatcher() _state->getTexCoordAliasList()[i]._location="<<_state->getTexCoordAliasList()[i]._location<<std::endl;
|
||||
_texCoordArrays.push_back( new VertexAttribArrayDispatch(_state->getTexCoordAliasList()[i]._location) );
|
||||
@ -642,8 +650,7 @@ void VertexArrayState::assignTexCoordArrayDispatcher(unsigned int numUnits)
|
||||
|
||||
void VertexArrayState::assignVertexAttribArrayDispatcher(unsigned int numUnits)
|
||||
{
|
||||
_vertexAttribArrays.clear();
|
||||
for(unsigned int i=0; i<numUnits; ++i)
|
||||
for(unsigned int i=_vertexAttribArrays.size(); i<numUnits; ++i)
|
||||
{
|
||||
_vertexAttribArrays.push_back( new VertexAttribArrayDispatch(i) );
|
||||
}
|
||||
@ -759,3 +766,103 @@ void VertexArrayState::dirty()
|
||||
setRequiresSetArrays(true);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
VertexArrayStateList::VertexArrayStateList():
|
||||
_array(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
VertexArrayStateList& VertexArrayStateList::operator = (const VertexArrayStateList& rhs)
|
||||
{
|
||||
if (&rhs==this) return *this;
|
||||
|
||||
_array = rhs._array;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void VertexArrayStateList::assignAllDispatchers()
|
||||
{
|
||||
for(Array::iterator itr = _array.begin();
|
||||
itr != _array.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->valid()) (*itr)->assignAllDispatchers();
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArrayStateList::assignVertexArrayDispatcher()
|
||||
{
|
||||
for(Array::iterator itr = _array.begin();
|
||||
itr != _array.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->valid()) (*itr)->assignVertexArrayDispatcher();
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArrayStateList::assignNormalArrayDispatcher()
|
||||
{
|
||||
for(Array::iterator itr = _array.begin();
|
||||
itr != _array.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->valid()) (*itr)->assignNormalArrayDispatcher();
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArrayStateList::assignColorArrayDispatcher()
|
||||
{
|
||||
for(Array::iterator itr = _array.begin();
|
||||
itr != _array.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->valid()) (*itr)->assignColorArrayDispatcher();
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArrayStateList::assignSecondaryColorArrayDispatcher()
|
||||
{
|
||||
for(Array::iterator itr = _array.begin();
|
||||
itr != _array.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->valid()) (*itr)->assignSecondaryColorArrayDispatcher();
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArrayStateList::assignFogCoordArrayDispatcher()
|
||||
{
|
||||
for(Array::iterator itr = _array.begin();
|
||||
itr != _array.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->valid()) (*itr)->assignFogCoordArrayDispatcher();
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArrayStateList::assignTexCoordArrayDispatcher(unsigned int numUnits)
|
||||
{
|
||||
for(Array::iterator itr = _array.begin();
|
||||
itr != _array.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->valid())
|
||||
{
|
||||
(*itr)->assignTexCoordArrayDispatcher(numUnits);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArrayStateList::assignVertexAttribArrayDispatcher(unsigned int numUnits)
|
||||
{
|
||||
for(Array::iterator itr = _array.begin();
|
||||
itr != _array.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->valid()) (*itr)->assignVertexAttribArrayDispatcher(numUnits);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user