Revert "merge _usage and bufferstorage bitfield utilization"

This reverts commit 30e749ae54.
This commit is contained in:
Julien Valentin 2020-01-03 00:02:08 +01:00
parent 3526292de3
commit eaaf83329e
3 changed files with 38 additions and 30 deletions

View File

@ -243,13 +243,11 @@ ELSE(DYNAMIC_OPENSCENEGRAPH)
#needed on win32 or the linker get confused by _declspec declarations
ADD_DEFINITIONS(-DOSG_LIBRARY_STATIC)
ADD_SUBDIRECTORY(osgstaticviewer)
# IPHONE_PORT@tom
IF(OSG_BUILD_PLATFORM_IPHONE OR OSG_BUILD_PLATFORM_IPHONE_SIMULATOR)
IF(OSG_BUILD_PLATFORM_IPHONE)
ADD_SUBDIRECTORY(osgviewerIPhone)
ELSE()
ADD_SUBDIRECTORY(osgstaticviewer)
ENDIF()
# IPHONE_PORT@tom
ENDIF(DYNAMIC_OPENSCENEGRAPH)

View File

@ -101,17 +101,20 @@ class BufferObjectProfile
BufferObjectProfile():
_target(0),
_usage(0),
_size(0) {}
_size(0),
_mappingbitfield(0) {}
BufferObjectProfile(GLenum target, GLenum usage, unsigned int size):
BufferObjectProfile(GLenum target, GLenum usage, unsigned int size, GLbitfield mappingbitfield ):
_target(target),
_usage(usage),
_size(size) {}
_size(size),
_mappingbitfield(mappingbitfield) {}
BufferObjectProfile(const BufferObjectProfile& bpo):
_target(bpo._target),
_usage(bpo._usage),
_size(bpo._size) {}
_size(bpo._size),
_mappingbitfield(bpo._mappingbitfield) {}
bool operator < (const BufferObjectProfile& rhs) const
{
@ -119,6 +122,8 @@ class BufferObjectProfile
else if (_target > rhs._target) return false;
if (_usage < rhs._usage) return true;
else if (_usage > rhs._usage) return false;
if (_mappingbitfield < rhs._mappingbitfield) return true;
else if (_mappingbitfield > rhs._mappingbitfield) return false;
return _size < rhs._size;
}
@ -126,14 +131,16 @@ class BufferObjectProfile
{
return (_target == rhs._target) &&
(_usage == rhs._usage) &&
(_size == rhs._size);
(_size == rhs._size) &&
(_mappingbitfield == rhs._mappingbitfield);
}
void setProfile(GLenum target, GLenum usage, unsigned int size)
void setProfile(GLenum target, GLenum usage, unsigned int size, GLbitfield mappingbitfield )
{
_target = target;
_usage = usage;
_size = size;
_mappingbitfield = mappingbitfield;
}
BufferObjectProfile& operator = (const BufferObjectProfile& rhs)
@ -141,12 +148,14 @@ class BufferObjectProfile
_target = rhs._target;
_usage = rhs._usage;
_size = rhs._size;
_mappingbitfield = rhs._mappingbitfield;
return *this;
}
GLenum _target;
GLenum _usage;
GLuint _size;
GLbitfield _mappingbitfield;
};
// forward declare
@ -427,15 +436,16 @@ class OSG_EXPORT BufferObject : public Object
* GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY,
* GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY,
* GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, or GL_DYNAMIC_COPY.
*or buffer storage features as bitfield composed with:
* GL_MAP_READ_BIT, GL_MAP_WRITE_BIT, GL_MAP_PERSISTENT_BIT, GL_MAP_COHERENT_BIT,
* GL_MAP_INVALIDATE_RANGE_BIT, GL_MAP_FLUSH_EXPLICIT_BIT, GL_MAP_UNSYNCHRONIZED_BIT.
*/
void setUsage(GLenum usage) { _profile._usage = usage; }
/** Get the type of usage the buffer object has been set up for.*/
GLenum getUsage() const { return _profile._usage; }
/** Enable GL4 buffer storage features (override usage if setted) */
void setMappingBitfield(GLbitfield b){ if(_profile._mappingbitfield == b) return; _profile._mappingbitfield = b; }
GLbitfield getMappingBitfield() const { return _profile._mappingbitfield; }
BufferObjectProfile& getProfile() { return _profile; }
const BufferObjectProfile& getProfile() const { return _profile; }

View File

@ -54,7 +54,7 @@ unsigned int GLBufferObject::BufferEntry::getNumClients() const
GLBufferObject::GLBufferObject(unsigned int contextID, BufferObject* bufferObject, unsigned int glObjectID):
_contextID(contextID),
_glObjectID(glObjectID),
_profile(0,0,0),
_profile(0,0,0,0),
_allocatedSize(0),
_dirty(true),
_bufferObject(0),
@ -106,7 +106,7 @@ void GLBufferObject::assign(BufferObject* bufferObject)
}
else
{
_profile.setProfile(0,0,0);
_profile.setProfile(0,0,0,0);
// clear all previous entries;
_bufferEntries.clear();
@ -214,19 +214,19 @@ void GLBufferObject::compileBuffer()
_allocatedSize = _profile._size;
OSG_INFO<<" Allocating new glBufferData(), _allocatedSize="<<_allocatedSize<<std::endl;
if( _profile._usage < GL_STREAM_DRAW_ARB) // any bitfield is lower
if(_profile._mappingbitfield != 0)
{
_extensions->glBufferStorage(_profile._target, _profile._size, NULL, _profile._usage);
if(_profile._usage & GL_MAP_PERSISTENT_BIT)
if(_profile._usage & GL_MAP_PERSISTENT_BIT )
{
// invalidate mapping of previously allocated
/// invalidate mapping of previously allocated
if(_persistentDMA)
{
_extensions->glUnmapBuffer(_profile._target);
_persistentDMA = 0;
}
_persistentDMA = _extensions->glMapBufferRange( _profile._target, 0, _profile._size, _profile._usage);
_persistentDMA = _extensions->glMapBufferRange(_profile._target, 0, _profile._size, _profile._mappingbitfield);
}
}
else
@ -259,9 +259,9 @@ void GLBufferObject::compileBuffer()
}
else
{
if( _profile._usage < GL_STREAM_DRAW_ARB) // any bitfield is lower
if(_profile._mappingbitfield != 0 )
{
if(_profile._usage & GL_MAP_PERSISTENT_BIT)
if(_profile._mappingbitfield & GL_MAP_PERSISTENT_BIT)
{
if(_persistentDMA)
{
@ -271,10 +271,10 @@ void GLBufferObject::compileBuffer()
}
else OSG_WARN<<" GL_MAP_PERSISTENT_BIT problem"<<std::endl;
}
else if(_profile._usage & GL_MAP_WRITE_BIT)
else if(_profile._mappingbitfield & GL_MAP_WRITE_BIT)
{
GLvoid *src = const_cast<GLvoid*>(entry.dataSource->getDataPointer()),
*dst = _extensions->glMapBufferRange( _profile._target, (GLintptr)entry.offset, (GLsizeiptr)entry.dataSize, _profile._usage);
*dst = _extensions->glMapBufferRange( _profile._target, (GLintptr)entry.offset, (GLsizeiptr)entry.dataSize, _profile._mappingbitfield);
memcpy(dst, src, entry.dataSize);
_extensions->glUnmapBuffer(_profile._target);
}
@ -290,19 +290,19 @@ void GLBufferObject::compileBuffer()
void GLBufferObject::commitDMA(unsigned int entryidx)
{
if( !(_profile._usage & GL_MAP_PERSISTENT_BIT) ) return;
if (entryidx >= _bufferEntries.size()) compileBuffer();
if( !(_profile._mappingbitfield & GL_MAP_PERSISTENT_BIT) ) return;
if (entryidx>=_bufferEntries.size()) compileBuffer();
BufferEntry& entry = _bufferEntries[entryidx];
_extensions->glFlushMappedBufferRange(_profile._target, (GLintptr)entry.offset, (GLsizeiptr)entry.dataSize);
}
void GLBufferObject::downloadBuffer(unsigned int entryidx)
{
if( !(_profile._usage & GL_MAP_READ_BIT) ) return;
if (entryidx >= _bufferEntries.size()) compileBuffer();
if( !(_profile._mappingbitfield & GL_MAP_READ_BIT) ) return;
if (entryidx>=_bufferEntries.size()) compileBuffer();
BufferEntry& entry = _bufferEntries[entryidx];
GLvoid *dst = const_cast<GLvoid*>(entry.dataSource->getDataPointer()),
*src = _extensions->glMapBufferRange( _profile._target, (GLintptr)entry.offset, (GLsizeiptr)entry.dataSize, _profile._usage);
*src = _extensions->glMapBufferRange( _profile._target, (GLintptr)entry.offset, (GLsizeiptr)entry.dataSize, _profile._mappingbitfield);
memcpy(dst, src, entry.dataSize);
_extensions->glUnmapBuffer(_profile._target);
}
@ -977,7 +977,7 @@ osg::ref_ptr<GLBufferObject> GLBufferObjectManager::generateGLBufferObject(const
unsigned int requiredBufferSize = osg::maximum(bufferObject->computeRequiredBufferSize(), bufferObject->getProfile()._size);
BufferObjectProfile profile(bufferObject->getTarget(), bufferObject->getUsage(), requiredBufferSize);
BufferObjectProfile profile(bufferObject->getTarget(), bufferObject->getUsage(), requiredBufferSize, bufferObject->getMappingBitfield());
// OSG_NOTICE<<"GLBufferObjectManager::generateGLBufferObject size="<<requiredBufferSize<<std::endl;