[vtk-developers] OpenGL 1.2 mystery solved

Francois Bertel francois.bertel at kitware.com
Fri Jul 13 14:26:02 EDT 2007


This message is mainly for Ken Moreland, but it might interest other VTK developers about the wonderful world of OpenGL extensions.

VTK/Rendering/Testing/Cxx/LoadOpenGLExtension.cxx used to have the following lines:

if (!extensions->LoadSupportedExtension("GL_VERSION_1_2"))
    {
    cout << "Is it possible that your driver does not support OpenGL 1.2?"
         << endl << endl;
    int forceLoad = 0;
    for (int i = 0; i < argc; i++)
      {
      if (strcmp("-ForceLoad", argv[i]) == 0)
        {
        forceLoad = 1;
        break;
        }
      }
    if (forceLoad)
      {
      cout << "Some drivers report supporting only GL 1.1 even though they\n"
           << "actually support 1.2 (and probably higher).  I'm going to\n"
           << "try to load the extension anyway.  You will definitely get\n"
           << "a warning from vtkOpenGLExtensionManager about it.  If GL 1.2\n"
           << "really is not supported (or something else is wrong), I will\n"
           << "seg fault." << endl << endl;
      }
    else
      {
      cout << "Your OpenGL driver reports that it does not support\n"
           << "OpenGL 1.2.  If this is true, I cannot perform this test.\n"
           << "There are a few drivers that report only supporting GL 1.1\n"
           << "when they in fact actually support 1.2 (and probably higher).\n"
           << "If you think this might be the case, try rerunning this test\n"
           << "with the -ForceLoad flag.  However, if Opengl 1.2 is really\n"
           << "not supported, a seg fault will occur." << endl << endl;

[...]

     cout << "Set up convolution filter." << endl;
    vtkgl::ConvolutionFilter2D(vtkgl::CONVOLUTION_2D, GL_LUMINANCE, 3, 3,
                             GL_LUMINANCE, GL_FLOAT, laplacian);



The story is I just get access to an ATI Radeon X1300 Pro card under Vista. This card is OpenGL 2.0 but falls into this case.
I tracked down why the failure happened.

In the generated file vtkgl.cxx, in function vtkgl::LoadExtension(), some of the OpenGL 1.2 function pointers are actually initialized, like vtkgl::TexImage3D() but not vtkgl::ConvolutionFilter2D().

The reason is OpenGL 1.2 defines a set of functions that have to be there (like TexImage3D() ) but also an optional imaging subset, only available if the string GL_ARB_imaging exists.

Therefore, loading extension GL_VERSION_1_2 fails on the ATI card because GL_ARB_imaging does not exist and not all the functions are defined.

This is a really special case and I don't think it can be handled through the parser itself. Instead I modified
VTK/Rendering/vtkOpenGLExtensionManager:

vtkOpenGLExtensionManager::LoadExtension() and vtkOpenGLExtensionManager::LoadSupportedExtension() used to call the generated function vtkgl::LoadExtension() directly.
Now they call a new method vtkOpenGLExtensionManager::SafeLoadExtension().

This new method bypasses the generated function if the name of the extension is GL_VERSION_1_2 or GL_ARB_imaging and initializes only the relevant function pointers. In any other case, a call to SafeLoadExtension()
is equivalent to a call to the generated function vtkgl::LoadExtension(). There is another special case when the extension name is GL_VERSION_1_4 because BlendEquation and
BlendColor are only available through GL_ARB_imaging in OpenGL 1.2 or 1.3,  but are actually supported directly with OpenGL 1.4. In this case, SafeLoadExtension()
delegates its job to vtkgl::LoadExtension() first, but in addition it initializes those two functions.

The test has been changed to reflect this bug fix. It is now testing for GL_ARB_imaging instead of GL_VERSION_1_2 to initialize  vtkgl::ConvolutionFilter2D().
And the ForceLoad argument has been removed.

I tested both cases: with this ATI card I covered the case when GL_ARB_imaging does not exist and with my Linux box with an nVidia GeForce 6800, I covered the case when GL_ARB_imaging is supported.


-- 
François Bertel, PhD  | Kitware Inc. Suite 204
1 (518) 371 3971 x113 | 28 Corporate Drive
                      | Clifton Park NY 12065, USA



More information about the vtk-developers mailing list