Direct2D canvas for SharpDX


I have contributed to SharpDX the following feature : a cached Direct2D surface.

My contribution started when I asked for help for an issue with Direct2D, the SharpDX team was of great help; it ended up talking about how repetitive calls quickly affect performance and suggested a caching system.

I decided to adopt the philosophy that the Toolkit does, encompass native types into simpler ones to use. I started something with some ideas taken from my experience with WPF.


Here 3 canvases (background, static/dynamic texts) along some 3D content:

(project at

For the formatted text, it is drawn using the following syntax:

Thanks to the Named and Optional Arguments features of C# we can get a terse syntax but still provide customization if needed, this is approximately the usage I was expecting when drawing such content.

The other feature is the caching of content, currently it is quite primitive but efficient nonetheless. The user pushes and pulls objects onto canvases and by using multiple instances of them with a minimum of discipline in regard to the placement of objects, one can render thousands of objects at each frame without a performance penalty.


About 30% of the methods in DeviceContext and RenderTarget classes are implemented. I am quite confident with implementing the remaining bits as the text-related functions were the trickiest but it went pretty well in the end.

I am finished with the initial work on this feature and have committed this feature to my fork; I am waiting for their review about the whole thing prior continuing my work.

Leave a Reply

Your email address will not be published. Required fields are marked *