diff --git a/src/osg/BufferObject.cpp b/src/osg/BufferObject.cpp index be914a00d..34adbc7bb 100644 --- a/src/osg/BufferObject.cpp +++ b/src/osg/BufferObject.cpp @@ -1,13 +1,13 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include @@ -28,7 +28,7 @@ using namespace osg; -// static cache of deleted buffer object lists which can only +// static cache of deleted buffer object lists which can only // by completely deleted once the appropriate OpenGL context // is set. Used osg::BufferObject::deleteDisplayList(..) and flushDeletedBufferObjects(..) below. typedef std::multimap DisplayListMap; @@ -42,7 +42,7 @@ void BufferObject::deleteBufferObject(unsigned int contextID,GLuint globj) if (globj!=0) { OpenThreads::ScopedLock lock(s_mutex_deletedBufferObjectCache); - + // insert the globj into the cache for the appropriate context. s_deletedBufferObjectCache[contextID].insert(DisplayListMap::value_type(0,globj)); } @@ -79,8 +79,8 @@ void BufferObject::flushDeletedBufferObjects(unsigned int contextID,double /*cur if (ditr!=dll.begin()) dll.erase(dll.begin(),ditr); if (noDeleted!=0) notify(osg::INFO)<<"Number VBOs deleted = "<=_bufferEntryArrayPairs.size()) _bufferEntryArrayPairs.resize(i+1); - + if (i+1>=_bufferEntryArrayPairs.size()) _bufferEntryArrayPairs.resize(i+1); + _bufferEntryArrayPairs[i].second = array; _bufferEntryArrayPairs[i].first.modifiedCount.setAllElementsTo(0xffffffff); _bufferEntryArrayPairs[i].first.offset = 0; dirty(); -} +} void VertexBufferObject::compileBuffer(State& state) const { unsigned int contextID = state.getContextID(); _compiledList[contextID] = 1; - + Extensions* extensions = getExtensions(contextID,true); // osg::notify(osg::NOTICE)<<"VertexBufferObject::compileBuffer frameNumber="<getFrameNumber()<glGenBuffers(1, &vbo); extensions->glBindBuffer(_target, vbo); extensions->glBufferData(_target, _totalSize, NULL, _usage); - - copyAll = true; + + copyAll = true; } else { @@ -395,15 +395,15 @@ void VertexBufferObject::compileBuffer(State& state) const // resize vbo. _totalSize = totalSizeRequired; extensions->glBufferData(_target, _totalSize, NULL, _usage); - - copyAll = true; + + copyAll = true; } } // osg::Timer_t start_tick = osg::Timer::instance()->tick(); - void* vboMemory = 0; + void* vboMemory = 0; #if 0 vboMemory = extensions->glMapBuffer(_target, GL_WRITE_ONLY_ARB); @@ -418,22 +418,22 @@ void VertexBufferObject::compileBuffer(State& state) const const Array* de = bep.second; if (de) { - if (copyAll || + if (copyAll || bep.first.modifiedCount[contextID] != bep.second->getModifiedCount() || bep.first.dataSize != bep.second->getTotalDataSize()) { // copy data across bep.first.dataSize = bep.second->getTotalDataSize(); bep.first.modifiedCount[contextID] = de->getModifiedCount(); - if (copyAll) + if (copyAll) { bep.first.offset = offset; de->setVertexBufferObjectOffset((GLvoid*)offset); offset += bep.first.dataSize; } - + // osg::notify(osg::NOTICE)<<" copying vertex buffer data "<getDataPointer(), bep.first.dataSize); else @@ -443,10 +443,10 @@ void VertexBufferObject::compileBuffer(State& state) const } } - + // Unmap the texture image buffer if (vboMemory) extensions->glUnmapBuffer(_target); - + // osg::notify(osg::NOTICE)<<"pbo _totalSize="<<_totalSize<delta_m(start_tick,osg::Timer::instance()->tick())<<"ms"<=_bufferEntryDrawElementsPairs.size()) _bufferEntryDrawElementsPairs.resize(i+1); - + if (i+1>=_bufferEntryDrawElementsPairs.size()) _bufferEntryDrawElementsPairs.resize(i+1); + _bufferEntryDrawElementsPairs[i].second = drawElements; _bufferEntryDrawElementsPairs[i].first.modifiedCount.setAllElementsTo(0xffffffff); _bufferEntryDrawElementsPairs[i].first.dataSize = 0; @@ -521,7 +521,7 @@ void ElementBufferObject::compileBuffer(State& state) const _compiledList[contextID] = 1; // osg::notify(osg::NOTICE)<<"ElementBufferObject::compile"<glGenBuffers(1, &ebo); extensions->glBindBuffer(_target, ebo); extensions->glBufferData(_target, _totalSize, NULL, _usage); - - copyAll = true; + + copyAll = true; } else { @@ -564,15 +564,15 @@ void ElementBufferObject::compileBuffer(State& state) const // resize EBO. _totalSize = totalSizeRequired; extensions->glBufferData(_target, _totalSize, NULL, _usage); - - copyAll = true; + + copyAll = true; } } // osg::Timer_t start_tick = osg::Timer::instance()->tick(); - void* eboMemory = 0; + void* eboMemory = 0; #if 0 eboMemory = extensions->glMapBuffer(_target, GL_WRITE_ONLY_ARB); @@ -587,20 +587,20 @@ void ElementBufferObject::compileBuffer(State& state) const const DrawElements* de = bep.second; if (de) { - if (copyAll || + if (copyAll || bep.first.modifiedCount[contextID] != bep.second->getModifiedCount() || bep.first.dataSize != bep.second->getTotalDataSize()) { // copy data across bep.first.dataSize = bep.second->getTotalDataSize(); bep.first.modifiedCount[contextID] = de->getModifiedCount(); - if (copyAll) + if (copyAll) { bep.first.offset = offset; de->setElementBufferObjectOffset((GLvoid*)offset); offset += bep.first.dataSize; } - + if (eboMemory) memcpy((char*)eboMemory + bep.first.offset, de->getDataPointer(), bep.first.dataSize); else @@ -610,7 +610,7 @@ void ElementBufferObject::compileBuffer(State& state) const } } - + // Unmap the texture image buffer if (eboMemory) extensions->glUnmapBuffer(_target); @@ -621,7 +621,7 @@ void ElementBufferObject::compileBuffer(State& state) const void ElementBufferObject::resizeGLObjectBuffers(unsigned int maxSize) { BufferObject::resizeGLObjectBuffers(maxSize); - + for(BufferEntryDrawElementsPairs::iterator itr = _bufferEntryDrawElementsPairs.begin(); itr != _bufferEntryDrawElementsPairs.end(); ++itr) @@ -656,15 +656,15 @@ PixelBufferObject::~PixelBufferObject() void PixelBufferObject::setImage(osg::Image* image) { if (_bufferEntryImagePair.second == image) return; - + _bufferEntryImagePair.second = image; - + dirty(); } void PixelBufferObject::compileBuffer(State& state) const { unsigned int contextID = state.getContextID(); - + _compiledList[contextID] = 1; osg::Image* image = _bufferEntryImagePair.second; @@ -681,13 +681,13 @@ void PixelBufferObject::compileBuffer(State& state) const _totalSize = image->getTotalSizeInBytes(); - // don't generate buffer if size is zero. + // don't generate buffer if size is zero. if (_totalSize==0) return; extensions->glGenBuffers(1, &pbo); extensions->glBindBuffer(_target, pbo); extensions->glBufferData(_target, _totalSize, NULL, _usage); - + } else { @@ -708,7 +708,7 @@ void PixelBufferObject::compileBuffer(State& state) const // copy data across memcpy(pboMemory, image->data(), _totalSize); - + // Unmap the texture image buffer extensions->glUnmapBuffer(_target); @@ -721,6 +721,6 @@ void PixelBufferObject::compileBuffer(State& state) const void PixelBufferObject::resizeGLObjectBuffers(unsigned int maxSize) { BufferObject::resizeGLObjectBuffers(maxSize); - + _bufferEntryImagePair.first.modifiedCount.resize(maxSize); }