PDA

View Full Version : glGetIntegerv(GL_MAJOR_VERSION) returns GL_INVALID_ENUM on core context



Stephen A
02-06-2014, 07:17 AM
What is the correct way to get the OpenGL version on an OpenGL core context?

I am using:


int major = 0;
int minor = 0;
glGetIntegerv(GL_MAJOR_VERSION, &major);
glGetIntegerv(GL_MINOR_VERSION, &minor);


but both lines return an invalid enum error.

glGetIntegerv (https://www.opengl.org/sdk/docs/man4/xhtml/glGet.xml) says that both tokens are allowed. What gives?

This is on Mac OS X 10.9, using a Nvidia 650M and a core context.

nenad*
02-06-2014, 08:24 AM
GL_MINOR_VERSION and GL_MAJOR_VERSION are not valid in Opengl 1.1 and for some reason your program might be calling 1.1 version of glGet*. Quick workaround would be to use glGetString(GL_VERSION) instead.

Aleksandar
02-06-2014, 01:48 PM
Stephen, this is a very platform-specific question, so you should post it into MacOS section.
I can only confirm that GL_MAJOR_VERSION and GL_MINOR_VERSION are both valid in core profile.
You probably have a problem with an enumeration. I'm not sure how it is defined in your environment on Mac OS.

The values are well known (at least for Win/Linux):


#define GL_MAJOR_VERSION 0x821B
#define GL_MINOR_VERSION 0x821C

but try to find why it is not already defined. As far as I know Mac OS doesn't need glext.h/glcorearb.h. By default MacOS X 10.9 should create GL 4.1 core profile (if not used kCGLOGLPVersion_Legacy).

In Windows, drivers aways return highest supported version. Even if created with wglCreateContext(), the context is highest supported with compatibility profile. wglCreateContextAttribsARB() just enables defining values of the attributes (choosing a context type). Early GL 3.x drivers created GL 2.1 context with wglCreateContext() call, but nowadays it is always the highest supported.

arekkusu
02-06-2014, 03:16 PM
By default MacOS X 10.9 should create GL 4.1 core profile
This is incorrect. By default OSX creates a Legacy 2.1 context, because Core Profile is not backwards compatible. Apps must explicitly request Core Profile to get it. (Note that OSX does not support a Compatibility Profile version higher than 2.1.) Circa Mavericks, the returned Core Profile version will either be 3.3 or 4.1, depending on the driver's capabilities. (Also note that OSX supports heterogeneous drivers in a single context, and the version (and extensions, limits etc) can change when the virtualscreen (https://developer.apple.com/library/mac/documentation/graphicsimaging/conceptual/OpenGL-MacProgGuide/opengl_pg_concepts/opengl_pg_concepts.html#//apple_ref/doc/uid/TP40001987-CH208-SW21) changes.)


As far as I know Mac OS doesn't need glext.h/glcorearb.h
In the OSX SDK you will find:


OpenGL/OpenGL.h, gltypes.h // platform
OpenGL/gl.h, glext.h // Legacy Profile
OpenGL/gl3.h, gl3ext.h // Core Profile


The unfortunately-named gl3.h was shipped in Lion, before the ARB had renamed glcorearb.h. This header includes only Core Profile API (for everything in GL4.1, circa Mavericks) but unlike glcorearb.h does not include extensions.






This is on Mac OS X 10.9, using a Nvidia 650M and a core context.
I suspect your pixel format is just wrong. Verify:

printf("%s %s\n", glGetString(GL_RENDERER), glGetString(GL_VERSION));

I can confirm that if you've actually created a Core Profile context, the version enums return the proper values.
Alternatively, for desktop GL (not ES) it is fairly safe to derive the version this way:

float version;
sscanf(glGetString(GL_VERSION), "%f", &version);
...which unlike GL_MAJOR_VERSION, will work in both Legacy and Core profiles.

ES needs a slightly different approach due to its spec'd string formatting requirements.

Aleksandar
02-07-2014, 01:08 AM
This is incorrect. By default OSX creates a Legacy 2.1 context.
Thanks for the clarification! I have never program on Mac. My assumption was relied on other peoples claims.


Circa Mavericks, the returned Core Profile version will either be 3.3 or 4.1, depending on the driver's capabilities.
I also thought it is based on GPU capabilities, not driver ones. OK, it can be thought on that way, since OS delivers a driver bundle. When I said 4.1, I meant for GF6xx.


The unfortunately-named gl3.h was shipped in Lion, before the ARB had renamed glcorearb.h. This header includes only Core Profile API (for everything in GL4.1, circa Mavericks) but unlike glcorearb.h does not include extensions.Also good to know. Thanks!