OpenGL/GLEW: How to choose the correct/existing enum without provoking a compile time error

StackOverflow https://stackoverflow.com/questions/7499493

  •  24-01-2021
  •  | 
  •  

Question

I am currently using glew to detect some GPU features of the bound openGL context.

Imagine a texture class where I want to use the openGL 3.0 enums if available and fallback to extensions if opengl 3.0 is not in place but the extension is i.e:

uint32 chooseGlInternalFormat(uint32 _pixelType, uint32 _pixelFormat)
{
    uint32 ret;
    //...
    if(GLEW_EXT_texture_integer || GLEW_VERSION_3_0)
    {
        bool bUseExt = !GLEW_VERSION_3_0; //if only the extension is available but not gl 3.0, fallback
        ret = bUseIntEXT ? GL_LUMINANCE8UI_EXT : GL_R8UI;
    }
    //...
}

obviously this causes a compile time error since GL_R8UI won't exist if opengl 3.0 is not supported.- What is the common way to solve this?

Was it helpful?

Solution

Some larger applications take the newest enum specification and add their own enums based on it. If you only need it this one time you can just define your own enum for this single case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top