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

Revision 9969, 26.3 kB (checked in by robert, 5 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
RevLine 
[5328]1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
[1529]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*/
[1166]13
[3440]14#ifndef OSG_PRIMITIVESET
15#define OSG_PRIMITIVESET 1
[1166]16
[3819]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>
[7601]23#include <osg/Vec2d>
24#include <osg/Vec3d>
25#include <osg/Vec4d>
[8467]26#include <osg/MixinVector>
[1166]27
[6555]28#include <osg/BufferObject>
29
[3819]30#include <vector>
31
[1166]32namespace osg {
33
[8467]34typedef MixinVector<GLsizei> VectorGLsizei;
35typedef MixinVector<GLubyte> VectorGLubyte;
36typedef MixinVector<GLushort> VectorGLushort;
37typedef MixinVector<GLuint> VectorGLuint;
[4871]38
[5180]39class State;
[4878]40
[5180]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 */
[3819]51class PrimitiveFunctor
52{
53public:
54
55    virtual ~PrimitiveFunctor() {}
56
[5180]57    /** Sets the array of vertices used to describe the primitives. Somehow
58     *  mimics the OpenGL \c glVertexPointer() function.
59     */
[3819]60    virtual void setVertexArray(unsigned int count,const Vec2* vertices) = 0;
[5180]61
62    /** Sets the array of vertices used to describe the primitives. Somehow
63     *  mimics the OpenGL \c glVertexPointer() function.
64     */
[3819]65    virtual void setVertexArray(unsigned int count,const Vec3* vertices) = 0;
[5180]66
67    /** Sets the array of vertices used to describe the primitives. Somehow
68     *  mimics the OpenGL \c glVertexPointer() function.
69     */
[3819]70    virtual void setVertexArray(unsigned int count,const Vec4* vertices) = 0;
71
[7601]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
[5180]87    /// Mimics the OpenGL \c glDrawArrays() function.
[3819]88    virtual void drawArrays(GLenum mode,GLint first,GLsizei count) = 0;
[5180]89
90    /// Mimics the OpenGL \c glDrawElements() function.
[3819]91    virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices) = 0;
[5180]92
93    /// Mimics the OpenGL \c glDrawElements() function.
[3819]94    virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices) = 0;
[5180]95
96    /// Mimics the OpenGL \c glDrawElements() function.
[3819]97    virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices) = 0;
98
[5180]99    /// Mimics the OpenGL \c glBegin() function.
[3819]100    virtual void begin(GLenum mode) = 0;
[5180]101
102    /// Mimics the OpenGL \c glVertex() "family of functions".
[3819]103    virtual void vertex(const Vec2& vert) = 0;
[5180]104
105    /// Mimics the OpenGL \c glVertex() "family of functions".
[3819]106    virtual void vertex(const Vec3& vert) = 0;
[5180]107
108    /// Mimics the OpenGL \c glVertex() "family of functions".
[3819]109    virtual void vertex(const Vec4& vert) = 0;
[5180]110
111    /// Mimics the OpenGL \c glVertex() "family of functions".
[3819]112    virtual void vertex(float x,float y) = 0;
[5180]113
114    /// Mimics the OpenGL \c glVertex() "family of functions".
[3819]115    virtual void vertex(float x,float y,float z) = 0;
[5180]116
117    /// Mimics the OpenGL \c glVertex() "family of functions".
[3819]118    virtual void vertex(float x,float y,float z,float w) = 0;
[5180]119
120    /// Mimics the OpenGL \c glEnd() function.
[3819]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
[7601]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
[3819]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
[6563]148class DrawElements;
149
[4878]150class OSG_EXPORT PrimitiveSet : public Object
[1166]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
[9447]178        PrimitiveSet(Type primType=PrimitiveType,GLenum mode=0, int numInstances=0):
[1166]179            _primitiveType(primType),
[9447]180            _numInstances(numInstances),
[3819]181            _mode(mode),
[5863]182            _modifiedCount(0),
183            _rangeModifiedCount(0) {}
[1166]184   
185        PrimitiveSet(const PrimitiveSet& prim,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
186            Object(prim,copyop),
187            _primitiveType(prim._primitiveType),
[9447]188            _numInstances(prim._numInstances),
[3819]189            _mode(prim._mode),
[5863]190            _modifiedCount(0),
191            _rangeModifiedCount(0) {}
[1166]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       
[3819]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; }
[6563]201
202        virtual DrawElements* getDrawElements() { return 0; }
203        virtual const DrawElements* getDrawElements() const { return 0; }
[3819]204           
[9447]205        void setNumInstances(int n) { _numInstances = n; }
206        int getNumInstances() const { return _numInstances; }
207
[1166]208        void setMode(GLenum mode) { _mode = mode; }
209        GLenum getMode() const { return _mode; }
210
[3093]211        virtual void draw(State& state, bool useVertexBufferObjects) const = 0;
[1166]212       
[3819]213        virtual void accept(PrimitiveFunctor& functor) const = 0;
214        virtual void accept(PrimitiveIndexFunctor& functor) const = 0;
[1166]215       
[1207]216        virtual unsigned int index(unsigned int pos) const = 0;
217        virtual unsigned int getNumIndices() const = 0;
[1166]218        virtual void offsetIndices(int offset) = 0;
219
[4877]220        virtual unsigned int getNumPrimitives() const;
[1207]221
[3819]222        /** Dirty the primitive, which increments the modified count, to force buffer objects to update. */
[6574]223        virtual void dirty() { ++_modifiedCount; }     
[3819]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
[5882]231        /** Resize any per context GLObject buffers to specified size. */
232        virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/) {}
233
[4842]234        /** If State is non-zero, this function releases OpenGL objects for
[7648]235          * the specified graphics context. Otherwise, releases OpenGL objects
[4842]236          * for all graphics contexts. */
237        virtual void releaseGLObjects(State* /*state*/=0) const {}
238
[5863]239        virtual void computeRange() const {}
240
[1166]241    protected:
242
[1463]243        virtual ~PrimitiveSet() {}
244
[3819]245        Type            _primitiveType;
[9447]246        int             _numInstances;
[3819]247        GLenum          _mode;
248        unsigned int    _modifiedCount;
[5863]249        mutable unsigned int    _rangeModifiedCount;
[4842]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;
[1166]273};
274
[4021]275class OSG_EXPORT DrawArrays : public PrimitiveSet
[1166]276{
277    public:
278
279        DrawArrays(GLenum mode=0):
280            PrimitiveSet(DrawArraysPrimitiveType,mode),
281            _first(0),
282            _count(0) {}
283   
[9447]284        DrawArrays(GLenum mode, GLint first, GLsizei count, int numInstances=0):
285            PrimitiveSet(DrawArraysPrimitiveType, mode, numInstances),
[1166]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
[1418]294        virtual Object* cloneType() const { return new DrawArrays(); }
295        virtual Object* clone(const CopyOp& copyop) const { return new DrawArrays(*this,copyop); }       
[1166]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
[3093]314        virtual void draw(State& state, bool useVertexBufferObjects) const;
[1166]315       
[3819]316        virtual void accept(PrimitiveFunctor& functor) const;
317        virtual void accept(PrimitiveIndexFunctor& functor) const;
[1166]318       
[9599]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; }
[1166]321        virtual void offsetIndices(int offset) { _first += offset; }
322
323    protected:
324
[1463]325        virtual ~DrawArrays() {}
326
[1166]327        GLint   _first;
328        GLsizei _count;
329};
330
[4871]331class OSG_EXPORT DrawArrayLengths : public PrimitiveSet, public VectorGLsizei
[1166]332{
333    public:
334
[4871]335        typedef VectorGLsizei vector_type;
[4406]336
[1166]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),
[4406]343            vector_type(dal),
[1166]344            _first(dal._first) {}
345
346        DrawArrayLengths(GLenum mode, GLint first, unsigned int no, GLsizei* ptr) :
347            PrimitiveSet(DrawArrayLengthsPrimitiveType,mode),
[4406]348            vector_type(ptr,ptr+no),
[1166]349            _first(first) {}
350
351        DrawArrayLengths(GLenum mode,GLint first, unsigned int no) :
352            PrimitiveSet(DrawArrayLengthsPrimitiveType,mode),
[4406]353            vector_type(no),
[1166]354            _first(first) {}
355
[1481]356        DrawArrayLengths(GLenum mode,GLint first) :
[1166]357            PrimitiveSet(DrawArrayLengthsPrimitiveType,mode),
[4406]358            vector_type(),
[1166]359            _first(first) {}
360
[1481]361
[1418]362        virtual Object* cloneType() const { return new DrawArrayLengths(); }
363        virtual Object* clone(const CopyOp& copyop) const { return new DrawArrayLengths(*this,copyop); }       
[1166]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       
[3093]372        virtual void draw(State& state, bool useVertexBufferObjects) const;
[1166]373       
[3819]374        virtual void accept(PrimitiveFunctor& functor) const;
375        virtual void accept(PrimitiveIndexFunctor& functor) const;
[1166]376       
[1207]377        virtual unsigned int getNumIndices() const;
378        virtual unsigned int index(unsigned int pos) const { return _first+pos; }
[1166]379        virtual void offsetIndices(int offset) { _first += offset; }
380
[4877]381        virtual unsigned int getNumPrimitives() const;
[1166]382
383    protected:
384
[1463]385        virtual ~DrawArrayLengths() {}
386
[1166]387        GLint   _first;
388};
389
[6555]390class DrawElements : public PrimitiveSet
[1166]391{
392    public:
[6555]393       
[9447]394        DrawElements(Type primType=PrimitiveType, GLenum mode=0, int numInstances=0):
395            PrimitiveSet(primType,mode, numInstances),
[6582]396            _eboOffset(0) {}
[4401]397   
[6555]398        DrawElements(const DrawElements& copy,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
399            PrimitiveSet(copy,copyop),
[6582]400            _eboOffset(0) {}
[6555]401
402
[6563]403        virtual DrawElements* getDrawElements() { return this; }
404        virtual const DrawElements* getDrawElements() const { return this; }
405
[6574]406        virtual void dirty() { ++_modifiedCount; if (_ebo.valid()) _ebo->dirty(); }
407
[6578]408        /** Set the ElementBufferObject.*/
409        inline void setElementBufferObject(osg::ElementBufferObject* ebo)
[6559]410        {
411            if (_ebo == ebo) return;
412           
413            if (_ebo.valid())
414            {
[6582]415                _ebo->removeDrawElements(this);
[6559]416            }
[6582]417           
[6559]418            _ebo = ebo;
419
420            if (_ebo.valid())
421            {
[6582]422                _ebo->addDrawElements(this);
[6559]423            }
424        }
[6555]425       
[6578]426        /** Get the ElementBufferObject. If no EBO is assigned returns NULL*/
427        inline osg::ElementBufferObject* getElementBufferObject() { return _ebo.get(); }
[6555]428
[6578]429        /** Get the const ElementBufferObject. If no EBO is assigned returns NULL*/
430        inline const osg::ElementBufferObject* getElementBufferObject() const { return _ebo.get(); }
[6555]431
[6582]432        /** Set the offset into the ElementBufferObject, if used.*/
433        inline void setElementBufferObjectOffset(const GLvoid* offset) const { _eboOffset = offset; }
[6555]434
[6582]435        /** Get the offset into the ElementBufferOffset, if used.*/
436        inline const GLvoid* getElementBufferObjectOffset() const { return _eboOffset; }
[6555]437
438
[6582]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
[7648]446          * the specified graphics context. Otherwise, releases OpenGL objects
[6582]447          * for all graphics contexts. */
448        virtual void releaseGLObjects(State* state=0) const
449        {
450            if (_ebo.valid()) _ebo->releaseGLObjects(state);
451        }
[9969]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;
[6582]458
[6555]459    protected:
460   
[6559]461        virtual ~DrawElements()
462        {
463            if (_ebo.valid())
464            {
[6582]465                _ebo->removeDrawElements(this);
[6559]466            }
467        }
468
[6582]469        osg::ref_ptr<ElementBufferObject>   _ebo;
470        mutable const GLvoid*               _eboOffset;
471
[6555]472};
473
474class OSG_EXPORT DrawElementsUByte : public DrawElements, public VectorGLubyte
475{
476    public:
477   
[4871]478        typedef VectorGLubyte vector_type;
[1166]479
480        DrawElementsUByte(GLenum mode=0):
[6555]481            DrawElements(DrawElementsUBytePrimitiveType,mode) {}
[1166]482   
[7856]483        DrawElementsUByte(const DrawElementsUByte& array, const CopyOp& copyop=CopyOp::SHALLOW_COPY):
[6555]484            DrawElements(array,copyop),
[4401]485            vector_type(array) {}
[1166]486
[9447]487        DrawElementsUByte(GLenum mode, unsigned int no, const GLubyte* ptr, int numInstances=0) :
488            DrawElements(DrawElementsUBytePrimitiveType,mode,numInstances),
[4401]489            vector_type(ptr,ptr+no) {}
[1166]490
[7856]491        DrawElementsUByte(GLenum mode, unsigned int no) :
[6555]492            DrawElements(DrawElementsUBytePrimitiveType,mode),
[4401]493            vector_type(no) {}
[1166]494
[1418]495        virtual Object* cloneType() const { return new DrawElementsUByte(); }
496        virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUByte(*this,copyop); }       
[1166]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
[3819]501        virtual const GLvoid*   getDataPointer() const { return empty()?0:&front(); }
[9599]502        virtual unsigned int    getTotalDataSize() const { return static_cast<unsigned int>(size()); }
[3819]503        virtual bool            supportsBufferObject() const { return false; }
504
[3093]505        virtual void draw(State& state, bool useVertexBufferObjects) const ;
[1166]506       
[3819]507        virtual void accept(PrimitiveFunctor& functor) const;
508        virtual void accept(PrimitiveIndexFunctor& functor) const;
[1166]509
[9599]510        virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(size()); }
[1207]511        virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
[1166]512        virtual void offsetIndices(int offset);
[4842]513       
[5863]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       
[9969]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
[1463]540    protected:
541
[4842]542        virtual ~DrawElementsUByte();
543
[5863]544        mutable unsigned int    _minIndex;
545        mutable unsigned int    _maxIndex;
[1166]546};
547
548
[6555]549class OSG_EXPORT DrawElementsUShort : public DrawElements, public VectorGLushort
[1166]550{
551    public:
552
[4871]553        typedef VectorGLushort vector_type;
[4401]554
[1166]555        DrawElementsUShort(GLenum mode=0):
[6555]556            DrawElements(DrawElementsUShortPrimitiveType,mode) {}
[1166]557   
558        DrawElementsUShort(const DrawElementsUShort& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
[6555]559            DrawElements(array,copyop),
[4401]560            vector_type(array) {}
[1166]561
[9447]562        DrawElementsUShort(GLenum mode, unsigned int no, const GLushort* ptr, int numInstances=0) :
563            DrawElements(DrawElementsUShortPrimitiveType,mode,numInstances),
[4401]564            vector_type(ptr,ptr+no) {}
[1166]565
[7856]566        DrawElementsUShort(GLenum mode, unsigned int no) :
[6555]567            DrawElements(DrawElementsUShortPrimitiveType,mode),
[4401]568            vector_type(no) {}
[1166]569
570        template <class InputIterator>
571        DrawElementsUShort(GLenum mode, InputIterator first,InputIterator last) :
[6555]572            DrawElements(DrawElementsUShortPrimitiveType,mode),
[4401]573            vector_type(first,last) {}
[1166]574
[1418]575        virtual Object* cloneType() const { return new DrawElementsUShort(); }
576        virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUShort(*this,copyop); }       
[1166]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
[3819]581        virtual const GLvoid*   getDataPointer() const { return empty()?0:&front(); }
[9599]582        virtual unsigned int    getTotalDataSize() const { return 2u*static_cast<unsigned int>(size()); }
[3819]583        virtual bool            supportsBufferObject() const { return false; }
584
[3093]585        virtual void draw(State& state, bool useVertexBufferObjects) const;
[1166]586       
[3819]587        virtual void accept(PrimitiveFunctor& functor) const;
588        virtual void accept(PrimitiveIndexFunctor& functor) const;
[1166]589
[9599]590        virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(size()); }
[1207]591        virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
[1166]592        virtual void offsetIndices(int offset);
[1463]593
[5863]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
[9969]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
[1463]620    protected:
621
[4842]622        virtual ~DrawElementsUShort();
623
[5863]624        mutable unsigned int    _minIndex;
625        mutable unsigned int    _maxIndex;       
[1166]626};
627
[6555]628class OSG_EXPORT DrawElementsUInt : public DrawElements, public VectorGLuint
[1166]629{
630    public:
631
[4871]632        typedef VectorGLuint vector_type;
[4401]633
[1166]634        DrawElementsUInt(GLenum mode=0):
[6555]635            DrawElements(DrawElementsUIntPrimitiveType,mode) {}
[1166]636   
637        DrawElementsUInt(const DrawElementsUInt& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
[6555]638            DrawElements(array,copyop),
[4401]639            vector_type(array) {}
[1166]640
[9447]641        DrawElementsUInt(GLenum mode, unsigned int no, const GLuint* ptr, int numInstances=0) :
642            DrawElements(DrawElementsUIntPrimitiveType,mode,numInstances),
[4401]643            vector_type(ptr,ptr+no) {}
[1166]644
[7856]645        DrawElementsUInt(GLenum mode, unsigned int no) :
[6555]646            DrawElements(DrawElementsUIntPrimitiveType,mode),
[4401]647            vector_type(no) {}
[1166]648
[2298]649        template <class InputIterator>
650        DrawElementsUInt(GLenum mode, InputIterator first,InputIterator last) :
[6555]651            DrawElements(DrawElementsUIntPrimitiveType,mode),
[4401]652            vector_type(first,last) {}
[2298]653
[1418]654        virtual Object* cloneType() const { return new DrawElementsUInt(); }
655        virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUInt(*this,copyop); }       
[1166]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
[3819]660        virtual const GLvoid*   getDataPointer() const { return empty()?0:&front(); }
[9599]661        virtual unsigned int    getTotalDataSize() const { return 4u*static_cast<unsigned int>(size()); }
[3819]662        virtual bool            supportsBufferObject() const { return false; }
663
[3093]664        virtual void draw(State& state, bool useVertexBufferObjects) const;
[1166]665       
[3819]666        virtual void accept(PrimitiveFunctor& functor) const;
667        virtual void accept(PrimitiveIndexFunctor& functor) const;
[1166]668
[9599]669        virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(size()); }
[1207]670        virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
[1166]671        virtual void offsetIndices(int offset);
[1463]672
[4842]673       
[5863]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
[9969]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
[1463]700    protected:
701
[3422]702        virtual ~DrawElementsUInt();
[4842]703       
[5863]704        mutable unsigned int    _minIndex;
705        mutable unsigned int    _maxIndex;
[1166]706};
707
708}
709
710#endif
Note: See TracBrowser for help on using the browser.