I have a project with a floor built from with small cubes (100x100 of them). If I exceed that size, the performance of my game suffers. How can I efficiently draw a larger number of identical models?
Here's how I'm currently drawing the ground:
//Function to draw my ground ( 100 X 100 X 1)
public void DrawGround(GameTime gameTime)
{
// Copy any parent transforms.
Matrix[] transforms = new Matrix[this.model.Bones.Count];
this.model.CopyAbsoluteBoneTransformsTo(transforms);
//loop 1 cube high
for (int a = 0; a < 1; a++)
{
//loop 100 along cube
for (int b = 0; b < 100; b++)
{
//loop 100 cubic wide
for (int c = 0; c < 100; c++)
{
// Draw the model. A model can have multiple meshes, so loop.
foreach (ModelMesh mesh in this.model.Meshes)
{
// This is where the mesh orientation is set, as well
// as our camera and projection.
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(this.position);
effect.View = this.view;
effect.Projection = this.projection;
}
// Draw the mesh, using the effects set above.
mesh.Draw();
}
}
}
}
}
I think it is better to use the a vertex buffer, but I have not found a tutorial for that I want to do. Can you explain how I can do this?