18

I'd like to draw heavy usage graphics in the fastest way. If I use standard C# graphics callbacks (es.graphics.drawline) am I doing it right? Or am I to use different libraries?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Patrick
  • 3,073
  • 2
  • 22
  • 60
  • 1
    Why this downvote, the question isn't silly ? –  Jul 21 '15 at 14:17
  • Are you using winforms or wpf? – PatrickSchiefer Jul 21 '15 at 14:18
  • 2
    @YvesDaoust seems to be a lot of down voting going on without a justifiable reason, but if you read the first comment to this question then you can see that some people are just 'like that!' ... http://meta.stackexchange.com/questions/135/encouraging-people-to-explain-downvotes – 3-14159265358979323846264 Jul 21 '15 at 14:21
  • maybe you can use a library for converting c# to cuda check [this](http://stackoverflow.com/questions/375011/utilizing-the-gpu-with-c-sharp) answer if you cant use cuda directly – Milad Qasemi Jul 21 '15 at 14:26
  • 1
    The Graphics class uses the legacy video driver interface, it has been 2D accelerated for decades. It is up to the video driver to actually implement it, non-zero odds that modern ones use GPU resources. But that's totally invisible and no programmer would ever use the term when talking about System.Drawing.Graphics. You'd need DirectX to truly take advantage of GPU rendering, such as provided by WPF or Modern UI. – Hans Passant Jul 21 '15 at 14:47

1 Answers1

10

Graphics.DrawLine is a GDI+ call. If you're using Windows Forms and doing your drawing with the System.Drawing classes, you're using GDI+, which is not hardware-accelerated. To get hardware acceleration, you need to use WPF in place of WinForms or draw with Direct3D/Direct2D. The latter two (Direct3D/Direct2D) are COM-based, so you'll need a .NET wrapper. Microsoft wrapped Direct3D for .NET with Managed DirectX followed by XNA. Both (I believe) are now deprecated. There are also third-party wrappers for the DirectX libraries that are more up-to-date.

Edit: I just learned from @HansPassant's comment that GDI+ is 2D accelerated. I thought that only applied to GDI (as opposed to GDI+) because GDI+ handles things like antialiasing that (as I understood it) 2D hardware didn't do. But apparently I was wrong.

adv12
  • 8,443
  • 2
  • 24
  • 48
  • 1
    Just wanted to mention that `MonoGame` wraps directX or OpenGL in the same API that XNA uses, but is still actively maintained, – Bradley Uffner Jul 21 '15 at 14:34
  • In addition to this, I highly recommend SharpDX as a managed wrapper around DirectX. – Kyle Jul 21 '15 at 14:35