I use GLFW3 and GLEW wrappers in Emscripten, so I don't call emscripten_webgl_create_context
manually and don't set context's properties. The context version is determined only by JS code, which is out of my scope. In my C++ code I need to know whether we run in WebGL1 or WebGL2 context. Is there a document-independent way to do it? Something like:
const auto ctx = emscripten_webgl_get_current_context();
emscripten_webgl_get_context_version(ctx);// Should return 1 or 2.
In C++
const char ES_VERSION_2_0[] = "OpenGL ES 2.0";
const char ES_VERSION_3_0[] = "OpenGL ES 3.0";
const char* version = glGetString(GL_VERSION);
if (strncmp(version, ES_VERSION_2_0, sizeof(ES_VERSION_2_0)) == 0) {
// it's WebGL1
} else if (strncmp(version, ES_VERSION_3_0, sizeof(ES_VERSION_3_0)) == 0) {
// it's WebGL2
} else {
// it's something else
}
Version strings in WebGL have a required non-hardware dependent starting format. See the spec for WebGL2
VERSION: Returns a version or release number of the form WebGL<space>2.0<optional><space><vendor-specific information></optional>.
and for WebGL1
VERSION: Returns a version or release number of the form WebGL<space>1.0<space><vendor-specific information>.
Emscripten also returns fixed strings. See the source