merge _usage and bufferstorage bitfield utilization
This commit is contained in:
parent
2c942f4771
commit
30e749ae54
@ -101,20 +101,17 @@ class BufferObjectProfile
|
||||
BufferObjectProfile():
|
||||
_target(0),
|
||||
_usage(0),
|
||||
_size(0),
|
||||
_mappingbitfield(0) {}
|
||||
_size(0) {}
|
||||
|
||||
BufferObjectProfile(GLenum target, GLenum usage, unsigned int size, GLbitfield mappingbitfield ):
|
||||
BufferObjectProfile(GLenum target, GLenum usage, unsigned int size):
|
||||
_target(target),
|
||||
_usage(usage),
|
||||
_size(size),
|
||||
_mappingbitfield(mappingbitfield) {}
|
||||
_size(size) {}
|
||||
|
||||
BufferObjectProfile(const BufferObjectProfile& bpo):
|
||||
_target(bpo._target),
|
||||
_usage(bpo._usage),
|
||||
_size(bpo._size),
|
||||
_mappingbitfield(bpo._mappingbitfield) {}
|
||||
_size(bpo._size) {}
|
||||
|
||||
bool operator < (const BufferObjectProfile& rhs) const
|
||||
{
|
||||
@ -122,8 +119,6 @@ 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;
|
||||
}
|
||||
|
||||
@ -131,16 +126,14 @@ class BufferObjectProfile
|
||||
{
|
||||
return (_target == rhs._target) &&
|
||||
(_usage == rhs._usage) &&
|
||||
(_size == rhs._size) &&
|
||||
(_mappingbitfield == rhs._mappingbitfield);
|
||||
(_size == rhs._size);
|
||||
}
|
||||
|
||||
void setProfile(GLenum target, GLenum usage, unsigned int size, GLbitfield mappingbitfield )
|
||||
void setProfile(GLenum target, GLenum usage, unsigned int size)
|
||||
{
|
||||
_target = target;
|
||||
_usage = usage;
|
||||
_size = size;
|
||||
_mappingbitfield = mappingbitfield;
|
||||
}
|
||||
|
||||
BufferObjectProfile& operator = (const BufferObjectProfile& rhs)
|
||||
@ -148,14 +141,12 @@ 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
|
||||
@ -436,16 +427,15 @@ 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; }
|
||||
|
||||
|
@ -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,0),
|
||||
_profile(0,0,0),
|
||||
_allocatedSize(0),
|
||||
_dirty(true),
|
||||
_bufferObject(0),
|
||||
@ -106,7 +106,7 @@ void GLBufferObject::assign(BufferObject* bufferObject)
|
||||
}
|
||||
else
|
||||
{
|
||||
_profile.setProfile(0,0,0,0);
|
||||
_profile.setProfile(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._mappingbitfield != 0)
|
||||
if( _profile._usage < GL_STREAM_DRAW_ARB) // any bitfield is lower
|
||||
{
|
||||
_extensions->glBufferStorage(_profile._target, _profile._size, NULL, _profile._mappingbitfield);
|
||||
_extensions->glBufferStorage(_profile._target, _profile._size, NULL, _profile._usage);
|
||||
|
||||
if(_profile._mappingbitfield & GL_MAP_PERSISTENT_BIT )
|
||||
if(_profile._usage & GL_MAP_PERSISTENT_BIT)
|
||||
{
|
||||
/// invalidate mapping of previously allocated
|
||||
// invalidate mapping of previously allocated
|
||||
if(_persistantDMA)
|
||||
{
|
||||
_extensions->glUnmapBuffer(_profile._target);
|
||||
_persistantDMA = 0;
|
||||
}
|
||||
_persistantDMA = _extensions->glMapBufferRange( _profile._target, 0, _profile._size, _profile._mappingbitfield );
|
||||
_persistantDMA = _extensions->glMapBufferRange( _profile._target, 0, _profile._size, _profile._usage);
|
||||
}
|
||||
|
||||
}
|
||||
@ -260,22 +260,22 @@ void GLBufferObject::compileBuffer()
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_profile._mappingbitfield != 0 )
|
||||
if( _profile._usage < GL_STREAM_DRAW_ARB) // any bitfield is lower
|
||||
{
|
||||
if(_profile._mappingbitfield & GL_MAP_PERSISTENT_BIT)
|
||||
if(_profile._usage & GL_MAP_PERSISTENT_BIT)
|
||||
{
|
||||
if(_persistantDMA)
|
||||
{
|
||||
GLvoid* src = const_cast<GLvoid*>(entry.dataSource->getDataPointer());
|
||||
memcpy((unsigned char*)_persistantDMA + entry.offset, src, entry.dataSize);
|
||||
_extensions->glFlushMappedBufferRange(_profile._target, (GLintptr)entry.offset, (GLsizeiptr)entry.dataSize );
|
||||
_extensions->glFlushMappedBufferRange(_profile._target, (GLintptr)entry.offset, (GLsizeiptr)entry.dataSize);
|
||||
}
|
||||
else OSG_WARN<<" GL_MAP_PERSISTENT_BIT problem"<<std::endl;
|
||||
}
|
||||
else if(_profile._mappingbitfield & GL_MAP_WRITE_BIT)
|
||||
else if(_profile._usage & GL_MAP_WRITE_BIT)
|
||||
{
|
||||
GLvoid *src = const_cast<GLvoid*>(entry.dataSource->getDataPointer()),
|
||||
*dst = _extensions->glMapBufferRange( _profile._target, (GLintptr)entry.offset, (GLsizeiptr)entry.dataSize, _profile._mappingbitfield);
|
||||
*dst = _extensions->glMapBufferRange( _profile._target, (GLintptr)entry.offset, (GLsizeiptr)entry.dataSize, _profile._usage);
|
||||
memcpy(dst, src, entry.dataSize);
|
||||
_extensions->glUnmapBuffer(_profile._target);
|
||||
}
|
||||
@ -291,19 +291,19 @@ void GLBufferObject::compileBuffer()
|
||||
|
||||
void GLBufferObject::commitDMA(unsigned int entryidx)
|
||||
{
|
||||
if( !(_profile._mappingbitfield & GL_MAP_PERSISTENT_BIT) ) return;
|
||||
if (entryidx>=_bufferEntries.size()) compileBuffer();
|
||||
if( !(_profile._usage & 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._mappingbitfield & GL_MAP_READ_BIT) ) return;
|
||||
if (entryidx>=_bufferEntries.size()) compileBuffer();
|
||||
if( !(_profile._usage & 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._mappingbitfield);
|
||||
*src = _extensions->glMapBufferRange( _profile._target, (GLintptr)entry.offset, (GLsizeiptr)entry.dataSize, _profile._usage);
|
||||
memcpy(dst, src, entry.dataSize);
|
||||
_extensions->glUnmapBuffer(_profile._target);
|
||||
}
|
||||
@ -970,7 +970,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, bufferObject->getMappingBitfield());
|
||||
BufferObjectProfile profile(bufferObject->getTarget(), bufferObject->getUsage(), requiredBufferSize);
|
||||
|
||||
// OSG_NOTICE<<"GLBufferObjectManager::generateGLBufferObject size="<<requiredBufferSize<<std::endl;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user