Once a program has been written, optimizing the code and data files can often take as long as writing the code in the first place. 

This is especially true when trying to improve the performance of OpenGL®. Many factors can affect performance, from the size and format of texture files to the amount of geometry in a scene, to the rendering options used during rasterization. In reality, adding code can make a program run faster if that code is intended to detect and avoid special features not supported by a graphics card. Good programming practices and an understanding of common OpenGL® performance bottlenecks can go a long way in improving the speed and quality of an OpenGL® application.

One area where great improvements to OpenGL® performance can be achieved is within the data structures of the application itself. OpenGL® scenes and animations usually require a large amount of data trees, data structures and arrays. Using container structures and search algorithms that use as little time as possible while still meeting the needs of your application can speed up the rate at which data is processed and moved to the graphics processing unit (GPU) for display. Understanding how OpenGL® requires data formatting can also help, as some compile-time optimizations may occur depending on the language used.

Texture files are a common area where OpenGL® performance can be improved. These image files should have dimensions in pixels that are only powers of two, even if the hardware doesn’t require it. They should also be optimized within an image editor to be as small as possible. Generally, animated or moving objects don’t need as detailed textures as objects that stay still. Using the smallest textures possible without sacrificing too much quality can dramatically increase your frame rate.

A common pitfall, especially for new programmers or artists, is using too much geometry. There are a number of tricks that can help reduce the number of polygons in a model without sacrificing detail. A mistake often made is to use model geometry to represent details that can be shown much more efficiently in a texture image. Most of the models are actually very simple and the complex features are really implemented using bump maps, normals and texture mapping. The simplified and optimized models will increase the performance of OpenGL® by reducing the number of calculations that need to be performed on each vertex.

For some applications, it can be beneficial to program for the lowest common denominator when it comes to hardware. Some high-end graphics cards implement OpenGL® features that are incredibly cool but not supported by most other cards. By using a few extensions and relying on hardware acceleration for only basic tasks, OpenGL® performance can be improved on almost any system, preventing situations where a given line of graphics cards is unable to hit a frame rate acceptable.

Profiling software is also very important when trying to improve OpenGL® performance. A profiler will measure the time it takes to execute each line of code, each function, and each operation within a program. This can be an incredibly effective way to identify the location of a bottleneck. If a certain feature takes longer than others, it can be targeted for optimization. This can sometimes lead to extensive rewrites of certain segments of code but, ultimately, can create a program that runs as smoothly as possible.

Angelo Raguso
Author: Angelo Raguso

Leave a Reply

Your email address will not be published. Required fields are marked *