tower120
tower120

Reputation: 5255

How to detect is opengl ruunning on Desktop or ES

I'm writing crossplatform library on C++ and OpenGL. I want to know how to detect whether I running on OpenGL Desktop, or ES?

Maybe sowehow with glGetString(GL_SHADING_LANGUAGE_VERSION)?

Upvotes: 2

Views: 1960

Answers (2)

tower120
tower120

Reputation: 5255

Inside Shader:
According to http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf (page 12) there should be GL_ES define. If it is 0, or absent - you using dektop implementation, otherwise - ES.

In other places:
GL_ES_VERSION_2_0 defined here http://www.khronos.org/registry/gles/api/GLES2/gl2.h. So if it defined - we're on ES system.
Wikibooks recommend it, also: http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_03

Upvotes: 2

Andon M. Coleman
Andon M. Coleman

Reputation: 43319

Parsing version strings to tell anything about an OpenGL implementation has always been taboo. They are for human eyes only, otherwise there would be a stricter set of rules governing how the string had to be formatted and compliance guarantees before a version number could be reported.


That said, the GLES specification is stricter than GL on this matter so it could be possible:

OpenGL ES 2.0 Specification - 6.1.5 String Queries - pp. 128

The GL_VERSION string is laid out as follows:

"OpenGL ES N.M vendor-specific information"

In OpenGL a compliant implementation will format its GL_VERSION string this way:

OpenGL 4.4 Core Specification - 22.2 String Queries - pp. 488

The GL_VERSION and GL_SHADING_LANGUAGE_VERSION strings are laid out as follows:

<version number><space><vendor-specific information>

[...]

The version number is either of the form major number.minor number or major number.minor number.release number, where the numbers all have one or more digits.

What this means is that in a compliant OpenGL ES implementation the version string will begin with OpenGL ES where as in OpenGL it will begin with a number (though I would not assume that "number" is limited to the characters [0-9] given the vague language used). You could theoretically use this information to distinguish between the two.

But you should not infer that because an implementation reports a certain version number that it actually implements the required feature set for compliance - this was a huge issue back in the days of OpenGL 2.0.

Upvotes: 3

Related Questions