| 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 | |
|---|
| 32 | namespace osg { |
|---|
| 33 | |
|---|
| 34 | typedef MixinVector<GLsizei> VectorGLsizei; |
|---|
| 35 | typedef MixinVector<GLubyte> VectorGLubyte; |
|---|
| 36 | typedef MixinVector<GLushort> VectorGLushort; |
|---|
| 37 | typedef MixinVector<GLuint> VectorGLuint; |
|---|
| 38 | |
|---|
| 39 | class 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 | */ |
|---|
| 51 | class PrimitiveFunctor |
|---|
| 52 | { |
|---|
| 53 | public: |
|---|
| 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 | |
|---|
| 124 | class PrimitiveIndexFunctor |
|---|
| 125 | { |
|---|
| 126 | public: |
|---|
| 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 | |
|---|
| 148 | class DrawElements; |
|---|
| 149 | |
|---|
| 150 | class OSG_EXPORT PrimitiveSet : public BufferData |
|---|
| 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 | _rangeModifiedCount(0) {} |
|---|
| 183 | |
|---|
| 184 | PrimitiveSet(const PrimitiveSet& prim,const CopyOp& copyop=CopyOp::SHALLOW_COPY): |
|---|
| 185 | BufferData(prim,copyop), |
|---|
| 186 | _primitiveType(prim._primitiveType), |
|---|
| 187 | _numInstances(prim._numInstances), |
|---|
| 188 | _mode(prim._mode), |
|---|
| 189 | _rangeModifiedCount(0) {} |
|---|
| 190 | |
|---|
| 191 | virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const PrimitiveSet*>(obj)!=NULL; } |
|---|
| 192 | virtual const char* libraryName() const { return "osg"; } |
|---|
| 193 | virtual const char* className() const { return "PrimitiveSet"; } |
|---|
| 194 | |
|---|
| 195 | Type getType() const { return _primitiveType; } |
|---|
| 196 | virtual const GLvoid* getDataPointer() const { return 0; } |
|---|
| 197 | virtual unsigned int getTotalDataSize() const { return 0; } |
|---|
| 198 | virtual bool supportsBufferObject() const { return false; } |
|---|
| 199 | |
|---|
| 200 | virtual DrawElements* getDrawElements() { return 0; } |
|---|
| 201 | virtual const DrawElements* getDrawElements() const { return 0; } |
|---|
| 202 | |
|---|
| 203 | void setNumInstances(int n) { _numInstances = n; } |
|---|
| 204 | int getNumInstances() const { return _numInstances; } |
|---|
| 205 | |
|---|
| 206 | void setMode(GLenum mode) { _mode = mode; } |
|---|
| 207 | GLenum getMode() const { return _mode; } |
|---|
| 208 | |
|---|
| 209 | virtual void draw(State& state, bool useVertexBufferObjects) const = 0; |
|---|
| 210 | |
|---|
| 211 | virtual void accept(PrimitiveFunctor& functor) const = 0; |
|---|
| 212 | virtual void accept(PrimitiveIndexFunctor& functor) const = 0; |
|---|
| 213 | |
|---|
| 214 | virtual unsigned int index(unsigned int pos) const = 0; |
|---|
| 215 | virtual unsigned int getNumIndices() const = 0; |
|---|
| 216 | virtual void offsetIndices(int offset) = 0; |
|---|
| 217 | |
|---|
| 218 | virtual unsigned int getNumPrimitives() const; |
|---|
| 219 | |
|---|
| 220 | virtual void computeRange() const {} |
|---|
| 221 | |
|---|
| 222 | protected: |
|---|
| 223 | |
|---|
| 224 | virtual ~PrimitiveSet() {} |
|---|
| 225 | |
|---|
| 226 | Type _primitiveType; |
|---|
| 227 | int _numInstances; |
|---|
| 228 | GLenum _mode; |
|---|
| 229 | mutable unsigned int _rangeModifiedCount; |
|---|
| 230 | }; |
|---|
| 231 | |
|---|
| 232 | class OSG_EXPORT DrawArrays : public PrimitiveSet |
|---|
| 233 | { |
|---|
| 234 | public: |
|---|
| 235 | |
|---|
| 236 | DrawArrays(GLenum mode=0): |
|---|
| 237 | PrimitiveSet(DrawArraysPrimitiveType,mode), |
|---|
| 238 | _first(0), |
|---|
| 239 | _count(0) {} |
|---|
| 240 | |
|---|
| 241 | DrawArrays(GLenum mode, GLint first, GLsizei count, int numInstances=0): |
|---|
| 242 | PrimitiveSet(DrawArraysPrimitiveType, mode, numInstances), |
|---|
| 243 | _first(first), |
|---|
| 244 | _count(count) {} |
|---|
| 245 | |
|---|
| 246 | DrawArrays(const DrawArrays& da,const CopyOp& copyop=CopyOp::SHALLOW_COPY): |
|---|
| 247 | PrimitiveSet(da,copyop), |
|---|
| 248 | _first(da._first), |
|---|
| 249 | _count(da._count) {} |
|---|
| 250 | |
|---|
| 251 | virtual Object* cloneType() const { return new DrawArrays(); } |
|---|
| 252 | virtual Object* clone(const CopyOp& copyop) const { return new DrawArrays(*this,copyop); } |
|---|
| 253 | virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawArrays*>(obj)!=NULL; } |
|---|
| 254 | virtual const char* libraryName() const { return "osg"; } |
|---|
| 255 | virtual const char* className() const { return "DrawArrays"; } |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | void set(GLenum mode,GLint first, GLsizei count) |
|---|
| 259 | { |
|---|
| 260 | _mode = mode; |
|---|
| 261 | _first = first; |
|---|
| 262 | _count = count; |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | void setFirst(GLint first) { _first = first; } |
|---|
| 266 | GLint getFirst() const { return _first; } |
|---|
| 267 | |
|---|
| 268 | void setCount(GLsizei count) { _count = count; } |
|---|
| 269 | GLsizei getCount() const { return _count; } |
|---|
| 270 | |
|---|
| 271 | virtual void draw(State& state, bool useVertexBufferObjects) const; |
|---|
| 272 | |
|---|
| 273 | virtual void accept(PrimitiveFunctor& functor) const; |
|---|
| 274 | virtual void accept(PrimitiveIndexFunctor& functor) const; |
|---|
| 275 | |
|---|
| 276 | virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(_count); } |
|---|
| 277 | virtual unsigned int index(unsigned int pos) const { return static_cast<unsigned int>(_first)+pos; } |
|---|
| 278 | virtual void offsetIndices(int offset) { _first += offset; } |
|---|
| 279 | |
|---|
| 280 | protected: |
|---|
| 281 | |
|---|
| 282 | virtual ~DrawArrays() {} |
|---|
| 283 | |
|---|
| 284 | GLint _first; |
|---|
| 285 | GLsizei _count; |
|---|
| 286 | }; |
|---|
| 287 | |
|---|
| 288 | class OSG_EXPORT DrawArrayLengths : public PrimitiveSet, public VectorGLsizei |
|---|
| 289 | { |
|---|
| 290 | public: |
|---|
| 291 | |
|---|
| 292 | typedef VectorGLsizei vector_type; |
|---|
| 293 | |
|---|
| 294 | DrawArrayLengths(GLenum mode=0): |
|---|
| 295 | PrimitiveSet(DrawArrayLengthsPrimitiveType,mode), |
|---|
| 296 | _first(0) {} |
|---|
| 297 | |
|---|
| 298 | DrawArrayLengths(const DrawArrayLengths& dal,const CopyOp& copyop=CopyOp::SHALLOW_COPY): |
|---|
| 299 | PrimitiveSet(dal,copyop), |
|---|
| 300 | vector_type(dal), |
|---|
| 301 | _first(dal._first) {} |
|---|
| 302 | |
|---|
| 303 | DrawArrayLengths(GLenum mode, GLint first, unsigned int no, GLsizei* ptr) : |
|---|
| 304 | PrimitiveSet(DrawArrayLengthsPrimitiveType,mode), |
|---|
| 305 | vector_type(ptr,ptr+no), |
|---|
| 306 | _first(first) {} |
|---|
| 307 | |
|---|
| 308 | DrawArrayLengths(GLenum mode,GLint first, unsigned int no) : |
|---|
| 309 | PrimitiveSet(DrawArrayLengthsPrimitiveType,mode), |
|---|
| 310 | vector_type(no), |
|---|
| 311 | _first(first) {} |
|---|
| 312 | |
|---|
| 313 | DrawArrayLengths(GLenum mode,GLint first) : |
|---|
| 314 | PrimitiveSet(DrawArrayLengthsPrimitiveType,mode), |
|---|
| 315 | vector_type(), |
|---|
| 316 | _first(first) {} |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | virtual Object* cloneType() const { return new DrawArrayLengths(); } |
|---|
| 320 | virtual Object* clone(const CopyOp& copyop) const { return new DrawArrayLengths(*this,copyop); } |
|---|
| 321 | virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawArrayLengths*>(obj)!=NULL; } |
|---|
| 322 | virtual const char* libraryName() const { return "osg"; } |
|---|
| 323 | virtual const char* className() const { return "DrawArrayLengths"; } |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | void setFirst(GLint first) { _first = first; } |
|---|
| 327 | GLint getFirst() const { return _first; } |
|---|
| 328 | |
|---|
| 329 | virtual void draw(State& state, bool useVertexBufferObjects) const; |
|---|
| 330 | |
|---|
| 331 | virtual void accept(PrimitiveFunctor& functor) const; |
|---|
| 332 | virtual void accept(PrimitiveIndexFunctor& functor) const; |
|---|
| 333 | |
|---|
| 334 | virtual unsigned int getNumIndices() const; |
|---|
| 335 | virtual unsigned int index(unsigned int pos) const { return _first+pos; } |
|---|
| 336 | virtual void offsetIndices(int offset) { _first += offset; } |
|---|
| 337 | |
|---|
| 338 | virtual unsigned int getNumPrimitives() const; |
|---|
| 339 | |
|---|
| 340 | protected: |
|---|
| 341 | |
|---|
| 342 | virtual ~DrawArrayLengths() {} |
|---|
| 343 | |
|---|
| 344 | GLint _first; |
|---|
| 345 | }; |
|---|
| 346 | |
|---|
| 347 | class DrawElements : public PrimitiveSet |
|---|
| 348 | { |
|---|
| 349 | public: |
|---|
| 350 | |
|---|
| 351 | DrawElements(Type primType=PrimitiveType, GLenum mode=0, int numInstances=0): |
|---|
| 352 | PrimitiveSet(primType,mode, numInstances) {} |
|---|
| 353 | |
|---|
| 354 | DrawElements(const DrawElements& copy,const CopyOp& copyop=CopyOp::SHALLOW_COPY): |
|---|
| 355 | PrimitiveSet(copy,copyop) {} |
|---|
| 356 | |
|---|
| 357 | |
|---|
| 358 | virtual DrawElements* getDrawElements() { return this; } |
|---|
| 359 | virtual const DrawElements* getDrawElements() const { return this; } |
|---|
| 360 | |
|---|
| 361 | /** Set the ElementBufferObject.*/ |
|---|
| 362 | inline void setElementBufferObject(osg::ElementBufferObject* ebo) { setBufferObject(ebo); } |
|---|
| 363 | |
|---|
| 364 | /** Get the ElementBufferObject. If no EBO is assigned returns NULL*/ |
|---|
| 365 | inline osg::ElementBufferObject* getElementBufferObject() { return dynamic_cast<osg::ElementBufferObject*>(_bufferObject.get()); } |
|---|
| 366 | |
|---|
| 367 | /** Get the const ElementBufferObject. If no EBO is assigned returns NULL*/ |
|---|
| 368 | inline const osg::ElementBufferObject* getElementBufferObject() const { return dynamic_cast<const osg::ElementBufferObject*>(_bufferObject.get()); } |
|---|
| 369 | |
|---|
| 370 | virtual void reserveElements(unsigned int numIndices) = 0; |
|---|
| 371 | virtual void setElement(unsigned int, unsigned int) = 0; |
|---|
| 372 | virtual unsigned int getElement(unsigned int) = 0; |
|---|
| 373 | virtual void addElement(unsigned int) = 0; |
|---|
| 374 | |
|---|
| 375 | protected: |
|---|
| 376 | |
|---|
| 377 | virtual ~DrawElements() {} |
|---|
| 378 | }; |
|---|
| 379 | |
|---|
| 380 | class OSG_EXPORT DrawElementsUByte : public DrawElements, public VectorGLubyte |
|---|
| 381 | { |
|---|
| 382 | public: |
|---|
| 383 | |
|---|
| 384 | typedef VectorGLubyte vector_type; |
|---|
| 385 | |
|---|
| 386 | DrawElementsUByte(GLenum mode=0): |
|---|
| 387 | DrawElements(DrawElementsUBytePrimitiveType,mode) {} |
|---|
| 388 | |
|---|
| 389 | DrawElementsUByte(const DrawElementsUByte& array, const CopyOp& copyop=CopyOp::SHALLOW_COPY): |
|---|
| 390 | DrawElements(array,copyop), |
|---|
| 391 | vector_type(array) {} |
|---|
| 392 | |
|---|
| 393 | DrawElementsUByte(GLenum mode, unsigned int no, const GLubyte* ptr, int numInstances=0) : |
|---|
| 394 | DrawElements(DrawElementsUBytePrimitiveType,mode,numInstances), |
|---|
| 395 | vector_type(ptr,ptr+no) {} |
|---|
| 396 | |
|---|
| 397 | DrawElementsUByte(GLenum mode, unsigned int no) : |
|---|
| 398 | DrawElements(DrawElementsUBytePrimitiveType,mode), |
|---|
| 399 | vector_type(no) {} |
|---|
| 400 | |
|---|
| 401 | virtual Object* cloneType() const { return new DrawElementsUByte(); } |
|---|
| 402 | virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUByte(*this,copyop); } |
|---|
| 403 | virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsUByte*>(obj)!=NULL; } |
|---|
| 404 | virtual const char* libraryName() const { return "osg"; } |
|---|
| 405 | virtual const char* className() const { return "DrawElementsUByte"; } |
|---|
| 406 | |
|---|
| 407 | virtual const GLvoid* getDataPointer() const { return empty()?0:&front(); } |
|---|
| 408 | virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(size()); } |
|---|
| 409 | virtual bool supportsBufferObject() const { return false; } |
|---|
| 410 | |
|---|
| 411 | virtual void draw(State& state, bool useVertexBufferObjects) const ; |
|---|
| 412 | |
|---|
| 413 | virtual void accept(PrimitiveFunctor& functor) const; |
|---|
| 414 | virtual void accept(PrimitiveIndexFunctor& functor) const; |
|---|
| 415 | |
|---|
| 416 | virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(size()); } |
|---|
| 417 | virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; } |
|---|
| 418 | virtual void offsetIndices(int offset); |
|---|
| 419 | |
|---|
| 420 | virtual void computeRange() const |
|---|
| 421 | { |
|---|
| 422 | if (empty()) |
|---|
| 423 | { |
|---|
| 424 | _minIndex = 0; |
|---|
| 425 | _maxIndex = 0; |
|---|
| 426 | _rangeModifiedCount = _modifiedCount; |
|---|
| 427 | return; |
|---|
| 428 | } |
|---|
| 429 | |
|---|
| 430 | _minIndex = front(); |
|---|
| 431 | _maxIndex = _minIndex; |
|---|
| 432 | |
|---|
| 433 | for(vector_type::const_iterator itr=begin(); itr!=end(); ++itr) |
|---|
| 434 | { |
|---|
| 435 | if (*itr<_minIndex) _minIndex = *itr; |
|---|
| 436 | if (*itr>_maxIndex) _maxIndex = *itr; |
|---|
| 437 | } |
|---|
| 438 | _rangeModifiedCount = _modifiedCount; |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | virtual void reserveElements(unsigned int numIndices) { reserve(numIndices); } |
|---|
| 442 | virtual void setElement(unsigned int i, unsigned int v) { (*this)[i] = v; } |
|---|
| 443 | virtual unsigned int getElement(unsigned int i) { return (*this)[i]; } |
|---|
| 444 | virtual void addElement(unsigned int v) { push_back(GLubyte(v)); } |
|---|
| 445 | |
|---|
| 446 | protected: |
|---|
| 447 | |
|---|
| 448 | virtual ~DrawElementsUByte(); |
|---|
| 449 | |
|---|
| 450 | mutable unsigned int _minIndex; |
|---|
| 451 | mutable unsigned int _maxIndex; |
|---|
| 452 | }; |
|---|
| 453 | |
|---|
| 454 | |
|---|
| 455 | class OSG_EXPORT DrawElementsUShort : public DrawElements, public VectorGLushort |
|---|
| 456 | { |
|---|
| 457 | public: |
|---|
| 458 | |
|---|
| 459 | typedef VectorGLushort vector_type; |
|---|
| 460 | |
|---|
| 461 | DrawElementsUShort(GLenum mode=0): |
|---|
| 462 | DrawElements(DrawElementsUShortPrimitiveType,mode) {} |
|---|
| 463 | |
|---|
| 464 | DrawElementsUShort(const DrawElementsUShort& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): |
|---|
| 465 | DrawElements(array,copyop), |
|---|
| 466 | vector_type(array) {} |
|---|
| 467 | |
|---|
| 468 | DrawElementsUShort(GLenum mode, unsigned int no, const GLushort* ptr, int numInstances=0) : |
|---|
| 469 | DrawElements(DrawElementsUShortPrimitiveType,mode,numInstances), |
|---|
| 470 | vector_type(ptr,ptr+no) {} |
|---|
| 471 | |
|---|
| 472 | DrawElementsUShort(GLenum mode, unsigned int no) : |
|---|
| 473 | DrawElements(DrawElementsUShortPrimitiveType,mode), |
|---|
| 474 | vector_type(no) {} |
|---|
| 475 | |
|---|
| 476 | template <class InputIterator> |
|---|
| 477 | DrawElementsUShort(GLenum mode, InputIterator first,InputIterator last) : |
|---|
| 478 | DrawElements(DrawElementsUShortPrimitiveType,mode), |
|---|
| 479 | vector_type(first,last) {} |
|---|
| 480 | |
|---|
| 481 | virtual Object* cloneType() const { return new DrawElementsUShort(); } |
|---|
| 482 | virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUShort(*this,copyop); } |
|---|
| 483 | virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsUShort*>(obj)!=NULL; } |
|---|
| 484 | virtual const char* libraryName() const { return "osg"; } |
|---|
| 485 | virtual const char* className() const { return "DrawElementsUShort"; } |
|---|
| 486 | |
|---|
| 487 | virtual const GLvoid* getDataPointer() const { return empty()?0:&front(); } |
|---|
| 488 | virtual unsigned int getTotalDataSize() const { return 2u*static_cast<unsigned int>(size()); } |
|---|
| 489 | virtual bool supportsBufferObject() const { return false; } |
|---|
| 490 | |
|---|
| 491 | virtual void draw(State& state, bool useVertexBufferObjects) const; |
|---|
| 492 | |
|---|
| 493 | virtual void accept(PrimitiveFunctor& functor) const; |
|---|
| 494 | virtual void accept(PrimitiveIndexFunctor& functor) const; |
|---|
| 495 | |
|---|
| 496 | virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(size()); } |
|---|
| 497 | virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; } |
|---|
| 498 | virtual void offsetIndices(int offset); |
|---|
| 499 | |
|---|
| 500 | virtual void computeRange() const |
|---|
| 501 | { |
|---|
| 502 | if (empty()) |
|---|
| 503 | { |
|---|
| 504 | _minIndex = 0; |
|---|
| 505 | _maxIndex = 0; |
|---|
| 506 | _rangeModifiedCount = _modifiedCount; |
|---|
| 507 | return; |
|---|
| 508 | } |
|---|
| 509 | |
|---|
| 510 | _minIndex = front(); |
|---|
| 511 | _maxIndex = _minIndex; |
|---|
| 512 | |
|---|
| 513 | for(vector_type::const_iterator itr=begin(); itr!=end(); ++itr) |
|---|
| 514 | { |
|---|
| 515 | if (*itr<_minIndex) _minIndex = *itr; |
|---|
| 516 | if (*itr>_maxIndex) _maxIndex = *itr; |
|---|
| 517 | } |
|---|
| 518 | _rangeModifiedCount = _modifiedCount; |
|---|
| 519 | } |
|---|
| 520 | |
|---|
| 521 | virtual void reserveElements(unsigned int numIndices) { reserve(numIndices); } |
|---|
| 522 | virtual void setElement(unsigned int i, unsigned int v) { (*this)[i] = v; } |
|---|
| 523 | virtual unsigned int getElement(unsigned int i) { return (*this)[i]; } |
|---|
| 524 | virtual void addElement(unsigned int v) { push_back(GLushort(v)); } |
|---|
| 525 | |
|---|
| 526 | protected: |
|---|
| 527 | |
|---|
| 528 | virtual ~DrawElementsUShort(); |
|---|
| 529 | |
|---|
| 530 | mutable unsigned int _minIndex; |
|---|
| 531 | mutable unsigned int _maxIndex; |
|---|
| 532 | }; |
|---|
| 533 | |
|---|
| 534 | class OSG_EXPORT DrawElementsUInt : public DrawElements, public VectorGLuint |
|---|
| 535 | { |
|---|
| 536 | public: |
|---|
| 537 | |
|---|
| 538 | typedef VectorGLuint vector_type; |
|---|
| 539 | |
|---|
| 540 | DrawElementsUInt(GLenum mode=0): |
|---|
| 541 | DrawElements(DrawElementsUIntPrimitiveType,mode) {} |
|---|
| 542 | |
|---|
| 543 | DrawElementsUInt(const DrawElementsUInt& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): |
|---|
| 544 | DrawElements(array,copyop), |
|---|
| 545 | vector_type(array) {} |
|---|
| 546 | |
|---|
| 547 | DrawElementsUInt(GLenum mode, unsigned int no, const GLuint* ptr, int numInstances=0) : |
|---|
| 548 | DrawElements(DrawElementsUIntPrimitiveType,mode,numInstances), |
|---|
| 549 | vector_type(ptr,ptr+no) {} |
|---|
| 550 | |
|---|
| 551 | DrawElementsUInt(GLenum mode, unsigned int no) : |
|---|
| 552 | DrawElements(DrawElementsUIntPrimitiveType,mode), |
|---|
| 553 | vector_type(no) {} |
|---|
| 554 | |
|---|
| 555 | template <class InputIterator> |
|---|
| 556 | DrawElementsUInt(GLenum mode, InputIterator first,InputIterator last) : |
|---|
| 557 | DrawElements(DrawElementsUIntPrimitiveType,mode), |
|---|
| 558 | vector_type(first,last) {} |
|---|
| 559 | |
|---|
| 560 | virtual Object* cloneType() const { return new DrawElementsUInt(); } |
|---|
| 561 | virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUInt(*this,copyop); } |
|---|
| 562 | virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsUInt*>(obj)!=NULL; } |
|---|
| 563 | virtual const char* libraryName() const { return "osg"; } |
|---|
| 564 | virtual const char* className() const { return "DrawElementsUInt"; } |
|---|
| 565 | |
|---|
| 566 | virtual const GLvoid* getDataPointer() const { return empty()?0:&front(); } |
|---|
| 567 | virtual unsigned int getTotalDataSize() const { return 4u*static_cast<unsigned int>(size()); } |
|---|
| 568 | virtual bool supportsBufferObject() const { return false; } |
|---|
| 569 | |
|---|
| 570 | virtual void draw(State& state, bool useVertexBufferObjects) const; |
|---|
| 571 | |
|---|
| 572 | virtual void accept(PrimitiveFunctor& functor) const; |
|---|
| 573 | virtual void accept(PrimitiveIndexFunctor& functor) const; |
|---|
| 574 | |
|---|
| 575 | virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(size()); } |
|---|
| 576 | virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; } |
|---|
| 577 | virtual void offsetIndices(int offset); |
|---|
| 578 | |
|---|
| 579 | |
|---|
| 580 | virtual void computeRange() const |
|---|
| 581 | { |
|---|
| 582 | if (empty()) |
|---|
| 583 | { |
|---|
| 584 | _minIndex = 0; |
|---|
| 585 | _maxIndex = 0; |
|---|
| 586 | _rangeModifiedCount = _modifiedCount; |
|---|
| 587 | return; |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | _minIndex = front(); |
|---|
| 591 | _maxIndex = _minIndex; |
|---|
| 592 | |
|---|
| 593 | for(vector_type::const_iterator itr=begin(); itr!=end(); ++itr) |
|---|
| 594 | { |
|---|
| 595 | if (*itr<_minIndex) _minIndex = *itr; |
|---|
| 596 | if (*itr>_maxIndex) _maxIndex = *itr; |
|---|
| 597 | } |
|---|
| 598 | _rangeModifiedCount = _modifiedCount; |
|---|
| 599 | } |
|---|
| 600 | |
|---|
| 601 | virtual void reserveElements(unsigned int numIndices) { reserve(numIndices); } |
|---|
| 602 | virtual void setElement(unsigned int i, unsigned int v) { (*this)[i] = v; } |
|---|
| 603 | virtual unsigned int getElement(unsigned int i) { return (*this)[i]; } |
|---|
| 604 | virtual void addElement(unsigned int v) { push_back(GLuint(v)); } |
|---|
| 605 | |
|---|
| 606 | protected: |
|---|
| 607 | |
|---|
| 608 | virtual ~DrawElementsUInt(); |
|---|
| 609 | |
|---|
| 610 | mutable unsigned int _minIndex; |
|---|
| 611 | mutable unsigned int _maxIndex; |
|---|
| 612 | }; |
|---|
| 613 | |
|---|
| 614 | } |
|---|
| 615 | |
|---|
| 616 | #endif |
|---|