From 6a6c5bccdabd15dd1428bb0f5133042c40bfa9fd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 14 Jun 2011 10:15:12 +0000 Subject: [PATCH] Added GLBufferObject::computeBufferAlignment(..) method to enable buffer entries to be aligned along specified buffer alignment boundaries, currently defaulting to 4. --- include/osg/BufferObject | 7 +++++++ src/osg/BufferObject.cpp | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/osg/BufferObject b/include/osg/BufferObject index d1315035d..5c3e243a1 100644 --- a/include/osg/BufferObject +++ b/include/osg/BufferObject @@ -334,6 +334,13 @@ class OSG_EXPORT GLBufferObject : public Referenced virtual ~GLBufferObject(); + 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; + } + unsigned int _contextID; GLuint _glObjectID; diff --git a/src/osg/BufferObject.cpp b/src/osg/BufferObject.cpp index 3aea3eaac..c51079c67 100644 --- a/src/osg/BufferObject.cpp +++ b/src/osg/BufferObject.cpp @@ -110,6 +110,8 @@ void GLBufferObject::compileBuffer() bool compileAll = false; bool offsetChanged = false; + unsigned int bufferAlignment = 4; + unsigned int newTotalSize = 0; unsigned int i=0; for(; i<_bufferObject->getNumBufferData(); ++i) @@ -122,7 +124,7 @@ void GLBufferObject::compileBuffer() entry.dataSource != bd || entry.dataSize != bd->getTotalDataSize()) { - unsigned int previousEndOfBufferDataMarker = entry.offset + entry.dataSize; + unsigned int previousEndOfBufferDataMarker = computeBufferAlignment(entry.offset + entry.dataSize, bufferAlignment); // OSG_NOTICE<<"GLBufferObject::compileBuffer(..) updating BufferEntry"<