1
votes

I am learning Direct2D for a application (in c# using sharpdx) but I have an hard time to find which is the up-to-date way to work..

Here is my current problem :

At first, I used Direct2D only with the D2D1Factory like descripted in the "quick start" of MSDN. But when looking to optimize performance, it seem that I should draw using the ID2D1DeviceContext to have access to some caching mechanism. So I followed this MSDN article to update my application.

But the SharpDX contructor of SolidColorBrush only accept RenderTarget as first parameter, it doesn't seem to have a constructor accepting a DeviceContext. But it used to have it, I have found SharpDX code sample with it.

Is that method decrepated ? Why SharpDX has deleted this constructor ? Because I need to initialize the Brushes from the DeviceContext to use them with my DeviceContext draw calls.

Creating a RenderTarget from the ID2D1Factory to create my brushes and then try to use them with ID2D1DeviceContext.Draw_something() throw a DirectX resources exception (which seem logic...)

Anyone can light me up please ?

Thank a lot.

1
I don't know about sharpdx, never had a need in it, but have you looked at actual Direct2D SDK? ID2D1DeviceContext is itself a render target, it inherits from ID2D1RenderTarget.bunglehead
I am stupid... I haven't noticed that ! I just have to pass my DeviceContext as a RenderTarget... If you want, reply to my post with your comment so I can mark it as Accepted Answer. Thank you ;)Karnalta
Ok, posted as an answer.bunglehead

1 Answers

2
votes

According to SDK ID2D1DeviceContext is itself a render target, it inherits from ID2D1RenderTarget. So you should be able to use device context pointer as render target pointer argument value.