Avoid Drawing

Graphics APIs let programs move large amounts of data around with a few function calls. Performing blits, drawing filled shapes or large numbers of lines, rendering textured 3D polygons, all increase the time it takes to render a single frame. Larger displays, higher colour depths, antialiasing, alpha channels (translucency) and other goodies beloved of our users all exacerbate this performance hot-spot.

Therefore: avoid drawing as much as possible.

Precalculate as much as possible to reduce the amount of screen real estate that needs to be updated. For example, calculate the mimimum RefreshRectangles that can be used to draw any changes to the display and clip any drawing to this area of the display. As a general rule of thumb, doing more maths to reduce the amount of blitting will pay off, especially if you draw to a DoubleBuffer image and then blit that to the display.

Use DeferredUpdates and precalculate as much as possible to avoid drawing the same pixels multiple times per frame. Example precalculations that can be performed include hidden-surface removal in 3D graphics or clipping in 2D graphics.

Additionally, take advantage of the graphics driver. Use AggregateGraphicCommands to AvoidMultiplePrimitiveGraphicCommands and so reduce communication overhead between your program and the driver. For example, most display managers offer both Line and Poly'Line primitives. The latter also goes straight through the renderer, so it is faster to make one Poly'Line request than multiple Line requests.

3D graphics applications can use algorithms such as ViewFrustumCulling?, to avoid drawing polygons that are not in the field of view, and BackFaceCulling?, to avoid drawing faces of solid objects that face away from the viewer and are therefore occluded by other faces. More sophisticated algorithms include using QuadTree?s or BinarySpacePartitionTree?s to precalculate spatial relationships that are used to determine visibility.

Large 3D environments are split into zones, in an application specific manner, and only objects in the same zone as the viewer are drawn. For example, zones may be rooms with closed doors between them.


Also see GraphicsPatterns.

CategoryGraphicsPattern, CategoryPattern


EditText of this page (last edited January 3, 2014) or FindPage with title or text search