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