Category: 

What Are the Best Tips for OpenGL® Performance?

Article Details
  • Written By: Eugene P.
  • Edited By: Angela B.
  • Last Modified Date: 26 July 2014
  • Copyright Protected:
    2003-2014
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
In the US, workers under 25 have unemployment rates that are twice the national average.  more...

July 28 ,  1945 :  14 people were killed when a US Army bomber crashed into the Empire State building.  more...

Once a program is written, it often can take just as long to optimize the code and data files as it did to write the code in the first place. This is especially true when attempting to improve OpenGL® performance. 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 employed during rasterization. Actually adding code can make a program run faster if that code is meant to detect and avoid special functions that are not supported by a graphics card. Good programming practices and an understanding of common OpenGL® performance bottlenecks can go a long way toward improving the speed and quality of an OpenGL® application.

One area in which great improvements to OpenGL® performance can be gained is within the data structures of the application itself. OpenGL® scenes and animation usually require an extensive amount of data trees, data structures and arrays. Employing container structures and search algorithms that use the least time possible while still fulfilling the needs of the application can speed up how quickly data are processed and moved to the graphics processing unit (GPU) for display. Understanding how OpenGL® requires data to be formatted also can help, because some compile-time optimizations could occur depending on the language used.

Ad

Texture files are a common area in which OpenGL® performance can be improved. These image files should have pixel dimensions that are only powers of two, even if the hardware does not require it. They also should be optimized inside an image editor to be as small as possible. Generally, animated or moving objects do not need textures that are as detailed as objects that remain still. Using the smallest textures possible without sacrificing too much quality can greatly increase the frame rate.

One common pitfall, especially for new programmers or artists, is to use too much geometry. There are a number of tricks that can help to reduce the number of polygons in a model without sacrificing detail. One mistake often made is to use the geometry of a model to represent details that can much more efficiently be shown in a texture image. Most models are actually very simple, and the complex features are really implemented using bump maps, normals and texture mapping. Simplified, optimized models will increase OpenGL® performance 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 exciting but not supported by most other cards. By using few extensions and relying on hardware acceleration only for basic tasks, OpenGL® performance can be improved across nearly all systems, preventing situations in which a certain line of graphics cards are incapable of achieving an acceptable frame rate.

Profiling software also is very important when attempting to enhance OpenGL® performance. A profiler will measure how long 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 a bottleneck's location. If a certain function is taking longer than others, then it can be targeted for optimization. This can sometimes lead to extensive re-writes of certain code segments but, ultimately, it can create a program that runs as smoothly as possible.

Ad

Discuss this Article

Post your comments

Post Anonymously

Login

username
password
forgot password?

Register

username
password
confirm
email