public IndexBuffer GetIndexBuffer()
{
if (this.indexBuffer == null)
{
int uCount = GetUCount(interval);
int vCount = GetVCount(interval);
int length = (uCount + 1) * vCount + (vCount + 1 + 1) * uCount;
OneIndexBuffer buffer = CSharpGL.Buffer.Create(IndexBufferElementType.UInt, length, DrawMode.LineStrip, BufferUsage.StaticDraw);
unsafe
{
IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly);
var array = (uint*)pointer;
int index = 0;
// vertical lines.
for (int i = 0; i < vCount; i++)
{
for (int j = 0; j < uCount; j++)
{
array[index++] = (uint)(i + j * vCount);
}
array[index++] = uint.MaxValue;// primitive restart index.
}
// horizontal lines.
for (int i = 0; i < uCount; i++)
{
for (int j = 0; j < vCount; j++)
{
array[index++] = (uint)(j + i * vCount);
}
array[index++] = (uint)(0 + i * vCount);
array[index++] = uint.MaxValue;// primitive restart index.
}
buffer.UnmapBuffer();
}
this.indexBuffer = buffer;
}
return this.indexBuffer;
}