什么是更快的方式来绘制图形比绘制单独的行? [英] What are the quicker ways to draw graphs than by drawing separate lines?
问题描述
截至目前我画与拉伸到必要的高度1px的矩形我调试性能图表,而是借鉴了很多数据,这种方式会导致显著的性能损失。
As of now I'm drawing my debug performance graphs with 1px rectangles stretched to necessary height, but drawing a lot of data this way causes significant performance loss.
目前的逻辑是:收集所有时序为当前帧,将它们放置到问答LT;浮动>
和按图纸300拉伸1px的精灵绘制每个队列的图表。有4个图形,所以它仅在调试覆盖,这是资源消耗1200精灵。
Currently the logic is: collect all timings for current frame, place them into the Queue<float>
s and draw a graph for each queue by drawing 300 stretched 1px sprites. There are 4 graphs, so it's 1200 sprites in debug overlay alone, which is resource consuming.
有没有更好的方式来画,至少不需要绘制图表这么多的精灵?
Is there a better way to draw graphs that at least won't require drawing so many sprites?
推荐答案
您可以使用< A HREF =http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.vertexpositioncolor.aspx> VertexPositionColor
阵列来存储个人图表值,然后使用 GraphicsDevice.DrawUserIndexedPrimitives< VertexPositionColor>
与定义线一起列表(指数)与正交投影绘制它们。
Line List
You could use VertexPositionColor
arrays to store individual graph values, then use GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>
together with a defined line list (indices) to draw them with orthographic projection.
将.gif文件的大小,由于文件大小的50%。
我画这些样品(图4 300价值点/像素,每个像素),在60fps。
I'm drawing these samples (4 graphs with 300 value points/pixels each) at 60fps.
如果您需要填充线下图,你可以得出一个三角形条替代(用点图的底部)。
If you need to fill the graphs below the line, you could draw a triangle strip instead (with points at bottom of the graph).
下面是相关的代码上面呈现的第一个图:
Here is the relevant code for the first graph rendered above:
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<VertexPositionColor>(
PrimitiveType.LineList,
pointList,
0,
pointList.Length,
lineListIndices,
0,
pointList.Length - 1
);
}
有关三角形带图,修改代码来显示的triangle条,并在图形曲线的每个点放一上该图的底部。
For the triangle strip graph, modify the code to display a triangle strip, and for each point in the graph curve put one on the bottom of the graph.
这篇关于什么是更快的方式来绘制图形比绘制单独的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!