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

Revision 9599, 25.1 kB (checked in by robert, 6 years ago)

Fixed warnings, updated NEWS

  • 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        }
452
[6555]453    protected:
454   
[6559]455        virtual ~DrawElements()
456        {
457            if (_ebo.valid())
458            {
[6582]459                _ebo->removeDrawElements(this);
[6559]460            }
461        }
462
[6582]463        osg::ref_ptr<ElementBufferObject>   _ebo;
464        mutable const GLvoid*               _eboOffset;
465
[6555]466};
467
468class OSG_EXPORT DrawElementsUByte : public DrawElements, public VectorGLubyte
469{
470    public:
471   
[4871]472        typedef VectorGLubyte vector_type;
[1166]473
474        DrawElementsUByte(GLenum mode=0):
[6555]475            DrawElements(DrawElementsUBytePrimitiveType,mode) {}
[1166]476   
[7856]477        DrawElementsUByte(const DrawElementsUByte& array, const CopyOp& copyop=CopyOp::SHALLOW_COPY):
[6555]478            DrawElements(array,copyop),
[4401]479            vector_type(array) {}
[1166]480
[9447]481        DrawElementsUByte(GLenum mode, unsigned int no, const GLubyte* ptr, int numInstances=0) :
482            DrawElements(DrawElementsUBytePrimitiveType,mode,numInstances),
[4401]483            vector_type(ptr,ptr+no) {}
[1166]484
[7856]485        DrawElementsUByte(GLenum mode, unsigned int no) :
[6555]486            DrawElements(DrawElementsUBytePrimitiveType,mode),
[4401]487            vector_type(no) {}
[1166]488
[1418]489        virtual Object* cloneType() const { return new DrawElementsUByte(); }
490        virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUByte(*this,copyop); }       
[1166]491        virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsUByte*>(obj)!=NULL; }
492        virtual const char* libraryName() const { return "osg"; }
493        virtual const char* className() const { return "DrawElementsUByte"; }
494
[3819]495        virtual const GLvoid*   getDataPointer() const { return empty()?0:&front(); }
[9599]496        virtual unsigned int    getTotalDataSize() const { return static_cast<unsigned int>(size()); }
[3819]497        virtual bool            supportsBufferObject() const { return false; }
498
[3093]499        virtual void draw(State& state, bool useVertexBufferObjects) const ;
[1166]500       
[3819]501        virtual void accept(PrimitiveFunctor& functor) const;
502        virtual void accept(PrimitiveIndexFunctor& functor) const;
[1166]503
[9599]504        virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(size()); }
[1207]505        virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
[1166]506        virtual void offsetIndices(int offset);
[4842]507       
[5863]508        virtual void computeRange() const
509        {
510            if (empty())
511            {
512                _minIndex = 0;
513                _maxIndex = 0;
514                _rangeModifiedCount = _modifiedCount;
515                return;
516            }
517           
518            _minIndex = front();
519            _maxIndex = _minIndex;
520
521            for(vector_type::const_iterator itr=begin(); itr!=end();  ++itr)
522            {
523                if (*itr<_minIndex) _minIndex = *itr;
524                if (*itr>_maxIndex) _maxIndex = *itr;
525            }
526            _rangeModifiedCount = _modifiedCount;
527        }
528       
[1463]529    protected:
530
[4842]531        virtual ~DrawElementsUByte();
532
[5863]533        mutable unsigned int    _minIndex;
534        mutable unsigned int    _maxIndex;
[1166]535};
536
537
[6555]538class OSG_EXPORT DrawElementsUShort : public DrawElements, public VectorGLushort
[1166]539{
540    public:
541
[4871]542        typedef VectorGLushort vector_type;
[4401]543
[1166]544        DrawElementsUShort(GLenum mode=0):
[6555]545            DrawElements(DrawElementsUShortPrimitiveType,mode) {}
[1166]546   
547        DrawElementsUShort(const DrawElementsUShort& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
[6555]548            DrawElements(array,copyop),
[4401]549            vector_type(array) {}
[1166]550
[9447]551        DrawElementsUShort(GLenum mode, unsigned int no, const GLushort* ptr, int numInstances=0) :
552            DrawElements(DrawElementsUShortPrimitiveType,mode,numInstances),
[4401]553            vector_type(ptr,ptr+no) {}
[1166]554
[7856]555        DrawElementsUShort(GLenum mode, unsigned int no) :
[6555]556            DrawElements(DrawElementsUShortPrimitiveType,mode),
[4401]557            vector_type(no) {}
[1166]558
559        template <class InputIterator>
560        DrawElementsUShort(GLenum mode, InputIterator first,InputIterator last) :
[6555]561            DrawElements(DrawElementsUShortPrimitiveType,mode),
[4401]562            vector_type(first,last) {}
[1166]563
[1418]564        virtual Object* cloneType() const { return new DrawElementsUShort(); }
565        virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUShort(*this,copyop); }       
[1166]566        virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsUShort*>(obj)!=NULL; }
567        virtual const char* libraryName() const { return "osg"; }
568        virtual const char* className() const { return "DrawElementsUShort"; }
569
[3819]570        virtual const GLvoid*   getDataPointer() const { return empty()?0:&front(); }
[9599]571        virtual unsigned int    getTotalDataSize() const { return 2u*static_cast<unsigned int>(size()); }
[3819]572        virtual bool            supportsBufferObject() const { return false; }
573
[3093]574        virtual void draw(State& state, bool useVertexBufferObjects) const;
[1166]575       
[3819]576        virtual void accept(PrimitiveFunctor& functor) const;
577        virtual void accept(PrimitiveIndexFunctor& functor) const;
[1166]578
[9599]579        virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(size()); }
[1207]580        virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
[1166]581        virtual void offsetIndices(int offset);
[1463]582
[5863]583        virtual void computeRange() const
584        {
585            if (empty())
586            {
587                _minIndex = 0;
588                _maxIndex = 0;
589                _rangeModifiedCount = _modifiedCount;
590                return;
591            }
592           
593            _minIndex = front();
594            _maxIndex = _minIndex;
595
596            for(vector_type::const_iterator itr=begin(); itr!=end();  ++itr)
597            {
598                if (*itr<_minIndex) _minIndex = *itr;
599                if (*itr>_maxIndex) _maxIndex = *itr;
600            }
601            _rangeModifiedCount = _modifiedCount;
602        }
603
[1463]604    protected:
605
[4842]606        virtual ~DrawElementsUShort();
607
[5863]608        mutable unsigned int    _minIndex;
609        mutable unsigned int    _maxIndex;       
[1166]610};
611
[6555]612class OSG_EXPORT DrawElementsUInt : public DrawElements, public VectorGLuint
[1166]613{
614    public:
615
[4871]616        typedef VectorGLuint vector_type;
[4401]617
[1166]618        DrawElementsUInt(GLenum mode=0):
[6555]619            DrawElements(DrawElementsUIntPrimitiveType,mode) {}
[1166]620   
621        DrawElementsUInt(const DrawElementsUInt& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
[6555]622            DrawElements(array,copyop),
[4401]623            vector_type(array) {}
[1166]624
[9447]625        DrawElementsUInt(GLenum mode, unsigned int no, const GLuint* ptr, int numInstances=0) :
626            DrawElements(DrawElementsUIntPrimitiveType,mode,numInstances),
[4401]627            vector_type(ptr,ptr+no) {}
[1166]628
[7856]629        DrawElementsUInt(GLenum mode, unsigned int no) :
[6555]630            DrawElements(DrawElementsUIntPrimitiveType,mode),
[4401]631            vector_type(no) {}
[1166]632
[2298]633        template <class InputIterator>
634        DrawElementsUInt(GLenum mode, InputIterator first,InputIterator last) :
[6555]635            DrawElements(DrawElementsUIntPrimitiveType,mode),
[4401]636            vector_type(first,last) {}
[2298]637
[1418]638        virtual Object* cloneType() const { return new DrawElementsUInt(); }
639        virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUInt(*this,copyop); }       
[1166]640        virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsUInt*>(obj)!=NULL; }
641        virtual const char* libraryName() const { return "osg"; }
642        virtual const char* className() const { return "DrawElementsUInt"; }
643
[3819]644        virtual const GLvoid*   getDataPointer() const { return empty()?0:&front(); }
[9599]645        virtual unsigned int    getTotalDataSize() const { return 4u*static_cast<unsigned int>(size()); }
[3819]646        virtual bool            supportsBufferObject() const { return false; }
647
[3093]648        virtual void draw(State& state, bool useVertexBufferObjects) const;
[1166]649       
[3819]650        virtual void accept(PrimitiveFunctor& functor) const;
651        virtual void accept(PrimitiveIndexFunctor& functor) const;
[1166]652
[9599]653        virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(size()); }
[1207]654        virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
[1166]655        virtual void offsetIndices(int offset);
[1463]656
[4842]657       
[5863]658        virtual void computeRange() const
659        {
660            if (empty())
661            {
662                _minIndex = 0;
663                _maxIndex = 0;
664                _rangeModifiedCount = _modifiedCount;
665                return;
666            }
667           
668            _minIndex = front();
669            _maxIndex = _minIndex;
670
671            for(vector_type::const_iterator itr=begin(); itr!=end();  ++itr)
672            {
673                if (*itr<_minIndex) _minIndex = *itr;
674                if (*itr>_maxIndex) _maxIndex = *itr;
675            }
676            _rangeModifiedCount = _modifiedCount;
677        }
678
[1463]679    protected:
680
[3422]681        virtual ~DrawElementsUInt();
[4842]682       
[5863]683        mutable unsigned int    _minIndex;
684        mutable unsigned int    _maxIndex;
[1166]685};
686
687}
688
689#endif
Note: See TracBrowser for help on using the browser.