1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
14#ifndef OSG_ATTRIBUTEDISPATCHERS
15#define OSG_ATTRIBUTEDISPATCHERS 1
25class AttributeDispatchMap;
27struct AttributeDispatch : public osg::Referenced
29 virtual void assign(const GLvoid*) {}
30 virtual void operator() (unsigned int) {};
33/** Helper class for managing the dispatch to OpenGL of various attribute arrays such as stored in osg::Geometry.*/
34class OSG_EXPORT AttributeDispatchers : public osg::Referenced
38 AttributeDispatchers();
39 ~AttributeDispatchers();
41 void setState(osg::State* state);
45 void setUseVertexAttribAlias(bool flag) { _useVertexAttribAlias = flag; }
46 bool getUseVertexAttribAlias() const { return _useVertexAttribAlias; }
49 #define DISPATCH_OR_ACTIVATE(array, dispatcher) \
51 unsigned int binding = array->getBinding(); \
52 if (binding==osg::Array::BIND_OVERALL) \
54 AttributeDispatch* at = dispatcher; \
57 else if (binding==osg::Array:: BIND_PER_PRIMITIVE_SET) \
59 AttributeDispatch* at = dispatcher; \
60 if (at) _activeDispatchList.push_back(at); \
65 void activateColorArray(osg::Array* array) { DISPATCH_OR_ACTIVATE(array, colorDispatcher(array)); }
66 void activateNormalArray(osg::Array* array) { DISPATCH_OR_ACTIVATE(array, normalDispatcher(array)); }
67 void activateSecondaryColorArray(osg::Array* array) { DISPATCH_OR_ACTIVATE(array, secondaryColorDispatcher(array)); }
68 void activateFogCoordArray(osg::Array* array) { DISPATCH_OR_ACTIVATE(array, fogCoordDispatcher(array)); }
69 void activateVertexAttribArray(unsigned int unit, osg::Array* array) { DISPATCH_OR_ACTIVATE(array, vertexAttribDispatcher(unit , array)); }
71 AttributeDispatch* normalDispatcher(Array* array);
72 AttributeDispatch* colorDispatcher(Array* array);
73 AttributeDispatch* secondaryColorDispatcher(Array* array);
74 AttributeDispatch* fogCoordDispatcher(Array* array);
75 AttributeDispatch* vertexAttribDispatcher(unsigned int unit, Array* array);
77 void dispatch(unsigned int index)
79 for(AttributeDispatchList::iterator itr = _activeDispatchList.begin();
80 itr != _activeDispatchList.end();
87 bool active() const { return !_activeDispatchList.empty(); }
93 void assignTexCoordDispatchers(unsigned int unit);
94 void assignVertexAttribDispatchers(unsigned int unit);
99 AttributeDispatchMap* _normalDispatchers;
100 AttributeDispatchMap* _colorDispatchers;
101 AttributeDispatchMap* _secondaryColorDispatchers;
102 AttributeDispatchMap* _fogCoordDispatchers;
104 typedef std::vector<AttributeDispatchMap*> AttributeDispatchMapList;
105 AttributeDispatchMapList _vertexAttribDispatchers;
107 typedef std::vector<AttributeDispatch*> AttributeDispatchList;
109 AttributeDispatchList _activeDispatchList;
111 bool _useVertexAttribAlias;