1
我刚刚开始使用XNA,现在我面临初学者问题,性能问题。我绘制的对象具有自己的顶点缓冲区,所以当我有〜50k个对象时,fps显着下降(从60到5-12)。XNA初学者:如何将顶点数组合并到单个顶点缓冲区中
我得到了我应该合并我顶点成块的小费,但我不知道该怎么做..
希望得到任何帮助,我可以用代码的例子得到。
编辑:这是我想出了与帮助来自布劳
var cubes = newChunk.Where(c => c != null && !badIndex.Contains(c.BlockType));
VertexPositionColorTextureNormal[] verts = new VertexPositionColorTextureNormal[cubes.Sum(c => c.Vertices.Count)];
int VertexOffset = 0;
var inTheRightOrder = cubes;
foreach (var cube in inTheRightOrder)
{
var cb = cube.Vertices.ToArray();
for (int v = 0; v < cb.Length; v++)
{
verts[VertexOffset + v] = cb[v];
}
VertexOffset += cb.Length;
}
VertexBuffer newVB = new VertexBuffer(device, VertexPositionColorTextureNormal.VertexDeclaration, verts.Length, BufferUsage.WriteOnly);
newVB.SetData(verts);
var ck = new Cube { Vertices = verts, BoundingBox = BoundingBox.CreateFromPoints(verts.Select(i => i.Position)), Buffer = newVB, Cubes = cubes.Count() };
Cubes.Add(ck);
50.000个对象?也许你需要在绘制之前剪切物体... – Blau
这些物体仅由可见的顶点构成,因此如果一个立方体仅从顶部可见,则只有顶部顶点被制成。 – NoLifeKing