Streamlined the dispatch and activation of attribute dispatchers
This commit is contained in:
@@ -45,16 +45,28 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced
|
||||
void setUseVertexAttribAlias(bool flag) { _useVertexAttribAlias = flag; }
|
||||
bool getUseVertexAttribAlias() const { return _useVertexAttribAlias; }
|
||||
|
||||
void activate(unsigned int binding, AttributeDispatch* at)
|
||||
{
|
||||
if (at) _activeDispatchList[binding].push_back(at);
|
||||
}
|
||||
|
||||
void activateColorArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), colorDispatcher(array)); }
|
||||
void activateNormalArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), normalDispatcher(array)); }
|
||||
void activateSecondaryColorArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), secondaryColorDispatcher(array)); }
|
||||
void activateFogCoordArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), fogCoordDispatcher(array)); }
|
||||
void activateVertexAttribArray(unsigned int unit, osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), vertexAttribDispatcher(unit, array)); }
|
||||
#define DISPATCH_OR_ACTIVATE(array, dispatcher) \
|
||||
if (array) { \
|
||||
unsigned int binding = array->getBinding(); \
|
||||
if (binding==osg::Array::BIND_OVERALL) \
|
||||
{ \
|
||||
AttributeDispatch* at = dispatcher; \
|
||||
if (at) (*at)(0); \
|
||||
} \
|
||||
else if (binding==osg::Array:: BIND_PER_PRIMITIVE_SET) \
|
||||
{ \
|
||||
AttributeDispatch* at = dispatcher; \
|
||||
if (at) _activeDispatchList.push_back(at); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
void activateColorArray(osg::Array* array) { DISPATCH_OR_ACTIVATE(array, colorDispatcher(array)); }
|
||||
void activateNormalArray(osg::Array* array) { DISPATCH_OR_ACTIVATE(array, normalDispatcher(array)); }
|
||||
void activateSecondaryColorArray(osg::Array* array) { DISPATCH_OR_ACTIVATE(array, secondaryColorDispatcher(array)); }
|
||||
void activateFogCoordArray(osg::Array* array) { DISPATCH_OR_ACTIVATE(array, fogCoordDispatcher(array)); }
|
||||
void activateVertexAttribArray(unsigned int unit, osg::Array* array) { DISPATCH_OR_ACTIVATE(array, vertexAttribDispatcher(unit , array)); }
|
||||
|
||||
AttributeDispatch* normalDispatcher(Array* array);
|
||||
AttributeDispatch* colorDispatcher(Array* array);
|
||||
@@ -62,18 +74,17 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced
|
||||
AttributeDispatch* fogCoordDispatcher(Array* array);
|
||||
AttributeDispatch* vertexAttribDispatcher(unsigned int unit, Array* array);
|
||||
|
||||
void dispatch(unsigned int binding, unsigned int index)
|
||||
void dispatch(unsigned int index)
|
||||
{
|
||||
AttributeDispatchList& ad = _activeDispatchList[binding];
|
||||
for(AttributeDispatchList::iterator itr = ad.begin();
|
||||
itr != ad.end();
|
||||
for(AttributeDispatchList::iterator itr = _activeDispatchList.begin();
|
||||
itr != _activeDispatchList.end();
|
||||
++itr)
|
||||
{
|
||||
(*(*itr))(index);
|
||||
}
|
||||
}
|
||||
|
||||
bool active(unsigned int binding) const { return !_activeDispatchList[binding].empty(); }
|
||||
bool active() const { return !_activeDispatchList.empty(); }
|
||||
|
||||
protected:
|
||||
|
||||
@@ -95,8 +106,7 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced
|
||||
|
||||
typedef std::vector<AttributeDispatch*> AttributeDispatchList;
|
||||
|
||||
typedef std::vector<AttributeDispatchList> ActiveDispatchList;
|
||||
ActiveDispatchList _activeDispatchList;
|
||||
AttributeDispatchList _activeDispatchList;
|
||||
|
||||
bool _useVertexAttribAlias;
|
||||
};
|
||||
|
||||
@@ -268,12 +268,7 @@ void ArrayDispatchers::reset()
|
||||
|
||||
_useVertexAttribAlias = false;
|
||||
|
||||
for(ActiveDispatchList::iterator itr = _activeDispatchList.begin();
|
||||
itr != _activeDispatchList.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr).clear();
|
||||
}
|
||||
_activeDispatchList.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -840,15 +840,12 @@ void Geometry::drawVertexArraysImplementation(RenderInfo& renderInfo) const
|
||||
}
|
||||
}
|
||||
|
||||
// activate or dispatch any attributes that are bound overall
|
||||
arrayDispatchers.activateNormalArray(_normalArray.get());
|
||||
arrayDispatchers.activateColorArray(_colorArray.get());
|
||||
arrayDispatchers.activateSecondaryColorArray(_secondaryColorArray.get());
|
||||
arrayDispatchers.activateFogCoordArray(_fogCoordArray.get());
|
||||
|
||||
// dispatch any attributes that are bound overall
|
||||
arrayDispatchers.dispatch(osg::Array::BIND_OVERALL,0);
|
||||
|
||||
|
||||
if (state.useVertexArrayObject(_useVertexArrayObject))
|
||||
{
|
||||
if (!vas->getRequiresSetArrays()) return;
|
||||
@@ -902,11 +899,11 @@ void Geometry::drawPrimitivesImplementation(RenderInfo& renderInfo) const
|
||||
ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers();
|
||||
bool usingVertexBufferObjects = state.useVertexBufferObject(_supportsVertexBufferObjects && _useVertexBufferObjects);
|
||||
|
||||
bool bindPerPrimitiveSetActive = arrayDispatchers.active(osg::Array::BIND_PER_PRIMITIVE_SET);
|
||||
bool bindPerPrimitiveSetActive = arrayDispatchers.active();
|
||||
for(unsigned int primitiveSetNum=0; primitiveSetNum!=_primitives.size(); ++primitiveSetNum)
|
||||
{
|
||||
// dispatch any attributes that are bound per primitive
|
||||
if (bindPerPrimitiveSetActive) arrayDispatchers.dispatch(osg::Array::BIND_PER_PRIMITIVE_SET, primitiveSetNum);
|
||||
if (bindPerPrimitiveSetActive) arrayDispatchers.dispatch(primitiveSetNum);
|
||||
|
||||
const PrimitiveSet* primitiveset = _primitives[primitiveSetNum].get();
|
||||
|
||||
|
||||
@@ -876,9 +876,6 @@ void SharedGeometry::drawImplementation(osg::RenderInfo& renderInfo) const
|
||||
arrayDispatchers.activateNormalArray(_normalArray.get());
|
||||
arrayDispatchers.activateColorArray(_colorArray.get());
|
||||
|
||||
// dispatch any attributes that are bound overall
|
||||
arrayDispatchers.dispatch(osg::Array::BIND_OVERALL,0);
|
||||
|
||||
state.lazyDisablingOfVertexAttributes();
|
||||
|
||||
// set up arrays
|
||||
|
||||
Reference in New Issue
Block a user