Exemplo n.º 1
0
unsigned int BufferObject::computeRequiredBufferSize() const
{
    unsigned int newTotalSize = 0;
    for(BufferDataList::const_iterator itr = _bufferDataList.begin();
        itr != _bufferDataList.end();
        ++itr)
    {
        BufferData* bd = *itr;
        newTotalSize += bd->getTotalDataSize();
    }
    return newTotalSize;
}
Exemplo n.º 2
0
unsigned int BufferObject::computeRequiredBufferSize() const
{
    unsigned int newTotalSize = 0;
    for(BufferDataList::const_iterator itr = _bufferDataList.begin();
        itr != _bufferDataList.end();
        ++itr)
    {
        BufferData* bd = *itr;
        if (bd) newTotalSize += bd->getTotalDataSize();
        else
        {
            OSG_NOTICE<<"BufferObject::"<<this<<":"<<className()<<"::BufferObject::computeRequiredBufferSize() error, BufferData is 0x0"<<std::endl;
        }
    }
    //OSG_NOTICE<<"BufferObject::"<<this<<":"<<className()<<"::BufferObject::computeRequiredBufferSize() size="<<newTotalSize<<std::endl;
    return newTotalSize;
}
Exemplo n.º 3
0
void GLBufferObject::compileBuffer()
{
    _dirty = false;

    _bufferEntries.reserve(_bufferObject->getNumBufferData());

    bool compileAll = false;
    bool offsetChanged = false;

    unsigned int newTotalSize = 0;
    unsigned int i=0;
    for(; i<_bufferObject->getNumBufferData(); ++i)
    {
        BufferData* bd = _bufferObject->getBufferData(i);
        if (i<_bufferEntries.size())
        {
            BufferEntry& entry = _bufferEntries[i];
            if (offsetChanged ||
                entry.dataSource != bd ||
                entry.dataSize != bd->getTotalDataSize())
            {
                unsigned int previousEndOfBufferDataMarker = entry.offset + entry.dataSize;

                // OSG_NOTIFY(osg::NOTICE)<<"GLBufferObject::compileBuffer(..) updating BufferEntry"<<std::endl;


                entry.offset = newTotalSize;
                entry.modifiedCount = 0xffffff;
                entry.dataSize = bd->getTotalDataSize();
                entry.dataSource = bd;

                newTotalSize += entry.dataSize;
                if (previousEndOfBufferDataMarker==newTotalSize)
                {
                    offsetChanged = true;
                }
            }
        }
        else
        {
            BufferEntry entry;
            entry.offset = newTotalSize;
            entry.modifiedCount = 0xffffff;
            entry.dataSize = bd->getTotalDataSize();
            entry.dataSource = bd;
#if 0
            OSG_NOTIFY(osg::NOTICE)<<"entry"<<std::endl;
            OSG_NOTIFY(osg::NOTICE)<<"   offset "<<entry.offset<<std::endl;
            OSG_NOTIFY(osg::NOTICE)<<"   dataSize "<<entry.dataSize<<std::endl;
            OSG_NOTIFY(osg::NOTICE)<<"   dataSource "<<entry.dataSource<<std::endl;
            OSG_NOTIFY(osg::NOTICE)<<"   modifiedCount "<<entry.modifiedCount<<std::endl;
#endif
            newTotalSize += entry.dataSize;

            _bufferEntries.push_back(entry);
        }
    }


    if (i<_bufferEntries.size())
    {
        // triming end of bufferEntries as the source data is has less entries than the originally held.
        _bufferEntries.erase(_bufferEntries.begin()+i, _bufferEntries.end());
    }

    _extensions->glBindBuffer(_profile._target, _glObjectID);

    if (newTotalSize > _profile._size)
    {
        OSG_NOTIFY(osg::INFO)<<"newTotalSize="<<newTotalSize<<", _profile._size="<<_profile._size<<std::endl;

        _profile._size = newTotalSize;

        if (_set)
        {
            _set->moveToSet(this, _set->getParent()->getGLBufferObjectSet(_profile));
        }

    }

    if (_allocatedSize != _profile._size)
    {
        _allocatedSize = _profile._size;
        _extensions->glBufferData(_profile._target, _profile._size, NULL, _profile._usage);
    }

    char* vboMemory = 0;

#if 0
    vboMemory = extensions->glMapBuffer(_target, GL_WRITE_ONLY_ARB);
#endif

    for(BufferEntries::iterator itr = _bufferEntries.begin();
        itr != _bufferEntries.end();
        ++itr)
    {
        BufferEntry& entry = *itr;
        if (compileAll || entry.modifiedCount != entry.dataSource->getModifiedCount())
        {
            // OSG_NOTIFY(osg::NOTICE)<<"GLBufferObject::compileBuffer(..) downloading BufferEntry "<<&entry<<std::endl;
            entry.modifiedCount = entry.dataSource->getModifiedCount();

            if (vboMemory)
                memcpy(vboMemory + (GLsizeiptrARB)entry.offset, entry.dataSource->getDataPointer(), entry.dataSize);
            else
                _extensions->glBufferSubData(_profile._target, (GLintptrARB)entry.offset, (GLsizeiptrARB)entry.dataSize, entry.dataSource->getDataPointer());

        }
    }

    // Unmap the texture image buffer
    if (vboMemory) _extensions->glUnmapBuffer(_profile._target);


}
Exemplo n.º 4
0
void GLBufferObject::compileBuffer()
{
    _dirty = false;

    _bufferEntries.reserve(_bufferObject->getNumBufferData());

    bool compileAll = false;
    bool offsetChanged = false;

    unsigned int bufferAlignment = 4;

    unsigned int newTotalSize = 0;
    unsigned int i=0;
    for(; i<_bufferObject->getNumBufferData(); ++i)
    {
        BufferData* bd = _bufferObject->getBufferData(i);
        if (i<_bufferEntries.size())
        {
            BufferEntry& entry = _bufferEntries[i];
            if (offsetChanged ||
                entry.dataSource != bd ||
                entry.dataSize != bd->getTotalDataSize())
            {
                unsigned int previousEndOfBufferDataMarker = computeBufferAlignment(entry.offset + entry.dataSize, bufferAlignment);

                // OSG_NOTICE<<"GLBufferObject::compileBuffer(..) updating BufferEntry"<<std::endl;

                entry.numRead = 0;
                entry.modifiedCount = 0xffffff;
                entry.offset = newTotalSize;
                entry.dataSize = bd->getTotalDataSize();
                entry.dataSource = bd;

                newTotalSize += entry.dataSize;
                if (previousEndOfBufferDataMarker!=newTotalSize)
                {
                    offsetChanged = true;
                }
            }
            else
            {
                newTotalSize = computeBufferAlignment(newTotalSize + entry.dataSize, bufferAlignment);
            }
        }
        else
        {
            BufferEntry entry;
            entry.offset = newTotalSize;
            entry.modifiedCount = 0xffffff;
            entry.dataSize = bd ? bd->getTotalDataSize() : 0;
            entry.dataSource = bd;
#if 0
            OSG_NOTICE<<"entry"<<std::endl;
            OSG_NOTICE<<"   offset "<<entry.offset<<std::endl;
            OSG_NOTICE<<"   dataSize "<<entry.dataSize<<std::endl;
            OSG_NOTICE<<"   dataSource "<<entry.dataSource<<std::endl;
            OSG_NOTICE<<"   modifiedCount "<<entry.modifiedCount<<std::endl;
#endif
            newTotalSize = computeBufferAlignment(newTotalSize + entry.dataSize, bufferAlignment);

            _bufferEntries.push_back(entry);
        }
    }


    if (i<_bufferEntries.size())
    {
        // triming end of bufferEntries as the source data is has less entries than the originally held.
        _bufferEntries.erase(_bufferEntries.begin()+i, _bufferEntries.end());
    }

    _extensions->glBindBuffer(_profile._target, _glObjectID);

    _extensions->debugObjectLabel(GL_BUFFER, _glObjectID, _bufferObject->getName());

    if (newTotalSize > _profile._size)
    {
        OSG_INFO<<"newTotalSize="<<newTotalSize<<", _profile._size="<<_profile._size<<std::endl;

        unsigned int sizeDifference = newTotalSize - _profile._size;
        _profile._size = newTotalSize;

        if (_set)
        {
            _set->moveToSet(this, _set->getParent()->getGLBufferObjectSet(_profile));
            _set->getParent()->getCurrGLBufferObjectPoolSize() += sizeDifference;
        }

    }

    if (_allocatedSize != _profile._size)
    {
        _allocatedSize = _profile._size;
        OSG_INFO<<"    Allocating new glBufferData(), _allocatedSize="<<_allocatedSize<<std::endl;
        _extensions->glBufferData(_profile._target, _profile._size, NULL, _profile._usage);
        compileAll = true;
    }

    for(BufferEntries::iterator itr = _bufferEntries.begin();
        itr != _bufferEntries.end();
        ++itr)
    {
        BufferEntry& entry = *itr;
        if (entry.dataSource && (compileAll || entry.modifiedCount != entry.dataSource->getModifiedCount()))
        {
            // OSG_NOTICE<<"GLBufferObject::compileBuffer(..) downloading BufferEntry "<<&entry<<std::endl;
            entry.numRead = 0;
            entry.modifiedCount = entry.dataSource->getModifiedCount();

            const osg::Image* image = entry.dataSource->asImage();
            if (image && !(image->isDataContiguous()))
            {
                unsigned int offset = entry.offset;
                for(osg::Image::DataIterator img_itr(image); img_itr.valid(); ++img_itr)
                {
                    _extensions->glBufferSubData(_profile._target, (GLintptr)offset, (GLsizeiptr)img_itr.size(), img_itr.data());
                    offset += img_itr.size();
                }
            }
            else
            {
                _extensions->glBufferSubData(_profile._target, (GLintptr)entry.offset, (GLsizeiptr)entry.dataSize, entry.dataSource->getDataPointer());
            }
        }
    }
}