71
72
DoubleArrayType = 18,
72
73
Vec2dArrayType = 19,
73
74
Vec3dArrayType = 20,
77
79
Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0):
78
80
_arrayType(arrayType),
79
81
_dataSize(dataSize),
82
_dataType(dataType) {}
84
84
Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
85
BufferData(array,copyop),
86
86
_arrayType(array._arrayType),
87
87
_dataSize(array._dataSize),
88
_dataType(array._dataType),
88
_dataType(array._dataType) {}
92
90
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Array*>(obj)!=NULL; }
93
91
virtual const char* libraryName() const { return "osg"; }
94
92
virtual const char* className() const;
96
94
virtual void accept(ArrayVisitor&) = 0;
97
95
virtual void accept(ConstArrayVisitor&) const = 0;
113
111
/** Frees unused space on this vector - i.e. the difference between size() and max_size() of the underlying vector.*/
114
112
virtual void trim() {}
116
/** Dirty the primitive, which increments the modified count, to force buffer objects to update. */
117
inline void dirty() { ++_modifiedCount; if (_vbo.valid()) _vbo->dirty(); }
119
/** Set the modified count value.*/
120
inline void setModifiedCount(unsigned int value) { _modifiedCount=value; }
122
/** Get modified count value.*/
123
inline unsigned int getModifiedCount() const { return _modifiedCount; }
125
114
/** Set the VertexBufferObject.*/
126
inline void setVertexBufferObject(osg::VertexBufferObject* vbo)
128
if (_vbo == vbo) return;
132
_vbo->removeArray(this);
139
_vbo->addArray(this);
115
inline void setVertexBufferObject(osg::VertexBufferObject* vbo) { setBufferObject(vbo); }
143
117
/** Get the VertexBufferObject. If no VBO is assigned returns NULL*/
144
inline osg::VertexBufferObject* getVertexBufferObject() { return _vbo.get(); }
118
inline osg::VertexBufferObject* getVertexBufferObject() { return dynamic_cast<osg::VertexBufferObject*>(_bufferObject.get()); }
146
120
/** Get the const VertexBufferObject. If no VBO is assigned returns NULL*/
147
inline const osg::VertexBufferObject* getVertexBufferObject() const { return _vbo.get(); }
149
/** Set the offset into the VertexBufferObject, if used.*/
150
void setVertexBufferObjectOffset(const GLvoid* offset ) const { _vboOffset = offset; }
152
/** Get the offset into the VertexBufferObject, if used.*/
153
const GLvoid* getVertexBufferObjectOffset() const { return _vboOffset; }
121
inline const osg::VertexBufferObject* getVertexBufferObject() const { return dynamic_cast<const osg::VertexBufferObject*>(_bufferObject.get()); }
161
_vbo->removeArray(this);
167
129
GLenum _dataType;
168
unsigned int _modifiedCount;
169
osg::ref_ptr<osg::VertexBufferObject> _vbo;
170
mutable const GLvoid* _vboOffset;
173
132
template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
174
133
class TemplateArray : public Array, public MixinVector<T>
178
137
TemplateArray() : Array(ARRAYTYPE,DataSize,DataType) {}
180
139
TemplateArray(const TemplateArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
181
140
Array(ta,copyop),
182
141
MixinVector<T>(ta) {}
184
143
TemplateArray(unsigned int no) :
185
144
Array(ARRAYTYPE,DataSize,DataType),
186
145
MixinVector<T>(no) {}
188
TemplateArray(unsigned int no,T* ptr) :
147
TemplateArray(unsigned int no,const T* ptr) :
189
148
Array(ARRAYTYPE,DataSize,DataType),
190
149
MixinVector<T>(ptr,ptr+no) {}
244
203
IndexArray(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0):
245
204
Array(arrayType,dataSize,dataType) {}
247
206
IndexArray(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
248
207
Array(array,copyop) {}
250
209
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const IndexArray*>(obj)!=NULL; }
252
211
virtual unsigned int index(unsigned int pos) const = 0;
256
215
virtual ~IndexArray() {}
260
219
class TemplateIndexArray : public IndexArray, public MixinVector<T>
264
223
TemplateIndexArray() : IndexArray(ARRAYTYPE,DataSize,DataType) {}
266
225
TemplateIndexArray(const TemplateIndexArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
267
226
IndexArray(ta,copyop),
268
227
MixinVector<T>(ta) {}
270
229
TemplateIndexArray(unsigned int no) :
271
230
IndexArray(ARRAYTYPE,DataSize,DataType),
272
231
MixinVector<T>(no) {}
352
311
typedef TemplateArray<Vec3d,Array::Vec3dArrayType,3,GL_DOUBLE> Vec3dArray;
353
312
typedef TemplateArray<Vec4d,Array::Vec4dArrayType,4,GL_DOUBLE> Vec4dArray;
314
typedef TemplateArray<Matrixf,Array::MatrixArrayType,16,GL_FLOAT> MatrixfArray;
356
317
class ArrayVisitor
491
458
virtual void apply(const Vec2d&) {}
492
459
virtual void apply(const Vec3d&) {}
493
460
virtual void apply(const Vec4d&) {}
462
virtual void apply(const Matrixf&) {}
496
465
template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>