Search code examples
direct2dsharpdxgdi

SharpDX/SolidColorBrush constructor with DeviceContext?


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.


Solution

  • 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.