| 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/Vec2> |
|---|
| 20 | #include <osg/Vec3> |
|---|
| 21 | #include <osg/Vec4> |
|---|
| 22 | #include <osg/Vec2d> |
|---|
| 23 | #include <osg/Vec3d> |
|---|
| 24 | #include <osg/Vec4d> |
|---|
| 25 | #include <osg/Vec4ub> |
|---|
| 26 | #include <osg/Vec2s> |
|---|
| 27 | #include <osg/Vec3s> |
|---|
| 28 | #include <osg/Vec4s> |
|---|
| 29 | #include <osg/Vec2b> |
|---|
| 30 | #include <osg/Vec3b> |
|---|
| 31 | #include <osg/Vec4b> |
|---|
| 32 | |
|---|
| 33 | #include <osg/BufferObject> |
|---|
| 34 | |
|---|
| 35 | #include <osg/Object> |
|---|
| 36 | #include <osg/GL> |
|---|
| 37 | |
|---|
| 38 | namespace osg { |
|---|
| 39 | |
|---|
| 40 | class ArrayVisitor; |
|---|
| 41 | class ConstArrayVisitor; |
|---|
| 42 | |
|---|
| 43 | class ValueVisitor; |
|---|
| 44 | class ConstValueVisitor; |
|---|
| 45 | |
|---|
| 46 | class OSG_EXPORT Array : public BufferData |
|---|
| 47 | { |
|---|
| 48 | |
|---|
| 49 | public: |
|---|
| 50 | |
|---|
| 51 | enum Type |
|---|
| 52 | { |
|---|
| 53 | ArrayType = 0, |
|---|
| 54 | ByteArrayType = 1, |
|---|
| 55 | ShortArrayType = 2, |
|---|
| 56 | IntArrayType = 3, |
|---|
| 57 | UByteArrayType = 4, |
|---|
| 58 | UShortArrayType = 5, |
|---|
| 59 | UIntArrayType = 6, |
|---|
| 60 | Vec4ubArrayType = 7, |
|---|
| 61 | FloatArrayType = 8, |
|---|
| 62 | Vec2ArrayType = 9, |
|---|
| 63 | Vec3ArrayType = 10, |
|---|
| 64 | Vec4ArrayType = 11, |
|---|
| 65 | Vec2sArrayType = 12, |
|---|
| 66 | Vec3sArrayType = 13, |
|---|
| 67 | Vec4sArrayType = 14, |
|---|
| 68 | Vec2bArrayType = 15, |
|---|
| 69 | Vec3bArrayType = 16, |
|---|
| 70 | Vec4bArrayType = 17, |
|---|
| 71 | DoubleArrayType = 18, |
|---|
| 72 | Vec2dArrayType = 19, |
|---|
| 73 | Vec3dArrayType = 20, |
|---|
| 74 | Vec4dArrayType = 21 |
|---|
| 75 | }; |
|---|
| 76 | |
|---|
| 77 | Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0): |
|---|
| 78 | _arrayType(arrayType), |
|---|
| 79 | _dataSize(dataSize), |
|---|
| 80 | _dataType(dataType) {} |
|---|
| 81 | |
|---|
| 82 | Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): |
|---|
| 83 | BufferData(array,copyop), |
|---|
| 84 | _arrayType(array._arrayType), |
|---|
| 85 | _dataSize(array._dataSize), |
|---|
| 86 | _dataType(array._dataType) {} |
|---|
| 87 | |
|---|
| 88 | virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Array*>(obj)!=NULL; } |
|---|
| 89 | virtual const char* libraryName() const { return "osg"; } |
|---|
| 90 | virtual const char* className() const; |
|---|
| 91 | |
|---|
| 92 | virtual void accept(ArrayVisitor&) = 0; |
|---|
| 93 | virtual void accept(ConstArrayVisitor&) const = 0; |
|---|
| 94 | |
|---|
| 95 | virtual void accept(unsigned int index,ValueVisitor&) = 0; |
|---|
| 96 | virtual void accept(unsigned int index,ConstValueVisitor&) const = 0; |
|---|
| 97 | |
|---|
| 98 | /** Return -1 if lhs element is less than rhs element, 0 if equal, |
|---|
| 99 | * 1 if lhs element is greater than rhs element. */ |
|---|
| 100 | virtual int compare(unsigned int lhs,unsigned int rhs) const = 0; |
|---|
| 101 | |
|---|
| 102 | Type getType() const { return _arrayType; } |
|---|
| 103 | GLint getDataSize() const { return _dataSize; } |
|---|
| 104 | GLenum getDataType() const { return _dataType; } |
|---|
| 105 | virtual const GLvoid* getDataPointer() const = 0; |
|---|
| 106 | virtual unsigned int getTotalDataSize() const = 0; |
|---|
| 107 | virtual unsigned int getNumElements() const = 0; |
|---|
| 108 | |
|---|
| 109 | /** Frees unused space on this vector - i.e. the difference between size() and max_size() of the underlying vector.*/ |
|---|
| 110 | virtual void trim() {} |
|---|
| 111 | |
|---|
| 112 | /** Set the VertexBufferObject.*/ |
|---|
| 113 | inline void setVertexBufferObject(osg::VertexBufferObject* vbo) { setBufferObject(vbo); } |
|---|
| 114 | |
|---|
| 115 | /** Get the VertexBufferObject. If no VBO is assigned returns NULL*/ |
|---|
| 116 | inline osg::VertexBufferObject* getVertexBufferObject() { return dynamic_cast<osg::VertexBufferObject*>(_bufferObject.get()); } |
|---|
| 117 | |
|---|
| 118 | /** Get the const VertexBufferObject. If no VBO is assigned returns NULL*/ |
|---|
| 119 | inline const osg::VertexBufferObject* getVertexBufferObject() const { return dynamic_cast<const osg::VertexBufferObject*>(_bufferObject.get()); } |
|---|
| 120 | |
|---|
| 121 | protected: |
|---|
| 122 | |
|---|
| 123 | virtual ~Array() {} |
|---|
| 124 | |
|---|
| 125 | Type _arrayType; |
|---|
| 126 | GLint _dataSize; |
|---|
| 127 | GLenum _dataType; |
|---|
| 128 | }; |
|---|
| 129 | |
|---|
| 130 | template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType> |
|---|
| 131 | class TemplateArray : public Array, public MixinVector<T> |
|---|
| 132 | { |
|---|
| 133 | public: |
|---|
| 134 | |
|---|
| 135 | TemplateArray() : Array(ARRAYTYPE,DataSize,DataType) {} |
|---|
| 136 | |
|---|
| 137 | TemplateArray(const TemplateArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY): |
|---|
| 138 | Array(ta,copyop), |
|---|
| 139 | MixinVector<T>(ta) {} |
|---|
| 140 | |
|---|
| 141 | TemplateArray(unsigned int no) : |
|---|
| 142 | Array(ARRAYTYPE,DataSize,DataType), |
|---|
| 143 | MixinVector<T>(no) {} |
|---|
| 144 | |
|---|
| 145 | TemplateArray(unsigned int no,const T* ptr) : |
|---|
| 146 | Array(ARRAYTYPE,DataSize,DataType), |
|---|
| 147 | MixinVector<T>(ptr,ptr+no) {} |
|---|
| 148 | |
|---|
| 149 | template <class InputIterator> |
|---|
| 150 | TemplateArray(InputIterator first,InputIterator last) : |
|---|
| 151 | Array(ARRAYTYPE,DataSize,DataType), |
|---|
| 152 | MixinVector<T>(first,last) {} |
|---|
| 153 | |
|---|
| 154 | TemplateArray& operator = (const TemplateArray& array) |
|---|
| 155 | { |
|---|
| 156 | if (this==&array) return *this; |
|---|
| 157 | assign(array.begin(),array.end()); |
|---|
| 158 | return *this; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | virtual Object* cloneType() const { return new TemplateArray(); } |
|---|
| 162 | virtual Object* clone(const CopyOp& copyop) const { return new TemplateArray(*this,copyop); } |
|---|
| 163 | |
|---|
| 164 | inline virtual void accept(ArrayVisitor& av); |
|---|
| 165 | inline virtual void accept(ConstArrayVisitor& av) const; |
|---|
| 166 | |
|---|
| 167 | inline virtual void accept(unsigned int index,ValueVisitor& vv); |
|---|
| 168 | inline virtual void accept(unsigned int index,ConstValueVisitor& vv) const; |
|---|
| 169 | |
|---|
| 170 | virtual int compare(unsigned int lhs,unsigned int rhs) const |
|---|
| 171 | { |
|---|
| 172 | const T& elem_lhs = (*this)[lhs]; |
|---|
| 173 | const T& elem_rhs = (*this)[rhs]; |
|---|
| 174 | if (elem_lhs<elem_rhs) return -1; |
|---|
| 175 | if (elem_rhs<elem_lhs) return 1; |
|---|
| 176 | return 0; |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | /** Frees unused space on this vector - i.e. the difference between size() and max_size() of the underlying vector.*/ |
|---|
| 180 | virtual void trim() |
|---|
| 181 | { |
|---|
| 182 | MixinVector<T>( *this ).swap( *this ); |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; } |
|---|
| 186 | virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(T)); } |
|---|
| 187 | virtual unsigned int getNumElements() const { return static_cast<unsigned int>(this->size()); } |
|---|
| 188 | |
|---|
| 189 | typedef T ElementDataType; // expose T |
|---|
| 190 | |
|---|
| 191 | protected: |
|---|
| 192 | |
|---|
| 193 | virtual ~TemplateArray() {} |
|---|
| 194 | }; |
|---|
| 195 | |
|---|
| 196 | class OSG_EXPORT IndexArray : public Array |
|---|
| 197 | { |
|---|
| 198 | |
|---|
| 199 | public: |
|---|
| 200 | |
|---|
| 201 | IndexArray(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0): |
|---|
| 202 | Array(arrayType,dataSize,dataType) {} |
|---|
| 203 | |
|---|
| 204 | IndexArray(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): |
|---|
| 205 | Array(array,copyop) {} |
|---|
| 206 | |
|---|
| 207 | virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const IndexArray*>(obj)!=NULL; } |
|---|
| 208 | |
|---|
| 209 | virtual unsigned int index(unsigned int pos) const = 0; |
|---|
| 210 | |
|---|
| 211 | protected: |
|---|
| 212 | |
|---|
| 213 | virtual ~IndexArray() {} |
|---|
| 214 | }; |
|---|
| 215 | |
|---|
| 216 | template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType> |
|---|
| 217 | class TemplateIndexArray : public IndexArray, public MixinVector<T> |
|---|
| 218 | { |
|---|
| 219 | public: |
|---|
| 220 | |
|---|
| 221 | TemplateIndexArray() : IndexArray(ARRAYTYPE,DataSize,DataType) {} |
|---|
| 222 | |
|---|
| 223 | TemplateIndexArray(const TemplateIndexArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY): |
|---|
| 224 | IndexArray(ta,copyop), |
|---|
| 225 | MixinVector<T>(ta) {} |
|---|
| 226 | |
|---|
| 227 | TemplateIndexArray(unsigned int no) : |
|---|
| 228 | IndexArray(ARRAYTYPE,DataSize,DataType), |
|---|
| 229 | MixinVector<T>(no) {} |
|---|
| 230 | |
|---|
| 231 | TemplateIndexArray(unsigned int no,T* ptr) : |
|---|
| 232 | IndexArray(ARRAYTYPE,DataSize,DataType), |
|---|
| 233 | MixinVector<T>(ptr,ptr+no) {} |
|---|
| 234 | |
|---|
| 235 | template <class InputIterator> |
|---|
| 236 | TemplateIndexArray(InputIterator first,InputIterator last) : |
|---|
| 237 | IndexArray(ARRAYTYPE,DataSize,DataType), |
|---|
| 238 | MixinVector<T>(first,last) {} |
|---|
| 239 | |
|---|
| 240 | TemplateIndexArray& operator = (const TemplateIndexArray& array) |
|---|
| 241 | { |
|---|
| 242 | if (this==&array) return *this; |
|---|
| 243 | assign(array.begin(),array.end()); |
|---|
| 244 | return *this; |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | virtual Object* cloneType() const { return new TemplateIndexArray(); } |
|---|
| 248 | virtual Object* clone(const CopyOp& copyop) const { return new TemplateIndexArray(*this,copyop); } |
|---|
| 249 | |
|---|
| 250 | inline virtual void accept(ArrayVisitor& av); |
|---|
| 251 | inline virtual void accept(ConstArrayVisitor& av) const; |
|---|
| 252 | |
|---|
| 253 | inline virtual void accept(unsigned int index,ValueVisitor& vv); |
|---|
| 254 | inline virtual void accept(unsigned int index,ConstValueVisitor& vv) const; |
|---|
| 255 | |
|---|
| 256 | virtual int compare(unsigned int lhs,unsigned int rhs) const |
|---|
| 257 | { |
|---|
| 258 | const T& elem_lhs = (*this)[lhs]; |
|---|
| 259 | const T& elem_rhs = (*this)[rhs]; |
|---|
| 260 | if (elem_lhs<elem_rhs) return -1; |
|---|
| 261 | if (elem_rhs<elem_lhs) return 1; |
|---|
| 262 | return 0; |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | /** Frees unused space on this vector - i.e. the difference between size() and max_size() of the underlying vector.*/ |
|---|
| 266 | virtual void trim() |
|---|
| 267 | { |
|---|
| 268 | MixinVector<T>( *this ).swap( *this ); |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; } |
|---|
| 272 | virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(T)); } |
|---|
| 273 | virtual unsigned int getNumElements() const { return static_cast<unsigned int>(this->size()); } |
|---|
| 274 | |
|---|
| 275 | virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; } |
|---|
| 276 | |
|---|
| 277 | typedef T ElementDataType; // expose T |
|---|
| 278 | |
|---|
| 279 | protected: |
|---|
| 280 | |
|---|
| 281 | virtual ~TemplateIndexArray() {} |
|---|
| 282 | }; |
|---|
| 283 | |
|---|
| 284 | typedef TemplateIndexArray<GLbyte,Array::ByteArrayType,1,GL_BYTE> ByteArray; |
|---|
| 285 | typedef TemplateIndexArray<GLshort,Array::ShortArrayType,1,GL_SHORT> ShortArray; |
|---|
| 286 | typedef TemplateIndexArray<GLint,Array::IntArrayType,1,GL_INT> IntArray; |
|---|
| 287 | typedef TemplateIndexArray<GLubyte,Array::UByteArrayType,1,GL_UNSIGNED_BYTE> UByteArray; |
|---|
| 288 | typedef TemplateIndexArray<GLushort,Array::UShortArrayType,1,GL_UNSIGNED_SHORT> UShortArray; |
|---|
| 289 | typedef TemplateIndexArray<GLuint,Array::UIntArrayType,1,GL_UNSIGNED_INT> UIntArray; |
|---|
| 290 | |
|---|
| 291 | typedef TemplateArray<GLfloat,Array::FloatArrayType,1,GL_FLOAT> FloatArray; |
|---|
| 292 | |
|---|
| 293 | typedef TemplateArray<Vec2,Array::Vec2ArrayType,2,GL_FLOAT> Vec2Array; |
|---|
| 294 | typedef TemplateArray<Vec3,Array::Vec3ArrayType,3,GL_FLOAT> Vec3Array; |
|---|
| 295 | typedef TemplateArray<Vec4,Array::Vec4ArrayType,4,GL_FLOAT> Vec4Array; |
|---|
| 296 | |
|---|
| 297 | typedef TemplateArray<Vec4ub,Array::Vec4ubArrayType,4,GL_UNSIGNED_BYTE> Vec4ubArray; |
|---|
| 298 | |
|---|
| 299 | typedef TemplateArray<Vec2s,Array::Vec2sArrayType,2,GL_SHORT> Vec2sArray; |
|---|
| 300 | typedef TemplateArray<Vec3s,Array::Vec3sArrayType,3,GL_SHORT> Vec3sArray; |
|---|
| 301 | typedef TemplateArray<Vec4s,Array::Vec4sArrayType,4,GL_SHORT> Vec4sArray; |
|---|
| 302 | |
|---|
| 303 | typedef TemplateArray<Vec2b,Array::Vec2bArrayType,2,GL_BYTE> Vec2bArray; |
|---|
| 304 | typedef TemplateArray<Vec3b,Array::Vec3bArrayType,3,GL_BYTE> Vec3bArray; |
|---|
| 305 | typedef TemplateArray<Vec4b,Array::Vec4bArrayType,4,GL_BYTE> Vec4bArray; |
|---|
| 306 | |
|---|
| 307 | typedef TemplateArray<GLdouble,Array::DoubleArrayType,1,GL_DOUBLE> DoubleArray; |
|---|
| 308 | typedef TemplateArray<Vec2d,Array::Vec2dArrayType,2,GL_DOUBLE> Vec2dArray; |
|---|
| 309 | typedef TemplateArray<Vec3d,Array::Vec3dArrayType,3,GL_DOUBLE> Vec3dArray; |
|---|
| 310 | typedef TemplateArray<Vec4d,Array::Vec4dArrayType,4,GL_DOUBLE> Vec4dArray; |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | class ArrayVisitor |
|---|
| 314 | { |
|---|
| 315 | public: |
|---|
| 316 | ArrayVisitor() {} |
|---|
| 317 | virtual ~ArrayVisitor() {} |
|---|
| 318 | |
|---|
| 319 | virtual void apply(Array&) {} |
|---|
| 320 | virtual void apply(ByteArray&) {} |
|---|
| 321 | virtual void apply(ShortArray&) {} |
|---|
| 322 | virtual void apply(IntArray&) {} |
|---|
| 323 | virtual void apply(UByteArray&) {} |
|---|
| 324 | virtual void apply(UShortArray&) {} |
|---|
| 325 | virtual void apply(UIntArray&) {} |
|---|
| 326 | virtual void apply(FloatArray&) {} |
|---|
| 327 | virtual void apply(DoubleArray&) {} |
|---|
| 328 | |
|---|
| 329 | virtual void apply(Vec2Array&) {} |
|---|
| 330 | virtual void apply(Vec3Array&) {} |
|---|
| 331 | virtual void apply(Vec4Array&) {} |
|---|
| 332 | |
|---|
| 333 | virtual void apply(Vec4ubArray&) {} |
|---|
| 334 | |
|---|
| 335 | virtual void apply(Vec2bArray&) {} |
|---|
| 336 | virtual void apply(Vec3bArray&) {} |
|---|
| 337 | virtual void apply(Vec4bArray&) {} |
|---|
| 338 | |
|---|
| 339 | virtual void apply(Vec2sArray&) {} |
|---|
| 340 | virtual void apply(Vec3sArray&) {} |
|---|
| 341 | virtual void apply(Vec4sArray&) {} |
|---|
| 342 | |
|---|
| 343 | virtual void apply(Vec2dArray&) {} |
|---|
| 344 | virtual void apply(Vec3dArray&) {} |
|---|
| 345 | virtual void apply(Vec4dArray&) {} |
|---|
| 346 | }; |
|---|
| 347 | |
|---|
| 348 | class ConstArrayVisitor |
|---|
| 349 | { |
|---|
| 350 | public: |
|---|
| 351 | ConstArrayVisitor() {} |
|---|
| 352 | virtual ~ConstArrayVisitor() {} |
|---|
| 353 | |
|---|
| 354 | virtual void apply(const Array&) {} |
|---|
| 355 | virtual void apply(const ByteArray&) {} |
|---|
| 356 | virtual void apply(const ShortArray&) {} |
|---|
| 357 | virtual void apply(const IntArray&) {} |
|---|
| 358 | virtual void apply(const UByteArray&) {} |
|---|
| 359 | virtual void apply(const UShortArray&) {} |
|---|
| 360 | virtual void apply(const UIntArray&) {} |
|---|
| 361 | virtual void apply(const FloatArray&) {} |
|---|
| 362 | virtual void apply(const DoubleArray&) {} |
|---|
| 363 | |
|---|
| 364 | virtual void apply(const Vec2Array&) {} |
|---|
| 365 | virtual void apply(const Vec3Array&) {} |
|---|
| 366 | virtual void apply(const Vec4Array&) {} |
|---|
| 367 | |
|---|
| 368 | virtual void apply(const Vec4ubArray&) {} |
|---|
| 369 | |
|---|
| 370 | virtual void apply(const Vec2bArray&) {} |
|---|
| 371 | virtual void apply(const Vec3bArray&) {} |
|---|
| 372 | virtual void apply(const Vec4bArray&) {} |
|---|
| 373 | |
|---|
| 374 | virtual void apply(const Vec2sArray&) {} |
|---|
| 375 | virtual void apply(const Vec3sArray&) {} |
|---|
| 376 | virtual void apply(const Vec4sArray&) {} |
|---|
| 377 | |
|---|
| 378 | virtual void apply(const Vec2dArray&) {} |
|---|
| 379 | virtual void apply(const Vec3dArray&) {} |
|---|
| 380 | virtual void apply(const Vec4dArray&) {} |
|---|
| 381 | }; |
|---|
| 382 | |
|---|
| 383 | |
|---|
| 384 | class ValueVisitor |
|---|
| 385 | { |
|---|
| 386 | public: |
|---|
| 387 | ValueVisitor() {} |
|---|
| 388 | virtual ~ValueVisitor() {} |
|---|
| 389 | |
|---|
| 390 | virtual void apply(GLbyte&) {} |
|---|
| 391 | virtual void apply(GLshort&) {} |
|---|
| 392 | virtual void apply(GLint&) {} |
|---|
| 393 | virtual void apply(GLushort&) {} |
|---|
| 394 | virtual void apply(GLubyte&) {} |
|---|
| 395 | virtual void apply(GLuint&) {} |
|---|
| 396 | virtual void apply(GLfloat&) {} |
|---|
| 397 | virtual void apply(GLdouble&) {} |
|---|
| 398 | |
|---|
| 399 | |
|---|
| 400 | virtual void apply(Vec2&) {} |
|---|
| 401 | virtual void apply(Vec3&) {} |
|---|
| 402 | virtual void apply(Vec4&) {} |
|---|
| 403 | |
|---|
| 404 | virtual void apply(Vec4ub&) {} |
|---|
| 405 | |
|---|
| 406 | virtual void apply(Vec2b&) {} |
|---|
| 407 | virtual void apply(Vec3b&) {} |
|---|
| 408 | virtual void apply(Vec4b&) {} |
|---|
| 409 | |
|---|
| 410 | virtual void apply(Vec2s&) {} |
|---|
| 411 | virtual void apply(Vec3s&) {} |
|---|
| 412 | virtual void apply(Vec4s&) {} |
|---|
| 413 | |
|---|
| 414 | virtual void apply(Vec2d&) {} |
|---|
| 415 | virtual void apply(Vec3d&) {} |
|---|
| 416 | virtual void apply(Vec4d&) {} |
|---|
| 417 | }; |
|---|
| 418 | |
|---|
| 419 | class ConstValueVisitor |
|---|
| 420 | { |
|---|
| 421 | public: |
|---|
| 422 | ConstValueVisitor() {} |
|---|
| 423 | virtual ~ConstValueVisitor() {} |
|---|
| 424 | |
|---|
| 425 | virtual void apply(const GLbyte&) {} |
|---|
| 426 | virtual void apply(const GLshort&) {} |
|---|
| 427 | virtual void apply(const GLint&) {} |
|---|
| 428 | virtual void apply(const GLushort&) {} |
|---|
| 429 | virtual void apply(const GLubyte&) {} |
|---|
| 430 | virtual void apply(const GLuint&) {} |
|---|
| 431 | virtual void apply(const GLfloat&) {} |
|---|
| 432 | virtual void apply(const GLdouble&) {} |
|---|
| 433 | |
|---|
| 434 | virtual void apply(const Vec4ub&) {} |
|---|
| 435 | |
|---|
| 436 | virtual void apply(const Vec2&) {} |
|---|
| 437 | virtual void apply(const Vec3&) {} |
|---|
| 438 | virtual void apply(const Vec4&) {} |
|---|
| 439 | |
|---|
| 440 | virtual void apply(const Vec2b&) {} |
|---|
| 441 | virtual void apply(const Vec3b&) {} |
|---|
| 442 | virtual void apply(const Vec4b&) {} |
|---|
| 443 | |
|---|
| 444 | virtual void apply(const Vec2s&) {} |
|---|
| 445 | virtual void apply(const Vec3s&) {} |
|---|
| 446 | virtual void apply(const Vec4s&) {} |
|---|
| 447 | |
|---|
| 448 | virtual void apply(const Vec2d&) {} |
|---|
| 449 | virtual void apply(const Vec3d&) {} |
|---|
| 450 | virtual void apply(const Vec4d&) {} |
|---|
| 451 | }; |
|---|
| 452 | |
|---|
| 453 | template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType> |
|---|
| 454 | inline void TemplateArray<T,ARRAYTYPE,DataSize,DataType>::accept(ArrayVisitor& av) { av.apply(*this); } |
|---|
| 455 | |
|---|
| 456 | template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType> |
|---|
| 457 | inline void TemplateArray<T,ARRAYTYPE,DataSize,DataType>::accept(ConstArrayVisitor& av) const { av.apply(*this); } |
|---|
| 458 | |
|---|
| 459 | template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType> |
|---|
| 460 | inline void TemplateArray<T,ARRAYTYPE,DataSize,DataType>::accept(unsigned int index,ValueVisitor& vv) { vv.apply( (*this)[index] ); } |
|---|
| 461 | |
|---|
| 462 | template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType> |
|---|
| 463 | inline void TemplateArray<T,ARRAYTYPE,DataSize,DataType>::accept(unsigned int index,ConstValueVisitor& vv) const { vv.apply( (*this)[index] );} |
|---|
| 464 | |
|---|
| 465 | template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType> |
|---|
| 466 | inline void TemplateIndexArray<T,ARRAYTYPE,DataSize,DataType>::accept(ArrayVisitor& av) { av.apply(*this); } |
|---|
| 467 | |
|---|
| 468 | template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType> |
|---|
| 469 | inline void TemplateIndexArray<T,ARRAYTYPE,DataSize,DataType>::accept(ConstArrayVisitor& av) const { av.apply(*this); } |
|---|
| 470 | |
|---|
| 471 | template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType> |
|---|
| 472 | inline void TemplateIndexArray<T,ARRAYTYPE,DataSize,DataType>::accept(unsigned int index,ValueVisitor& vv) { vv.apply( (*this)[index] ); } |
|---|
| 473 | |
|---|
| 474 | template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType> |
|---|
| 475 | inline void TemplateIndexArray<T,ARRAYTYPE,DataSize,DataType>::accept(unsigned int index,ConstValueVisitor& vv) const { vv.apply( (*this)[index] );} |
|---|
| 476 | |
|---|
| 477 | } |
|---|
| 478 | |
|---|
| 479 | #endif |
|---|