I'm new in Monogame (OpenGL).
I want to draw 10.000+ primitives, just rectangles.
public class RectangleObject
{
public BasicEffect Effect { get; set; }
public Matrix PointTranslation { get; set; }
public Matrix PointRotation { get; set; }
public Matrix PointScale { get; set; }
public VertexPositionColor[] VerticesList { get; set; }
private VertexBuffer vertexBuffer;
private Game game;
public RectangleObject(Game game)
{
this.game = game;
Effect = new BasicEffect(game.GraphicsDevice) { VertexColorEnabled = true };
VerticesList = new VertexPositionColor[4];
vertexBuffer = new VertexBuffer(game.GraphicsDevice,
typeof(VertexPositionColor),
VerticesList.Length,
BufferUsage.WriteOnly);
vertexBuffer.SetData<VertexPositionColor>(VerticesList.ToArray());
game.GraphicsDevice.SetVertexBuffer(vertexBuffer);
}
public void DrawRectangle()
{
Effect.World = PointScale * PointRotation * PointTranslation;
Effect.CurrentTechnique.Passes[0].Apply();
game.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
PrimitiveType.TriangleStrip,
VerticesList,
0,
vertexBuffer.VertexCount / 2);
}
}
I want to rotate/translate/scale each rectangle object, because each object have 3 matrices. Application is loading content creating 100*100 grid of RectangleObjects and in Draw() method I'm calling DrawRectangle() method of RectangleObject. When I try to draw 50*50, it keeps 60FPS. But if I try to draw 10.000 rectangles, application running with 15-25FPS.
The questions are:
- Is this effective method to draw objects?
- There I can increase performance of application?
- Could you give me links, where I can read about performance?