public void AddObject( IRenderable obj )
{
if ( obj == null )
throw new ArgumentNullException();
RenderOperation renderOp = obj.RenderOperation;
IndexData indexData;
if ( renderOp.useIndices )
{
indexData = renderOp.indexData;
}
else
{
//Create custom index buffer
int vertexCount = renderOp.vertexData.vertexCount;
IndexType itype = vertexCount > UInt16.MaxValue ?
IndexType.Size32 : IndexType.Size16;
DefaultHardwareIndexBuffer ibuf = new DefaultHardwareIndexBuffer( itype, vertexCount, BufferUsage.Static );
customIndexBufferList.Add( ibuf ); //to be disposed later
indexData = new IndexData();
indexData.indexBuffer = ibuf;
indexData.indexCount = vertexCount;
indexData.indexStart = 0;
//Fill buffer with indices
IntPtr ibuffer =
indexData.indexBuffer.Lock( BufferLocking.Normal );
try
{
unsafe
{
Int16* ibuf16 = (Int16*)ibuffer;
Int32* ibuf32 = (Int32*)ibuffer;
for ( int i = 0; i < indexData.indexCount; i++ )
{
if ( itype == IndexType.Size16 )
{
ibuf16[ i ] = (Int16)i;
}
else
{
ibuf32[ i ] = i;
}
}
} //unsafe
}
finally
{
indexData.indexBuffer.Unlock();
}
}
AddVertexData( renderOp.vertexData );
AddIndexData( indexData, vertexDataList.Count - 1,
renderOp.operationType );
}