OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ArrayDispatchers.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
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.
7  *
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.
12 */
13 
14 #ifndef OSG_ArrayDispatchers
15 #define OSG_ArrayDispatchers 1
16 
17 #include <osg/ref_ptr>
18 #include <osg/Array>
19 #include <osg/Matrixd>
20 
21 namespace osg {
22 
23 // forward declare
24 class State;
25 class AttributeDispatchMap;
26 
28 {
29  virtual void assign(const GLvoid*) {}
30  virtual void operator() (unsigned int) {};
31 };
32 
35 {
36  public:
37 
40 
41  void setState(osg::State* state);
42 
43  void reset();
44 
45  void setUseVertexAttribAlias(bool flag) { _useVertexAttribAlias = flag; }
46  bool getUseVertexAttribAlias() const { return _useVertexAttribAlias; }
47 
48  void activate(unsigned int binding, AttributeDispatch* at)
49  {
50  if (at) _activeDispatchList[binding].push_back(at);
51  }
52 
53  void activateVertexArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), vertexDispatcher(array)); }
54  void activateColorArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), colorDispatcher(array)); }
55  void activateNormalArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), normalDispatcher(array)); }
56  void activateSecondaryColorArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), secondaryColorDispatcher(array)); }
57  void activateFogCoordArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), fogCoordDispatcher(array)); }
58  void activateTexCoordArray(unsigned int unit, osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), texCoordDispatcher(unit, array)); }
59  void activateVertexAttribArray(unsigned int unit, osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), vertexAttribDispatcher(unit, array)); }
60 
61  AttributeDispatch* vertexDispatcher(Array* array);
62  AttributeDispatch* normalDispatcher(Array* array);
63  AttributeDispatch* colorDispatcher(Array* array);
64  AttributeDispatch* secondaryColorDispatcher(Array* array);
65  AttributeDispatch* fogCoordDispatcher(Array* array);
66  AttributeDispatch* texCoordDispatcher(unsigned int unit, Array* array);
67  AttributeDispatch* vertexAttribDispatcher(unsigned int unit, Array* array);
68 
69  void dispatch(unsigned int binding, unsigned int index)
70  {
71  AttributeDispatchList& ad = _activeDispatchList[binding];
72  for(AttributeDispatchList::iterator itr = ad.begin();
73  itr != ad.end();
74  ++itr)
75  {
76  (*(*itr))(index);
77  }
78  }
79 
80  bool active(unsigned int binding) const { return !_activeDispatchList[binding].empty(); }
81 
82  protected:
83 
84  void init();
85 
86  void assignTexCoordDispatchers(unsigned int unit);
87  void assignVertexAttribDispatchers(unsigned int unit);
88 
91 
92  AttributeDispatchMap* _vertexDispatchers;
93  AttributeDispatchMap* _normalDispatchers;
94  AttributeDispatchMap* _colorDispatchers;
95  AttributeDispatchMap* _secondaryColorDispatchers;
96  AttributeDispatchMap* _fogCoordDispatchers;
97 
98  typedef std::vector<AttributeDispatchMap*> AttributeDispatchMapList;
99  AttributeDispatchMapList _texCoordDispatchers;
100  AttributeDispatchMapList _vertexAttribDispatchers;
101 
102  typedef std::vector<AttributeDispatch*> AttributeDispatchList;
103 
104  typedef std::vector<AttributeDispatchList> ActiveDispatchList;
105  ActiveDispatchList _activeDispatchList;
106 
108 };
109 
110 }
111 
112 #endif
bool getUseVertexAttribAlias() const
#define OSG_EXPORT
Definition: Export.h:43
std::vector< AttributeDispatchList > ActiveDispatchList
AttributeDispatchMap * _colorDispatchers
ActiveDispatchList _activeDispatchList
AttributeDispatchMap * _vertexDispatchers
void setUseVertexAttribAlias(bool flag)
void dispatch(unsigned int binding, unsigned int index)
std::vector< AttributeDispatch * > AttributeDispatchList
void activateColorArray(osg::Array *array)
void activate(unsigned int binding, AttributeDispatch *at)
AttributeDispatchMapList _vertexAttribDispatchers
AttributeDispatchMap * _normalDispatchers
void activateNormalArray(osg::Array *array)
std::vector< AttributeDispatchMap * > AttributeDispatchMapList
virtual void operator()(unsigned int)
void activateVertexAttribArray(unsigned int unit, osg::Array *array)
Binding getBinding() const
Definition: Array.h:174
AttributeDispatchMapList _texCoordDispatchers
void activateVertexArray(osg::Array *array)
void activateFogCoordArray(osg::Array *array)
Definition: AlphaFunc.h:19
AttributeDispatchMap * _secondaryColorDispatchers
void activateTexCoordArray(unsigned int unit, osg::Array *array)
AttributeDispatchMap * _fogCoordDispatchers
virtual void assign(const GLvoid *)
void activateSecondaryColorArray(osg::Array *array)
bool active(unsigned int binding) const