Drawing millions of segments on screen
I would lik开发者_运维百科e to draw millions of line segments to the screen. Most of the time user will see only certain area of "universe", but the user should have the ability to "zoom" out to see all line segments at once.
My understanding is that the primitive is a "triangle", so I will have to express my line segments as triangles. Millions of triangles.
Is XNA the right tool for this job, or will it be too slow?
Additional Detail:
- This is not for a game, but for a modeling program of some processes.
- I do not care which language to use (XNA was recommended to me)
P.S.: Please let me know if you need additional detail.
My understanding is that the primitive is a "triangle", so I will have to express my line segments as triangles. Millions of triangles.
Incorrect, XNA can perfectly draw lines for you in the following manner:
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.LineList, vertexOffset, 0, numVertices, startIndex, primitiveCount);
(Or PrimitiveType.LineStrip if the end vertex of line1 is the start vertex of line2).
Is XNA the right tool for this job, or will it be too slow?
XNA is "a tool", and if you're drawing a lot of lines this is definately going to be faster than GDI+ and easy to implement than C++ in combo with Unmannaged D3D. Drawing a line is a very cheap operation. I would advice you to just install XNA and do a quick prototype to see how many lines you can draw at the same time. (My guess is at least 1 million). Then see if you really need to use the advanced techniques described by the other posters.
Also the "Polyline simplification" technique suggested by Felice Pollano doesn't work for individual lines, only for models made up of triangles (you can exchange a lot of small triangles for a few bigger once to increase performance but decrease visuals, if you're zoomed out pritty far nobody will notice) It also won't work for "thickened up lines" because they will always consist of 2 triangles. (Unless if you allow bended lines).
When you zoom into details simple bounding box check if the triangle is visible to avoid drawing invisible objects. When user zoom all, you should apply some algorithm of polyline simplification http://www.softsurfer.com/Archive/algorithm_0205/algorithm_0205.htm to avoid have too many things to draw.
This guy had your same problem, and this might help (here are the sources).
Yes, as Felice alludes to, simplifying the problem-set is the name of the game. There are obvious limits to hardware and algorithms, so the only way to draw "more stuff" is actually to draw "less stuff".
You can use techniques such as dividing your scene into an OctTree so that you can do View Frustrum Culling. There are tons of techniques for scaling out what you're drawing. One of my favorites is the use of impostors to create a composite scene which is easier to draw. Here's a paper which explains the technique: http://academic.research.microsoft.com/Paper/1241430.aspx
Impostors are image-based primitives commonly used to replace complex *geometry* in order to reduce the rendering time needed for displaying complex scenes. However, a big problem is the huge amount of memory required for impostors. This paper presents an algorithm that automatically places impostors into a scene so that a desired frame rate image quality is always met, while at the same time not requiring enormous amounts of impostor memory. The low memory requirements are provided by a new placement method and through the simultaneous use of other acceleration techniques like visibility culling and geometric levels of detail.
精彩评论