AttributeDispatchers
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_ATTRIBUTEDISPATCHERS
#define OSG_ATTRIBUTEDISPATCHERS 1
#include <osg/ref_ptr>
#include <osg/Array>
#include <osg/Matrixd>
namespace osg {
// forward declare
class State;
class AttributeDispatchMap;
struct AttributeDispatch : public osg::Referenced
{
virtual void assign(const GLvoid*) {}
virtual void operator() (unsigned int) {};
};
class OSG_EXPORT AttributeDispatchers : public osg::Referenced
{
public:
AttributeDispatchers();
~AttributeDispatchers();
void setState(osg::State* state);
void reset();
void setUseVertexAttribAlias(bool flag) { _useVertexAttribAlias = flag; }
bool getUseVertexAttribAlias() const { return _useVertexAttribAlias; }
#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);
AttributeDispatch* secondaryColorDispatcher(Array* array);
AttributeDispatch* fogCoordDispatcher(Array* array);
AttributeDispatch* vertexAttribDispatcher(unsigned int unit, Array* array);
void dispatch(unsigned int index)
{
for(AttributeDispatchList::iterator itr = _activeDispatchList.begin();
itr != _activeDispatchList.end();
++itr)
{
(*(*itr))(index);
}
}
bool active() const { return !_activeDispatchList.empty(); }
protected:
void init();
void assignTexCoordDispatchers(unsigned int unit);
void assignVertexAttribDispatchers(unsigned int unit);
bool _initialized;
State* _state;
AttributeDispatchMap* _normalDispatchers;
AttributeDispatchMap* _colorDispatchers;
AttributeDispatchMap* _secondaryColorDispatchers;
AttributeDispatchMap* _fogCoordDispatchers;
typedef std::vector<AttributeDispatchMap*> AttributeDispatchMapList;
AttributeDispatchMapList _vertexAttribDispatchers;
typedef std::vector<AttributeDispatch*> AttributeDispatchList;
AttributeDispatchList _activeDispatchList;
bool _useVertexAttribAlias;
};
}
#endif
Array
DISPATCH_OR_ACTIVATE
#define DISPATCH_OR_ACTIVATE(array, dispatcher)
Definition AttributeDispatchers:49
Matrixd
osg::Array
Definition Array:61
osg::AttributeDispatchers::_secondaryColorDispatchers
AttributeDispatchMap * _secondaryColorDispatchers
Definition AttributeDispatchers:101
osg::AttributeDispatchers::colorDispatcher
AttributeDispatch * colorDispatcher(Array *array)
osg::AttributeDispatchers::AttributeDispatchers
AttributeDispatchers()
osg::AttributeDispatchers::activateVertexAttribArray
void activateVertexAttribArray(unsigned int unit, osg::Array *array)
Definition AttributeDispatchers:69
osg::AttributeDispatchers::fogCoordDispatcher
AttributeDispatch * fogCoordDispatcher(Array *array)
osg::AttributeDispatchers::_activeDispatchList
AttributeDispatchList _activeDispatchList
Definition AttributeDispatchers:109
osg::AttributeDispatchers::_state
State * _state
Definition AttributeDispatchers:97
osg::AttributeDispatchers::dispatch
void dispatch(unsigned int index)
Definition AttributeDispatchers:77
osg::AttributeDispatchers::assignVertexAttribDispatchers
void assignVertexAttribDispatchers(unsigned int unit)
osg::AttributeDispatchers::~AttributeDispatchers
~AttributeDispatchers()
osg::AttributeDispatchers::activateSecondaryColorArray
void activateSecondaryColorArray(osg::Array *array)
Definition AttributeDispatchers:67
osg::AttributeDispatchers::reset
void reset()
osg::AttributeDispatchers::_useVertexAttribAlias
bool _useVertexAttribAlias
Definition AttributeDispatchers:111
osg::AttributeDispatchers::secondaryColorDispatcher
AttributeDispatch * secondaryColorDispatcher(Array *array)
osg::AttributeDispatchers::activateNormalArray
void activateNormalArray(osg::Array *array)
Definition AttributeDispatchers:66
osg::AttributeDispatchers::setUseVertexAttribAlias
void setUseVertexAttribAlias(bool flag)
Definition AttributeDispatchers:45
osg::AttributeDispatchers::_initialized
bool _initialized
Definition AttributeDispatchers:96
osg::AttributeDispatchers::AttributeDispatchList
std::vector< AttributeDispatch * > AttributeDispatchList
Definition AttributeDispatchers:107
osg::AttributeDispatchers::_fogCoordDispatchers
AttributeDispatchMap * _fogCoordDispatchers
Definition AttributeDispatchers:102
osg::AttributeDispatchers::AttributeDispatchMapList
std::vector< AttributeDispatchMap * > AttributeDispatchMapList
Definition AttributeDispatchers:104
osg::AttributeDispatchers::normalDispatcher
AttributeDispatch * normalDispatcher(Array *array)
osg::AttributeDispatchers::init
void init()
osg::AttributeDispatchers::_vertexAttribDispatchers
AttributeDispatchMapList _vertexAttribDispatchers
Definition AttributeDispatchers:105
osg::AttributeDispatchers::assignTexCoordDispatchers
void assignTexCoordDispatchers(unsigned int unit)
osg::AttributeDispatchers::vertexAttribDispatcher
AttributeDispatch * vertexAttribDispatcher(unsigned int unit, Array *array)
osg::AttributeDispatchers::activateFogCoordArray
void activateFogCoordArray(osg::Array *array)
Definition AttributeDispatchers:68
osg::AttributeDispatchers::activateColorArray
void activateColorArray(osg::Array *array)
Definition AttributeDispatchers:65
osg::AttributeDispatchers::getUseVertexAttribAlias
bool getUseVertexAttribAlias() const
Definition AttributeDispatchers:46
osg::AttributeDispatchers::setState
void setState(osg::State *state)
osg::AttributeDispatchers::_colorDispatchers
AttributeDispatchMap * _colorDispatchers
Definition AttributeDispatchers:100
osg::AttributeDispatchers::active
bool active() const
Definition AttributeDispatchers:87
osg::AttributeDispatchers::_normalDispatchers
AttributeDispatchMap * _normalDispatchers
Definition AttributeDispatchers:99
osg::Referenced
Definition Referenced:44
osg::State
Definition State:80
osg
Definition AlphaFunc:19
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39
ref_ptr
osg::AttributeDispatch
Definition AttributeDispatchers:28
osg::AttributeDispatch::operator()
virtual void operator()(unsigned int)
Definition AttributeDispatchers:30
osg::AttributeDispatch::assign
virtual void assign(const GLvoid *)
Definition AttributeDispatchers:29