Fixed the GLBufferObject size computation so that it takes into account padding.

This commit is contained in:
Robert Osfield
2018-04-19 19:41:51 +01:00
parent bf6db4eee7
commit f95fdd4d4e
2 changed files with 13 additions and 6 deletions

View File

@@ -152,6 +152,14 @@ class BufferObjectProfile
class GLBufferObjectSet;
class GLBufferObjectManager;
inline unsigned int computeBufferAlignment(unsigned int pos, unsigned int bufferAlignment)
{
if (bufferAlignment<2) return pos;
if ((pos%bufferAlignment)==0) return pos;
return ((pos/bufferAlignment)+1)*bufferAlignment;
}
class OSG_EXPORT GLBufferObject : public GraphicsObject
{
public:
@@ -235,9 +243,7 @@ class OSG_EXPORT GLBufferObject : public GraphicsObject
unsigned int computeBufferAlignment(unsigned int pos, unsigned int bufferAlignment) const
{
if (bufferAlignment<2) return pos;
if ((pos%bufferAlignment)==0) return pos;
return ((pos/bufferAlignment)+1)*bufferAlignment;
return osg::computeBufferAlignment(pos, bufferAlignment);
}
unsigned int _contextID;

View File

@@ -140,7 +140,7 @@ void GLBufferObject::compileBuffer()
entry.dataSource != bd ||
entry.dataSize != bd->getTotalDataSize())
{
unsigned int previousEndOfBufferDataMarker = computeBufferAlignment(entry.offset + entry.dataSize, bufferAlignment);
unsigned int previousEndOfBufferDataMarker = osg::computeBufferAlignment(entry.offset + entry.dataSize, bufferAlignment);
// OSG_NOTICE<<"GLBufferObject::compileBuffer(..) updating BufferEntry"<<std::endl;
@@ -158,7 +158,7 @@ void GLBufferObject::compileBuffer()
}
else
{
newTotalSize = computeBufferAlignment(newTotalSize + entry.dataSize, bufferAlignment);
newTotalSize = osg::computeBufferAlignment(newTotalSize + entry.dataSize, bufferAlignment);
}
}
else
@@ -1188,13 +1188,14 @@ void BufferObject::removeBufferData(BufferData* bd)
unsigned int BufferObject::computeRequiredBufferSize() const
{
unsigned int bufferAlignment = 4;
unsigned int newTotalSize = 0;
for(BufferDataList::const_iterator itr = _bufferDataList.begin();
itr != _bufferDataList.end();
++itr)
{
BufferData* bd = *itr;
if (bd) newTotalSize += bd->getTotalDataSize();
if (bd) newTotalSize = osg::computeBufferAlignment(newTotalSize + bd->getTotalDataSize(), bufferAlignment);
else
{
OSG_NOTICE<<"BufferObject::"<<this<<":"<<className()<<"::BufferObject::computeRequiredBufferSize() error, BufferData is 0x0"<<std::endl;