~ubuntu-branches/debian/experimental/openscenegraph/experimental

« back to all changes in this revision

Viewing changes to OpenSceneGraph/include/osg/Array

  • Committer: Bazaar Package Importer
  • Author(s): Alberto Luaces
  • Date: 2011-01-29 11:36:29 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110129113629-qisrm2kdqlurc7t3
Tags: 2.9.11-1
* Removed bug-555869-ftbfs_with_binutils_gold.dpatch since upstream has
  already taken care of the issue.
* Removed bug-528229.dpatch since the pkgconfig files are now also split
  in upstream.
* Removed explicit dependency on GLU.
* Upstream no longer includes osgIntrospection (Closes: #592420).
* Disabled zip plugin as its implementation stores an embedded copy of
  zlib.
* Enabled Qt support. Thanks James Goppert.
* Enabled SVG and PDF plugins. Thanks James Goppert.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <osg/Vec2b>
30
30
#include <osg/Vec3b>
31
31
#include <osg/Vec4b>
 
32
#include <osg/Matrix>
32
33
 
33
34
#include <osg/BufferObject>
34
35
 
43
44
class ValueVisitor;
44
45
class ConstValueVisitor;
45
46
 
46
 
class OSG_EXPORT Array : public Object
 
47
class OSG_EXPORT Array : public BufferData
47
48
{
48
49
 
49
50
    public:
71
72
            DoubleArrayType   = 18,
72
73
            Vec2dArrayType    = 19,
73
74
            Vec3dArrayType    = 20,
74
 
            Vec4dArrayType    = 21            
 
75
            Vec4dArrayType    = 21,
 
76
            MatrixArrayType   = 22            
75
77
        };
76
78
 
77
79
        Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0):
78
80
            _arrayType(arrayType),
79
81
            _dataSize(dataSize),
80
 
            _dataType(dataType),
81
 
            _modifiedCount(0),
82
 
            _vboOffset(0) {}
83
 
    
 
82
            _dataType(dataType) {}
 
83
 
84
84
        Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
85
 
            Object(array,copyop),
 
85
            BufferData(array,copyop),
86
86
            _arrayType(array._arrayType),
87
87
            _dataSize(array._dataSize),
88
 
            _dataType(array._dataType),
89
 
            _modifiedCount(0),
90
 
            _vboOffset(0) {}
 
88
            _dataType(array._dataType) {}
91
89
 
92
90
        virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Array*>(obj)!=NULL; }
93
91
        virtual const char* libraryName() const { return "osg"; }
94
92
        virtual const char* className() const;
95
 
        
 
93
 
96
94
        virtual void accept(ArrayVisitor&) = 0;
97
95
        virtual void accept(ConstArrayVisitor&) const = 0;
98
96
 
113
111
        /** Frees unused space on this vector - i.e. the difference between size() and max_size() of the underlying vector.*/
114
112
        virtual void trim() {}
115
113
 
116
 
        /** Dirty the primitive, which increments the modified count, to force buffer objects to update. */
117
 
        inline void dirty() { ++_modifiedCount; if (_vbo.valid()) _vbo->dirty(); }
118
 
      
119
 
        /** Set the modified count value.*/
120
 
        inline void setModifiedCount(unsigned int value) { _modifiedCount=value; }
121
 
 
122
 
        /** Get modified count value.*/
123
 
        inline unsigned int getModifiedCount() const { return _modifiedCount; }
124
 
 
125
114
        /** Set the VertexBufferObject.*/
126
 
        inline void setVertexBufferObject(osg::VertexBufferObject* vbo)
127
 
        {
128
 
            if (_vbo == vbo) return;
129
 
            
130
 
            if (_vbo.valid())
131
 
            {
132
 
                _vbo->removeArray(this);
133
 
            }
134
 
            
135
 
            _vbo = vbo;
136
 
            
137
 
            if (_vbo.valid())
138
 
            {
139
 
                _vbo->addArray(this);
140
 
            }
141
 
        }
142
 
        
 
115
        inline void setVertexBufferObject(osg::VertexBufferObject* vbo) { setBufferObject(vbo); }
 
116
 
143
117
        /** Get the VertexBufferObject. If no VBO is assigned returns NULL*/
144
 
        inline osg::VertexBufferObject* getVertexBufferObject() { return _vbo.get(); }
 
118
        inline osg::VertexBufferObject* getVertexBufferObject() { return dynamic_cast<osg::VertexBufferObject*>(_bufferObject.get()); }
145
119
 
146
120
        /** Get the const VertexBufferObject. If no VBO is assigned returns NULL*/
147
 
        inline const osg::VertexBufferObject* getVertexBufferObject() const { return _vbo.get(); }
148
 
 
149
 
        /** Set the offset into the VertexBufferObject, if used.*/
150
 
        void setVertexBufferObjectOffset(const GLvoid* offset ) const { _vboOffset = offset; }
151
 
 
152
 
        /** Get the offset into the VertexBufferObject, if used.*/
153
 
        const GLvoid* getVertexBufferObjectOffset() const { return _vboOffset; }
 
121
        inline const osg::VertexBufferObject* getVertexBufferObject() const { return dynamic_cast<const osg::VertexBufferObject*>(_bufferObject.get());  }
154
122
 
155
123
    protected:
156
 
    
157
 
        virtual ~Array()
158
 
        {
159
 
            if (_vbo.valid())
160
 
            {
161
 
                _vbo->removeArray(this);
162
 
            }
163
 
        }
 
124
 
 
125
        virtual ~Array() {}
164
126
 
165
127
        Type                                    _arrayType;
166
128
        GLint                                   _dataSize;
167
129
        GLenum                                  _dataType;
168
 
        unsigned int                            _modifiedCount;
169
 
        osg::ref_ptr<osg::VertexBufferObject>   _vbo;
170
 
        mutable const GLvoid*                   _vboOffset;
171
130
};
172
131
 
173
132
template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
174
133
class TemplateArray : public Array, public MixinVector<T>
175
134
{
176
135
    public:
177
 
    
 
136
 
178
137
        TemplateArray() : Array(ARRAYTYPE,DataSize,DataType) {}
179
138
 
180
139
        TemplateArray(const TemplateArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
181
140
            Array(ta,copyop),
182
141
            MixinVector<T>(ta) {}
183
 
        
 
142
 
184
143
        TemplateArray(unsigned int no) : 
185
144
            Array(ARRAYTYPE,DataSize,DataType),
186
145
            MixinVector<T>(no) {}
187
146
 
188
 
        TemplateArray(unsigned int no,T* ptr) : 
 
147
        TemplateArray(unsigned int no,const T* ptr) : 
189
148
            Array(ARRAYTYPE,DataSize,DataType),
190
149
            MixinVector<T>(ptr,ptr+no) {}
191
150
 
224
183
        {
225
184
            MixinVector<T>( *this ).swap( *this );
226
185
        }
227
 
        
 
186
 
228
187
        virtual const GLvoid*   getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; }
229
188
        virtual unsigned int    getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(T)); }
230
189
        virtual unsigned int    getNumElements() const { return static_cast<unsigned int>(this->size()); }
243
202
 
244
203
        IndexArray(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0):
245
204
            Array(arrayType,dataSize,dataType) {}
246
 
    
 
205
 
247
206
        IndexArray(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
248
207
            Array(array,copyop) {}
249
208
 
250
209
        virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const IndexArray*>(obj)!=NULL; }
251
 
        
 
210
 
252
211
        virtual unsigned int index(unsigned int pos) const = 0;
253
212
 
254
213
    protected:
255
 
    
 
214
 
256
215
        virtual ~IndexArray() {}
257
216
};
258
217
 
260
219
class TemplateIndexArray : public IndexArray, public MixinVector<T>
261
220
{
262
221
    public:
263
 
    
 
222
 
264
223
        TemplateIndexArray() : IndexArray(ARRAYTYPE,DataSize,DataType) {}
265
224
 
266
225
        TemplateIndexArray(const TemplateIndexArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
267
226
            IndexArray(ta,copyop),
268
227
            MixinVector<T>(ta) {}
269
 
        
 
228
 
270
229
        TemplateIndexArray(unsigned int no) : 
271
230
            IndexArray(ARRAYTYPE,DataSize,DataType),
272
231
            MixinVector<T>(no) {}
310
269
        {
311
270
            MixinVector<T>( *this ).swap( *this );
312
271
        }
313
 
        
 
272
 
314
273
        virtual const GLvoid*   getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; }
315
274
        virtual unsigned int    getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(T)); }
316
275
        virtual unsigned int    getNumElements() const { return static_cast<unsigned int>(this->size()); }
320
279
        typedef T ElementDataType; // expose T
321
280
 
322
281
    protected:
323
 
    
 
282
 
324
283
        virtual ~TemplateIndexArray() {}
325
284
};
326
285
 
352
311
typedef TemplateArray<Vec3d,Array::Vec3dArrayType,3,GL_DOUBLE>                   Vec3dArray;
353
312
typedef TemplateArray<Vec4d,Array::Vec4dArrayType,4,GL_DOUBLE>                   Vec4dArray;
354
313
 
 
314
typedef TemplateArray<Matrixf,Array::MatrixArrayType,16,GL_FLOAT>                MatrixfArray;
 
315
 
355
316
 
356
317
class ArrayVisitor
357
318
{
386
347
        virtual void apply(Vec2dArray&) {}
387
348
        virtual void apply(Vec3dArray&) {}
388
349
        virtual void apply(Vec4dArray&) {}
 
350
        
 
351
        virtual void apply(MatrixfArray&) {}
389
352
};
390
353
 
391
354
class ConstArrayVisitor
421
384
        virtual void apply(const Vec2dArray&) {}
422
385
        virtual void apply(const Vec3dArray&) {}
423
386
        virtual void apply(const Vec4dArray&) {}
 
387
        
 
388
        virtual void apply(const MatrixfArray&) {}
424
389
};
425
390
 
426
391
 
457
422
        virtual void apply(Vec2d&) {}
458
423
        virtual void apply(Vec3d&) {}
459
424
        virtual void apply(Vec4d&) {}
 
425
        
 
426
        virtual void apply(Matrixf&) {}
460
427
};
461
428
 
462
429
class ConstValueVisitor
491
458
        virtual void apply(const Vec2d&) {}
492
459
        virtual void apply(const Vec3d&) {}
493
460
        virtual void apply(const Vec4d&) {}
 
461
        
 
462
        virtual void apply(const Matrixf&) {}
494
463
};
495
464
 
496
465
template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>