Sign in to follow this  

"SlimDX:D3D11 & Direct2D Interop"

This topic is 2402 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a DirectX11 engine based on SlimDX, and I've hit a major snag. I'm trying to integrate Direct2D into the engine to render 2D graphics, but I'm unable to do so. The problem is that the RenderTarget.FromDXGI method fails and throws an E_NO_INTERFACE error every time I try to create my Direct2D RenderTarget. I do everything by the book: I create a valid Device and SwapChain, get a Surface instance from SwapChain back-buffer, create a valid D2D Factory,etc. I've verified that everything is correct by stepping through with my debugger. But the method always fails! I've tried different Formats, used the BgraSupport flag to create my Device, tried every combination of settings/params possible - all to no avail. Disturbingly, everything suddenly works fine when I switch to D3D10.1 and edit a couple lines to use the Device1 interface! So it begs the question: why can't D3D11 work with Direct2D? How can any 2D graphics berendered if I can't interop with Direct2D? This is a real show-stopper, and I have [color="#366388"]countless hours of work[/color] on the line. I'm hoping someone can point me in the right direction. What's wrong, and how can D3D11 & D2D be used together? And if it's not possible, which would shock me, how the heck can I do 2D rendering at all? MSDN and the documentation for [color="#366388"]DirectX[/color] and SlimDX offer no answers. The DX docs mention only D3D10.1 / Direct2D interop, and offer no explanation ofhow we render 2D graphics now that the Font and Sprite classes are removed in 11. So can anyone help me out? I'm terribly frustrated after wasting days trying to find a solution. So I hope someone knows what I need to do. Thanks for your time and any help/advice you can provide!

Share this post


Link to post
Share on other sites
Thanks for posting this question for me, Alex! ;)

And thanks for answering, Mike.

But that's absolutely ridiculous... "Stupid" isn't quite the word for it I'm afraid, Mike. Damn you, Microsoft!

So where does that leave us?

A) Use a D3D11 AND a D3D10.1 Device? No way...what a waste of resources and super sloppy code...
B) Use DXUT? Nope... I'm using SlimDX, and have written my own some-what complete engine. Sloppy hack-n-splice would be the only way, and I'm not fond of that idea.
C) Hack DirectX itself? lol...

So how the heck can we render simple text and sprites without doing something really whacky, sloppy and wasteful? Am I going to be stuck writing my own 2D rendering API that can spit pixels onto my back-buffer, just to get a decent, clean 2D interface?

The only other thing I can think of is writing something that will rasterize fonts and sprites into a texture and putting them on a 3D quad with an orthographic matrix. I don't like that idea either.

So WTF, Microsoft? What do you expect us to do for 2D graphics?

Share this post


Link to post
Share on other sites
For me I found this library for text rendering in D3D11:
http://www.rufelt.com/fw1fontwrapper/

It uses DirectWrite (and thus Direct2D) to create the fonts. Works like a charm :)

Share this post


Link to post
Share on other sites
[quote name='ATC' timestamp='1308595814' post='4825599']
So where does that leave us?

A) Use a D3D11 AND a D3D10.1 Device? No way...what a waste of resources and super sloppy code...
B) Use DXUT? Nope... I'm using SlimDX, and have written my own some-what complete engine. Sloppy hack-n-splice would be the only way, and I'm not fond of that idea.
C) Hack DirectX itself? lol...

So how the heck can we render simple text and sprites without doing something really whacky, sloppy and wasteful? Am I going to be stuck writing my own 2D rendering API that can spit pixels onto my back-buffer, just to get a decent, clean 2D interface?

The only other thing I can think of is writing something that will rasterize fonts and sprites into a texture and putting them on a 3D quad with an orthographic matrix. I don't like that idea either.

So WTF, Microsoft? What do you expect us to do for 2D graphics?
[/quote]

A) I find using two devices rather elegant. I'm working on a UI library that uses Direct2D and DirectWrite with SlimDX. Direct2D alone isn't versatile enough to handle custom blending and shader effects, so my drawing model is split into Direct2D drawing and Direct3D composition all on its own Direct3D 10.1 device. Most Direct2D drawing is cached in dynamic texture atlases for speed. Ultimately, whatever is being drawn is composited onto a shared and synchronized texture. The other device simply calls OpenSharedResource<Texture2D> with the shared handle and creates a KeyedMutex for the resulting texture. Aside from the mutex lock and release each frame, the texture is used just like any other. The overhead in my code seems to be less than 0.5 milliseconds using two Direct3D 10.1 devices. I don't see why it wouldn't work between 10.1 and 11 devices.

Share this post


Link to post
Share on other sites
Sign in to follow this