Jump to content
  • Advertisement
Sign in to follow this  

[SharpDX] trying to setup D2D1 on D3D11

This topic is 2772 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 using SharpDX to call DirectX from C#

I'm trying to setup a class which contains a D3D11.Texture2D shared with a D2D1 .RenderTarget
I try to follow these recommendations:

my code is as follow:
public override void Reset(int w, int h)
//base.Reset(w, h); // no base.Reset() let's do it our self!

// work in progress... inspired by
// http://www.gamedev.net/topic/547920-how-to-use-d2d-with-d3d11/

if (w < 1)
throw new ArgumentOutOfRangeException("w");
if (h < 1)
throw new ArgumentOutOfRangeException("h");

var desc = new Texture2DDescription
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
Format = Format.B8G8R8A8_UNorm,
Width = w,
Height = h,
MipLevels = 1,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
OptionFlags = ResourceOptionFlags.Shared | ResourceOptionFlags.SharedKeyedmutex,
CpuAccessFlags = CpuAccessFlags.None,
ArraySize = 1

// ====== crash here ===== if OptionFlags is SharedKeyedmutex
renderTarget = new Texture2D(this.Device, desc);

renderTargetView = new RenderTargetView(this.Device, this.renderTarget);

using (var res11 = RenderTarget.QueryInterface<SharpDX.DXGI.Resource>())
using (var res10 = device10.OpenSharedResource<SharpDX.DXGI.Resource>(res11.SharedHandle))
using (var surface = res10.QueryInterface<Surface>())
renderTarget2D = new RenderTarget(
new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied))
renderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;

Device.ImmediateContext.Rasterizer.SetViewports(new Viewport(0, 0, w, h, 0.0f, 1.0f));

Unfortunately this crash when I try to setup the D3D11.Texture2D if I used SharedKeyedMutex flag!
Any tips ?

Or maybe another way to have D2D1 on D3D11?

I'm also a DirectX newbie..... :(

Share this post

Link to post
Share on other sites
Damn, I just saw in the documentation that Shared and SharedKeyedMutex are mutually exclusive!

But, mm.. I have another problem... I turn my surface in a D3D9 surface later with the code which requires the Shared flag! (because it is displayed in a WPF's D3DImage which takes a D3D9.Texture2D as parameter....) it's a catch 22!!!

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!