Permalink
Browse files

Splitting BufferObj::mapWriteOnly(bool) into mapWriteOnly() and mapRe…

…place()
  • Loading branch information...
andrewfb committed Jul 15, 2015
1 parent 2058020 commit 440feca71821abd3b197fc02641e763b3bb3e4cc
Showing with 25 additions and 10 deletions.
  1. +4 −2 include/cinder/gl/BufferObj.h
  2. +15 −5 src/cinder/gl/BufferObj.cpp
  3. +6 −3 src/cinder/gl/VboMesh.cpp
@@ -59,8 +59,10 @@ class BufferObj {
void* map( GLenum access ) const;
#endif
#if (! defined( CINDER_GL_ANGLE )) || defined( CINDER_GL_ES_3 )
//! Abstracts glMapBuffer() vs. glMapBufferRange() with appropriate write-only parameters for the platform. Passing \c true for \a invalidPrevious allows the GL to flush the contents of the buffer as an optimization.
void* mapWriteOnly( bool invalidatePrevious );
//! Maps the Buffer for writing, but does not invalidate the Buffer's existing contents. Slower than mapReplace(). Abstracts glMapBuffer() vs. glMapBufferRange() with appropriate write-only parameters for the platform.
void* mapWriteOnly();
//! Invalidates the Buffer's existing contents and maps it for writing. Preferable to mapWriteOnly() when invalidation is acceptable. Abstracts glMapBuffer() vs. glMapBufferRange() with appropriate write-only parameters for the platform.
void* mapReplace();
//! Analogous to glMapBufferRange(). On iOS ES 2 only \c GL_WRITE_ONLY_OES is valid.
void* mapBufferRange( GLintptr offset, GLsizeiptr length, GLbitfield access ) const;
void unmap() const;
@@ -125,19 +125,29 @@ void* BufferObj::map( GLenum access ) const
#endif
#if (! defined( CINDER_GL_ANGLE )) || defined( CINDER_GL_ES_3 )
void* BufferObj::mapWriteOnly( bool invalidatePrevious )
void* BufferObj::mapWriteOnly()
{
ScopedBuffer bufferBind( mTarget, mId );
// iOS ES 2 only has glMapBufferOES()
#if defined( CINDER_GL_ES_2 )
if( invalidatePrevious )
glBufferData( mTarget, mSize, nullptr, mUsage );
return reinterpret_cast<void*>( glMapBufferOES( mTarget, GL_WRITE_ONLY_OES ) );
#else
// ES 3 has only glMapBufferRange
GLbitfield access = GL_MAP_WRITE_BIT;
if( invalidatePrevious )
access |= GL_MAP_INVALIDATE_BUFFER_BIT;
return reinterpret_cast<void*>( glMapBufferRange( mTarget, 0, mSize, access ) );
#endif
}
void* BufferObj::mapReplace()
{
ScopedBuffer bufferBind( mTarget, mId );
// iOS ES 2 only has glMapBufferOES()
#if defined( CINDER_GL_ES_2 )
glBufferData( mTarget, mSize, nullptr, mUsage );
return reinterpret_cast<void*>( glMapBufferOES( mTarget, GL_WRITE_ONLY_OES ) );
#else
// ES 3 has only glMapBufferRange
GLbitfield access = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT;
return reinterpret_cast<void*>( glMapBufferRange( mTarget, 0, mSize, access ) );
#endif
}
@@ -525,7 +525,7 @@ void VboMesh::bufferAttrib( geom::Attrib attrib, size_t dataSizeBytes, const voi
}
else { // interleaved data
#if ! defined( CINDER_GL_ANGLE ) || defined( CINDER_GL_ES_3 )
uint8_t *ptr = reinterpret_cast<uint8_t*>( layoutVbo->second->mapWriteOnly( false ) );
uint8_t *ptr = reinterpret_cast<uint8_t*>( layoutVbo->second->mapWriteOnly() );
if( ! ptr ) {
CI_LOG_E( "Failed to map VBO" );
return;
@@ -557,7 +557,7 @@ void VboMesh::bufferIndices( size_t dataSizeBytes, const void *data )
mIndices->bufferSubData( 0, dataSizeBytes, data );
}
#if defined(CINDER_GL_ES_3) || (! defined( CINDER_GL_ANGLE ))
#if defined( CINDER_GL_ES_3 ) || (! defined( CINDER_GL_ANGLE ))
template<typename T>
VboMesh::MappedAttrib<T> VboMesh::mapAttribImpl( geom::Attrib attr, int dims, bool orphanExisting )
{
@@ -576,7 +576,10 @@ VboMesh::MappedAttrib<T> VboMesh::mapAttribImpl( geom::Attrib attr, int dims, bo
else {
MappedVboInfo mappedVboInfo;
mappedVboInfo.mRefCount = 1;
mappedVboInfo.mPtr = layoutVbo->second->mapWriteOnly( orphanExisting );
if( orphanExisting )
mappedVboInfo.mPtr = layoutVbo->second->mapReplace();
else
mappedVboInfo.mPtr = layoutVbo->second->mapWriteOnly();
mMappedVbos[layoutVbo->second] = mappedVboInfo;
dataPtr = mappedVboInfo.mPtr;
}

0 comments on commit 440feca

Please sign in to comment.