Search code examples
performancevisual-c++drawgdi

How to improve the drawing efficiency of big number of objects with GDI or Qt


I have made a software similar to AutoCAD, which can read and show dwg files and draw lines or curves on top of the dwg background. And I can use mouse wheel to zoom in or zoom out the drawing.

Now I encounter a drawing effiency problem and I can't find a solution, I use MFC GDI to draw objects and I already use double buffer to avoid blink, and I also use the clipbox to avoid drawing invisible objects. With this solution, it's OK for small dwg files. But when it comes to big dwg files, for example there is 200,000+ lines in the dwg file, the time to draw these objects with GDI is about 2.0+ second, and if I use mouse wheel to zoom in or zoom out, the software will be freezed for a few seconds.

So I'd like to know if there is some solutions for this problem. It will be appreciated that if someone could give me some clue. Thanks for advance.


Solution

  • I believe that the only possible solution is to use DirectX or Direct2D to display that amount of data. The difference of these technologies is described in the Comparing Direct2D and GDI Hardware Acceleration article. The core is that GDI uses CPU while Direct2D uses GPU. It is simply impossible to force GDI to render huge number of objects because of that. In oposite, I have faced a problem when the Direct2D rendering was performed by CPU because of some problems with drivers. In this case Direct2D rendering was as slow as GDI.