Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does C# natively use GPU for graphics?

Tags:

c#

graphics

gpu

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?

like image 549
Patrick Avatar asked Jul 21 '15 14:07

Patrick


1 Answers

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.

like image 127
adv12 Avatar answered Oct 11 '22 12:10

adv12