|
Aug
12
Written by:
Jeremiah Morrill
8/12/2008 2:28 AM
The new D3DImage in WPF opens up worlds for WPF. Direct3D content rendered with WPF...it doesn't get any better! The downside is it seems (correct me if I'm wrong) that Microsoft was only targeting unmanaged Direct3D. Yes there is Managed DirectX, but it seems as if MDX is no longer being maintained and it's not so obvious how to get a D3D surface pointer from the API. It really seems MDX has been left in the dust in favor for XNA, which is a very intuitive D3D wrapper. XNA further exacerbates the issue with XNA and WPF. A couple of the issues are: 1.) XNA hides all the nasty D3D COM pointers, so you can't get the surface pointer via the XNA API. 2.) XNA creates a IDirect3DDevice9 internally. WPF D3DImage needs a IDirect3DDevice9Ex for maximum performance on Vista. Initially, my plan was create a 9Ex device, inject it into the XNA GraphicsDevice class via reflection, which *worked* until you tried to load a texture. The XNA libraries are hard coded for a D3DPOOL_MANAGED pool, which is incompatible with the 9Ex device (Thanks Doc!). Ok, so we can live without break-neck performance of 9Ex...for now. So I just focused on getting the surface pointer and setting the render target. Here is a quick snippet for the Microsoft.Xna.Framework.Game subclass. You will need to add reference to the MDX assembly Microsoft.DirectX.Direct3D. Ignore all "LoaderLock" exceptions or just turn them off in Visual Studio. You will also need to throw an event on the Draw override to notify your D3DImage that there is a dirty rect. You should probably also add an event for when a new surface is available also, for when the D3D device is lost. private Surface m_surface;
private int WIDTH = 300;
private int HEIGHT = 300;
unsafe protected override void BeginRun()
{
Type deviceType = typeof(GraphicsDevice);
FieldInfo fi = deviceType.GetField("pComPtr",
BindingFlags.NonPublic | BindingFlags.Instance);
object ptr = fi.GetValue(graphics.GraphicsDevice);
IntPtr pComPtr = new IntPtr(Pointer.Unbox(ptr));
Microsoft.DirectX.Direct3D.Device dev = new Microsoft.DirectX.Direct3D.Device(pComPtr);
m_surface = dev.CreateRenderTarget(WIDTH,
HEIGHT,
Format.X8R8G8B8,
Microsoft.DirectX.Direct3D.MultiSampleType.None,
0,
System.Environment.OSVersion.Version.Major >= 6);
dev.SetRenderTarget(0, m_surface);
base.BeginRun();
}
unsafe public IntPtr GetSurfacePointer()
{
/* TODO: Figure out how to convert Surface.UnmanagedComPointer to IntPtr */
return m_surface.GetObjectByValue(unchecked((int)0xd2b543af));
}
Tags:
27 comment(s) so far...
Re: XNA, Meet WPF
Awesome stuff! Thanks for posting this, Jer.
I totally agree that XNA should be extended to support the 9Ex device. It would be great if there were a global setting that controlled this. Then the XNA framework could dynamically allocate resources in the default pool, rather than the managed pool, for 9Ex devices. Let's hope this is planned for the future. :-)
By Dr. WPF on
8/12/2008 9:44 AM
|
Re: XNA, Meet WPF
Hey Doc!
I think XNA is a fantastic framework. And it's just becoming more and more popular, supporting thinks like the 360 and Zune. It just makes sense to support WPF. I sure hope theres somebody on the inside lobbying for it.
By Jeremiah Morrill on
8/14/2008 6:03 AM
|
Re: XNA, Meet WPF
Even when XNA was still in preview the DirectX SDK read-me said that MDX 2.0 would be cancelled infavour of XNA so there isn't any ambiguity.
[)amien
By Damien Guard on
8/14/2008 6:24 PM
|
Re: XNA, Meet WPF
This is great - that d3dimage forces us to use unmanaged DirectX just seems like such a backwards step to me, so it makes me glad to see someone else working on this problem. Hopefully they'll release some mods for XNA so you won't have to resort to hacks to get it to work.
Thanks for the post =)
By Erik on
8/14/2008 7:47 PM
|
Re: XNA, Meet WPF
Have you thought about using SlimDX? It's a low level wrapper for DirectX which does not use MDX or XNA.
http://slimdx.mdxinfo.com/wiki/index.php?title=Main_Page
By Pekka Heikura on
8/15/2008 2:36 AM
|
Re: XNA, Meet WPF
Thanks for the link to SlimDX Pekka!
I have not really looked into any other managed wrappers, though there is one here that supports DX9, DX9Ex and DX10. http://www.codeplex.com/MD3D10
I do prefer the XNA model much more though ;)
By Jeremiah Morrill on
8/15/2008 7:06 AM
|
Re: XNA, Meet WPF
I'd certainly like to see XNA evolve to allow greater control and access to the DirectX plumbing for experienced coders who wish to 'deep dive' into it.Official and internal efforts to extend XNA in such a manner would help make leveraging other APIs like WPF an achievable goal without too much hassle.
Sadly, my impression is that the evolution of XNA will always suffer from being shackled to the ultimate capabilities of the XBox360 and Zune. I would guess that much of the time spent by the talented XNA development team will be biased towards features that can be used across the three hardware platforms, so the extra power and capabilities of what's possible on XNA under Windows will not be reliaed to its fullest.
As such, those who would like to see XNA gradually enhanced with more and more features available in Unmanaged DirectX, such as DirectX 10 and maybe even the forthcoming DirectX 11 capabilities, will likely reamain dissapointed.
This is why I doubt we will see any official attempts to enable WPF to be leveraged within XNA somehow, and it will be left to others to hack away in order to get things working, alebit in a less than performant manner.
I hope I'm proved wrong in all this. In my mind, 'Rich Multimedia' includes all technologies such as WPF and XNA. I'm no software expert but maybe there's scope for a 'software architecture oversight' team whose task is to maintain comminication with all the other teams at Microsoft that are working on cool graphics APIs such as WPF, XNA, Silverlight etc. The sole purpose of this team would be to develop ways in which all these disparate media API's could be made to easily 'interop'?
By Seefer on
11/26/2008 8:30 AM
|
Re: XNA, Meet WPF
I'm sorry about my lack of knowledge on this topic, but how would I get the D3DImage that is going to be rendered from the device/surface? Thanks so much for your help.
By Zane Kaminski on
1/3/2009 5:37 PM
|
Re: XNA, Meet WPF
Hi Zane,
The D3DImage class is in WPF 3.5 SP1. With that you just pass the native COM pointer of the surface to be rendered, then you invalidate the D3DImage to get it to render.
-Jer
By Jeremiah Morrill on
1/3/2009 7:01 PM
|
Re: XNA, Meet WPF
Another option for targeting PC only is via the Ogre graphics engine (which builds on Direct3D, I think they support 9 but I also hacked it to use 9Ex). This article shows off using D3DImage: www.codeproject.com/KB/WPF/OgreInTheWpf.aspx
By Meharin on
1/14/2009 11:17 AM
|
Re: XNA, Meet WPF
Microsoft seems to target a better fuse of WPF and XNA, check out this PDC Video (go to minute 38) channel9.msdn.com/pdc2008/PC46/
By Thomas Haller on
4/22/2009 11:27 AM
|
Re: XNA, Meet WPF
Jeremiah Morrill, thanks for your post, very helpful!
Could you post a full source code for this example? Or send me via e-mail: nevsoft@mail.ru
I don't undersand how to run XNA's Game object properly. Did you use Game.Run() method? Or what?
Anyway, thanks!
By Evgeny Nazarov on
6/16/2009 3:31 AM
|
Re: XNA, Meet WPF
Thank u so much. i just need to launch a project to insert XNA into WPF. I tried a lot but the gamewindow is shown all the time. I'll try wehter ur solution works. Thank u for sharing
By Franco on
8/8/2009 5:19 AM
|
Re: XNA, Meet WPF
Could you post a full source code for this example? Or send me via e-mail: sam.kalma@yahoo dot com
By SK on
11/2/2009 3:31 PM
|
Re: XNA, Meet WPF
Could you post a full source code for this example? Or send me via e-mail: sam.kalma@yahoo dot com
By SK on
11/2/2009 3:33 PM
|
Re: XNA, Meet WPF
So, some tip about this issue are welcome and really sorry if my question is very simple. Thanks in advance
By replica Mulberry handbags on
1/5/2010 11:42 PM
|
|
ed hardy
ED Hardy Hoodies ED Hardy Hoodies Ed Hardy Swimwear Ed Hardy Swimwear ed hardy tops ed hardy tops ed hardy shoes ed hardy shoes ed hardy t shirt ed hardy t shirt ed hardy shirts ed hardy shirts christian audigier christian audigier ed hardy kids ed hardy kids Ed Hardy Sunglasses Ed Hardy Sunglasses ED Hardy belts ED Hardy belts ed hardy Bags ed hardy Bags ed hardy purse ed hardy purse ed hardy mens ed hardy mens ed hardy womens d hardy womens ed hardy mens shirts ed hardy mens shirts ed hardy mens tops ed hardy mens tops ed hardy mens hoodies d hardy mens hoodies ed hardy mens swim trunks ed hardy mens swim trunks ed hardy mens shoes ed hardy mens shoes ed hardy womens swimwear ed hardy womens swimwear ed hardy womens t shirt ed hardy womens t shirt ed hardy womens tops ed hardy womens tops ed hardy womens pants ed hardy womens pants ed hardy womens hoodies ed hardy womens hoodies ed hardy womens shoes ed hardy womens shoes ed hardy womens clothing ed hardy womens clothing
By ed hardy on
3/15/2010 9:23 PM
|
cheap nike shox
There are wide variety of Nike Shox for both men and women's selection.The Nike Shox Sale are best selling nowadays.Get your own Cheap Nike Shox now.It's definitely time for you to buy womens nike shox and wens nike shox, Wearing them will keep you in a perfect condition.
By nike shox on
3/16/2010 10:05 PM
|
|
Re: XNA, Meet WPF
After morning’s class, abercrombieandfitch.com we couldn’t help rushing to the cafeteria. It always brought us coolness. Men Abercrombie Tees The food was so-so, but the home-cooking is much delicious. Abercrombie When we almost finished eating, I suddenly saw a familiar face— Mens Abercrombie Outerwears —our foreign teacher Nick. A girl was sitting beside him. Abercrombie Tees They were talking over lunch. Abercrombie Scarve I at once told my friends Sandy and Jenny about it. We were so excited. abercrombie men I slowed my speed of eating to wait for that girl. At the moment, abercrombie us they finished their lunch and walked by us with the smile on their faces. Abercrombie Slipper Nick seemed so different from how he looked in the class. Women Abercrombie Outwears I guess that is the power of love. Hope they will enjoy Abercrombie Polos everyday when they get together. Abercrombie Couple Shirt So romantic! I expect that Nick abercrombie fitch will tell his love story to us.
By abercrombie on
9/25/2010 3:39 AM
|
Re: XNA, Meet WPF
It was sunny today. abercrombieandfitch.com I was excited. I got up at a quarter Men Abercrombie Tees to seven. I made a appointment Abercrombie to meet at nine o’clock. After I had my breakfast, Mens Abercrombie Outerwears I went to the Wanjia Market.It was hot outside. Abercrombie Tees When I arrived, my friends didn’t arrive. Abercrombie Scarve I waited for him in front abercrombie men of the KFC’s door. I haven’t seen abercrombie us them for a year. It is very Abercrombie Slipper hot and wet today and is Women Abercrombie Outwears called sauna weather. And in a year, Abercrombie Polos we didn’t come into contact with others frequently. Abercrombie Couple Shirt It is very hot and wet abercrombie fitch today and is called sauna weather. About ten minutes left, Men Abercrombie Henleys Crews my friends arrived one by one.
By abercrombie on
9/25/2010 3:42 AM
|
Re: XNA, Meet WPF
Today I found [url=http://www.abercrombiefitchstyle.com/[b]abercrombieandfitch.com[/b][/url] time was a cruel thing. time always goes on. [url=http://www.abercrombiefitchstyle.com/>[b]Abercrombie[/b][/url] It won’t stay to wait for
somebody. You can’t use [url=http://www.abercrombiefitchstyle.com/2010-new-arrivals/abercrombie-tees][b]Abercrombie Tees[/b][/url]
anything to exchange time. Time is also a fair thing. [url=http://www.abercrombiefitchstyle.com/classic-scarves][b]Abercrombie Scarve[/b][/url]
Although you have [url=hhttp://www.abercrombiefitchstyle.com/men][b]abercrombie men[/b][/url] a lot of money or you enjoy high
reputation, time won’t leave [url=http://www.abercrombiefitchstyle.com/][b]abercrombie us[/b][/url] them more. Today I found I hadn’t enough time. [url=http://www.abercrombiefitchstyle.com/slippers][b]Abercrombie Slipper[/b][/url]
Although I have more [url=http://www.abercrombiefitchstyle.com/women/outerwears][b]Women Abercrombie Outwears[/b][/url] than a-month
holiday, but I found [url=http://www.abercrombiefitchstyle.com/2010-new-arrivals/abercrombie-polos][b]Abercrombie Polos[/b][/url] I
had a lot of things to do. I had [url=http://www.abercrombiefitchstyle.com/2010-new-arrivals/a-f-couple-shirts][b]Abercrombie Couple Shirt[/b][/url] a
lot of homework to do and [url=http://www.abercrombiefitchstyle.com/][b]abercrombie fitch[/b][/url] I am essential to complete
[url=http://www.abercrombiefitchstyle.com/men/henleys-crews][b]Men Abercrombie Henleys Crews[/b][/url] the homework as soon as [url=http://www.abercrombiefitchstyle.com/][b]labercrombie online[/b][/url] I have time.
By abercrombie on
9/25/2010 3:45 AM
|
Re: XNA, Meet WPF
After morning’s class, href="http://www.abercrombiefitchstyle.com/" abercrombieandfitch.com we couldn’t help
rushing to the cafeteria. It always brought us coolness. href="http://www.abercrombiefitchstyle.com/men/tees" Men Abercrombie Tees The food was so-so, but the home-cooking is much delicious. href="http://www.abercrombiefitchstyle.com/" Abercrombie When we almost finished eating, I suddenly saw a familiar face— href="http://www.abercrombiefitchstyle.com/men/outerwears" Mens Abercrombie Outerwears —our foreign teacher Nick. A girl was sitting beside him. href="http://www.abercrombiefitchstyle.com/2010-new-arrivals/abercrombie-tees" Abercrombie Tees They were talking over lunch. href="http://www.abercrombiefitchstyle.com/classic-scarves" Abercrombie Scarve I at once told my friends Sandy and Jenny about it. We were so excited. abercrombie men I slowed my speed of eating to wait for that girl. At the moment, href="http://www.abercrombiefitchstyle.com/" abercrombie us they finished their lunch and walked by us with the smile on their faces. href="http://www.abercrombiefitchstyle.com/slippers" Abercrombie Slipper Nick seemed so different from how he looked in the class. href="http://www.abercrombiefitchstyle.com/women/outerwears" Women Abercrombie Outwears I guess that is the power of love. Hope they will enjoy href="http://www.abercrombiefitchstyle.com/2010-new-arrivals/abercrombie-polos" Abercrombie Polos everyday when they get together. href="http://www.abercrombiefitchstyle.com/2010-new-arrivals/a-f-couple-shirts" Abercrombie Couple Shirt So romantic! I expect that Nick href="http://www.abercrombiefitchstyle.com/" abercrombie fitch will tell his love story to us.
By abercrombie on
9/25/2010 3:59 AM
|
Re: XNA, Meet WPF
After morning’s class, href="http://www.abercrombiefitchstyle.com/" abercrombieandfitch.com we couldn’t help
rushing to the cafeteria. It always brought us coolness. href="http://www.abercrombiefitchstyle.com/men/tees" Men Abercrombie Tees The food was so-so, but the home-cooking is much delicious. href="http://www.abercrombiefitchstyle.com/" Abercrombie When we almost finished eating, I suddenly saw a familiar face— href="http://www.abercrombiefitchstyle.com/men/outerwears" Mens Abercrombie Outerwears —our foreign teacher Nick. A girl was sitting beside him. href="http://www.abercrombiefitchstyle.com/2010-new-arrivals/abercrombie-tees" Abercrombie Tees They were talking over lunch. href="http://www.abercrombiefitchstyle.com/classic-scarves" Abercrombie Scarve I at once told my friends Sandy and Jenny about it. We were so excited. abercrombie men I slowed my speed of eating to wait for that girl. At the moment, href="http://www.abercrombiefitchstyle.com/" abercrombie us they finished their lunch and walked by us with the smile on their faces. href="http://www.abercrombiefitchstyle.com/slippers" Abercrombie Slipper Nick seemed so different from how he looked in the class. href="http://www.abercrombiefitchstyle.com/women/outerwears" Women Abercrombie Outwears I guess that is the power of love. Hope they will enjoy href="http://www.abercrombiefitchstyle.com/2010-new-arrivals/abercrombie-polos" Abercrombie Polos everyday when they get together. href="http://www.abercrombiefitchstyle.com/2010-new-arrivals/a-f-couple-shirts" Abercrombie Couple Shirt So romantic! I expect that Nick href="http://www.abercrombiefitchstyle.com/" abercrombie fitch will tell his love story to us.
By abercrombie on
9/25/2010 4:09 AM
|
Re: XNA, Meet WPF
After morning’s class, abercrombieandfitch.com we couldn’t help rushing to the cafeteria. It always brought us coolness. Men Abercrombie Tees The food was so-so, but the home-cooking is much delicious. Abercrombie When we almost finished eating, I suddenly saw a familiar face— Mens Abercrombie Outerwears —our foreign teacher Nick. A girl was sitting beside him. Abercrombie Tees They were talking over lunch. Abercrombie Scarve I at once told my friends Sandy and Jenny about it. We were so excited. abercrombie men I slowed my speed of eating to wait for that girl. At the moment, abercrombie us they finished their lunch and walked by us with the smile on their faces. Abercrombie Slipper Nick seemed so different from how he looked in the class. Women Abercrombie Outwears I guess that is the power of love. Hope they will enjoy Abercrombie Polos everyday when they get together. Abercrombie Couple Shirt So romantic! I expect that Nick abercrombie fitch will tell his love story to us.
By abercrombie on
9/25/2010 4:18 AM
|
Re: XNA, Meet WPF
After morning’s class, abercrombieandfitch.com we couldn’t help rushing to the cafeteria. It always brought us coolness. Men Abercrombie Tees The food was so-so, but the home-cooking is much delicious. Abercrombie When we almost finished eating, I suddenly saw a familiar face— Mens Abercrombie Outerwears —our foreign teacher Nick. A girl was sitting beside him. Abercrombie Tees They were talking over lunch. Abercrombie Scarve I at once told my friends Sandy and Jenny about it. We were so excited. abercrombie men I slowed my speed of eating to wait for that girl. At the moment, abercrombie us they finished their lunch and walked by us with the smile on their faces. Abercrombie Slipper Nick seemed so different from how he looked in the class. Women Abercrombie Outwears I guess that is the power of love. Hope they will enjoy Abercrombie Polos everyday when they get together. Abercrombie Couple Shirt So romantic! I expect that Nick abercrombie fitch will tell his love story to us.
By abercrombie on
9/25/2010 4:29 AM
|
|
|
|