开发者

WPF vs XNA to render thousands of sprites

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


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.


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜