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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user