绘制图形的方法比绘制单独的线条更快捷的方法是什么?

截至目前,我正在绘制我的调试性能图,其中1px矩形被拉伸到必要的高度,但是以这种方式绘制大量数据会导致显着的性能损失。

目前的逻辑是:收集当前帧的所有时序,将它们放入Queue并通过绘制300个拉伸的1px精灵为每个队列绘制一个图形。 有4个图,因此仅在调试覆盖中有1200个精灵,这是资源消耗。

是否有更好的方法来绘制图表,至少不需要绘制这么多精灵?

行列表

您可以使用VertexPositionColor数组存储单个图形值,然后使用GraphicsDevice.DrawUserIndexedPrimitives以及定义的线列表(索引)以使用正交投影绘制它们。

在此处输入图像描述
由于文件大小,.gif的大小调整为50%。

我正在以60fps绘制这些样本(4个图表,每个值为300个值点/像素)。

在此处输入图像描述


三角带

如果需要填充线下方的图形,则可以绘制三角形条 (在图形底部有点)。

在此处输入图像描述


行列表代码

以下是上面呈现的第一个图表的相关代码:

 Matrix worldMatrix; Matrix viewMatrix; Matrix projectionMatrix; BasicEffect basicEffect; VertexPositionColor[] pointList; short[] lineListIndices; protected override void Initialize() { int n = 300; //GeneratePoints generates a random graph, implementation irrelevant pointList = new VertexPositionColor[n]; for (int i = 0; i < n; i++) pointList[i] = new VertexPositionColor() { Position = new Vector3(i, (float)(Math.Sin((i / 15.0)) * height / 2.0 + height / 2.0 + minY), 0), Color = Color.Blue }; //links the points into a list lineListIndices = new short[(n * 2) - 2]; for (int i = 0; i < n - 1; i++) { lineListIndices[i * 2] = (short)(i); lineListIndices[(i * 2) + 1] = (short)(i + 1); } worldMatrix = Matrix.Identity; viewMatrix = Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up); projectionMatrix = Matrix.CreateOrthographicOffCenter(0, (float)GraphicsDevice.Viewport.Width, (float)GraphicsDevice.Viewport.Height, 0, 1.0f, 1000.0f); basicEffect = new BasicEffect(graphics.GraphicsDevice); basicEffect.World = worldMatrix; basicEffect.View = viewMatrix; basicEffect.Projection = projectionMatrix; basicEffect.VertexColorEnabled = true; //important for color base.Initialize(); } 

绘制它:

 foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserIndexedPrimitives( PrimitiveType.LineList, pointList, 0, pointList.Length, lineListIndices, 0, pointList.Length - 1 ); } 

对于三角形条形图,修改代码以显示三角形条带 ,对于图形曲线中的每个点,将一个放在图形的底部。