Changeset 10600 for OpenSceneGraph/trunk/src/osg/BufferObject.cpp
- Timestamp:
- 10/01/09 22:19:42 (4 years ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osg/BufferObject.cpp (modified) (31 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osg/BufferObject.cpp
r9362 r10600 38 38 static DeletedBufferObjectCache s_deletedBufferObjectCache; 39 39 40 void BufferObject::deleteBufferObject(unsigned int contextID,GLuint globj) 40 ////////////////////////////////////////////////////////////////////////////////////////////////////// 41 // 42 // GLBufferObject 43 // 44 GLBufferObject::GLBufferObject(unsigned int contextID, BufferObject* bufferObject): 45 _contextID(contextID), 46 _glObjectID(0), 47 _target(0), 48 _usage(0), 49 _dirty(true), 50 _totalSize(0), 51 _bufferObject(0), 52 _extensions(0) 53 { 54 assign(bufferObject); 55 _extensions = GLBufferObject::getExtensions(contextID, true); 56 _extensions->glGenBuffers(1, &_glObjectID); 57 } 58 59 GLBufferObject::~GLBufferObject() 60 { 61 if (_glObjectID!=0) GLBufferObject::deleteBufferObject(_contextID, _glObjectID); 62 63 } 64 65 void GLBufferObject::assign(BufferObject* bufferObject) 66 { 67 _bufferObject = bufferObject; 68 69 if (_bufferObject) 70 { 71 _target = bufferObject->getTarget(); 72 _usage = bufferObject->getUsage(); 73 74 _totalSize = 0; 75 76 _dirty = true; 77 78 _bufferEntries.clear(); 79 } 80 else 81 { 82 _target = 0; 83 _usage = 0; 84 85 _totalSize = 0; 86 87 // clear all previous entries; 88 _bufferEntries.clear(); 89 } 90 } 91 92 void GLBufferObject::clear() 93 { 94 _bufferEntries.clear(); 95 _dirty = true; 96 } 97 98 void GLBufferObject::compileBuffer() 99 { 100 _dirty = false; 101 102 _bufferEntries.reserve(_bufferObject->getNumBufferData()); 103 104 _totalSize = 0; 105 106 bool compileAll = false; 107 bool offsetChanged = false; 108 109 GLsizeiptrARB newTotalSize = 0; 110 unsigned int i=0; 111 for(; i<_bufferObject->getNumBufferData(); ++i) 112 { 113 BufferData* bd = _bufferObject->getBufferData(i); 114 if (i<_bufferEntries.size()) 115 { 116 BufferEntry& entry = _bufferEntries[i]; 117 if (offsetChanged || 118 entry.dataSource != bd || 119 entry.dataSize != bd->getTotalDataSize()) 120 { 121 GLsizeiptrARB previousEndOfBufferDataMarker = GLsizeiptrARB(entry.offset) + entry.dataSize; 122 123 // osg::notify(osg::NOTICE)<<"GLBufferObject::compileBuffer(..) updating BufferEntry"<<std::endl; 124 125 126 entry.offset = newTotalSize; 127 entry.modifiedCount = 0xffffff; 128 entry.dataSize = bd->getTotalDataSize(); 129 entry.dataSource = bd; 130 131 newTotalSize += entry.dataSize; 132 if (previousEndOfBufferDataMarker==newTotalSize) 133 { 134 offsetChanged = true; 135 } 136 } 137 } 138 else 139 { 140 BufferEntry entry; 141 entry.offset = newTotalSize; 142 entry.modifiedCount = 0xffffff; 143 entry.dataSize = bd->getTotalDataSize(); 144 entry.dataSource = bd; 145 #if 0 146 osg::notify(osg::NOTICE)<<"entry"<<std::endl; 147 osg::notify(osg::NOTICE)<<" offset "<<entry.offset<<std::endl; 148 osg::notify(osg::NOTICE)<<" dataSize "<<entry.dataSize<<std::endl; 149 osg::notify(osg::NOTICE)<<" dataSource "<<entry.dataSource<<std::endl; 150 osg::notify(osg::NOTICE)<<" modifiedCount "<<entry.modifiedCount<<std::endl; 151 #endif 152 newTotalSize += entry.dataSize; 153 154 _bufferEntries.push_back(entry); 155 } 156 } 157 158 if (i<_bufferEntries.size()) 159 { 160 // triming end of bufferEntries as the source data is has less entries than the originally held. 161 _bufferEntries.erase(_bufferEntries.begin()+i, _bufferEntries.end()); 162 } 163 164 _extensions->glBindBuffer(_target, _glObjectID); 165 166 if (newTotalSize != _totalSize) 167 { 168 _totalSize = newTotalSize; 169 _extensions->glBufferData(_target, _totalSize, NULL, _usage); 170 } 171 172 char* vboMemory = 0; 173 174 #if 0 175 vboMemory = extensions->glMapBuffer(_target, GL_WRITE_ONLY_ARB); 176 #endif 177 178 for(BufferEntries::iterator itr = _bufferEntries.begin(); 179 itr != _bufferEntries.end(); 180 ++itr) 181 { 182 BufferEntry& entry = *itr; 183 if (compileAll || entry.modifiedCount != entry.dataSource->getModifiedCount()) 184 { 185 // osg::notify(osg::NOTICE)<<"GLBufferObject::compileBuffer(..) downloading BufferEntry "<<&entry<<std::endl; 186 entry.modifiedCount = entry.dataSource->getModifiedCount(); 187 188 if (vboMemory) 189 memcpy(vboMemory + (GLsizeiptrARB)entry.offset, entry.dataSource->getDataPointer(), entry.dataSize); 190 else 191 _extensions->glBufferSubData(_target, (GLintptrARB)entry.offset, (GLsizeiptrARB)entry.dataSize, entry.dataSource->getDataPointer()); 192 193 } 194 } 195 196 // Unmap the texture image buffer 197 if (vboMemory) _extensions->glUnmapBuffer(_target); 198 } 199 200 GLBufferObject* GLBufferObject::createGLBufferObject(unsigned int contextID, const BufferObject* bufferObject) 201 { 202 return new GLBufferObject(contextID, const_cast<BufferObject*>(bufferObject)); 203 } 204 205 void GLBufferObject::deleteGLObject() 206 { 207 if (_glObjectID!=0) 208 { 209 _extensions->glDeleteBuffers(1, &_glObjectID); 210 _glObjectID = 0; 211 212 _totalSize = 0; 213 _bufferEntries.clear(); 214 } 215 } 216 217 218 void GLBufferObject::deleteBufferObject(unsigned int contextID,GLuint globj) 41 219 { 42 220 if (globj!=0) … … 49 227 } 50 228 51 void BufferObject::flushDeletedBufferObjects(unsigned int contextID,double /*currentTime*/, double& availableTime)229 void GLBufferObject::flushDeletedBufferObjects(unsigned int contextID,double /*currentTime*/, double& availableTime) 52 230 { 53 231 // if no time available don't try to flush objects. … … 85 263 } 86 264 87 void BufferObject::discardDeletedBufferObjects(unsigned int contextID)265 void GLBufferObject::discardDeletedBufferObjects(unsigned int contextID) 88 266 { 89 267 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedBufferObjectCache); … … 92 270 } 93 271 94 95 BufferObject::BufferObject():96 _target(0),97 _usage(0),98 _totalSize(0)99 {100 }101 102 BufferObject::BufferObject(const BufferObject& bo,const CopyOp& copyop):103 Object(bo,copyop)104 {105 }106 107 BufferObject::~BufferObject()108 {109 releaseGLObjects(0);110 }111 112 void BufferObject::resizeGLObjectBuffers(unsigned int maxSize)113 {114 _bufferObjectList.resize(maxSize);115 }116 117 void BufferObject::releaseGLObjects(State* state) const118 {119 if (state)120 {121 unsigned int contextID = state->getContextID();122 if (_bufferObjectList[contextID])123 {124 deleteBufferObject(contextID,_bufferObjectList[contextID]);125 _bufferObjectList[contextID] = 0;126 }127 }128 else129 {130 for(unsigned int contextID=0;contextID<_bufferObjectList.size();++contextID)131 {132 if (_bufferObjectList[contextID])133 {134 deleteBufferObject(contextID,_bufferObjectList[contextID]);135 _bufferObjectList[contextID] = 0;136 }137 }138 }139 }140 141 272 ////////////////////////////////////////////////////////////////////////////// 142 273 // … … 144 275 // 145 276 146 typedef buffered_value< ref_ptr< BufferObject::Extensions> > BufferedExtensions;277 typedef buffered_value< ref_ptr<GLBufferObject::Extensions> > BufferedExtensions; 147 278 static BufferedExtensions s_extensions; 148 279 149 BufferObject::Extensions*BufferObject::getExtensions(unsigned int contextID,bool createIfNotInitalized)150 { 151 if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new BufferObject::Extensions(contextID);280 GLBufferObject::Extensions* GLBufferObject::getExtensions(unsigned int contextID,bool createIfNotInitalized) 281 { 282 if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new GLBufferObject::Extensions(contextID); 152 283 return s_extensions[contextID].get(); 153 284 } 154 285 155 void BufferObject::setExtensions(unsigned int contextID,Extensions* extensions)286 void GLBufferObject::setExtensions(unsigned int contextID,Extensions* extensions) 156 287 { 157 288 s_extensions[contextID] = extensions; 158 289 } 159 290 160 BufferObject::Extensions::Extensions(unsigned int contextID)291 GLBufferObject::Extensions::Extensions(unsigned int contextID) 161 292 { 162 293 setupGLExtensions(contextID); 163 294 } 164 295 165 BufferObject::Extensions::Extensions(const Extensions& rhs):296 GLBufferObject::Extensions::Extensions(const Extensions& rhs): 166 297 Referenced() 167 298 { … … 180 311 181 312 182 void BufferObject::Extensions::lowestCommonDenominator(const Extensions& rhs)313 void GLBufferObject::Extensions::lowestCommonDenominator(const Extensions& rhs) 183 314 { 184 315 if (!rhs._glGenBuffers) _glGenBuffers = rhs._glGenBuffers; … … 195 326 } 196 327 197 void BufferObject::Extensions::setupGLExtensions(unsigned int contextID)328 void GLBufferObject::Extensions::setupGLExtensions(unsigned int contextID) 198 329 { 199 330 setGLExtensionFuncPtr(_glGenBuffers, "glGenBuffers","glGenBuffersARB"); … … 211 342 } 212 343 213 void BufferObject::Extensions::glGenBuffers(GLsizei n, GLuint *buffers) const344 void GLBufferObject::Extensions::glGenBuffers(GLsizei n, GLuint *buffers) const 214 345 { 215 346 if (_glGenBuffers) _glGenBuffers(n, buffers); … … 217 348 } 218 349 219 void BufferObject::Extensions::glBindBuffer(GLenum target, GLuint buffer) const350 void GLBufferObject::Extensions::glBindBuffer(GLenum target, GLuint buffer) const 220 351 { 221 352 if (_glBindBuffer) _glBindBuffer(target, buffer); … … 223 354 } 224 355 225 void BufferObject::Extensions::glBufferData(GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage) const356 void GLBufferObject::Extensions::glBufferData(GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage) const 226 357 { 227 358 if (_glBufferData) _glBufferData(target, size, data, usage); … … 229 360 } 230 361 231 void BufferObject::Extensions::glBufferSubData(GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data) const362 void GLBufferObject::Extensions::glBufferSubData(GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data) const 232 363 { 233 364 if (_glBufferSubData) _glBufferSubData(target, offset, size, data); … … 235 366 } 236 367 237 void BufferObject::Extensions::glDeleteBuffers(GLsizei n, const GLuint *buffers) const368 void GLBufferObject::Extensions::glDeleteBuffers(GLsizei n, const GLuint *buffers) const 238 369 { 239 370 if (_glDeleteBuffers) _glDeleteBuffers(n, buffers); … … 241 372 } 242 373 243 GLboolean BufferObject::Extensions::glIsBuffer (GLuint buffer) const374 GLboolean GLBufferObject::Extensions::glIsBuffer (GLuint buffer) const 244 375 { 245 376 if (_glIsBuffer) return _glIsBuffer(buffer); … … 251 382 } 252 383 253 void BufferObject::Extensions::glGetBufferSubData (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data) const384 void GLBufferObject::Extensions::glGetBufferSubData (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data) const 254 385 { 255 386 if (_glGetBufferSubData) _glGetBufferSubData(target,offset,size,data); … … 257 388 } 258 389 259 GLvoid* BufferObject::Extensions::glMapBuffer (GLenum target, GLenum access) const390 GLvoid* GLBufferObject::Extensions::glMapBuffer (GLenum target, GLenum access) const 260 391 { 261 392 if (_glMapBuffer) return _glMapBuffer(target,access); … … 267 398 } 268 399 269 GLboolean BufferObject::Extensions::glUnmapBuffer (GLenum target) const400 GLboolean GLBufferObject::Extensions::glUnmapBuffer (GLenum target) const 270 401 { 271 402 if (_glUnmapBuffer) return _glUnmapBuffer(target); … … 277 408 } 278 409 279 void BufferObject::Extensions::glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params) const410 void GLBufferObject::Extensions::glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params) const 280 411 { 281 412 if (_glGetBufferParameteriv) _glGetBufferParameteriv(target,pname,params); … … 283 414 } 284 415 285 void BufferObject::Extensions::glGetBufferPointerv (GLenum target, GLenum pname, GLvoid* *params) const416 void GLBufferObject::Extensions::glGetBufferPointerv (GLenum target, GLenum pname, GLvoid* *params) const 286 417 { 287 418 if (_glGetBufferPointerv) _glGetBufferPointerv(target,pname,params); 288 419 else notify(WARN)<<"Error: glGetBufferPointerv not supported by OpenGL driver"<<std::endl; 420 } 421 422 #if 1 423 424 ////////////////////////////////////////////////////////////////////////////////////////////////////// 425 // 426 // BufferObject 427 // 428 BufferObject::BufferObject(): 429 _target(0), 430 _usage(0) 431 { 432 } 433 434 BufferObject::BufferObject(const BufferObject& bo,const CopyOp& copyop): 435 Object(bo,copyop) 436 { 437 } 438 439 BufferObject::~BufferObject() 440 { 441 releaseGLObjects(0); 442 } 443 444 void BufferObject::setBufferData(unsigned int index, BufferData* bd) 445 { 446 if (index>=_bufferDataList.size()) _bufferDataList.resize(index+1); 447 _bufferDataList[index] = bd; 448 } 449 450 void BufferObject::dirty() 451 { 452 for(unsigned int i=0; i<_glBufferObjects.size(); ++i) 453 { 454 if (_glBufferObjects[i].valid()) _glBufferObjects[i]->dirty(); 455 } 456 } 457 458 void BufferObject::resizeGLObjectBuffers(unsigned int maxSize) 459 { 460 _glBufferObjects.resize(maxSize); 461 } 462 463 void BufferObject::releaseGLObjects(State* state) const 464 { 465 if (state) 466 { 467 _glBufferObjects[state->getContextID()] = 0; 468 } 469 else 470 { 471 _glBufferObjects.clear(); 472 } 473 } 474 475 unsigned int BufferObject::addBufferData(BufferData* bd) 476 { 477 if (!bd) return 0; 478 479 // check to see if bd exists in BufferObject already, is so return without doing anything 480 for(BufferDataList::iterator itr = _bufferDataList.begin(); 481 itr != _bufferDataList.end(); 482 ++itr) 483 { 484 if (*itr == bd) return bd->getBufferIndex(); 485 } 486 487 // bd->setBufferIndex(_bufferDataList.size()); 488 489 _bufferDataList.push_back(bd); 490 491 // osg::notify(osg::NOTICE)<<"BufferObject "<<this<<":"<<className()<<"::addBufferData("<<bd<<"), bufferIndex= "<<_bufferDataList.size()-1<<std::endl; 492 493 return _bufferDataList.size()-1; 494 } 495 496 void BufferObject::removeBufferData(unsigned int index) 497 { 498 if (index>=_bufferDataList.size()) 499 { 500 osg::notify(osg::WARN)<<"Error "<<className()<<"::removeBufferData("<<index<<") out of range."<<std::endl; 501 return; 502 } 503 504 // osg::notify(osg::NOTICE)<<"BufferObject::"<<this<<":"<<className()<<"::removeBufferData("<<index<<"), size= "<<_bufferDataList.size()<<std::endl; 505 506 // alter the indices of the BufferData after the entry to be removed so their indices are correctly placed. 507 for(unsigned int i=index+1; i<_bufferDataList.size(); ++i) 508 { 509 _bufferDataList[i]->setBufferIndex(i-1); 510 } 511 512 // remove the entry 513 _bufferDataList.erase(_bufferDataList.begin() + index); 514 515 for(unsigned int i=0; i<_glBufferObjects.size(); ++i) 516 { 517 if (_glBufferObjects[i].valid()) _glBufferObjects[i]->clear(); 518 } 519 520 } 521 522 void BufferObject::removeBufferData(BufferData* bd) 523 { 524 // osg::notify(osg::NOTICE)<<"BufferObject::"<<this<<":"<<className()<<"::removeBufferData("<<bd<<"), index="<<bd->getBufferIndex()<<" size= "<<_bufferDataList.size()<<std::endl; 525 526 if (!bd || bd->getBufferObject()!=this) return; 527 528 removeBufferData(bd->getBufferIndex()); 529 } 530 531 ////////////////////////////////////////////////////////////////////////////////////////////////////// 532 // 533 // BufferData 534 // 535 BufferData::~BufferData() 536 { 537 setBufferObject(0); 538 } 539 540 void BufferData::setBufferObject(BufferObject* bufferObject) 541 { 542 if (_bufferObject==bufferObject) return; 543 544 if (_bufferObject.valid()) 545 { 546 _bufferObject->removeBufferData(_bufferIndex); 547 } 548 549 _bufferObject = bufferObject; 550 _bufferIndex = _bufferObject.valid() ? _bufferObject->addBufferData(this) : 0; 289 551 } 290 552 … … 312 574 unsigned int VertexBufferObject::addArray(osg::Array* array) 313 575 { 314 unsigned int i = _bufferEntryArrayPairs.size(); 315 316 _bufferEntryArrayPairs.resize(i+1); 317 _bufferEntryArrayPairs[i].second = array; 318 _bufferEntryArrayPairs[i].first.modifiedCount.setAllElementsTo(0xffffffff); 319 _bufferEntryArrayPairs[i].first.offset = 0; 320 321 dirty(); 322 323 return i; 576 return addBufferData(array); 324 577 } 325 578 326 579 void VertexBufferObject::removeArray(osg::Array* array) 327 580 { 328 BufferEntryArrayPairs::iterator itr; 329 for(itr = _bufferEntryArrayPairs.begin(); 330 itr != _bufferEntryArrayPairs.end(); 331 ++itr) 332 { 333 if (itr->second == array) break; 334 } 335 if (itr != _bufferEntryArrayPairs.end()) _bufferEntryArrayPairs.erase(itr); 581 removeBufferData(array); 336 582 } 337 583 338 584 void VertexBufferObject::setArray(unsigned int i, Array* array) 339 585 { 340 if (i+1>=_bufferEntryArrayPairs.size()) _bufferEntryArrayPairs.resize(i+1); 341 342 _bufferEntryArrayPairs[i].second = array; 343 _bufferEntryArrayPairs[i].first.modifiedCount.setAllElementsTo(0xffffffff); 344 _bufferEntryArrayPairs[i].first.offset = 0; 345 346 dirty(); 347 } 586 setBufferData(i,array); 587 } 588 589 Array* VertexBufferObject::getArray(unsigned int i) 590 { 591 return dynamic_cast<osg::Array*>(getBufferData(i)); 592 } 593 594 const Array* VertexBufferObject::getArray(unsigned int i) const 595 { 596 return dynamic_cast<const osg::Array*>(getBufferData(i)); 597 } 598 #if 0 348 599 void VertexBufferObject::compileBuffer(State& state) const 349 600 { … … 515 766 // osg::notify(osg::NOTICE)<<"pbo "<<osg::Timer::instance()->delta_m(start_tick,osg::Timer::instance()->tick())<<"ms"<<std::endl; 516 767 } 517 518 void VertexBufferObject::resizeGLObjectBuffers(unsigned int maxSize) 519 { 520 BufferObject::resizeGLObjectBuffers(maxSize); 521 522 for(BufferEntryArrayPairs::iterator itr = _bufferEntryArrayPairs.begin(); 523 itr != _bufferEntryArrayPairs.end(); 524 ++itr) 525 { 526 itr->first.modifiedCount.resize(maxSize); 527 } 528 } 768 #endif 529 769 530 770 ////////////////////////////////////////////////////////////////////////////////// … … 549 789 unsigned int ElementBufferObject::addDrawElements(osg::DrawElements* drawElements) 550 790 { 551 unsigned int i = _bufferEntryDrawElementsPairs.size(); 552 _bufferEntryDrawElementsPairs.resize(i+1); 553 _bufferEntryDrawElementsPairs[i].second = drawElements; 554 _bufferEntryDrawElementsPairs[i].first.modifiedCount.setAllElementsTo(0xffffffff); 555 _bufferEntryDrawElementsPairs[i].first.dataSize = 0; 556 557 return i; 791 return addBufferData(drawElements); 558 792 } 559 793 560 794 void ElementBufferObject::removeDrawElements(osg::DrawElements* drawElements) 561 795 { 562 BufferEntryDrawElementsPairs::iterator itr; 563 for(itr = _bufferEntryDrawElementsPairs.begin(); 564 itr != _bufferEntryDrawElementsPairs.end(); 565 ++itr) 566 { 567 if (itr->second == drawElements) break; 568 } 569 if (itr != _bufferEntryDrawElementsPairs.end()) _bufferEntryDrawElementsPairs.erase(itr); 796 removeBufferData(drawElements); 570 797 } 571 798 572 799 void ElementBufferObject::setDrawElements(unsigned int i, DrawElements* drawElements) 573 800 { 574 if (i+1>=_bufferEntryDrawElementsPairs.size()) _bufferEntryDrawElementsPairs.resize(i+1); 575 576 _bufferEntryDrawElementsPairs[i].second = drawElements; 577 _bufferEntryDrawElementsPairs[i].first.modifiedCount.setAllElementsTo(0xffffffff); 578 _bufferEntryDrawElementsPairs[i].first.dataSize = 0; 579 } 580 801 setBufferData(i,drawElements); 802 } 803 804 DrawElements* ElementBufferObject::getDrawElements(unsigned int i) 805 { 806 return dynamic_cast<DrawElements*>(getBufferData(i)); 807 } 808 809 const DrawElements* ElementBufferObject::getDrawElements(unsigned int i) const 810 { 811 return dynamic_cast<const DrawElements*>(getBufferData(i)); 812 } 813 814 815 #if 0 581 816 void ElementBufferObject::compileBuffer(State& state) const 582 817 { … … 682 917 // osg::notify(osg::NOTICE)<<"pbo "<<osg::Timer::instance()->delta_m(start_tick,osg::Timer::instance()->tick())<<"ms"<<std::endl; 683 918 } 684 685 void ElementBufferObject::resizeGLObjectBuffers(unsigned int maxSize) 686 { 687 BufferObject::resizeGLObjectBuffers(maxSize); 688 689 for(BufferEntryDrawElementsPairs::iterator itr = _bufferEntryDrawElementsPairs.begin(); 690 itr != _bufferEntryDrawElementsPairs.end(); 691 ++itr) 692 { 693 itr->first.modifiedCount.resize(maxSize); 694 } 695 } 919 #endif 696 920 697 921 ////////////////////////////////////////////////////////////////////////////////// … … 704 928 _target = GL_PIXEL_UNPACK_BUFFER_ARB; 705 929 _usage = GL_STREAM_DRAW_ARB; 706 _bufferEntryImagePair.second = image; 707 } 708 709 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ 930 931 osg::notify(osg::NOTICE)<<"Constructing PixelBufferObject for image="<<image<<std::endl; 932 933 setBufferData(0, image); 934 } 935 710 936 PixelBufferObject::PixelBufferObject(const PixelBufferObject& buffer,const CopyOp& copyop): 711 BufferObject(buffer,copyop), 712 _bufferEntryImagePair(buffer._bufferEntryImagePair) 937 BufferObject(buffer,copyop) 713 938 { 714 939 } … … 720 945 void PixelBufferObject::setImage(osg::Image* image) 721 946 { 722 if (_bufferEntryImagePair.second == image) return; 723 724 _bufferEntryImagePair.second = image; 725 726 dirty(); 727 } 947 setBufferData(0, image); 948 } 949 950 Image* PixelBufferObject::getImage() 951 { 952 return dynamic_cast<Image*>(getBufferData(0)); 953 } 954 955 const Image* PixelBufferObject::getImage() const 956 { 957 return dynamic_cast<const Image*>(getBufferData(0)); 958 } 959 960 #if 0 728 961 void PixelBufferObject::compileBuffer(State& state) const 729 962 { … … 782 1015 // osg::notify(osg::NOTICE)<<"pbo "<<osg::Timer::instance()->delta_m(start_tick,osg::Timer::instance()->tick())<<"ms"<<std::endl; 783 1016 } 784 785 void PixelBufferObject::resizeGLObjectBuffers(unsigned int maxSize) 786 { 787 BufferObject::resizeGLObjectBuffers(maxSize); 788 789 _bufferEntryImagePair.first.modifiedCount.resize(maxSize); 790 } 791 1017 #endif 792 1018 793 1019 ////////////////////////////////////////////////////////////////////////////////// … … 800 1026 _target = GL_ARRAY_BUFFER_ARB; 801 1027 _usage = GL_DYNAMIC_DRAW_ARB; 802 _bufferData.dataSize = 0;803 1028 } 804 1029 805 1030 //-------------------------------------------------------------------------------- 806 1031 PixelDataBufferObject::PixelDataBufferObject(const PixelDataBufferObject& buffer,const CopyOp& copyop): 807 BufferObject(buffer,copyop), 808 _bufferData(buffer._bufferData) 1032 BufferObject(buffer,copyop) 809 1033 { 810 1034 } … … 819 1043 { 820 1044 unsigned int contextID = state.getContextID(); 821 if (!isDirty(contextID) || _bufferData.dataSize == 0) return; 822 823 Extensions* extensions = getExtensions(contextID,true); 824 825 GLuint& pbo = buffer(contextID); 826 if (pbo == 0) 827 { 828 extensions->glGenBuffers(1, &pbo); 829 } 830 831 extensions->glBindBuffer(_target, pbo); 832 extensions->glBufferData(_target, _bufferData.dataSize, NULL, _usage); 833 extensions->glBindBuffer(_target, 0); 834 835 _compiledList[contextID] = 1; 1045 if ( _dataSize == 0) return; 1046 1047 GLBufferObject* bo = getOrCreateGLBufferObject(contextID); 1048 if (!bo || !bo->isDirty()) return; 1049 1050 bo->_extensions->glBindBuffer(_target, bo->getGLObjectID()); 1051 bo->_extensions->glBufferData(_target, _dataSize, NULL, _usage); 1052 bo->_extensions->glBindBuffer(_target, 0); 836 1053 } 837 1054 … … 840 1057 { 841 1058 unsigned int contextID = state.getContextID(); 842 if (isDirty(contextID)) compileBuffer(state); 843 844 Extensions* extensions = getExtensions(contextID,true); 845 846 extensions->glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, buffer(contextID)); 1059 1060 GLBufferObject* bo = getOrCreateGLBufferObject(contextID); 1061 if (!bo) return; 1062 1063 if (bo->isDirty()) compileBuffer(state); 1064 1065 bo->_extensions->glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, bo->getGLObjectID()); 1066 847 1067 _mode[contextID] = READ; 848 1068 } … … 852 1072 { 853 1073 unsigned int contextID = state.getContextID(); 854 if (isDirty(contextID)) compileBuffer(state); 855 856 Extensions* extensions = getExtensions(contextID,true); 857 858 extensions->glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer(contextID)); 1074 1075 GLBufferObject* bo = getOrCreateGLBufferObject(contextID); 1076 if (!bo) return; 1077 1078 if (bo->isDirty()) compileBuffer(state); 1079 1080 bo->_extensions->glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, bo->getGLObjectID()); 1081 859 1082 _mode[contextID] = WRITE; 860 1083 } … … 863 1086 void PixelDataBufferObject::unbindBuffer(unsigned int contextID) const 864 1087 { 865 Extensions* extensions =getExtensions(contextID,true);1088 GLBufferObject::Extensions* extensions = GLBufferObject::getExtensions(contextID,true); 866 1089 867 1090 switch(_mode[contextID]) … … 889 1112 } 890 1113 1114 1115 #endif
