From c64efd9e3083eb39d274021b0b82d78930132e85 Mon Sep 17 00:00:00 2001 From: kgv Date: Mon, 17 Feb 2020 13:59:58 +0300 Subject: [PATCH] 0031375: Visualization, TKOpenGl - suppress warning on WebGL 1.0 Check for WebGL version in advance. --- src/OpenGl/OpenGl_Context.cxx | 55 ++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/src/OpenGl/OpenGl_Context.cxx b/src/OpenGl/OpenGl_Context.cxx index 1623c3a91d..c2818ed519 100644 --- a/src/OpenGl/OpenGl_Context.cxx +++ b/src/OpenGl/OpenGl_Context.cxx @@ -1044,32 +1044,47 @@ void OpenGl_Context::ReadGlVersion (Standard_Integer& theGlVerMajor, theGlVerMajor = 0; theGlVerMinor = 0; -#ifdef GL_MAJOR_VERSION - // available since OpenGL 3.0 and OpenGL 3.0 ES - GLint aMajor = 0, aMinor = 0; - glGetIntegerv (GL_MAJOR_VERSION, &aMajor); - glGetIntegerv (GL_MINOR_VERSION, &aMinor); - // glGetError() sometimes does not report an error here even if - // GL does not know GL_MAJOR_VERSION and GL_MINOR_VERSION constants. - // This happens on some renderers like e.g. Cygwin MESA. - // Thus checking additionally if GL has put anything to - // the output variables. - if (::glGetError() == GL_NO_ERROR && aMajor != 0 && aMinor != 0) + bool toCheckVer3 = true; +#if defined(__EMSCRIPTEN__) + // WebGL 1.0 prints annoying invalid enumeration warnings to console. + toCheckVer3 = false; + if (EMSCRIPTEN_WEBGL_CONTEXT_HANDLE aWebGlCtx = emscripten_webgl_get_current_context()) { - theGlVerMajor = aMajor; - theGlVerMinor = aMinor; - return; - } - for (GLenum anErr = ::glGetError(), aPrevErr = GL_NO_ERROR;; aPrevErr = anErr, anErr = ::glGetError()) - { - if (anErr == GL_NO_ERROR - || anErr == aPrevErr) + EmscriptenWebGLContextAttributes anAttribs = {}; + if (emscripten_webgl_get_context_attributes (aWebGlCtx, &anAttribs) == EMSCRIPTEN_RESULT_SUCCESS) { - break; + toCheckVer3 = anAttribs.majorVersion >= 2; } } #endif + // Available since OpenGL 3.0 and OpenGL ES 3.0. + if (toCheckVer3) + { + GLint aMajor = 0, aMinor = 0; + glGetIntegerv (GL_MAJOR_VERSION, &aMajor); + glGetIntegerv (GL_MINOR_VERSION, &aMinor); + // glGetError() sometimes does not report an error here even if + // GL does not know GL_MAJOR_VERSION and GL_MINOR_VERSION constants. + // This happens on some renderers like e.g. Cygwin MESA. + // Thus checking additionally if GL has put anything to + // the output variables. + if (::glGetError() == GL_NO_ERROR && aMajor != 0 && aMinor != 0) + { + theGlVerMajor = aMajor; + theGlVerMinor = aMinor; + return; + } + for (GLenum anErr = ::glGetError(), aPrevErr = GL_NO_ERROR;; aPrevErr = anErr, anErr = ::glGetError()) + { + if (anErr == GL_NO_ERROR + || anErr == aPrevErr) + { + break; + } + } + } + // Read version string. // Notice that only first two numbers split by point '2.1 XXXXX' are significant. // Following trash (after space) is vendor-specific.