protected override IntPtr LockImpl( int offset, int length, BufferLocking locking )
{
int access = 0;
if ( isLocked )
{
throw new Exception( "Invalid attempt to lock an index buffer that has already been locked." );
}
// bind this buffer
Gl.glBindBufferARB( Gl.GL_ARRAY_BUFFER_ARB, bufferID );
if ( locking == BufferLocking.Discard )
{
// fixes issues with ATI cards
//Gl.glBufferDataARB(Gl.GL_ARRAY_BUFFER_ARB, length, IntPtr.Zero, GLHelper.ConvertEnum(usage));
// find out how we shall access this buffer
access = ( usage == BufferUsage.Dynamic ) ?
Gl.GL_READ_WRITE_ARB : Gl.GL_WRITE_ONLY_ARB;
}
else if ( locking == BufferLocking.ReadOnly )
{
if ( usage == BufferUsage.WriteOnly )
{
LogManager.Instance.Write( "Invalid attempt to lock a write-only vertex buffer as read-only." );
}
access = Gl.GL_READ_ONLY_ARB;
}
else if ( locking == BufferLocking.Normal || locking == BufferLocking.NoOverwrite )
{
access = ( usage == BufferUsage.Dynamic ) ?
Gl.GL_READ_WRITE_ARB : Gl.GL_WRITE_ONLY_ARB;
}
IntPtr ptr = Gl.glMapBufferARB( Gl.GL_ARRAY_BUFFER_ARB, access );
if ( ptr == IntPtr.Zero )
{
throw new Exception( "GL Vertex Buffer: Out of memory" );
}
isLocked = true;
return new IntPtr( ptr.ToInt64() + offset );
}