openscenegraph
Array
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_ARRAY
15#define OSG_ARRAY 1
16
17#include <osg/MixinVector>
18
19#include <osg/Vec2b>
20#include <osg/Vec3b>
21#include <osg/Vec4b>
22#include <osg/Vec2s>
23#include <osg/Vec3s>
24#include <osg/Vec4s>
25#include <osg/Vec2i>
26#include <osg/Vec3i>
27#include <osg/Vec4i>
28#include <osg/Vec2ub>
29#include <osg/Vec3ub>
30#include <osg/Vec4ub>
31#include <osg/Vec2us>
32#include <osg/Vec3us>
33#include <osg/Vec4us>
34#include <osg/Vec2ui>
35#include <osg/Vec3ui>
36#include <osg/Vec4ui>
37#include <osg/Vec2>
38#include <osg/Vec3>
39#include <osg/Vec4>
40#include <osg/Vec2d>
41#include <osg/Vec3d>
42#include <osg/Vec4d>
43#include <osg/Matrix>
44#include <osg/Matrixd>
45#include <osg/Quat>
46
47#include <osg/BufferObject>
48
49#include <osg/Object>
50#include <osg/GL>
51
52namespace osg {
53
54class ArrayVisitor;
55class ConstArrayVisitor;
56
57class ValueVisitor;
58class ConstValueVisitor;
59
60class OSG_EXPORT Array : public BufferData
61{
62
63 public:
64
65 /// The type of data stored in this array.
66 enum Type
67 {
68 ArrayType = 0,
69
70 ByteArrayType = 1,
71 ShortArrayType = 2,
72 IntArrayType = 3,
73
74 UByteArrayType = 4,
75 UShortArrayType = 5,
76 UIntArrayType = 6,
77
78 FloatArrayType = 7,
79 DoubleArrayType = 8,
80
81 Vec2bArrayType = 9,
82 Vec3bArrayType = 10,
83 Vec4bArrayType = 11,
84
85 Vec2sArrayType = 12,
86 Vec3sArrayType = 13,
87 Vec4sArrayType = 14,
88
89 Vec2iArrayType = 15,
90 Vec3iArrayType = 16,
91 Vec4iArrayType = 17,
92
93 Vec2ubArrayType = 18,
94 Vec3ubArrayType = 19,
95 Vec4ubArrayType = 20,
96
97 Vec2usArrayType = 21,
98 Vec3usArrayType = 22,
99 Vec4usArrayType = 23,
100
101 Vec2uiArrayType = 24,
102 Vec3uiArrayType = 25,
103 Vec4uiArrayType = 26,
104
105 Vec2ArrayType = 27,
106 Vec3ArrayType = 28,
107 Vec4ArrayType = 29,
108
109 Vec2dArrayType = 30,
110 Vec3dArrayType = 31,
111 Vec4dArrayType = 32,
112
113 MatrixArrayType = 33,
114 MatrixdArrayType = 34,
115
116 QuatArrayType = 35,
117
118 UInt64ArrayType = 36,
119 Int64ArrayType = 37,
120
121 LastArrayType = 37
122 // If new array types are added, update this and
123 // update Array::className() in src/osg/Array.cpp.
124 // Array::Type values are from ArrayType to
125 // LastArrayType, inclusive.
126 };
127
128 /// The scope of applicability of the values in this array
129 enum Binding
130 {
131 BIND_UNDEFINED=-1,
132 BIND_OFF=0,
133 BIND_OVERALL=1,
134 BIND_PER_PRIMITIVE_SET=2,
135 BIND_PER_VERTEX=4
136 };
137
138 Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0, Binding binding=BIND_UNDEFINED):
139 _arrayType(arrayType),
140 _dataSize(dataSize),
141 _dataType(dataType),
142 _binding(binding),
143 _normalize(false),
144 _preserveDataType(false) {}
145
146 Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
147 BufferData(array,copyop),
148 _arrayType(array._arrayType),
149 _dataSize(array._dataSize),
150 _dataType(array._dataType),
151 _binding(array._binding),
152 _normalize(array._normalize),
153 _preserveDataType(array._preserveDataType) {}
154
155 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Array*>(obj)!=NULL; }
156 virtual const char* libraryName() const { return "osg"; }
157
158 /// Get the class name of this array. Defined in src/osg/Array.cpp
159 /// for all concrete array types listed below --- doesn't use traits.
160 virtual const char* className() const;
161
162 virtual void accept(ArrayVisitor&) = 0;
163 virtual void accept(ConstArrayVisitor&) const = 0;
164
165 virtual void accept(unsigned int index,ValueVisitor&) = 0;
166 virtual void accept(unsigned int index,ConstValueVisitor&) const = 0;
167
168 /** Return -1 if lhs element is less than rhs element, 0 if equal,
169 * 1 if lhs element is greater than rhs element. */
170 virtual int compare(unsigned int lhs,unsigned int rhs) const = 0;
171
172 Type getType() const { return _arrayType; }
173 GLint getDataSize() const { return _dataSize; }
174 GLenum getDataType() const { return _dataType; }
175
176 virtual osg::Array* asArray() { return this; }
177 virtual const osg::Array* asArray() const { return this; }
178
179 virtual unsigned int getElementSize() const = 0;
180 virtual const GLvoid* getDataPointer() const = 0;
181 virtual const GLvoid* getDataPointer(unsigned int index) const = 0;
182 virtual unsigned int getTotalDataSize() const = 0;
183 virtual unsigned int getNumElements() const = 0;
184 virtual void reserveArray(unsigned int num) = 0;
185 virtual void resizeArray(unsigned int num) = 0;
186
187
188 /** Specify how this array should be passed to OpenGL.*/
189 void setBinding(Binding binding) { _binding = binding; }
190
191 /** Get how this array should be passed to OpenGL.*/
192 Binding getBinding() const { return _binding; }
193
194
195 /** Specify whether the array data should be normalized by OpenGL.*/
196 void setNormalize(bool normalize) { _normalize = normalize; }
197
198 /** Get whether the array data should be normalized by OpenGL.*/
199 bool getNormalize() const { return _normalize; }
200
201
202 /** Set hint to ask that the array data is passed via integer or double, or normal setVertexAttribPointer function.*/
203 void setPreserveDataType(bool preserve) { _preserveDataType = preserve; }
204
205 /** Get hint to ask that the array data is passed via integer or double, or normal setVertexAttribPointer function.*/
206 bool getPreserveDataType() const { return _preserveDataType; }
207
208
209 /** Frees unused space on this vector - i.e. the difference between size() and max_size() of the underlying vector.*/
210 virtual void trim() {}
211
212 /** Set the VertexBufferObject.*/
213 inline void setVertexBufferObject(osg::VertexBufferObject* vbo) { setBufferObject(vbo); }
214
215 /** Get the VertexBufferObject. If no VBO is assigned returns NULL*/
216 inline osg::VertexBufferObject* getVertexBufferObject() { return dynamic_cast<osg::VertexBufferObject*>(_bufferObject.get()); }
217
218 /** Get the const VertexBufferObject. If no VBO is assigned returns NULL*/
219 inline const osg::VertexBufferObject* getVertexBufferObject() const { return dynamic_cast<const osg::VertexBufferObject*>(_bufferObject.get()); }
220
221 protected:
222
223 virtual ~Array() {}
224
225 Type _arrayType;
226 GLint _dataSize;
227 GLenum _dataType;
228 Binding _binding;
229 bool _normalize;
230 bool _preserveDataType;
231};
232
233/** convenience function for getting the binding of array via a ptr that may be null.*/
234inline osg::Array::Binding getBinding(const osg::Array* array) { return array ? array->getBinding() : osg::Array::BIND_OFF; }
235
236/** convenience function for getting the binding of array via a ptr that may be null.*/
237inline bool getNormalize(const osg::Array* array) { return array ? array->getNormalize() : false; }
238
239
240/// A concrete array holding elements of type T.
241template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
242class TemplateArray : public Array, public MixinVector<T>
243{
244 public:
245
246 TemplateArray(Binding binding=BIND_UNDEFINED) : Array(ARRAYTYPE,DataSize,DataType, binding) {}
247
248 TemplateArray(const TemplateArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
249 Array(ta,copyop),
250 MixinVector<T>(ta) {}
251
252 TemplateArray(unsigned int no) :
253 Array(ARRAYTYPE,DataSize,DataType),
254 MixinVector<T>(no) {}
255
256 TemplateArray(unsigned int no,const T* ptr) :
257 Array(ARRAYTYPE,DataSize,DataType),
258 MixinVector<T>(ptr,ptr+no) {}
259
260 TemplateArray(Binding binding, unsigned int no) :
261 Array(ARRAYTYPE,DataSize,DataType, binding),
262 MixinVector<T>(no) {}
263
264 TemplateArray(Binding binding, unsigned int no,const T* ptr) :
265 Array(ARRAYTYPE,DataSize,DataType, binding),
266 MixinVector<T>(ptr,ptr+no) {}
267
268 template <class InputIterator>
269 TemplateArray(InputIterator first,InputIterator last) :
270 Array(ARRAYTYPE,DataSize,DataType),
271 MixinVector<T>(first,last) {}
272
273 TemplateArray& operator = (const TemplateArray& array)
274 {
275 if (this==&array) return *this;
276 this->assign(array.begin(),array.end());
277 return *this;
278 }
279
280 virtual Object* cloneType() const { return new TemplateArray(); }
281 virtual Object* clone(const CopyOp& copyop) const { return new TemplateArray(*this,copyop); }
282
283 inline virtual void accept(ArrayVisitor& av);
284 inline virtual void accept(ConstArrayVisitor& av) const;
285
286 inline virtual void accept(unsigned int index,ValueVisitor& vv);
287 inline virtual void accept(unsigned int index,ConstValueVisitor& vv) const;
288
289 virtual int compare(unsigned int lhs,unsigned int rhs) const
290 {
291 const T& elem_lhs = (*this)[lhs];
292 const T& elem_rhs = (*this)[rhs];
293 if (elem_lhs<elem_rhs) return -1;
294 if (elem_rhs<elem_lhs) return 1;
295 return 0;
296 }
297
298 /** Frees unused space on this vector - i.e. the difference between size() and max_size() of the underlying vector.*/
299 virtual void trim()
300 {
301 MixinVector<T>( *this ).swap( *this );
302 }
303
304 virtual unsigned int getElementSize() const { return sizeof(ElementDataType); }
305 virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; }
306 virtual const GLvoid* getDataPointer(unsigned int index) const { if (!this->empty()) return &((*this)[index]); else return 0; }
307 virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(ElementDataType)); }
308 virtual unsigned int getNumElements() const { return static_cast<unsigned int>(this->size()); }
309 virtual void reserveArray(unsigned int num) { this->reserve(num); }
310 virtual void resizeArray(unsigned int num) { this->resize(num); }
311
312 typedef T ElementDataType; // expose T
313
314 protected:
315
316 virtual ~TemplateArray() {}
317};
318
319class OSG_EXPORT IndexArray : public Array
320{
321
322 public:
323
324 IndexArray(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0):
325 Array(arrayType,dataSize,dataType) {}
326
327 IndexArray(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
328 Array(array,copyop) {}
329
330 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const IndexArray*>(obj)!=NULL; }
331
332 virtual unsigned int index(unsigned int pos) const = 0;
333
334 protected:
335
336 virtual ~IndexArray() {}
337};
338
339template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
340class TemplateIndexArray : public IndexArray, public MixinVector<T>
341{
342 public:
343
344 TemplateIndexArray() : IndexArray(ARRAYTYPE,DataSize,DataType) {}
345
346 TemplateIndexArray(const TemplateIndexArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
347 IndexArray(ta,copyop),
348 MixinVector<T>(ta) {}
349
350 TemplateIndexArray(unsigned int no) :
351 IndexArray(ARRAYTYPE,DataSize,DataType),
352 MixinVector<T>(no) {}
353
354 TemplateIndexArray(unsigned int no,T* ptr) :
355 IndexArray(ARRAYTYPE,DataSize,DataType),
356 MixinVector<T>(ptr,ptr+no) {}
357
358 template <class InputIterator>
359 TemplateIndexArray(InputIterator first,InputIterator last) :
360 IndexArray(ARRAYTYPE,DataSize,DataType),
361 MixinVector<T>(first,last) {}
362
363 TemplateIndexArray& operator = (const TemplateIndexArray& array)
364 {
365 if (this==&array) return *this;
366 this->assign(array.begin(),array.end());
367 return *this;
368 }
369
370 virtual Object* cloneType() const { return new TemplateIndexArray(); }
371 virtual Object* clone(const CopyOp& copyop) const { return new TemplateIndexArray(*this,copyop); }
372
373 inline virtual void accept(ArrayVisitor& av);
374 inline virtual void accept(ConstArrayVisitor& av) const;
375
376 inline virtual void accept(unsigned int index,ValueVisitor& vv);
377 inline virtual void accept(unsigned int index,ConstValueVisitor& vv) const;
378
379 virtual int compare(unsigned int lhs,unsigned int rhs) const
380 {
381 const T& elem_lhs = (*this)[lhs];
382 const T& elem_rhs = (*this)[rhs];
383 if (elem_lhs<elem_rhs) return -1;
384 if (elem_rhs<elem_lhs) return 1;
385 return 0;
386 }
387
388 /** Frees unused space on this vector - i.e. the difference between size() and max_size() of the underlying vector.*/
389 virtual void trim()
390 {
391 MixinVector<T>( *this ).swap( *this );
392 }
393
394 virtual unsigned int getElementSize() const { return sizeof(ElementDataType); }
395 virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; }
396 virtual const GLvoid* getDataPointer(unsigned int index) const { if (!this->empty()) return &((*this)[index]); else return 0; }
397 virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(T)); }
398 virtual unsigned int getNumElements() const { return static_cast<unsigned int>(this->size()); }
399 virtual void reserveArray(unsigned int num) { this->reserve(num); }
400 virtual void resizeArray(unsigned int num) { this->resize(num); }
401
402 virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
403
404 typedef T ElementDataType; // expose T
405
406 protected:
407
408 virtual ~TemplateIndexArray() {}
409};
410
411// The predefined array types
412
413typedef TemplateIndexArray<GLbyte,Array::ByteArrayType,1,GL_BYTE> ByteArray;
414typedef TemplateIndexArray<GLshort,Array::ShortArrayType,1,GL_SHORT> ShortArray;
415typedef TemplateIndexArray<GLint,Array::IntArrayType,1,GL_INT> IntArray;
416
417typedef TemplateIndexArray<GLubyte,Array::UByteArrayType,1,GL_UNSIGNED_BYTE> UByteArray;
418typedef TemplateIndexArray<GLushort,Array::UShortArrayType,1,GL_UNSIGNED_SHORT> UShortArray;
419typedef TemplateIndexArray<GLuint,Array::UIntArrayType,1,GL_UNSIGNED_INT> UIntArray;
420
421typedef TemplateArray<GLfloat,Array::FloatArrayType,1,GL_FLOAT> FloatArray;
422typedef TemplateArray<GLdouble,Array::DoubleArrayType,1,GL_DOUBLE> DoubleArray;
423
424typedef TemplateArray<Vec2b,Array::Vec2bArrayType,2,GL_BYTE> Vec2bArray;
425typedef TemplateArray<Vec3b,Array::Vec3bArrayType,3,GL_BYTE> Vec3bArray;
426typedef TemplateArray<Vec4b,Array::Vec4bArrayType,4,GL_BYTE> Vec4bArray;
427
428typedef TemplateArray<Vec2s,Array::Vec2sArrayType,2,GL_SHORT> Vec2sArray;
429typedef TemplateArray<Vec3s,Array::Vec3sArrayType,3,GL_SHORT> Vec3sArray;
430typedef TemplateArray<Vec4s,Array::Vec4sArrayType,4,GL_SHORT> Vec4sArray;
431
432typedef TemplateArray<Vec2i,Array::Vec2iArrayType,2,GL_INT> Vec2iArray;
433typedef TemplateArray<Vec3i,Array::Vec3iArrayType,3,GL_INT> Vec3iArray;
434typedef TemplateArray<Vec4i,Array::Vec4iArrayType,4,GL_INT> Vec4iArray;
435
436typedef TemplateArray<Vec2ub,Array::Vec2ubArrayType,2,GL_UNSIGNED_BYTE> Vec2ubArray;
437typedef TemplateArray<Vec3ub,Array::Vec3ubArrayType,3,GL_UNSIGNED_BYTE> Vec3ubArray;
438typedef TemplateArray<Vec4ub,Array::Vec4ubArrayType,4,GL_UNSIGNED_BYTE> Vec4ubArray;
439
440typedef TemplateArray<Vec2us,Array::Vec2usArrayType,2,GL_UNSIGNED_SHORT> Vec2usArray;
441typedef TemplateArray<Vec3us,Array::Vec3usArrayType,3,GL_UNSIGNED_SHORT> Vec3usArray;
442typedef TemplateArray<Vec4us,Array::Vec4usArrayType,4,GL_UNSIGNED_SHORT> Vec4usArray;
443
444typedef TemplateArray<Vec2ui,Array::Vec2uiArrayType,2,GL_UNSIGNED_INT> Vec2uiArray;
445typedef TemplateArray<Vec3ui,Array::Vec3uiArrayType,3,GL_UNSIGNED_INT> Vec3uiArray;
446typedef TemplateArray<Vec4ui,Array::Vec4uiArrayType,4,GL_UNSIGNED_INT> Vec4uiArray;
447
448typedef TemplateArray<Vec2,Array::Vec2ArrayType,2,GL_FLOAT> Vec2Array;
449typedef TemplateArray<Vec3,Array::Vec3ArrayType,3,GL_FLOAT> Vec3Array;
450typedef TemplateArray<Vec4,Array::Vec4ArrayType,4,GL_FLOAT> Vec4Array;
451
452typedef TemplateArray<Vec2d,Array::Vec2dArrayType,2,GL_DOUBLE> Vec2dArray;
453typedef TemplateArray<Vec3d,Array::Vec3dArrayType,3,GL_DOUBLE> Vec3dArray;
454typedef TemplateArray<Vec4d,Array::Vec4dArrayType,4,GL_DOUBLE> Vec4dArray;
455
456typedef TemplateArray<Matrixf,Array::MatrixArrayType,16,GL_FLOAT> MatrixfArray;
457typedef TemplateArray<Matrixd,Array::MatrixdArrayType,16,GL_DOUBLE> MatrixdArray;
458
459typedef TemplateArray<Quat,Array::QuatArrayType,4,GL_DOUBLE> QuatArray;
460
461typedef TemplateIndexArray<GLuint64,Array::UInt64ArrayType,1,GL_UNSIGNED_INT64_ARB> UInt64Array;
462typedef TemplateIndexArray<GLint64,Array::Int64ArrayType,1,GL_INT64_ARB> Int64Array;
463
464class ArrayVisitor
465{
466 public:
467 ArrayVisitor() {}
468 virtual ~ArrayVisitor() {}
469
470 virtual void apply(Array&) {}
471
472 virtual void apply(ByteArray&) {}
473 virtual void apply(ShortArray&) {}
474 virtual void apply(IntArray&) {}
475
476 virtual void apply(UByteArray&) {}
477 virtual void apply(UShortArray&) {}
478 virtual void apply(UIntArray&) {}
479
480 virtual void apply(FloatArray&) {}
481 virtual void apply(DoubleArray&) {}
482
483
484 virtual void apply(Vec2bArray&) {}
485 virtual void apply(Vec3bArray&) {}
486 virtual void apply(Vec4bArray&) {}
487
488 virtual void apply(Vec2sArray&) {}
489 virtual void apply(Vec3sArray&) {}
490 virtual void apply(Vec4sArray&) {}
491
492 virtual void apply(Vec2iArray&) {}
493 virtual void apply(Vec3iArray&) {}
494 virtual void apply(Vec4iArray&) {}
495
496 virtual void apply(Vec2ubArray&) {}
497 virtual void apply(Vec3ubArray&) {}
498 virtual void apply(Vec4ubArray&) {}
499
500 virtual void apply(Vec2usArray&) {}
501 virtual void apply(Vec3usArray&) {}
502 virtual void apply(Vec4usArray&) {}
503
504 virtual void apply(Vec2uiArray&) {}
505 virtual void apply(Vec3uiArray&) {}
506 virtual void apply(Vec4uiArray&) {}
507
508 virtual void apply(Vec2Array&) {}
509 virtual void apply(Vec3Array&) {}
510 virtual void apply(Vec4Array&) {}
511
512 virtual void apply(Vec2dArray&) {}
513 virtual void apply(Vec3dArray&) {}
514 virtual void apply(Vec4dArray&) {}
515
516 virtual void apply(MatrixfArray&) {}
517 virtual void apply(MatrixdArray&) {}
518
519 virtual void apply(UInt64Array&) {}
520 virtual void apply(Int64Array&) {}
521};
522
523class ConstArrayVisitor
524{
525 public:
526 ConstArrayVisitor() {}
527 virtual ~ConstArrayVisitor() {}
528
529 virtual void apply(const Array&) {}
530
531 virtual void apply(const ByteArray&) {}
532 virtual void apply(const ShortArray&) {}
533 virtual void apply(const IntArray&) {}
534
535 virtual void apply(const UByteArray&) {}
536 virtual void apply(const UShortArray&) {}
537 virtual void apply(const UIntArray&) {}
538
539 virtual void apply(const FloatArray&) {}
540 virtual void apply(const DoubleArray&) {}
541
542
543 virtual void apply(const Vec2bArray&) {}
544 virtual void apply(const Vec3bArray&) {}
545 virtual void apply(const Vec4bArray&) {}
546
547 virtual void apply(const Vec2sArray&) {}
548 virtual void apply(const Vec3sArray&) {}
549 virtual void apply(const Vec4sArray&) {}
550
551 virtual void apply(const Vec2iArray&) {}
552 virtual void apply(const Vec3iArray&) {}
553 virtual void apply(const Vec4iArray&) {}
554
555 virtual void apply(const Vec2ubArray&) {}
556 virtual void apply(const Vec3ubArray&) {}
557 virtual void apply(const Vec4ubArray&) {}
558
559 virtual void apply(const Vec2usArray&) {}
560 virtual void apply(const Vec3usArray&) {}
561 virtual void apply(const Vec4usArray&) {}
562
563 virtual void apply(const Vec2uiArray&) {}
564 virtual void apply(const Vec3uiArray&) {}
565 virtual void apply(const Vec4uiArray&) {}
566
567 virtual void apply(const Vec2Array&) {}
568 virtual void apply(const Vec3Array&) {}
569 virtual void apply(const Vec4Array&) {}
570
571 virtual void apply(const Vec2dArray&) {}
572 virtual void apply(const Vec3dArray&) {}
573 virtual void apply(const Vec4dArray&) {}
574
575 virtual void apply(const MatrixfArray&) {}
576 virtual void apply(const MatrixdArray&) {}
577
578 virtual void apply(const UInt64Array&) {}
579 virtual void apply(const Int64Array&) {}
580};
581
582
583class ValueVisitor
584{
585 public:
586 ValueVisitor() {}
587 virtual ~ValueVisitor() {}
588
589 virtual void apply(GLbyte&) {}
590 virtual void apply(GLshort&) {}
591 virtual void apply(GLint&) {}
592
593 virtual void apply(GLushort&) {}
594 virtual void apply(GLubyte&) {}
595 virtual void apply(GLuint&) {}
596
597 virtual void apply(GLfloat&) {}
598 virtual void apply(GLdouble&) {}
599
600
601 virtual void apply(Vec2b&) {}
602 virtual void apply(Vec3b&) {}
603 virtual void apply(Vec4b&) {}
604
605 virtual void apply(Vec2s&) {}
606 virtual void apply(Vec3s&) {}
607 virtual void apply(Vec4s&) {}
608
609 virtual void apply(Vec2i&) {}
610 virtual void apply(Vec3i&) {}
611 virtual void apply(Vec4i&) {}
612
613 virtual void apply(Vec2ub&) {}
614 virtual void apply(Vec3ub&) {}
615 virtual void apply(Vec4ub&) {}
616
617 virtual void apply(Vec2us&) {}
618 virtual void apply(Vec3us&) {}
619 virtual void apply(Vec4us&) {}
620
621 virtual void apply(Vec2ui&) {}
622 virtual void apply(Vec3ui&) {}
623 virtual void apply(Vec4ui&) {}
624
625 virtual void apply(Vec2&) {}
626 virtual void apply(Vec3&) {}
627 virtual void apply(Vec4&) {}
628
629 virtual void apply(Vec2d&) {}
630 virtual void apply(Vec3d&) {}
631 virtual void apply(Vec4d&) {}
632
633 virtual void apply(Matrixf&) {}
634 virtual void apply(Matrixd&) {}
635
636 virtual void apply(Quat&) {}
637
638 virtual void apply(GLuint64&){}
639 virtual void apply(GLint64&){}
640};
641
642class ConstValueVisitor
643{
644 public:
645 ConstValueVisitor() {}
646 virtual ~ConstValueVisitor() {}
647
648 virtual void apply(const GLbyte&) {}
649 virtual void apply(const GLshort&) {}
650 virtual void apply(const GLint&) {}
651
652 virtual void apply(const GLushort&) {}
653 virtual void apply(const GLubyte&) {}
654 virtual void apply(const GLuint&) {}
655
656 virtual void apply(const GLfloat&) {}
657 virtual void apply(const GLdouble&) {}
658
659
660 virtual void apply(const Vec2b&) {}
661 virtual void apply(const Vec3b&) {}
662 virtual void apply(const Vec4b&) {}
663
664 virtual void apply(const Vec2s&) {}
665 virtual void apply(const Vec3s&) {}
666 virtual void apply(const Vec4s&) {}
667
668 virtual void apply(const Vec2i&) {}
669 virtual void apply(const Vec3i&) {}
670 virtual void apply(const Vec4i&) {}
671
672 virtual void apply(const Vec2ub&) {}
673 virtual void apply(const Vec3ub&) {}
674 virtual void apply(const Vec4ub&) {}
675
676 virtual void apply(const Vec2us&) {}
677 virtual void apply(const Vec3us&) {}
678 virtual void apply(const Vec4us&) {}
679
680 virtual void apply(const Vec2ui&) {}
681 virtual void apply(const Vec3ui&) {}
682 virtual void apply(const Vec4ui&) {}
683
684 virtual void apply(const Vec2&) {}
685 virtual void apply(const Vec3&) {}
686 virtual void apply(const Vec4&) {}
687
688 virtual void apply(const Vec2d&) {}
689 virtual void apply(const Vec3d&) {}
690 virtual void apply(const Vec4d&) {}
691
692 virtual void apply(const Matrixf&) {}
693 virtual void apply(const Matrixd&) {}
694
695 virtual void apply(const Quat&) {}
696
697 virtual void apply(const GLuint64&){}
698 virtual void apply(const GLint64&){}
699};
700
701template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
702inline void TemplateArray<T,ARRAYTYPE,DataSize,DataType>::accept(ArrayVisitor& av) { av.apply(*this); }
703
704template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
705inline void TemplateArray<T,ARRAYTYPE,DataSize,DataType>::accept(ConstArrayVisitor& av) const { av.apply(*this); }
706
707template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
708inline void TemplateArray<T,ARRAYTYPE,DataSize,DataType>::accept(unsigned int index,ValueVisitor& vv) { vv.apply( (*this)[index] ); }
709
710template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
711inline void TemplateArray<T,ARRAYTYPE,DataSize,DataType>::accept(unsigned int index,ConstValueVisitor& vv) const { vv.apply( (*this)[index] );}
712
713template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
714inline void TemplateIndexArray<T,ARRAYTYPE,DataSize,DataType>::accept(ArrayVisitor& av) { av.apply(*this); }
715
716template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
717inline void TemplateIndexArray<T,ARRAYTYPE,DataSize,DataType>::accept(ConstArrayVisitor& av) const { av.apply(*this); }
718
719template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
720inline void TemplateIndexArray<T,ARRAYTYPE,DataSize,DataType>::accept(unsigned int index,ValueVisitor& vv) { vv.apply( (*this)[index] ); }
721
722template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
723inline void TemplateIndexArray<T,ARRAYTYPE,DataSize,DataType>::accept(unsigned int index,ConstValueVisitor& vv) const { vv.apply( (*this)[index] );}
724
725}
726
727#endif