jingwood / d2dlib

A .NET library for hardware-accelerated, high performance, immediate mode rendering via Direct2D.
MIT License
234 stars 40 forks source link

Performance idea #47

Open BergChristian opened 3 years ago

BergChristian commented 3 years ago

Hi!

An idea which might be wrong for D2D but for GDI+ drawing a line is very expensive. Since most time you draw a straight line, vertical or horizontal I figured out that instead of using draw line, drawing a 1pixel rectangle is 5x faster than draw line.

Not sure if it is the same case here but if, it could be interesting with a “drawlinevertical” and “drawlinehorisontal” function which simply Wraps the draw rectangle function.

Best Christian

jingwood commented 3 years ago

I think your idea is correct, it is about how a perfect line we want to draw. In many cases, the hardware-associated API will draw lines by polygon and do some antialiasing work. If we work with a buffered image in memory, it is faster to fill a part of pixels to draw a straight line.

But, even hardware-associated APIs render lines by polygon, it does more work, but it is finished on the GPU side with faster memory and optimized parallel calculation, it may faster than filling pixels on the CPU side. I haven't been strictly tested about this, just by logic.

BergChristian commented 3 years ago

I tried this and I can say that I could not really measure any performance increase so it works for GDI+ but for D2D it does not make a difference, easier to stick with drawline!