Changeset 10600 for OpenSceneGraph/trunk/include/osg/PrimitiveSet
- Timestamp:
- 10/01/09 22:19:42 (4 years ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/include/osg/PrimitiveSet (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osg/PrimitiveSet
r9969 r10600 148 148 class DrawElements; 149 149 150 class OSG_EXPORT PrimitiveSet : public Object150 class OSG_EXPORT PrimitiveSet : public BufferData 151 151 { 152 152 public: … … 180 180 _numInstances(numInstances), 181 181 _mode(mode), 182 _modifiedCount(0),183 182 _rangeModifiedCount(0) {} 184 183 185 184 PrimitiveSet(const PrimitiveSet& prim,const CopyOp& copyop=CopyOp::SHALLOW_COPY): 186 Object(prim,copyop),185 BufferData(prim,copyop), 187 186 _primitiveType(prim._primitiveType), 188 187 _numInstances(prim._numInstances), 189 188 _mode(prim._mode), 190 _modifiedCount(0),191 189 _rangeModifiedCount(0) {} 192 190 … … 220 218 virtual unsigned int getNumPrimitives() const; 221 219 222 /** Dirty the primitive, which increments the modified count, to force buffer objects to update. */223 virtual void dirty() { ++_modifiedCount; }224 225 /** Set the modified count value.*/226 inline void setModifiedCount(unsigned int value) { _modifiedCount=value; }227 228 /** Get modified count value.*/229 inline unsigned int getModifiedCount() const { return _modifiedCount; }230 231 /** Resize any per context GLObject buffers to specified size. */232 virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/) {}233 234 /** If State is non-zero, this function releases OpenGL objects for235 * the specified graphics context. Otherwise, releases OpenGL objects236 * for all graphics contexts. */237 virtual void releaseGLObjects(State* /*state*/=0) const {}238 239 220 virtual void computeRange() const {} 240 221 … … 246 227 int _numInstances; 247 228 GLenum _mode; 248 unsigned int _modifiedCount;249 229 mutable unsigned int _rangeModifiedCount; 250 251 struct ObjectIDModifiedCountPair252 {253 ObjectIDModifiedCountPair():254 _objectID(0),255 _modifiedCount(0) {}256 257 ObjectIDModifiedCountPair(const ObjectIDModifiedCountPair& obj):258 _objectID(obj._objectID),259 _modifiedCount(obj._modifiedCount) {}260 261 ObjectIDModifiedCountPair& operator = (const ObjectIDModifiedCountPair& obj)262 {263 _objectID = obj._objectID;264 _modifiedCount = obj._modifiedCount;265 return *this;266 }267 268 GLuint _objectID;269 unsigned int _modifiedCount;270 };271 272 typedef osg::buffered_object<ObjectIDModifiedCountPair> GLObjectList;273 230 }; 274 231 … … 393 350 394 351 DrawElements(Type primType=PrimitiveType, GLenum mode=0, int numInstances=0): 395 PrimitiveSet(primType,mode, numInstances), 396 _eboOffset(0) {} 352 PrimitiveSet(primType,mode, numInstances) {} 397 353 398 354 DrawElements(const DrawElements& copy,const CopyOp& copyop=CopyOp::SHALLOW_COPY): 399 PrimitiveSet(copy,copyop), 400 _eboOffset(0) {} 355 PrimitiveSet(copy,copyop) {} 401 356 402 357 … … 404 359 virtual const DrawElements* getDrawElements() const { return this; } 405 360 406 virtual void dirty() { ++_modifiedCount; if (_ebo.valid()) _ebo->dirty(); }407 408 361 /** Set the ElementBufferObject.*/ 409 inline void setElementBufferObject(osg::ElementBufferObject* ebo) 410 { 411 if (_ebo == ebo) return; 412 413 if (_ebo.valid()) 414 { 415 _ebo->removeDrawElements(this); 416 } 417 418 _ebo = ebo; 419 420 if (_ebo.valid()) 421 { 422 _ebo->addDrawElements(this); 423 } 424 } 425 362 inline void setElementBufferObject(osg::ElementBufferObject* ebo) { setBufferObject(ebo); } 363 426 364 /** Get the ElementBufferObject. If no EBO is assigned returns NULL*/ 427 inline osg::ElementBufferObject* getElementBufferObject() { return _ebo.get(); }365 inline osg::ElementBufferObject* getElementBufferObject() { return dynamic_cast<osg::ElementBufferObject*>(_bufferObject.get()); } 428 366 429 367 /** Get the const ElementBufferObject. If no EBO is assigned returns NULL*/ 430 inline const osg::ElementBufferObject* getElementBufferObject() const { return _ebo.get(); } 431 432 /** Set the offset into the ElementBufferObject, if used.*/ 433 inline void setElementBufferObjectOffset(const GLvoid* offset) const { _eboOffset = offset; } 434 435 /** Get the offset into the ElementBufferOffset, if used.*/ 436 inline const GLvoid* getElementBufferObjectOffset() const { return _eboOffset; } 437 438 439 /** Resize any per context GLObject buffers to specified size. */ 440 virtual void resizeGLObjectBuffers(unsigned int maxSize) 441 { 442 if (_ebo.valid()) _ebo->resizeGLObjectBuffers(maxSize); 443 } 444 445 /** If State is non-zero, this function releases OpenGL objects for 446 * the specified graphics context. Otherwise, releases OpenGL objects 447 * for all graphics contexts. */ 448 virtual void releaseGLObjects(State* state=0) const 449 { 450 if (_ebo.valid()) _ebo->releaseGLObjects(state); 451 } 452 453 368 inline const osg::ElementBufferObject* getElementBufferObject() const { return dynamic_cast<const osg::ElementBufferObject*>(_bufferObject.get()); } 369 454 370 virtual void reserveElements(unsigned int numIndices) = 0; 455 371 virtual void setElement(unsigned int, unsigned int) = 0; … … 458 374 459 375 protected: 460 461 virtual ~DrawElements() 462 { 463 if (_ebo.valid()) 464 { 465 _ebo->removeDrawElements(this); 466 } 467 } 468 469 osg::ref_ptr<ElementBufferObject> _ebo; 470 mutable const GLvoid* _eboOffset; 471 376 377 virtual ~DrawElements() {} 472 378 }; 473 379
