druid- 's   mail me
GL Journal

---
MAIN
JOURNAL
ARTICLES
PROBLEMS
FILES
LINKS
INFO
OLD NEWS
THANKS
---
OpenGL Extensions
by druid- (sfranke@usc.edu) - (6/22/99)

      Introduction
      OpenGL implements extensions as a way for hardware vendors to introduce new features into the GL without having to wait for the ARB to decide on a spec. This is useful in two ways: it speeds up the introduction of new features in the GL, and at the same time, doesn't force the ARB to redo the spec every year or more (like DirectX).

      The most notable extension in the recent gaming industry is ARB_multitexture. While it wasn't always an ARB extension (GLQuake used SGIS_multitexture), it has been one of the best examples of how the extension scheme works. The only problem is making sure a hardware vendor introduces new extensions when they add a new feature to their chipset. Luckily OpenGL is popular enough and has strong industry support (John Carmack at id and lots of ex-SGI engineers at NVIDIA), so we're seeing many new cool extensions.

      Check out my table of extensions, download the simple program and send me new information.

      Links
      Here are some links before I start showing some code:

      Checking for extensions
      This is from the sample:

        char *pext;
        const char *ext;
        bool ext_pal_support;
        
        [...]
        
        ext_pal_support = FALSE;
        
        ext = glGetString (GL_EXTENSIONS);
        pext = ext;
        while( !ext_pal_support && pext )
        {
        	int cnt = 0;
        	pext2 = pext;
        	while( *pext2 && *pext2++ != ' ' )
        		cnt++;
        	if( strncmp( pext,"GL_EXT_paletted_texture", cnt)==0 )
        		ext_pal_support = TRUE;
        	pext += cnt + 1;
        }
        					
      In this example, we're looking for the extension for paletted textures (GL_EXT_paletted_texture). Notice how it steps through the entire string looking for that specific extension. The string returned from glGetString() is a long list of the extensions seperated by a space and null terminated. See how easy this is? You can search for as many extensions as you like without much extra work.

      07/7/99 - Here's a simpler way to do it (if you like that sort of thing) sent in by Michael Steinberg:

        boolean suppExt(char extName[])
        {
         if ( strstr( (const char*)glGetString( GL_EXTENSIONS ), extName ) == NULL) return false;
         else return true;  // "else" not necessary...
        }
        					

      Using extensions
      This is a little troublesome because there are several ways in which extensions are used. It can be simply a new constant value (S3TC), or it can require new functions (multitexture) or both. The best thing to do is look at the spec to get any new constants and function declarations.

      This example is taken from my GLConsole for loading and using palettized images.

        extern BOOL ext_pal_support;
        static PFNGLCOLORTABLEEXTPROC glColorTable;
        					
      This is in a seperate file (tex.c) from the main code. PFNGLCOLORTABLEEXTPROC is a pointer to an OpenGL function. We will load this function from the OpenGL driver next.
        BOOL GLSetupPalSupport( void )
        {
        	if( !ext_pal_support )
        		return FALSE;
        	glColorTable = (PFNGLCOLORTABLEEXTPROC) wglGetProcAddress( "glColorTableEXT" );
        	if( !glColorTable )
        		return FALSE;
        	return TRUE;
        }
        					
      This is called after we've checked the extension list. If it is supported, we try to get a pointer to the function in the ICD with wglGetProcAddress, which needs to be typecast to the GL function pointer.
        glColorTable ( GL_TEXTURE_2D,
        	GL_RGBA,
        	256,
        	GL_RGBA,
        	GL_UNSIGNED_BYTE,
        	paldata );					
        					
      Then we make the call to the function as per it's definition. See the GLConsole code for complete functions for loading 8-bit bmps.

      Conclusion
      Aren't extensions great? Now if we can get vendors to post more information about their driver's extensions (especially the vendor specific ones). Kudos to ATI for putting up their list of extensions. Let me know if other vendors have done the same thing. I may have overlooked some.

    Click Here!
    last updated
    These apply to all of my pages linked from this one:
      QUAKE(R) is a registered trademark of Id Software, Inc. QUAKE(R), the stylized reproduction of the QUAKE(R) trademark, including, without limitation, the Q in QUAKE(R), and the images depicted in QUAKE(R) are the copyrighted property of Id Software, Inc.

      Microsoft VC++ and other phrases used to represent Microsoft Visual C++ Developer Studio are registered trademarks of Microsoft Corporation.

      OpenGL is a registered trademark of Silicon Graphics, Inc. (SGI)

    If I'm using / abusing any other trademarks, please inform me.