root/OpenSceneGraph/trunk/include/osg/PrimitiveSet @ 9969

Revision 9969, 26.3 kB (checked in by robert, 4 years ago)

Added new virtual reseveElements, setElement, getElment and addElement methods to DrawElements?
to make is easier to write code that can work on DrawElementUByte, UShort or UInt.

Changed the osgTerrain::GeometryTechnique? so that it automatically chooses
the use of DrawElementUShort or DrawElementsUInt accordining to the size of the tile.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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_PRIMITIVESET
15#define OSG_PRIMITIVESET 1
16
17#include <osg/GL>
18#include <osg/Object>
19#include <osg/buffered_value>
20#include <osg/Vec2>
21#include <osg/Vec3>
22#include <osg/Vec4>
23#include <osg/Vec2d>
24#include <osg/Vec3d>
25#include <osg/Vec4d>
26#include <osg/MixinVector>
27
28#include <osg/BufferObject>
29
30#include <vector>
31
32namespace osg {
33
34typedef MixinVector<GLsizei> VectorGLsizei;
35typedef MixinVector<GLubyte> VectorGLubyte;
36typedef MixinVector<GLushort> VectorGLushort;
37typedef MixinVector<GLuint> VectorGLuint;
38
39class State;
40
41/** A \c PrimitiveFunctor is used (in conjunction with
42 *  <tt>osg::Drawable::accept (PrimitiveFunctor&)</tt>) to get access to the
43 *  primitives that compose the things drawn by OSG.
44 *  <p>If \c osg::Drawable::accept() is called with a \c PrimitiveFunctor
45 *  parameter, the \c Drawable will "pretend" it is drawing itself, but instead
46 *  of calling real OpenGL functions, it will call <tt>PrimitiveFunctor</tt>'s
47 *  member functions that "mimic" the OpenGL calls.
48 *  <p>Concrete subclasses of \c PrimitiveFunctor must implement these methods
49 *  so that they performs whatever they want.
50 */
51class PrimitiveFunctor
52{
53public:
54
55    virtual ~PrimitiveFunctor() {}
56
57    /** Sets the array of vertices used to describe the primitives. Somehow
58     *  mimics the OpenGL \c glVertexPointer() function.
59     */
60    virtual void setVertexArray(unsigned int count,const Vec2* vertices) = 0;
61
62    /** Sets the array of vertices used to describe the primitives. Somehow
63     *  mimics the OpenGL \c glVertexPointer() function.
64     */
65    virtual void setVertexArray(unsigned int count,const Vec3* vertices) = 0;
66
67    /** Sets the array of vertices used to describe the primitives. Somehow
68     *  mimics the OpenGL \c glVertexPointer() function.
69     */
70    virtual void setVertexArray(unsigned int count,const Vec4* vertices) = 0;
71
72    /** Sets the array of vertices used to describe the primitives. Somehow
73     *  mimics the OpenGL \c glVertexPointer() function.
74     */
75    virtual void setVertexArray(unsigned int count,const Vec2d* vertices) = 0;
76
77    /** Sets the array of vertices used to describe the primitives. Somehow
78     *  mimics the OpenGL \c glVertexPointer() function.
79     */
80    virtual void setVertexArray(unsigned int count,const Vec3d* vertices) = 0;
81
82    /** Sets the array of vertices used to describe the primitives. Somehow
83     *  mimics the OpenGL \c glVertexPointer() function.
84     */
85    virtual void setVertexArray(unsigned int count,const Vec4d* vertices) = 0;
86
87    /// Mimics the OpenGL \c glDrawArrays() function.
88    virtual void drawArrays(GLenum mode,GLint first,GLsizei count) = 0;
89
90    /// Mimics the OpenGL \c glDrawElements() function.
91    virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices) = 0;
92
93    /// Mimics the OpenGL \c glDrawElements() function.
94    virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices) = 0;
95
96    /// Mimics the OpenGL \c glDrawElements() function.
97    virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices) = 0;
98
99    /// Mimics the OpenGL \c glBegin() function.
100    virtual void begin(GLenum mode) = 0;
101
102    /// Mimics the OpenGL \c glVertex() "family of functions".
103    virtual void vertex(const Vec2& vert) = 0;
104
105    /// Mimics the OpenGL \c glVertex() "family of functions".
106    virtual void vertex(const Vec3& vert) = 0;
107
108    /// Mimics the OpenGL \c glVertex() "family of functions".
109    virtual void vertex(const Vec4& vert) = 0;
110
111    /// Mimics the OpenGL \c glVertex() "family of functions".
112    virtual void vertex(float x,float y) = 0;
113
114    /// Mimics the OpenGL \c glVertex() "family of functions".
115    virtual void vertex(float x,float y,float z) = 0;
116
117    /// Mimics the OpenGL \c glVertex() "family of functions".
118    virtual void vertex(float x,float y,float z,float w) = 0;
119
120    /// Mimics the OpenGL \c glEnd() function.
121    virtual void end() = 0;
122};
123
124class PrimitiveIndexFunctor
125{
126public:
127
128    virtual ~PrimitiveIndexFunctor() {}
129
130    virtual void setVertexArray(unsigned int count,const Vec2* vertices) = 0;
131    virtual void setVertexArray(unsigned int count,const Vec3* vertices) = 0;
132    virtual void setVertexArray(unsigned int count,const Vec4* vertices) = 0;
133
134    virtual void setVertexArray(unsigned int count,const Vec2d* vertices) = 0;
135    virtual void setVertexArray(unsigned int count,const Vec3d* vertices) = 0;
136    virtual void setVertexArray(unsigned int count,const Vec4d* vertices) = 0;
137
138    virtual void drawArrays(GLenum mode,GLint first,GLsizei count) = 0;
139    virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices) = 0;
140    virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices) = 0;
141    virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices) = 0;
142
143    virtual void begin(GLenum mode) = 0;
144    virtual void vertex(unsigned int pos) = 0;
145    virtual void end() = 0;
146};
147
148class DrawElements;
149
150class OSG_EXPORT PrimitiveSet : public Object
151{
152    public:
153   
154        enum Type
155        {
156            PrimitiveType,
157            DrawArraysPrimitiveType,
158            DrawArrayLengthsPrimitiveType,
159            DrawElementsUBytePrimitiveType,
160            DrawElementsUShortPrimitiveType,
161            DrawElementsUIntPrimitiveType
162        };
163
164        enum Mode
165        {
166            POINTS = GL_POINTS,
167            LINES = GL_LINES,
168            LINE_STRIP = GL_LINE_STRIP,
169            LINE_LOOP = GL_LINE_LOOP,
170            TRIANGLES = GL_TRIANGLES,
171            TRIANGLE_STRIP = GL_TRIANGLE_STRIP,
172            TRIANGLE_FAN = GL_TRIANGLE_FAN,
173            QUADS = GL_QUADS,
174            QUAD_STRIP = GL_QUAD_STRIP,
175            POLYGON = GL_POLYGON
176        };
177
178        PrimitiveSet(Type primType=PrimitiveType,GLenum mode=0, int numInstances=0):
179            _primitiveType(primType),
180            _numInstances(numInstances),
181            _mode(mode),
182            _modifiedCount(0),
183            _rangeModifiedCount(0) {}
184   
185        PrimitiveSet(const PrimitiveSet& prim,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
186            Object(prim,copyop),
187            _primitiveType(prim._primitiveType),
188            _numInstances(prim._numInstances),
189            _mode(prim._mode),
190            _modifiedCount(0),
191            _rangeModifiedCount(0) {}
192
193        virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const PrimitiveSet*>(obj)!=NULL; }
194        virtual const char* libraryName() const { return "osg"; }
195        virtual const char* className() const { return "PrimitiveSet"; }
196       
197        Type                    getType() const { return _primitiveType; }
198        virtual const GLvoid*   getDataPointer() const { return 0; }
199        virtual unsigned int    getTotalDataSize() const { return 0; }
200        virtual bool            supportsBufferObject() const { return false; }
201
202        virtual DrawElements* getDrawElements() { return 0; }
203        virtual const DrawElements* getDrawElements() const { return 0; }
204           
205        void setNumInstances(int n) { _numInstances = n; }
206        int getNumInstances() const { return _numInstances; }
207
208        void setMode(GLenum mode) { _mode = mode; }
209        GLenum getMode() const { return _mode; }
210
211        virtual void draw(State& state, bool useVertexBufferObjects) const = 0;
212       
213        virtual void accept(PrimitiveFunctor& functor) const = 0;
214        virtual void accept(PrimitiveIndexFunctor& functor) const = 0;
215       
216        virtual unsigned int index(unsigned int pos) const = 0;
217        virtual unsigned int getNumIndices() const = 0;
218        virtual void offsetIndices(int offset) = 0;
219
220        virtual unsigned int getNumPrimitives() const;
221
222        /** Dirty the primitive, which increments the modified count, to force buffer objects to update. */
223        virtual void dirty() { ++_modifiedCount; }     
224     
225        /** Set the modified count value.*/
226        inline void setModifiedCount(unsigned int value) { _modifiedCount=value; }
227
228        /** Get modified count value.*/
229        inline unsigned int getModifiedCount() const { return _modifiedCount; }
230
231        /** Resize any per context GLObject buffers to specified size. */
232        virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/) {}
233
234        /** If State is non-zero, this function releases OpenGL objects for
235          * the specified graphics context. Otherwise, releases OpenGL objects
236          * for all graphics contexts. */
237        virtual void releaseGLObjects(State* /*state*/=0) const {}
238
239        virtual void computeRange() const {}
240
241    protected:
242
243        virtual ~PrimitiveSet() {}
244
245        Type            _primitiveType;
246        int             _numInstances;
247        GLenum          _mode;
248        unsigned int    _modifiedCount;
249        mutable unsigned int    _rangeModifiedCount;
250
251        struct ObjectIDModifiedCountPair
252        {
253            ObjectIDModifiedCountPair():
254                _objectID(0),
255                _modifiedCount(0) {}
256               
257            ObjectIDModifiedCountPair(const ObjectIDModifiedCountPair& obj):
258                _objectID(obj._objectID),
259                _modifiedCount(obj._modifiedCount) {}
260               
261            ObjectIDModifiedCountPair& operator = (const ObjectIDModifiedCountPair& obj)
262            {
263                _objectID = obj._objectID;
264                _modifiedCount = obj._modifiedCount;
265                return *this;
266            }
267
268            GLuint _objectID;
269            unsigned int _modifiedCount;
270        };
271       
272        typedef osg::buffered_object<ObjectIDModifiedCountPair> GLObjectList;
273};
274
275class OSG_EXPORT DrawArrays : public PrimitiveSet
276{
277    public:
278
279        DrawArrays(GLenum mode=0):
280            PrimitiveSet(DrawArraysPrimitiveType,mode),
281            _first(0),
282            _count(0) {}
283   
284        DrawArrays(GLenum mode, GLint first, GLsizei count, int numInstances=0):
285            PrimitiveSet(DrawArraysPrimitiveType, mode, numInstances),
286            _first(first),
287            _count(count) {}
288
289        DrawArrays(const DrawArrays& da,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
290            PrimitiveSet(da,copyop),
291            _first(da._first),
292            _count(da._count) {}
293
294        virtual Object* cloneType() const { return new DrawArrays(); }
295        virtual Object* clone(const CopyOp& copyop) const { return new DrawArrays(*this,copyop); }       
296        virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawArrays*>(obj)!=NULL; }
297        virtual const char* libraryName() const { return "osg"; }
298        virtual const char* className() const { return "DrawArrays"; }
299       
300
301        void set(GLenum mode,GLint first, GLsizei count)
302        {
303            _mode = mode;
304            _first = first;
305            _count = count;
306        }
307
308        void setFirst(GLint first) { _first = first; }
309        GLint getFirst() const { return _first; }
310       
311        void setCount(GLsizei count) { _count = count; }
312        GLsizei getCount() const { return _count; }
313
314        virtual void draw(State& state, bool useVertexBufferObjects) const;
315       
316        virtual void accept(PrimitiveFunctor& functor) const;
317        virtual void accept(PrimitiveIndexFunctor& functor) const;
318       
319        virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(_count); }
320        virtual unsigned int index(unsigned int pos) const { return static_cast<unsigned int>(_first)+pos; }
321        virtual void offsetIndices(int offset) { _first += offset; }
322
323    protected:
324
325        virtual ~DrawArrays() {}
326
327        GLint   _first;
328        GLsizei _count;
329};
330
331class OSG_EXPORT DrawArrayLengths : public PrimitiveSet, public VectorGLsizei
332{
333    public:
334
335        typedef VectorGLsizei vector_type;
336
337        DrawArrayLengths(GLenum mode=0):
338            PrimitiveSet(DrawArrayLengthsPrimitiveType,mode),
339            _first(0) {}
340   
341        DrawArrayLengths(const DrawArrayLengths& dal,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
342            PrimitiveSet(dal,copyop),
343            vector_type(dal),
344            _first(dal._first) {}
345
346        DrawArrayLengths(GLenum mode, GLint first, unsigned int no, GLsizei* ptr) :
347            PrimitiveSet(DrawArrayLengthsPrimitiveType,mode),
348            vector_type(ptr,ptr+no),
349            _first(first) {}
350
351        DrawArrayLengths(GLenum mode,GLint first, unsigned int no) :
352            PrimitiveSet(DrawArrayLengthsPrimitiveType,mode),
353            vector_type(no),
354            _first(first) {}
355
356        DrawArrayLengths(GLenum mode,GLint first) :
357            PrimitiveSet(DrawArrayLengthsPrimitiveType,mode),
358            vector_type(),
359            _first(first) {}
360
361
362        virtual Object* cloneType() const { return new DrawArrayLengths(); }
363        virtual Object* clone(const CopyOp& copyop) const { return new DrawArrayLengths(*this,copyop); }       
364        virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawArrayLengths*>(obj)!=NULL; }
365        virtual const char* libraryName() const { return "osg"; }
366        virtual const char* className() const { return "DrawArrayLengths"; }
367       
368
369        void setFirst(GLint first) { _first = first; }
370        GLint getFirst() const { return _first; }
371       
372        virtual void draw(State& state, bool useVertexBufferObjects) const;
373       
374        virtual void accept(PrimitiveFunctor& functor) const;
375        virtual void accept(PrimitiveIndexFunctor& functor) const;
376       
377        virtual unsigned int getNumIndices() const;
378        virtual unsigned int index(unsigned int pos) const { return _first+pos; }
379        virtual void offsetIndices(int offset) { _first += offset; }
380
381        virtual unsigned int getNumPrimitives() const;
382
383    protected:
384
385        virtual ~DrawArrayLengths() {}
386
387        GLint   _first;
388};
389
390class DrawElements : public PrimitiveSet
391{
392    public:
393       
394        DrawElements(Type primType=PrimitiveType, GLenum mode=0, int numInstances=0):
395            PrimitiveSet(primType,mode, numInstances),
396            _eboOffset(0) {}
397   
398        DrawElements(const DrawElements& copy,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
399            PrimitiveSet(copy,copyop),
400            _eboOffset(0) {}
401
402
403        virtual DrawElements* getDrawElements() { return this; }
404        virtual const DrawElements* getDrawElements() const { return this; }
405
406        virtual void dirty() { ++_modifiedCount; if (_ebo.valid()) _ebo->dirty(); }
407
408        /** Set the ElementBufferObject.*/
409        inline void setElementBufferObject(osg::ElementBufferObject* ebo)
410        {
411            if (_ebo == ebo) return;
412           
413            if (_ebo.valid())
414            {
415                _ebo->removeDrawElements(this);
416            }
417           
418            _ebo = ebo;
419
420            if (_ebo.valid())
421            {
422                _ebo->addDrawElements(this);
423            }
424        }
425       
426        /** Get the ElementBufferObject. If no EBO is assigned returns NULL*/
427        inline osg::ElementBufferObject* getElementBufferObject() { return _ebo.get(); }
428
429        /** Get the const ElementBufferObject. If no EBO is assigned returns NULL*/
430        inline const osg::ElementBufferObject* getElementBufferObject() const { return _ebo.get(); }
431
432        /** Set the offset into the ElementBufferObject, if used.*/
433        inline void setElementBufferObjectOffset(const GLvoid* offset) const { _eboOffset = offset; }
434
435        /** Get the offset into the ElementBufferOffset, if used.*/
436        inline const GLvoid* getElementBufferObjectOffset() const { return _eboOffset; }
437
438
439        /** Resize any per context GLObject buffers to specified size. */
440        virtual void resizeGLObjectBuffers(unsigned int maxSize)
441        {
442            if (_ebo.valid()) _ebo->resizeGLObjectBuffers(maxSize);
443        }
444
445        /** If State is non-zero, this function releases OpenGL objects for
446          * the specified graphics context. Otherwise, releases OpenGL objects
447          * for all graphics contexts. */
448        virtual void releaseGLObjects(State* state=0) const
449        {
450            if (_ebo.valid()) _ebo->releaseGLObjects(state);
451        }
452       
453       
454        virtual void reserveElements(unsigned int numIndices) = 0;
455        virtual void setElement(unsigned int, unsigned int) = 0;
456        virtual unsigned int getElement(unsigned int) = 0;
457        virtual void addElement(unsigned int) = 0;
458
459    protected:
460   
461        virtual ~DrawElements()
462        {
463            if (_ebo.valid())
464            {
465                _ebo->removeDrawElements(this);
466            }
467        }
468
469        osg::ref_ptr<ElementBufferObject>   _ebo;
470        mutable const GLvoid*               _eboOffset;
471
472};
473
474class OSG_EXPORT DrawElementsUByte : public DrawElements, public VectorGLubyte
475{
476    public:
477   
478        typedef VectorGLubyte vector_type;
479
480        DrawElementsUByte(GLenum mode=0):
481            DrawElements(DrawElementsUBytePrimitiveType,mode) {}
482   
483        DrawElementsUByte(const DrawElementsUByte& array, const CopyOp& copyop=CopyOp::SHALLOW_COPY):
484            DrawElements(array,copyop),
485            vector_type(array) {}
486
487        DrawElementsUByte(GLenum mode, unsigned int no, const GLubyte* ptr, int numInstances=0) :
488            DrawElements(DrawElementsUBytePrimitiveType,mode,numInstances),
489            vector_type(ptr,ptr+no) {}
490
491        DrawElementsUByte(GLenum mode, unsigned int no) :
492            DrawElements(DrawElementsUBytePrimitiveType,mode),
493            vector_type(no) {}
494
495        virtual Object* cloneType() const { return new DrawElementsUByte(); }
496        virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUByte(*this,copyop); }       
497        virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsUByte*>(obj)!=NULL; }
498        virtual const char* libraryName() const { return "osg"; }
499        virtual const char* className() const { return "DrawElementsUByte"; }
500
501        virtual const GLvoid*   getDataPointer() const { return empty()?0:&front(); }
502        virtual unsigned int    getTotalDataSize() const { return static_cast<unsigned int>(size()); }
503        virtual bool            supportsBufferObject() const { return false; }
504
505        virtual void draw(State& state, bool useVertexBufferObjects) const ;
506       
507        virtual void accept(PrimitiveFunctor& functor) const;
508        virtual void accept(PrimitiveIndexFunctor& functor) const;
509
510        virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(size()); }
511        virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
512        virtual void offsetIndices(int offset);
513       
514        virtual void computeRange() const
515        {
516            if (empty())
517            {
518                _minIndex = 0;
519                _maxIndex = 0;
520                _rangeModifiedCount = _modifiedCount;
521                return;
522            }
523           
524            _minIndex = front();
525            _maxIndex = _minIndex;
526
527            for(vector_type::const_iterator itr=begin(); itr!=end();  ++itr)
528            {
529                if (*itr<_minIndex) _minIndex = *itr;
530                if (*itr>_maxIndex) _maxIndex = *itr;
531            }
532            _rangeModifiedCount = _modifiedCount;
533        }
534       
535        virtual void reserveElements(unsigned int numIndices) { reserve(numIndices); }
536        virtual void setElement(unsigned int i, unsigned int v)  { (*this)[i] = v; }
537        virtual unsigned int getElement(unsigned int i) { return (*this)[i]; }
538        virtual void addElement(unsigned int v) { push_back(GLubyte(v)); }
539
540    protected:
541
542        virtual ~DrawElementsUByte();
543
544        mutable unsigned int    _minIndex;
545        mutable unsigned int    _maxIndex;
546};
547
548
549class OSG_EXPORT DrawElementsUShort : public DrawElements, public VectorGLushort
550{
551    public:
552
553        typedef VectorGLushort vector_type;
554
555        DrawElementsUShort(GLenum mode=0):
556            DrawElements(DrawElementsUShortPrimitiveType,mode) {}
557   
558        DrawElementsUShort(const DrawElementsUShort& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
559            DrawElements(array,copyop),
560            vector_type(array) {}
561
562        DrawElementsUShort(GLenum mode, unsigned int no, const GLushort* ptr, int numInstances=0) :
563            DrawElements(DrawElementsUShortPrimitiveType,mode,numInstances),
564            vector_type(ptr,ptr+no) {}
565
566        DrawElementsUShort(GLenum mode, unsigned int no) :
567            DrawElements(DrawElementsUShortPrimitiveType,mode),
568            vector_type(no) {}
569
570        template <class InputIterator>
571        DrawElementsUShort(GLenum mode, InputIterator first,InputIterator last) :
572            DrawElements(DrawElementsUShortPrimitiveType,mode),
573            vector_type(first,last) {}
574
575        virtual Object* cloneType() const { return new DrawElementsUShort(); }
576        virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUShort(*this,copyop); }       
577        virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsUShort*>(obj)!=NULL; }
578        virtual const char* libraryName() const { return "osg"; }
579        virtual const char* className() const { return "DrawElementsUShort"; }
580
581        virtual const GLvoid*   getDataPointer() const { return empty()?0:&front(); }
582        virtual unsigned int    getTotalDataSize() const { return 2u*static_cast<unsigned int>(size()); }
583        virtual bool            supportsBufferObject() const { return false; }
584
585        virtual void draw(State& state, bool useVertexBufferObjects) const;
586       
587        virtual void accept(PrimitiveFunctor& functor) const;
588        virtual void accept(PrimitiveIndexFunctor& functor) const;
589
590        virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(size()); }
591        virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
592        virtual void offsetIndices(int offset);
593
594        virtual void computeRange() const
595        {
596            if (empty())
597            {
598                _minIndex = 0;
599                _maxIndex = 0;
600                _rangeModifiedCount = _modifiedCount;
601                return;
602            }
603           
604            _minIndex = front();
605            _maxIndex = _minIndex;
606
607            for(vector_type::const_iterator itr=begin(); itr!=end();  ++itr)
608            {
609                if (*itr<_minIndex) _minIndex = *itr;
610                if (*itr>_maxIndex) _maxIndex = *itr;
611            }
612            _rangeModifiedCount = _modifiedCount;
613        }
614
615        virtual void reserveElements(unsigned int numIndices) { reserve(numIndices); }
616        virtual void setElement(unsigned int i, unsigned int v) { (*this)[i] = v; }
617        virtual unsigned int getElement(unsigned int i) { return (*this)[i]; }
618        virtual void addElement(unsigned int v) { push_back(GLushort(v)); }
619
620    protected:
621
622        virtual ~DrawElementsUShort();
623
624        mutable unsigned int    _minIndex;
625        mutable unsigned int    _maxIndex;       
626};
627
628class OSG_EXPORT DrawElementsUInt : public DrawElements, public VectorGLuint
629{
630    public:
631
632        typedef VectorGLuint vector_type;
633
634        DrawElementsUInt(GLenum mode=0):
635            DrawElements(DrawElementsUIntPrimitiveType,mode) {}
636   
637        DrawElementsUInt(const DrawElementsUInt& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
638            DrawElements(array,copyop),
639            vector_type(array) {}
640
641        DrawElementsUInt(GLenum mode, unsigned int no, const GLuint* ptr, int numInstances=0) :
642            DrawElements(DrawElementsUIntPrimitiveType,mode,numInstances),
643            vector_type(ptr,ptr+no) {}
644
645        DrawElementsUInt(GLenum mode, unsigned int no) :
646            DrawElements(DrawElementsUIntPrimitiveType,mode),
647            vector_type(no) {}
648
649        template <class InputIterator>
650        DrawElementsUInt(GLenum mode, InputIterator first,InputIterator last) :
651            DrawElements(DrawElementsUIntPrimitiveType,mode),
652            vector_type(first,last) {}
653
654        virtual Object* cloneType() const { return new DrawElementsUInt(); }
655        virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUInt(*this,copyop); }       
656        virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsUInt*>(obj)!=NULL; }
657        virtual const char* libraryName() const { return "osg"; }
658        virtual const char* className() const { return "DrawElementsUInt"; }
659
660        virtual const GLvoid*   getDataPointer() const { return empty()?0:&front(); }
661        virtual unsigned int    getTotalDataSize() const { return 4u*static_cast<unsigned int>(size()); }
662        virtual bool            supportsBufferObject() const { return false; }
663
664        virtual void draw(State& state, bool useVertexBufferObjects) const;
665       
666        virtual void accept(PrimitiveFunctor& functor) const;
667        virtual void accept(PrimitiveIndexFunctor& functor) const;
668
669        virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(size()); }
670        virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
671        virtual void offsetIndices(int offset);
672
673       
674        virtual void computeRange() const
675        {
676            if (empty())
677            {
678                _minIndex = 0;
679                _maxIndex = 0;
680                _rangeModifiedCount = _modifiedCount;
681                return;
682            }
683           
684            _minIndex = front();
685            _maxIndex = _minIndex;
686
687            for(vector_type::const_iterator itr=begin(); itr!=end();  ++itr)
688            {
689                if (*itr<_minIndex) _minIndex = *itr;
690                if (*itr>_maxIndex) _maxIndex = *itr;
691            }
692            _rangeModifiedCount = _modifiedCount;
693        }
694
695        virtual void reserveElements(unsigned int numIndices) { reserve(numIndices); }
696        virtual void setElement(unsigned int i, unsigned int v) { (*this)[i] = v; }
697        virtual unsigned int getElement(unsigned int i) { return (*this)[i]; }
698        virtual void addElement(unsigned int v) { push_back(GLuint(v)); }
699
700    protected:
701
702        virtual ~DrawElementsUInt();
703       
704        mutable unsigned int    _minIndex;
705        mutable unsigned int    _maxIndex;
706};
707
708}
709
710#endif
Note: See TracBrowser for help on using the browser.