354 IV Performance
will result in costly driver operations such as resource management, current state
error checking, or multiple shared context threads synchronizations.
This chapter presents solutions that can be used to reduce the number of calls to
the graphic driver in order to improve the performance. These solutions allow us to
reduce the CPU overhead and hence increase rendering complexity.
25.2 Efﬁcient OpenGL States Usage
Accessing and modifying OpenGL states can only be done through multiple calls to
the API functions. Each call can potentially consume a lot of processing power. As a
result, care must be taken to efﬁciently change OpenGL states using a s few API calls
as possible. In the OpenGL 1.0 days, state change operations could be accelerated
using display lists which stored precompiled commands that could be executed in
a single call. Despite being static, display lists were used as a fast way to change
OpenGL states. However, they were removed from the OpenGL 3.2 core proﬁle but
are still available in the compatibility proﬁle.
This section presents ways of detecting and avoiding unnecessary API calls. We
also present recent OpenGL features that allow us to increase the efﬁciency of each
call intended to change the current OpenGL states.
25.2.1 Detecting Redundant State Modiﬁcations
Debugging and optimizing an OpenGL application can be made easier by using
some speciﬁc existing software. gDEBugger [Remedy 11] is a free tool that can record
the OpenGL function call sequence for each frame independently. An important
feature of this software is the Statistics and Redundant Function Calls Viewer, as seen
in Figure 25.1, accessible using Ctrl+Shift+S. It allows us to count the number of
Figure 25.1. Using gDEBugger statistics to detect redundant OpenGL calls.