Array 26 KB

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