Chapter 5. Introduction to OpenGL Extensions

OpenGL extensions introduce new features and enhance performance. Some extensions provide completely new functionality; for example, the convolution extension allows you to blur or sharpen images using a filter kernel. Other extensions enhance existing functionality; for example, the fog function extension enhances the existing fog capability.

Several extensions provide functionality that existed in IRIS GL but is not available in OpenGL. If you are porting a program from IRIS GL to OpenGL, you may therefore find some extensions particularly helpful. See Appendix A, “OpenGL and IRIS GL,” for a list of IRIS GL commands and corresponding OpenGL functionality.

This chapter provides basic information about OpenGL extensions. You learn about

Determining Extension Availability

Function names and tokens for OpenGL extensions have EXT or a vendor-specific acronym as a suffix, for example glConvolutionFilter2DEXT() or glColorTableSGI(). The names of the extensions themselves (the extension strings) use prefixes, for example, SGI_color_table. Here is a detailed list of all suffixes and prefixes:

  • EXT is used for extensions that have been reviewed and approved by more than one OpenGL vendor.

  • SGI is used for extensions that are available across the Silicon Graphics product line, although the support for all products may not appear in the same release.

  • SGIS is used for extensions that are found only on a subset of Silicon Graphics platforms.

  • SGIX is used for extensions that are experimental: In future releases, the API for these extensions may change, or they may not be supported at all.

How to Check for OpenGL Extension Availability

All supported extensions have a corresponding definition in gl.h and a token in the extensions string returned by glGetString(). For example, if the ABGR extension (EXT_abgr) is supported, it is defined in gl.h as follows:

#define GL_EXT_abgr 1

GL_EXT_abgr appears in the extensions string returned by glGetString(). Use the definitions in gl.h at compile time to determine if procedure calls corresponding to an extension exist in the library.

Applications should do compile-time checking—for example, making sure GL_EXT_abgr is defined; and run-time checking—for example, making sure GL_EXT_abgr is in the extension string returned by glGetString().

  • Compile-time checking ensures that entry points such as new functions or new enums are supported. You cannot compile or link a program that uses a certain extension if the client-side development environment doesn't support it.

  • Run-time checking ensures that the extension is supported for the OpenGL server and run-time library you are using.

    Note that availability depends not only on the operating system version but also on the particular hardware you are using: even though the 5.3 OpenGL library supports GL_CONVOLUTION_2D_EXT, you get an GL_INVALID_OPERATION error if you call glConvolutionFilter2DEXT() on an Indy system.

Note that libdl interface allows users to dynamically load their own shared objects as needed. Applications can use this interface, particularly the dlsym() command, to compile their application on any system, even if some of the extensions used are not supported.

Example Program: Checking for Extension Availability

In Example 5-1, the function QueryExtension() checks whether an extension is available.

Example 5-1. Checking for Extensions


main(int argc, char* argv[]) {
...
    if (!QueryExtension("GL_EXT_texture_object")) {
        fprintf(stderr, "texture_object extension not supported.\n");
        	exit(1);
    }
...
}

static GLboolean QueryExtension(char *extName)
{
    /*
    ** Search for extName in the extensions string. Use of strstr()
    ** is not sufficient because extension names can be prefixes of
    ** other extension names. Could use strtok() but the constant
    ** string returned by glGetString might be in read-only memory.
    */
    char *p;
    char *end;
    int extNameLen;   

    extNameLen = strlen(extName);
        
    p = (char *)glGetString(GL_EXTENSIONS);
    if (NULL == p) {
        return GL_FALSE;
    }

    end = p + strlen(p);   

    while (p < end) {
        int n = strcspn(p, " ");
        if ((extNameLen == n) && (strncmp(extName, p, n) == 0)) {
            return GL_TRUE;
        }
        p += (n + 1);
    }
    return GL_FALSE;
}

As an alternative to checking for each extension explicitly, you can make the following calls to determine the system and IRIX release on which your program is running:

glGetString(GL_RENDERER)
...
glGetString(GL_VERSION) 

Given a list of extensions supported on that system for that release, you can usually determine whether the particular extension you need is available. For this to work on all systems, a table of different systems and the extensions supported has to be available. Some extensions have been included in patch releases, so be careful when using this approach.

When an extension is incomplete, it is not advertised in the extensions string. Some of the RealityEngine extensions that were supported in IRIX 5.3 (for example, the subtexture, sharpen texture, convolution, and histogram extensions) fall in that category.

Checking for GLX Extension Availability

If you use any of the extensions to GLX, described in Chapter 6, “Resource Control Extensions,” you also need to check for GLX extension availability.

Querying for GLX extension support is similar to querying for OpenGL extension support with the following exceptions:

  • Compile time defines are found in glx.h.

  • To get the list of supported GLX extensions, call glXQueryExtensionsString().

  • GLX versions must be 1.1 or greater (no extensions to GLX 1.0 exist).

Adapt the process described in “How to Check for OpenGL Extension Availability”, taking these exceptions into account.

Finding Information About Extensions

You can find information about the extensions through reference pages, example programs, and extension specifications.

Reference Pages

For the most up-to-date information on extensions, see the following reference pages:

glintro 

Information about the current state of extensions on your system.

glXintro 

Information on GLX extensions.

Note that individual OpenGL reference pages have a MACHINE DEPENDENCIES section that lists the systems on which certain extension functions or options are implemented. Here is an example from the glSampleMaskSGIS reference page:

MACHINE DEPENDENCIES

Multisampling is supported only on RealityEngine, RealityEngine2, VTX and InfiniteReality systems. Currently it can be used with windows of Multisampling-capable Visual types, but not with pixmaps.

Example Programs

All complete example programs included in this guide (though not the short code fragments) are available in /usr/share/src/OpenGL if you have the ogl_dev.sw.samples subsystem installed. You can also find example programs through the Silicon Graphics Developer Toolbox, http://www.sgi.com/Technology/toolbox.html.

Extension Specifications

Extension specifications describe extension functionality from the implementor's point of view. They are prepared to fit in with the OpenGL specification. Specification contain detailed information that goes beyond what developers usually need to know. If you need more detail on any of the extensions, search for its specification in the developer toolbox.