There is a need to visualize large quantity of 2d graphic objects (draw some schema of complex structure) using .NET framework – for example 10-20 thousand primitives on one canvas. Assume we have respective hardware – powerful server PC with multi-core CPU, huge amount of RAM and some recent videocard. According to books and MSDN the solution is to use WPF with its hardware acceleration, particularly Drawings subsystem. I’ve implemented simple scenario with GeometryDrawings and VisualHost and it is pretty decent, but there is a problem – visualized objects also need to have changing state (i.e. quickly change color without redrawing) and accept mouse events (click, drag’n’drop) which Freezables doesn’t support as they are no Framework Elements. Any ideas how to solve the problem most efficiently? Our graphical object looks very much alike framework-supplied Shape and its descendants, but it surely won’t match performance requirements.
* edit *
Graphic objects can have as simple structure (red rectangle) as complex (multiple nested objects that contains Paths – random-shaped curves). Objects may overlap. Layering (hide and show specific objects at some particular moment) may be implemented later as additional feature. State change may occur once every 2-5 seconds, triggered by external event.
There is a need to visualize large quantity of 2d graphic objects (draw some
Share
One word: shaders.
This looks like a decent tutorial on using shaders in WPF. Pixel and Vertex shaders themselves are pretty simple for drawing primitives.
A shader will let you take full advantage of hardware acceleration. On a decent GPU, 10k primitives is nothing.
Changing colors, etc. on a frame-to-frame basis is trivial in this context.
Most of the shader tutorials are for 3D, but they’re applicable to 2D as well.
You could also have a look at XNA. It doesn’t natively support putting a DirectX context inside of a WPF or Winforms window, but there are quite a few tutorials on that as well. XNA is pretty powerful and takes care of a lot of the boilerplate code like matrix manipulation, etc. that you’ll need. Even if you decide not to go with XNA, the tutorials on create.msdn.com can be very educational.
Update 10/2012
XNA is effectively dead, but there are quite a few examples out there of using shaders in WPF. If your C++ skills are up to snuff, you can use the D3DImage class to place a Direct3D window on your WPF form. The XNA samples are still valuable for their shader content and high-level approach to graphics development.
If you were excited about XNA, have a look at MonoGame, which is coming along nicely. I’m using it successfully for some cross-platform 3D stuff (Win7, OSX, iOS) and have no complaints.