diff --git a/src/OpenGl/OpenGl_Context.cxx b/src/OpenGl/OpenGl_Context.cxx index 303c398ec1..8bf742ef0a 100644 --- a/src/OpenGl/OpenGl_Context.cxx +++ b/src/OpenGl/OpenGl_Context.cxx @@ -74,25 +74,6 @@ IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Context,Standard_Transient) #ifdef __EMSCRIPTEN__ #include #include - - //! Check if WebGL extension is available and activate it - //! (usage of extension without activation will generate errors). - static bool checkEnableWebGlExtension (const OpenGl_Context& theCtx, - const char* theExtName) - { - if (!theCtx.CheckExtension (theExtName)) - { - return false; - } - if (EMSCRIPTEN_WEBGL_CONTEXT_HANDLE aWebGlCtx = emscripten_webgl_get_current_context()) - { - if (emscripten_webgl_enable_extension (aWebGlCtx, theExtName)) - { - return true; - } - } - return false; - } #endif namespace @@ -892,7 +873,25 @@ Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtName) const Messenger()->Send ("TKOpenGL: glGetString (GL_EXTENSIONS) has returned NULL! No GL context?", Message_Warning); return Standard_False; } - return CheckExtension (anExtString, theExtName); + if (!CheckExtension (anExtString, theExtName)) + { + return Standard_False; + } + +#ifdef __EMSCRIPTEN__ + //! Check if WebGL extension is available and activate it + //! (usage of extension without activation will generate errors). + if (EMSCRIPTEN_WEBGL_CONTEXT_HANDLE aWebGlCtx = emscripten_webgl_get_current_context()) + { + if (emscripten_webgl_enable_extension (aWebGlCtx, theExtName)) + { + return Standard_True; + } + } + return Standard_False; +#else + return Standard_True; +#endif } // ======================================================================= @@ -1700,14 +1699,14 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile) mySupportedFormats->Add (Image_Format_AlphaF); mySupportedFormats->Add (Image_Format_RGBF); mySupportedFormats->Add (Image_Format_RGBAF); - if (hasHalfFloatBuffer) + if (hasHalfFloatBuffer != OpenGl_FeatureNotAvailable) { mySupportedFormats->Add (Image_Format_RGBAF_half); } if (arbTexRG) { mySupportedFormats->Add (Image_Format_RGF); - if (hasHalfFloatBuffer) + if (hasHalfFloatBuffer != OpenGl_FeatureNotAvailable) { mySupportedFormats->Add (Image_Format_RGF_half); } @@ -1722,7 +1721,7 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile) } #ifdef __EMSCRIPTEN__ - if (checkEnableWebGlExtension (*this, "GL_WEBGL_compressed_texture_s3tc")) // GL_WEBGL_compressed_texture_s3tc_srgb for sRGB formats + if (CheckExtension ("GL_WEBGL_compressed_texture_s3tc")) // GL_WEBGL_compressed_texture_s3tc_srgb for sRGB formats { mySupportedFormats->Add (Image_CompressedFormat_RGB_S3TC_DXT1); mySupportedFormats->Add (Image_CompressedFormat_RGBA_S3TC_DXT1); @@ -1730,7 +1729,7 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile) mySupportedFormats->Add (Image_CompressedFormat_RGBA_S3TC_DXT5); } if (!extPDS - && checkEnableWebGlExtension (*this, "GL_WEBGL_depth_texture")) + && CheckExtension ("GL_WEBGL_depth_texture")) { extPDS = true; // WebGL 1.0 extension (in WebGL 2.0 core) } @@ -2012,7 +2011,7 @@ void OpenGl_Context::DiagnosticInformation (TColStd_IndexedDataMapOfStringString addInfo (theDict, "GLvendor", (const char*)::glGetString (GL_VENDOR)); addInfo (theDict, "GLdevice", (const char*)::glGetString (GL_RENDERER)); #ifdef __EMSCRIPTEN__ - if (checkEnableWebGlExtension (*this, "GL_WEBGL_debug_renderer_info")) + if (CheckExtension ("GL_WEBGL_debug_renderer_info")) { if (const char* aVendor = (const char*)::glGetString (0x9245)) { diff --git a/src/OpenGl/OpenGl_GlFunctions.cxx b/src/OpenGl/OpenGl_GlFunctions.cxx index ead3f3cdb3..a66a35d652 100644 --- a/src/OpenGl/OpenGl_GlFunctions.cxx +++ b/src/OpenGl/OpenGl_GlFunctions.cxx @@ -455,12 +455,25 @@ void OpenGl_GlFunctions::load (OpenGl_Context& theCtx, theCtx.hasDrawBuffers = OpenGl_FeatureInExtensions; } - theCtx.hasFloatBuffer = isGlGreaterEqualShort (3, 2) ? OpenGl_FeatureInCore : - checkExtensionShort ("GL_EXT_color_buffer_float") ? OpenGl_FeatureInExtensions - : OpenGl_FeatureNotAvailable; - theCtx.hasHalfFloatBuffer = isGlGreaterEqualShort (3, 2) ? OpenGl_FeatureInCore : - checkExtensionShort ("GL_EXT_color_buffer_half_float") ? OpenGl_FeatureInExtensions - : OpenGl_FeatureNotAvailable; + // float textures available since OpenGL ES 3.0+, + // but renderable only since 3.2+ or with extension + theCtx.hasFloatBuffer = theCtx.hasHalfFloatBuffer = OpenGl_FeatureNotAvailable; + if (isGlGreaterEqualShort (3, 2)) + { + theCtx.hasFloatBuffer = theCtx.hasHalfFloatBuffer = OpenGl_FeatureInCore; + } + else + { + if (checkExtensionShort ("GL_EXT_color_buffer_float")) + { + theCtx.hasFloatBuffer = isGlGreaterEqualShort (3, 0) ? OpenGl_FeatureInCore : OpenGl_FeatureInExtensions; + } + if (checkExtensionShort ("GL_EXT_color_buffer_half_float")) + { + // GL_HALF_FLOAT_OES for OpenGL ES 2.0 and GL_HALF_FLOAT for OpenGL ES 3.0+ + theCtx.hasHalfFloatBuffer = isGlGreaterEqualShort (3, 0) ? OpenGl_FeatureInCore : OpenGl_FeatureInExtensions; + } + } theCtx.oesSampleVariables = checkExtensionShort ("GL_OES_sample_variables"); theCtx.oesStdDerivatives = checkExtensionShort ("GL_OES_standard_derivatives");