In 2008, version 3.0 of the OpenGL specification was released. With this revision, the Fixed Function Pipeline as well as most of the related OpenGL functions and constants were declared deprecated. These deprecated elements and concepts are now commonly referred to as legacy OpenGL. Legacy OpenGL is still supported by certain implementations that support core OpenGL 3.1 or higher and the GL_ARB_compatibility extension. Implementations that do not expose this extension do only offer features defined in the core OpenGL specification the implementation is based upon.
Note: There is a distinction between the above extension and the corresponding profile which was introduced with OpenGL 3.2.
Implementations of compatibility contexts
Both AMD and NVIDIA provide backwards-compatible implementations at least on Windows and Linux. Apple does only provide an implementation of the core profile and supports core OpenGL 3.2 on Mac OSX. Intel provides an implementation for Windows up to OpenGL 3.1 with Sandy Bridge CPUs and OpenGL 4.0 with Ivy Bridge CPUs. However, Intel's Linux open-source driver developers have recently stated that they will not provide backward-compatibility on Linux.
Detecting legacy OpenGL
Although by no means exhaustive, the following examples are common in most legacy OpenGL applications.
One typical sign that code is using Legacy OpenGL is immediate mode vertex attribute specification starting with a call to glBegin() ending with a call to glEnd(). This concept is based on a procedural method, where vertex attributes are provided vertex by vertex and attribute by attribute. For instance
- setting the object-space position with glVertex*()
- setting the vertex color with glColor*()
- setting the direction of the normal at that vertex with glNormal*()
Other regularly employed facilities are the matrix stack and matrix manipulation commands:
glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(90.0, 0.0, 1.0, 0.0); glTranslatef(0.0, 0.0, -5.0);
Fixed-Function lighting is found in most legacy applications as well. For that purpose, command such as
- glLight*() for setting certain parameters of a specific light source
- glLightModel() for determining the shading algorithm
- glMaterial() for setting material properties that influence said shading algorithm
are used to coarsely approximate real-world lighting with either flat shading or Gouraud shading.
A comprehensive list of all functionality removed from core OpenGL 3.1 and higher can be found in Appendix E of the OpenGL 3.0 specification. The following enumeration shows some important areas that are affected by removal.
- Fixed-function vertex and fragment processing. These stages of the rendering pipeline are now the developers responsibility and can be fully programmed using shaders.
- Immediate-mode vertex attribute specification, client-side vertex arrays. Vertex attributes must be stored in one or more Buffer Objects, or be specified explicitly using glVertexAttrib*(). Since OpenGL 3.2 using Vertex Array Objects is mandatory.
- The GL_QUAD and GL_POLYGON primitive types.
- The matrix stack and related matrix manipulation functions. This includes projection, model-view and texture matrices. Corresponding built-in GLSL functions have also been removed. Managing matrices and sending data to shaders is now the developers responsibility. See this page for libraries designed for that purpose.
- Fixed-function lighting, materials and color materials, fixed-function shadow mapping and bump mapping. Everything possible with functions corresponding to these areas can easily be emulated with shaders.
- Accumulation and auxiliary buffers. If additional buffers are needed Framebuffer Objects can be used.
- Versions 1.10 and 1.20 of the GLSL.
Reasons to avoid legacy OpenGL
Much of the functionality that was promoted to core OpenGL 3.0 was available as extensions before the specification was released. However, most of the features already moved away from legacy concepts like immediate mode vertex attribute specification and offered advantages in one or more of the following fields.
Vertex attribute data can be transferred once to the GPU, and rendered many times. With immediate-mode concepts this was not the case. Vertex attributes would have been transfered every frame - even when using client-side vertex arrays. Immediate-mode attribute specification has two major drawbacks:
- it incurs a lot of API call, e.g. four calls for four different vertex attributes via glVertex*(), glNormal*(), glColor*() and glTexCoord*()
- data has to transfered to the GPU after specification, even with completely static geometry that does not change its appearance in any way
Depending on the number of vertices the geometry to be drawn is made up of, this will lead to a vast number of commands just to specify the vertex attributes. Client-side vertex arrays eliminate the CPU overhead by providing a way to large chunks of attributes with only a few API calls. However, they do not eliminate the need to transfer data to the GPU every time glDrawArrays() or glDrawElements() are called.
Vertex buffer objects offer few API calls while storing all attributes in GPU memory, eliminating both above mentioned drawbacks. Vertex array objects offers even more facilities to reduce the number of API calls, yielding, if all prerequisites are met, only a single draw call for geometry of arbitrary complexity.
Flexibility using shaders
- Sooner or later, real 3D projects come to a point where something more complicated needs to be done. At that point, the flexibility with the free data format of VBOs and the possibility to compute the results using flexible shader programs, will enable efficient design.
- OpenGL ES 2 and 3 don't support immediate mode. If the application is supposed to portable or compatible with mobile devices, the legacy options is not available. Also, although a new application which is supposed to work on more than one platform, e.g. Windows and Linux, drivers might not expose the compatibility extension and thus only support OpenGL 3.0 or higher core features. If so, the application will not work if only a legacy code path exists. Furthermore, if vendors should decide to drop the compatibility extension at some point, i.e. publish drivers only implementing the core profile, the same problem will arise. Writing applications that use only OpenGL 3.0 or higher core features have the advantage of being not only conforming to version 3.0 but also all other versions up to 4.3 and currently there are no known plans to deprecate more features. This means that applications are future proof regarding driver support on all major platforms until explicitly stated otherwise by hardware vendors.
Using the most recent OpenGL version
Remember: OpenGL is not a library, it is a specification. Like TCP/IP isn't a library; TCP and IP simply define communication protocols, which libraries can implement.
You should always use the latest driver version. But OpenGL versions correspond in part to hardware facilities. The major version numbers for OpenGL generally represent tiers of hardware. For example, OpenGL 3.x is roughly equivalent to Direct3D 10-level hardware. OpenGL 4.x is roughly equivalent to Direct3D 11-level hardware.
So to use OpenGL 4.x features (hardware-based features that is. There are several features of 4.x that are available in 3.x hardware as extensions) means to confine your program to only running on 4.x hardware.
GL 3.x hardware is widely available these days, though 4.x hardware has been around for several years now and will only become more widely available. Which you choose is up to you and your needs.