OpenSceneGraph 3.6.5
VertexArrayState
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_VertexArrayState
15#define OSG_VertexArrayState 1
16
17#include <osg/Referenced>
18#include <osg/GLExtensions>
19#include <osg/Array>
21
22namespace osg {
23
25{
26 public:
27
29
31 {
33 array(0),
34 modifiedCount(0xffffffff),
35 active(false) {}
36
37 virtual bool isVertexAttribDispatch() const { return false; }
38
39 virtual const char* className() const = 0; // { return "ArrayDispatch"; }
40
41 virtual void enable_and_dispatch(osg::State& /*state*/, const osg::Array* /*new_array*/) {} // = 0;
42
43 virtual void enable_and_dispatch(osg::State& /*state*/, const osg::Array* /*new_array*/, const osg::GLBufferObject* /*vbo*/) {} // = 0;
44
45 virtual void enable_and_dispatch(osg::State& /*state*/, GLint /*size*/, GLenum /*type*/, GLsizei /*stride*/, const GLvoid * /*ptr*/, GLboolean /*normalized*/) {} // = 0;
46
47 virtual void dispatch(osg::State& /*state*/, const osg::Array* /*new_array*/) {} // = 0;
48
49 virtual void dispatch(osg::State& /*state*/, const osg::Array* /*new_array*/, const osg::GLBufferObject* /*vbo*/) {} // = 0;
50
51 virtual void dispatch(osg::State& /*state*/, GLint /*size*/, GLenum /*type*/, GLsizei /*stride*/, const GLvoid * /*ptr*/, GLboolean /*normalized*/) {} // = 0;
52
53 virtual void disable(osg::State& /*state*/) {} // = 0;
54
56 unsigned int modifiedCount;
57 bool active;
58 };
59
60 typedef std::vector< ref_ptr<ArrayDispatch> > ArrayDispatchList;
61
64
66 {
67 if (vbo->isDirty())
68 {
69 vbo->compileBuffer();
70 _currentVBO = vbo;
71 }
72 else if (vbo != _currentVBO)
73 {
74 vbo->bindBuffer();
75 _currentVBO = vbo;
76 }
77 }
78
80 {
81 if (!_currentVBO) return;
82 _ext->glBindBuffer(GL_ARRAY_BUFFER_ARB,0);
83 _currentVBO = 0;
84 }
85
86
89
91 {
92 if (ebo->isDirty())
93 {
94 ebo->compileBuffer();
95 _currentEBO = ebo;
96 }
97 else if (ebo != _currentEBO)
98 {
99 ebo->bindBuffer();
100 _currentEBO = ebo;
101 }
102 }
103
105 {
106 if (!_currentEBO) return;
107 _ext->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
108 _currentEBO = 0;
109 }
110
112
114
116
122 void assignTexCoordArrayDispatcher(unsigned int numUnits);
123 void assignVertexAttribArrayDispatcher(unsigned int numUnits);
124
127
128 void setArray(ArrayDispatch* vad, osg::State& state, const osg::Array* new_array);
129 void setArray(ArrayDispatch* vad, osg::State& state, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized);
130
131 inline void disable(ArrayDispatch* vad, osg::State& state) { vad->disable(state); vad->array=0; vad->modifiedCount=0xffffffff; vad->active=false; }
132
133 void setInterleavedArrays( osg::State& state, GLenum format, GLsizei stride, const GLvoid* pointer);
134
135 inline void setVertexArray(osg::State& state, const osg::Array* array) { setArray(_vertexArray.get(), state, array); }
136 inline void setVertexArray(osg::State& state, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE) { setArray(_vertexArray.get(), state, size, type, stride, ptr, normalized); }
137 inline void disableVertexArray(osg::State& state) { disable(_vertexArray.get(), state); }
138
139 inline void setNormalArray(osg::State& state, const osg::Array* array) { setArray(_normalArray.get(), state, array); }
140 inline void setNormalArray(osg::State& state, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE ) { setArray(_normalArray.get(), state, 3, type, stride, ptr, normalized); }
141 inline void disableNormalArray(osg::State& state) { disable(_normalArray.get(), state); }
142
143 inline void setColorArray(osg::State& state, const osg::Array* array) { setArray(_colorArray.get(), state, array); }
144 inline void setColorArray(osg::State& state, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_TRUE ) { setArray(_colorArray.get(), state, size, type, stride, ptr, normalized); }
145 inline void disableColorArray(osg::State& state) { disable(_colorArray.get(), state); }
146
147 inline void setSecondaryColorArray(osg::State& state, const osg::Array* array) { setArray(_secondaryColorArray.get(), state, array); }
149
150 inline void setFogCoordArray(osg::State& state, const osg::Array* array) { setArray(_fogCoordArray.get(), state, array); }
151 inline void disableFogCoordArray(osg::State& state) { disable(_fogCoordArray.get(), state); }
152
153 inline void setTexCoordArray(osg::State& state, unsigned int unit, const osg::Array* array) { setArray(_texCoordArrays[unit].get(), state, array); }
154 inline void setTexCoordArray(osg::State& state, unsigned int unit, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE ) { setArray(_texCoordArrays[unit].get(), state, size, type, stride, ptr, normalized); }
155 inline void disableTexCoordArray(osg::State& state, unsigned int unit) { disable(_texCoordArrays[unit].get(),state); }
156 inline void disableTexCoordArrayAboveAndIncluding(osg::State& state, unsigned int index);
157
158 inline void setVertexAttribArray(osg::State& state, unsigned int unit, const osg::Array* array) { setArray(_vertexAttribArrays[unit].get(), state, array); }
159 inline void disableVertexAttribArray(osg::State& state, unsigned int unit) { disable(_vertexAttribArrays[unit].get(), state); }
160 inline void disableVertexAttribArrayAboveAndIncluding(osg::State& state, unsigned int index);
161
163 inline void lazyDisablingOfVertexAttributes();
164
166 inline void applyDisablingOfVertexAttributes(osg::State& state);
167
168 // Verex Array Object methods.
170
172
173 GLuint getVertexArrayObject() const { return _vertexArrayObject; }
174
175
176 void setRequiresSetArrays(bool flag) { _requiresSetArrays = flag; }
178
179 void dirty();
180
181 void release();
182
183 public:
184
186
187 // osg::GLBufferObject* getGLBufferObject(osg::Array* array);
188
192
194
196
197
205
206 typedef std::vector<ArrayDispatch*> ActiveDispatchers;
209
212
214};
215
216
217
219{
220 public:
221
223
225
226 inline void clear() { _array.clear(); }
227
228 inline bool empty() const { return _array.empty(); }
229
230 inline unsigned int size() const { return _array.size(); }
231
232 inline void resize(unsigned int newSize) { _array.resize(newSize); }
233
234 inline ref_ptr<VertexArrayState>& operator[] (unsigned int pos)
235 {
236 // automatically resize array.
237 if (_array.size()<=pos)
238 _array.resize(pos+1,0);
239
240 return _array[pos];
241 }
242
243 inline const ref_ptr<VertexArrayState>& operator[] (unsigned int pos) const
244 {
245 // automatically resize array.
246 if (_array.size()<=pos)
247 _array.resize(pos+1,0);
248
249 return _array[pos];
250 }
251
253
259 void assignTexCoordArrayDispatcher(unsigned int numUnits);
260 void assignVertexAttribArrayDispatcher(unsigned int numUnits);
261
262protected:
263
264 typedef std::vector< osg::ref_ptr<VertexArrayState> > Array;
265 mutable Array _array;
266};
267
268
269
271{
273 _activeDispatchers.clear();
274
275 for(ActiveDispatchers::iterator itr = _previous_activeDispatchers.begin();
276 itr != _previous_activeDispatchers.end();
277 ++itr)
278 {
279 ArrayDispatch* ad = (*itr);
280 // ad->array = 0;
281 ad->active = false;
282 }
283}
284
286{
287 for(ActiveDispatchers::iterator itr = _previous_activeDispatchers.begin();
288 itr != _previous_activeDispatchers.end();
289 ++itr)
290 {
291 ArrayDispatch* ad = (*itr);
292 if (!ad->active)
293 {
294 ad->disable(state);
295 ad->array = 0;
296 ad->modifiedCount = 0xffffffff;
297 }
298 }
300}
301
303{
304 for(unsigned int i=index; i<_texCoordArrays.size(); ++i)
305 {
306 disable(_texCoordArrays[i].get(), state);
307 }
308}
309
311{
312 for(unsigned int i=index; i<_vertexAttribArrays.size(); ++i)
313 {
314 disable(_vertexAttribArrays[i].get(), state);
315 }
316}
317
318
319
320}
321
322#endif
#define GL_ARRAY_BUFFER_ARB
Definition BufferObject:30
#define GL_ELEMENT_ARRAY_BUFFER_ARB
Definition BufferObject:31
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
T * get(unsigned int contextID)
Definition ContextData:152
Definition Array:61
Definition BufferObject:164
void bindBuffer()
Definition BufferObject:771
bool isDirty() const
Definition BufferObject:222
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Base class for providing reference counted objects.
Definition Referenced:44
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
void setArray(ArrayDispatch *vad, osg::State &state, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized)
osg::ref_ptr< ArrayDispatch > _secondaryColorArray
Definition VertexArrayState:201
void lazyDisablingOfVertexAttributes()
Mark all the vertex attributes as being disabled but leave the disabling till a later call to applyDi...
Definition VertexArrayState:270
void setInterleavedArrays(osg::State &state, GLenum format, GLsizei stride, const GLvoid *pointer)
void setVertexArray(osg::State &state, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE)
Definition VertexArrayState:136
GLBufferObject * _currentEBO
Definition VertexArrayState:211
void generateVertexArrayObject()
void assignColorArrayDispatcher()
GLuint _vertexArrayObject
Definition VertexArrayState:195
void setNormalArray(osg::State &state, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE)
Definition VertexArrayState:140
void assignVertexAttribArrayDispatcher(unsigned int numUnits)
osg::ref_ptr< ObserverSet > _stateObserverSet
Definition VertexArrayState:190
void bindElementBufferObject(osg::GLBufferObject *ebo)
Definition VertexArrayState:90
void disableVertexAttribArray(osg::State &state, unsigned int unit)
Definition VertexArrayState:159
bool _isVertexBufferObjectSupported
Definition VertexArrayState:193
void disableNormalArray(osg::State &state)
Definition VertexArrayState:141
void applyDisablingOfVertexAttributes(osg::State &state)
Disable all the vertex attributes that have been marked as to be disabled.
Definition VertexArrayState:285
ActiveDispatchers _activeDispatchers
Definition VertexArrayState:207
osg::ref_ptr< ArrayDispatch > _colorArray
Definition VertexArrayState:200
void bindVertexBufferObject(osg::GLBufferObject *vbo)
Definition VertexArrayState:65
void setVertexArray(osg::State &state, const osg::Array *array)
Definition VertexArrayState:135
void disable(ArrayDispatch *vad, osg::State &state)
Definition VertexArrayState:131
void assignSecondaryColorArrayDispatcher()
GLBufferObject * _currentVBO
Definition VertexArrayState:210
osg::ref_ptr< osg::GLExtensions > _ext
Definition VertexArrayState:191
GLBufferObject * getCurrentElementBufferObject()
Definition VertexArrayState:88
void assignTexCoordArrayDispatcher(unsigned int numUnits)
void disableTexCoordArrayAboveAndIncluding(osg::State &state, unsigned int index)
Definition VertexArrayState:302
std::vector< ArrayDispatch * > ActiveDispatchers
Definition VertexArrayState:206
bool getRequiresSetArrays() const
Definition VertexArrayState:177
GLuint getVertexArrayObject() const
Definition VertexArrayState:173
void setArray(ArrayDispatch *vad, osg::State &state, const osg::Array *new_array)
void assignNormalArrayDispatcher()
void disableColorArray(osg::State &state)
Definition VertexArrayState:145
GLBufferObject * getCurrentVertexBufferObject()
Definition VertexArrayState:63
void assignFogCoordArrayDispatcher()
void setVertexAttribArray(osg::State &state, unsigned int unit, const osg::Array *array)
Definition VertexArrayState:158
void resetBufferObjectPointers()
Definition VertexArrayState:111
void setTexCoordArray(osg::State &state, unsigned int unit, const osg::Array *array)
Definition VertexArrayState:153
void disableVertexAttribArrayAboveAndIncluding(osg::State &state, unsigned int index)
Definition VertexArrayState:310
bool _requiresSetArrays
Definition VertexArrayState:213
void unbindElementBufferObject()
Definition VertexArrayState:104
void setTexCoordArray(osg::State &state, unsigned int unit, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE)
Definition VertexArrayState:154
void assignVertexArrayDispatcher()
void unbindVertexBufferObject()
Definition VertexArrayState:79
ArrayDispatchList _texCoordArrays
Definition VertexArrayState:203
osg::State * _state
Definition VertexArrayState:189
void disableFogCoordArray(osg::State &state)
Definition VertexArrayState:151
osg::ref_ptr< ArrayDispatch > _vertexArray
Definition VertexArrayState:198
void setSecondaryColorArray(osg::State &state, const osg::Array *array)
Definition VertexArrayState:147
void setFogCoordArray(osg::State &state, const osg::Array *array)
Definition VertexArrayState:150
void setNormalArray(osg::State &state, const osg::Array *array)
Definition VertexArrayState:139
void setCurrentVertexBufferObject(osg::GLBufferObject *vbo)
Definition VertexArrayState:62
bool isVertexBufferObjectSupported() const
Definition VertexArrayState:126
virtual ~VertexArrayState()
osg::ref_ptr< ArrayDispatch > _fogCoordArray
Definition VertexArrayState:202
void disableTexCoordArray(osg::State &state, unsigned int unit)
Definition VertexArrayState:155
void setVertexBufferObjectSupported(bool flag)
Definition VertexArrayState:125
std::vector< ref_ptr< ArrayDispatch > > ArrayDispatchList
Definition VertexArrayState:60
void setColorArray(osg::State &state, const osg::Array *array)
Definition VertexArrayState:143
void setRequiresSetArrays(bool flag)
Definition VertexArrayState:176
void disableVertexArray(osg::State &state)
Definition VertexArrayState:137
osg::ref_ptr< ArrayDispatch > _normalArray
Definition VertexArrayState:199
void setCurrentElementBufferObject(osg::GLBufferObject *ebo)
Definition VertexArrayState:87
bool correctArrayDispatchAssigned(const ArrayDispatch *ad)
void setColorArray(osg::State &state, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_TRUE)
Definition VertexArrayState:144
VertexArrayState(osg::State *state)
ActiveDispatchers _previous_activeDispatchers
Definition VertexArrayState:208
ArrayDispatchList _vertexAttribArrays
Definition VertexArrayState:204
void disableSecondaryColorArray(osg::State &state)
Definition VertexArrayState:148
Definition VertexArrayState:31
virtual void enable_and_dispatch(osg::State &, const osg::Array *, const osg::GLBufferObject *)
Definition VertexArrayState:43
virtual void dispatch(osg::State &, const osg::Array *)
Definition VertexArrayState:47
virtual const char * className() const =0
virtual void dispatch(osg::State &, GLint, GLenum, GLsizei, const GLvoid *, GLboolean)
Definition VertexArrayState:51
virtual void enable_and_dispatch(osg::State &, GLint, GLenum, GLsizei, const GLvoid *, GLboolean)
Definition VertexArrayState:45
virtual bool isVertexAttribDispatch() const
Definition VertexArrayState:37
ArrayDispatch()
Definition VertexArrayState:32
virtual void disable(osg::State &)
Definition VertexArrayState:53
bool active
Definition VertexArrayState:57
virtual void enable_and_dispatch(osg::State &, const osg::Array *)
Definition VertexArrayState:41
const osg::Array * array
Definition VertexArrayState:55
virtual void dispatch(osg::State &, const osg::Array *, const osg::GLBufferObject *)
Definition VertexArrayState:49
unsigned int modifiedCount
Definition VertexArrayState:56
void resize(unsigned int newSize)
Definition VertexArrayState:232
bool empty() const
Definition VertexArrayState:228
Array _array
Definition VertexArrayState:265
void clear()
Definition VertexArrayState:226
unsigned int size() const
Definition VertexArrayState:230
void assignTexCoordArrayDispatcher(unsigned int numUnits)
void assignVertexAttribArrayDispatcher(unsigned int numUnits)
void assignSecondaryColorArrayDispatcher()
std::vector< osg::ref_ptr< VertexArrayState > > Array
Definition VertexArrayState:264
#define OSG_EXPORT
Definition Export:39

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.