Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF vs XNA to render thousands of sprites

Tags:

c#

wpf

xna

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

like image 811
Aurelien Ribon Avatar asked May 03 '10 14:05

Aurelien Ribon


4 Answers

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.

like image 122
bitbonk Avatar answered Sep 21 '22 22:09

bitbonk


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.

like image 23
Peter Lillevold Avatar answered Sep 23 '22 22:09

Peter Lillevold


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.

like image 34
ChrisF Avatar answered Sep 19 '22 22:09

ChrisF


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

like image 26
SiN Avatar answered Sep 22 '22 22:09

SiN