How to get if current GL context is Core or Compatibility

Is there a way to get wheter the current OpenGL version is CORE or COMPATIBILITY? …the same way I can get the version numbers glGetIntegerv(GL_MAJOR_VERSION, …). Thanks!

Use glGetIntegerv(GL_CONTEXT_PROFILE_MASK,…) in OpenGL 3.2 or above to query this. GL_CONTEXT_FLAGS might also be useful too if you want to check whether debug/forward-compatible/robust/… flags are set.

Thanks! Sadly, it returns 0. Which is according to this post is a driver bug:

I have no control over how the context is created on the lowest level since Im using SDL. I tell it to create a 3.3 Core context, …3.3 is OK, but it seems to be Compatibility.

Try to do something that’s not supported in a core context. Depending on your driver this may be as simple as a glBegin/glEnd call, followed by a glGetError. Or you might try a draw call with VAO 0 - you should get GL_INVALID_OPERATION on a core context.

To my knowledge nvidia blobs allow using the 0 VAO in core.

Trying checking for the GL_ARB_compatibility extension:


int num_ext = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &num_ext);
for(int i=0; i<num_ext; i++)
    if(!strcmp(glGetStringi(GL_EXTENSIONS,i), "GL_ARB_compatibility"))
         printf("Compatiblity Profile
");

If that is extension is present, you’re definitely in a compatibility profile. Otherwise, assume core.