tags:

views:

682

answers:

4

Hello,

I need to render thousand of ellipses linked each others with lines. What would be the best way (in terms of performances) to render it inside a WPF application. Is WPF Canvas painting a lot worse than XNA painting ?

Actually, the hidden question is : is it possible to do some xna-rendering inside a WPF host ? I saw some examples that used a borderless xna window overlay, but no native soluation...

Thanks, Aurélien

+1  A: 

I've just found this article on CodeProject:

We want to integrate our XNA scene in a WPF user interface in the same way that we integrate a canvas or any widget. But the best way to view a 3D scene in XNA is to incorporate it in a window. It is impossible to obtain the handle of any WPF control as can be done with a WinForm. The trick then is to rewrite part of the XNA framework revolving around the Game class. The goal is to inherit a new Game class from Panel (in our case, a Canvas) to be able to include it in the WPF visual tree. The visual bounds of the panel will be the viewing area of the XNA scene. Yet, we have just said that it is not possible to obtain a handle to a visual control that does not inherit from Window. How do we display 3D with XNA then? We will simply display a window without border just above the panel. This window will always be on top when the application has focus and the panel is visible and will be hidden in this case. Similarly, when the panel is not visible, we will halt the activity of the game.

This thread on the Microsoft forums has a discussion on this and one poster states:

Then, the conclusions is that you can have XNA rendering into a WPF form with no issues but you must avoid using the Game and GraphicsDeviceManager classes as the latter requires a Game instance to run (constructor is defined as new GraphicsDeviceManager(Game game)) and the Game class doesn't provide any way to define the window on which it renders.

So it looks like it is possible, but requires some work on the XNA side of the equation.

ChrisF
+2  A: 

If done right you can get some pretty high performance in WPF rendering which hast the advantage that you don't have to take the WPF-XNA interop pain. You can render (and animate) a very large amount of visuals if you use the low level rendering APIs of WPF such as CompositionTarget.Rendering and DrawingContext. You can also take take advantage of the new Cached Composition feature in .net 4.0. There is plenty more just take this as the starting point.

bitbonk
I think I'll go this way, but I need some user interactivity with every ellipse, and they are rendered in a ScrollViewer. Actually, I'm currently using a Control to render an ellipse and another Control to render a Line. That's just to prototype, and performances with more than a hundred ellipses are awfull. Thanks. Think I'll go with DrawingVisuals...
Aurélien Ribon
DrawingVisuals are much faster than Shape-derived controls (Line, Ellipse), but for dynamic content bitbonk's DrawingContext suggestion can be faster still.
Ray Burns
+2  A: 

I have successfully "integrated" XNA with WPF by first rendering an XNA scene to a WinForms control and then hosting that control in WPF using the WindowsFormsHost element.

Peter Lillevold
I wanted to do that, but I heard that performances are crushed down in a winform host. Guess that's only rumors, I'll have to test that asumption.
Aurélien Ribon
Yes, that assumption must be tested :) I'm running a 60k+ triangles scene with acceptable performance. I'm using `BasicEffect` with one lightsource and fog enabled, haven't tried textures yet. But I assume that the added overhead of putting it through WinForms should be constant no matter what is going on on the XNA side.
Peter Lillevold
In fact the rendering overhead of going through WinForms is exactly zero (as compared to an overlay window). Under the hood, both the WinForms method and the overlay window give Direct3D a rectanglar screen area to own and play with. Resizing and moving your window will be technically slower, but in practice undetectably so.
Ray Burns
There is a way to do the same thing with slightly less plumbing and no WinForms dependency by using HwndHost directly to get a HWND for XNA, but if you've already coded up the WinForms solution there is no reason to abandon it now.
Ray Burns
@Ray Burns: good input. `HwndHost` requires unmanaged code permissions though, but could be worth looking into.
Peter Lillevold
+1  A: 

Be aware however, XNA applications will not run on systems without at least 1.1 shader GPU.

SiN