Changeset 13041 for OpenSceneGraph/trunk/include/osg/PrimitiveSet
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/include/osg/PrimitiveSet (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osg/PrimitiveSet
r12912 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 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 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 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 152 152 { 153 153 public: 154 154 155 155 enum Type 156 156 { … … 175 175 QUAD_STRIP = GL_QUAD_STRIP, 176 176 POLYGON = GL_POLYGON, 177 LINES_ADJACENCY = GL_LINES_ADJACENCY_EXT, 178 LINE_STRIP_ADJACENCY = GL_LINE_STRIP_ADJACENCY_EXT, 179 TRIANGLES_ADJACENCY = GL_TRIANGLES_ADJACENCY_EXT, 177 LINES_ADJACENCY = GL_LINES_ADJACENCY_EXT, 178 LINE_STRIP_ADJACENCY = GL_LINE_STRIP_ADJACENCY_EXT, 179 TRIANGLES_ADJACENCY = GL_TRIANGLES_ADJACENCY_EXT, 180 180 TRIANGLE_STRIP_ADJACENCY = GL_TRIANGLE_STRIP_ADJACENCY_EXT, 181 181 PATCHES = GL_PATCHES … … 186 186 _numInstances(numInstances), 187 187 _mode(mode) {} 188 188 189 189 PrimitiveSet(const PrimitiveSet& prim,const CopyOp& copyop=CopyOp::SHALLOW_COPY): 190 190 BufferData(prim,copyop), … … 196 196 virtual const char* libraryName() const { return "osg"; } 197 197 virtual const char* className() const { return "PrimitiveSet"; } 198 198 199 199 Type getType() const { return _primitiveType; } 200 200 … … 208 208 virtual DrawElements* getDrawElements() { return 0; } 209 209 virtual const DrawElements* getDrawElements() const { return 0; } 210 210 211 211 void setNumInstances(int n) { _numInstances = n; } 212 212 int getNumInstances() const { return _numInstances; } … … 216 216 217 217 virtual void draw(State& state, bool useVertexBufferObjects) const = 0; 218 218 219 219 virtual void accept(PrimitiveFunctor& functor) const = 0; 220 220 virtual void accept(PrimitiveIndexFunctor& functor) const = 0; 221 221 222 222 virtual unsigned int index(unsigned int pos) const = 0; 223 223 virtual unsigned int getNumIndices() const = 0; 224 224 virtual void offsetIndices(int offset) = 0; 225 225 226 virtual unsigned int getNumPrimitives() const; 226 virtual unsigned int getNumPrimitives() const; 227 227 228 228 virtual void computeRange() const {} … … 245 245 _first(0), 246 246 _count(0) {} 247 247 248 248 DrawArrays(GLenum mode, GLint first, GLsizei count, int numInstances=0): 249 249 PrimitiveSet(DrawArraysPrimitiveType, mode, numInstances), … … 257 257 258 258 virtual Object* cloneType() const { return new DrawArrays(); } 259 virtual Object* clone(const CopyOp& copyop) const { return new DrawArrays(*this,copyop); } 259 virtual Object* clone(const CopyOp& copyop) const { return new DrawArrays(*this,copyop); } 260 260 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawArrays*>(obj)!=NULL; } 261 261 virtual const char* libraryName() const { return "osg"; } 262 262 virtual const char* className() const { return "DrawArrays"; } 263 263 264 264 265 265 void set(GLenum mode,GLint first, GLsizei count) … … 272 272 void setFirst(GLint first) { _first = first; } 273 273 GLint getFirst() const { return _first; } 274 274 275 275 void setCount(GLsizei count) { _count = count; } 276 276 GLsizei getCount() const { return _count; } 277 277 278 278 virtual void draw(State& state, bool useVertexBufferObjects) const; 279 279 280 280 virtual void accept(PrimitiveFunctor& functor) const; 281 281 virtual void accept(PrimitiveIndexFunctor& functor) const; 282 282 283 283 virtual unsigned int getNumIndices() const { return static_cast<unsigned int>(_count); } 284 284 virtual unsigned int index(unsigned int pos) const { return static_cast<unsigned int>(_first)+pos; } … … 302 302 PrimitiveSet(DrawArrayLengthsPrimitiveType,mode), 303 303 _first(0) {} 304 304 305 305 DrawArrayLengths(const DrawArrayLengths& dal,const CopyOp& copyop=CopyOp::SHALLOW_COPY): 306 306 PrimitiveSet(dal,copyop), … … 308 308 _first(dal._first) {} 309 309 310 DrawArrayLengths(GLenum mode, GLint first, unsigned int no, GLsizei* ptr) : 310 DrawArrayLengths(GLenum mode, GLint first, unsigned int no, GLsizei* ptr) : 311 311 PrimitiveSet(DrawArrayLengthsPrimitiveType,mode), 312 312 vector_type(ptr,ptr+no), 313 313 _first(first) {} 314 314 315 DrawArrayLengths(GLenum mode,GLint first, unsigned int no) : 315 DrawArrayLengths(GLenum mode,GLint first, unsigned int no) : 316 316 PrimitiveSet(DrawArrayLengthsPrimitiveType,mode), 317 317 vector_type(no), 318 318 _first(first) {} 319 319 320 DrawArrayLengths(GLenum mode,GLint first) : 320 DrawArrayLengths(GLenum mode,GLint first) : 321 321 PrimitiveSet(DrawArrayLengthsPrimitiveType,mode), 322 322 vector_type(), … … 325 325 326 326 virtual Object* cloneType() const { return new DrawArrayLengths(); } 327 virtual Object* clone(const CopyOp& copyop) const { return new DrawArrayLengths(*this,copyop); } 327 virtual Object* clone(const CopyOp& copyop) const { return new DrawArrayLengths(*this,copyop); } 328 328 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawArrayLengths*>(obj)!=NULL; } 329 329 virtual const char* libraryName() const { return "osg"; } 330 330 virtual const char* className() const { return "DrawArrayLengths"; } 331 331 332 332 333 333 void setFirst(GLint first) { _first = first; } 334 334 GLint getFirst() const { return _first; } 335 335 336 336 virtual void draw(State& state, bool useVertexBufferObjects) const; 337 337 338 338 virtual void accept(PrimitiveFunctor& functor) const; 339 339 virtual void accept(PrimitiveIndexFunctor& functor) const; 340 340 341 341 virtual unsigned int getNumIndices() const; 342 342 virtual unsigned int index(unsigned int pos) const { return _first+pos; } … … 355 355 { 356 356 public: 357 357 358 358 DrawElements(Type primType=PrimitiveType, GLenum mode=0, int numInstances=0): 359 359 PrimitiveSet(primType,mode, numInstances) {} 360 360 361 361 DrawElements(const DrawElements& copy,const CopyOp& copyop=CopyOp::SHALLOW_COPY): 362 362 PrimitiveSet(copy,copyop) {} … … 388 388 { 389 389 public: 390 390 391 391 typedef VectorGLubyte vector_type; 392 392 393 393 DrawElementsUByte(GLenum mode=0): 394 394 DrawElements(DrawElementsUBytePrimitiveType,mode) {} 395 395 396 396 DrawElementsUByte(const DrawElementsUByte& array, const CopyOp& copyop=CopyOp::SHALLOW_COPY): 397 397 DrawElements(array,copyop), … … 401 401 * \param no Number of intended elements. This will be the size of the underlying vector. 402 402 */ 403 DrawElementsUByte(GLenum mode, unsigned int no, const GLubyte* ptr, int numInstances=0) : 403 DrawElementsUByte(GLenum mode, unsigned int no, const GLubyte* ptr, int numInstances=0) : 404 404 DrawElements(DrawElementsUBytePrimitiveType,mode,numInstances), 405 405 vector_type(ptr,ptr+no) {} … … 408 408 * \param no Number of intended elements. This will be the size of the underlying vector. 409 409 */ 410 DrawElementsUByte(GLenum mode, unsigned int no) : 410 DrawElementsUByte(GLenum mode, unsigned int no) : 411 411 DrawElements(DrawElementsUBytePrimitiveType,mode), 412 412 vector_type(no) {} 413 413 414 414 virtual Object* cloneType() const { return new DrawElementsUByte(); } 415 virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUByte(*this,copyop); } 415 virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUByte(*this,copyop); } 416 416 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsUByte*>(obj)!=NULL; } 417 417 virtual const char* libraryName() const { return "osg"; } … … 423 423 424 424 virtual void draw(State& state, bool useVertexBufferObjects) const ; 425 425 426 426 virtual void accept(PrimitiveFunctor& functor) const; 427 427 virtual void accept(PrimitiveIndexFunctor& functor) const; … … 430 430 virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; } 431 431 virtual void offsetIndices(int offset); 432 432 433 433 virtual void reserveElements(unsigned int numIndices) { reserve(numIndices); } 434 434 virtual void setElement(unsigned int i, unsigned int v) { (*this)[i] = v; } 435 virtual unsigned int getElement(unsigned int i) { return (*this)[i]; } 436 virtual void addElement(unsigned int v) { push_back(GLubyte(v)); } 435 virtual unsigned int getElement(unsigned int i) { return (*this)[i]; } 436 virtual void addElement(unsigned int v) { push_back(GLubyte(v)); } 437 437 438 438 protected: … … 450 450 DrawElementsUShort(GLenum mode=0): 451 451 DrawElements(DrawElementsUShortPrimitiveType,mode) {} 452 452 453 453 DrawElementsUShort(const DrawElementsUShort& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): 454 454 DrawElements(array,copyop), … … 458 458 * \param no Number of intended elements. This will be the size of the underlying vector. 459 459 */ 460 DrawElementsUShort(GLenum mode, unsigned int no, const GLushort* ptr, int numInstances=0) : 460 DrawElementsUShort(GLenum mode, unsigned int no, const GLushort* ptr, int numInstances=0) : 461 461 DrawElements(DrawElementsUShortPrimitiveType,mode,numInstances), 462 462 vector_type(ptr,ptr+no) {} … … 465 465 * \param no Number of intended elements. This will be the size of the underlying vector. 466 466 */ 467 DrawElementsUShort(GLenum mode, unsigned int no) : 467 DrawElementsUShort(GLenum mode, unsigned int no) : 468 468 DrawElements(DrawElementsUShortPrimitiveType,mode), 469 469 vector_type(no) {} 470 470 471 471 template <class InputIterator> 472 DrawElementsUShort(GLenum mode, InputIterator first,InputIterator last) : 472 DrawElementsUShort(GLenum mode, InputIterator first,InputIterator last) : 473 473 DrawElements(DrawElementsUShortPrimitiveType,mode), 474 474 vector_type(first,last) {} 475 475 476 476 virtual Object* cloneType() const { return new DrawElementsUShort(); } 477 virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUShort(*this,copyop); } 477 virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUShort(*this,copyop); } 478 478 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsUShort*>(obj)!=NULL; } 479 479 virtual const char* libraryName() const { return "osg"; } … … 485 485 486 486 virtual void draw(State& state, bool useVertexBufferObjects) const; 487 487 488 488 virtual void accept(PrimitiveFunctor& functor) const; 489 489 virtual void accept(PrimitiveIndexFunctor& functor) const; … … 511 511 DrawElementsUInt(GLenum mode=0): 512 512 DrawElements(DrawElementsUIntPrimitiveType,mode) {} 513 513 514 514 DrawElementsUInt(const DrawElementsUInt& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): 515 515 DrawElements(array,copyop), … … 520 520 * \param no Number of intended elements. This will be the size of the underlying vector. 521 521 */ 522 DrawElementsUInt(GLenum mode, unsigned int no, const GLuint* ptr, int numInstances=0) : 522 DrawElementsUInt(GLenum mode, unsigned int no, const GLuint* ptr, int numInstances=0) : 523 523 DrawElements(DrawElementsUIntPrimitiveType,mode,numInstances), 524 524 vector_type(ptr,ptr+no) {} … … 527 527 * \param no Number of intended elements. This will be the size of the underlying vector. 528 528 */ 529 DrawElementsUInt(GLenum mode, unsigned int no) : 529 DrawElementsUInt(GLenum mode, unsigned int no) : 530 530 DrawElements(DrawElementsUIntPrimitiveType,mode), 531 531 vector_type(no) {} 532 532 533 533 template <class InputIterator> 534 DrawElementsUInt(GLenum mode, InputIterator first,InputIterator last) : 534 DrawElementsUInt(GLenum mode, InputIterator first,InputIterator last) : 535 535 DrawElements(DrawElementsUIntPrimitiveType,mode), 536 536 vector_type(first,last) {} 537 537 538 538 virtual Object* cloneType() const { return new DrawElementsUInt(); } 539 virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUInt(*this,copyop); } 539 virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUInt(*this,copyop); } 540 540 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsUInt*>(obj)!=NULL; } 541 541 virtual const char* libraryName() const { return "osg"; } … … 547 547 548 548 virtual void draw(State& state, bool useVertexBufferObjects) const; 549 549 550 550 virtual void accept(PrimitiveFunctor& functor) const; 551 551 virtual void accept(PrimitiveIndexFunctor& functor) const;
