I figured out the error. I had put effect = new BasicEffect(); in my cube constructor. Stupid mistake. I don't really need 100,000 effects for each cube. But anyway now that I have the 4 grids loaded my fps is down again, this time 7~9. I have a feeling it has something to do with my draw method, as each grid has its own buffer and I should not be getting as many draw calls as I have.
public void DrawMap(GameTime gameTime)
{
foreach (Cube block in cube.cubes)
{
effect.VertexColorEnabled = false;
effect.TextureEnabled = true;
effect.Texture = grass;
Matrix center = Matrix.CreateTranslation(new Vector3(-0.5f, -0.5f, -0.5f));
Matrix scale = Matrix.CreateScale(1f);
Matrix translate = Matrix.CreateTranslation(block.cubePosition);
effect.World = center * scale * translate;
effect.View = cam.view;
effect.Projection = cam.proj;
effect.FogEnabled = false;
effect.FogColor = Color.CornflowerBlue.ToVector3();
effect.FogStart = 1.0f;
effect.FogEnd = 50.0f;
cube.Draw(effect);
noc++;
}
}
Is there any way around this? I kinda need to the for loop to set the position of each cube, but I think its part of my fps drop issue.
My SetUp methods are:
private void SetUpIndices()
{
/*
//Front face
//bottom right triangle
indices.Add(0);
indices.Add(2);
indices.Add(3);
indices.Add(0);
indices.Add(1);
indices.Add(2);
indices.Add(1);
indices.Add(5);
indices.Add(6);
indices.Add(1);
indices.Add(6);
indices.Add(2);
indices.Add(2);
indices.Add(6);
indices.Add(7);
indices.Add(2);
indices.Add(7);
indices.Add(3);
indices.Add(4);
indices.Add(7);
indices.Add(6);
indices.Add(4);
indices.Add(6);
indices.Add(5);
indices.Add(1);
indices.Add(4);
indices.Add(5);
indices.Add(1);
indices.Add(0);
indices.Add(4);
indices.Add(0);
indices.Add(7);
indices.Add(4);
indices.Add(0);
indices.Add(3);
indices.Add(7);*/
#region IndicesArray
indices = new short[36];
indices[0] = 0;
indices[1] = 2;
indices[2] = 3;
//top left triangle
indices[3] = 0;
indices[4] = 1;
indices[5] = 2;
//back face
//bottom right triangle
indices[6] = 1;
indices[7] = 5;
indices[8] = 6;
//top left triangle
indices[9] = 1;
indices[10] = 6;
indices[11] = 2;
//Top face
//bottom right triangle
indices[12] = 2;
indices[13] = 6;
indices[14] = 7;
//top left triangle
indices[15] = 2;
indices[16] = 7;
indices[17] = 3;
//bottom face
//bottom right triangle
indices[18] = 4;
indices[19] = 7;
indices[20] = 6;
//top left triangle
indices[21] = 4;
indices[22] = 6;
indices[23] = 5;
//left face
//bottom right triangle
indices[24] = 1;
indices[25] = 4;
indices[26] = 5;
//top left triangle
indices[27] = 1;
indices[28] = 0;
indices[29] = 4;
//right face
//bottom right triangle
indices[30] = 0;
indices[31] = 7;
indices[32] = 4;
//top left triangle
indices[33] = 0;
indices[34] = 3;
indices[35] = 7;
#endregion IndicesArray
}
private void SetUpVertices()
{
#region VPNormalTexture
/*
//front left bottom corner
vertices.Add(new VertexPositionNormalTexture(new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector2(1, 0)));
//front left upper corner
vertices.Add(new VertexPositionNormalTexture(new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector2(0, 0)));
//front right upper corner
vertices.Add(new VertexPositionNormalTexture(new Vector3(1, 1, 0), new Vector3(1, 1, 0), new Vector2(0, 1)));
//front lower right corner
vertices.Add(new VertexPositionNormalTexture(new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector2(1, 1)));
//back left lower corner
vertices.Add(new VertexPositionNormalTexture(new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector2(1, 0)));
//back left upper corner
vertices.Add(new VertexPositionNormalTexture(new Vector3(0, 1, -1), new Vector3(0, 1, -1), new Vector2(0, 0)));
//back right upper corner
vertices.Add(new VertexPositionNormalTexture(new Vector3(1, 1, -1), new Vector3(1, 1, -1), new Vector2(0, 1)));
//back right lower corner
vertices.Add(new VertexPositionNormalTexture(new Vector3(1, 0, -1), new Vector3(1, 0, -1), new Vector2(1, 1)));
*/
#endregion VPNormalTexture
vertices = new VertexPositionTexture[8];
//front left bottom corner ok
vertices[0] = (new VertexPositionTexture(new Vector3(0, 0, 0), new Vector2(1, 0)));
//front left upper corner
vertices[1] = (new VertexPositionTexture(new Vector3(0, 1, 0), new Vector2(1, 1)));
//front right upper corner ok
vertices[2] = (new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(0, 1)));
//front lower right corner
vertices[3] = (new VertexPositionTexture(new Vector3(1, 0, 0), new Vector2(0, 0)));
//back left lower corner ok
vertices[4] = (new VertexPositionTexture(new Vector3(0, 0, -1), new Vector2(0, 1)));
//back left upper corner
vertices[5] = (new VertexPositionTexture(new Vector3(0, 1, -1), new Vector2(1, 1)));
//back right upper corner ok
vertices[6] = (new VertexPositionTexture(new Vector3(1, 1, -1), new Vector2(1, 0)));
//back right lower corner
vertices[7] = (new VertexPositionTexture(new Vector3(1, 0, -1), new Vector2(0, 0)));
#region VPColor
/*
//front left bottom corner
vertices.Add(new VertexPositionColor(new Vector3(0, 0, 0), color));
//front left upper corner
vertices.Add(new VertexPositionColor(new Vector3(0, 1, 0), color));
//front right upper corner
vertices.Add(new VertexPositionColor(new Vector3(1, 1, 0), color));
//front lower right corner
vertices.Add(new VertexPositionColor(new Vector3(1, 0, 0), color));
//back left lower corner
vertices.Add(new VertexPositionColor(new Vector3(0, 0, -1), color));
//back left upper corner
vertices.Add(new VertexPositionColor(new Vector3(0, 1, -1), color));
//back right upper corner
vertices.Add(new VertexPositionColor(new Vector3(1, 1, -1), color));
//back right lower corner
vertices.Add(new VertexPositionColor(new Vector3(1, 0, -1), color));
* */
#endregion VPColor
}
The commented out code are just things I've tried that I might need to go back to later. I don't know if its better to store my vertices and indices in a list or array, but both seem to work. Oh and if anybody can help me out with the U and V values of my vertices that'd be awesome. My texture is drawing horribly wrong, but it's not that big of an issue right now