I'm working on a minecraft style games on xna. I know it is not easy to draw a lot of cube with a good ratio of fps. I use the method "DrawUserPrimitive" with a buffer to draw a floor 250X250 cubes. But my game displays 20 fps for only 62,500 cubic drawn! I do not understand.
2,250,000 vertexPositionTexture is to lot ?
Here is my code explained on how I proceed-
Initialize Buffer:
//Initialize the vertex buffer 1 times before drawing
public void RenderToDevice()
{
int nbrVertexPositionTexture = vertexPositionStructureCube.Length; //2'250'000 ! to lot ?
//Declare and initialize a buffer
vertexBufferCube = new VertexBuffer(
Game.GraphicsDevice,
VertexPositionTexture.VertexDeclaration,
nbrVertexPositionTexture,//2'250'000
BufferUsage.WriteOnly);
vertexBufferCube.SetData<VertexPositionTexture>(
vertexPositionStructureCube);
//Set buffer to graphic card
Game.GraphicsDevice.SetVertexBuffer(vertexBufferCube);
}
Draw
// Draw all cube (10,000)
public void drawWorld(GameTime gameTime)
{
effet.LightingEnabled = false;
effet.VertexColorEnabled = false;
effet.TextureEnabled = true;
effet.FogEnabled = true;
effet.FogStart = arcadia.camera.NearPlane;
effet.FogEnd = arcadia.camera.FarPlane;
effet.FogColor = new Vector3(1, 1, 1);
effet.View = arcadia.camera.View;
effet.Projection = arcadia.camera.Projection;
effet.Texture = textureInstancedModel;
foreach (EffectPass pass in effet.CurrentTechnique.Passes)
{
pass.Apply();
//Draw
Game.GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, vertexPositionStructureCube, 0, vertexBufferCube.VertexCount / 4);
}
needToDraw = true;
}