Archived issue #0032084
Visualization - WebGL sample errors when run in Safari browser with experimental WebGL 2.0 option
Description
Safari developers are trying to implement WebGL 2.0 support to their browser, but so far it remains partially broken and can be enabled only as experimental feature:
https://trac.webkit.org/wiki/AngleforWebGL
Enabling this flag within OCCT WebGL samples on modern Safari 14 on both macOS and iOS devices shows that it's implementation is indeed still incomplete.
So far within OCCT viewer the issue with glUniform* methods have been observed (glUniform2fv, glUniform4fv, glUniformMatrix4fv actually triggered) - Safari generates weird GL_INVALID_OPERATION error message.
Investigation shown that issue happens specifically with "garbage-free entry points" introduced by WebGL 2.0 used by Emscripten SDK implicitly for optimization purposes.
Disabling this feature allows OCCT viewer to be initialized:
Unfortunately, this code is part of Emscripten SDK, so cannot be easily worked around on OCCT level.
This issue is to track state of the bug - when it will be fixed in Safari, Emscripten or another proposals will be given for implementing a workaround.
https://trac.webkit.org/wiki/AngleforWebGL
Enabling this flag within OCCT WebGL samples on modern Safari 14 on both macOS and iOS devices shows that it's implementation is indeed still incomplete.
So far within OCCT viewer the issue with glUniform* methods have been observed (glUniform2fv, glUniform4fv, glUniformMatrix4fv actually triggered) - Safari generates weird GL_INVALID_OPERATION error message.
Investigation shown that issue happens specifically with "garbage-free entry points" introduced by WebGL 2.0 used by Emscripten SDK implicitly for optimization purposes.
Disabling this feature allows OCCT viewer to be initialized:
function _glUniform4fv(location, count, value) {
GL.validateGLObjectID(GL.uniforms, location, 'glUniform4fv', 'location');
assert((value & 3) == 0, 'Pointer to float data passed to glUniform4fv must be aligned to four bytes!');
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
- GLctx.uniform4fv(GL.uniforms[location], HEAPF32, value>>2, count*4);
- return;
+ //GLctx.uniform4fv(GL.uniforms[location], HEAPF32, value>>2, count*4);
+ //return;
}
if (count <= 72) {
// avoid allocation when uploading few enough uniforms
var view = miniTempWebGLFloatBuffers[4*count-1];
// hoist the heap out of the loop for size and for pthreads+growth.
var heap = HEAPF32;
value >>= 2;
for (var i = 0; i < 4 * count; i += 4) {
var dst = value + i;
view[i] = heap[dst];
view[i + 1] = heap[dst + 1];
view[i + 2] = heap[dst + 2];
view[i + 3] = heap[dst + 3];
}
} else
{
var view = HEAPF32.subarray((value)>>2,(value+count*16)>>2);
}
GLctx.uniform4fv(GL.uniforms[location], view);
}
Unfortunately, this code is part of Emscripten SDK, so cannot be easily worked around on OCCT level.
This issue is to track state of the bug - when it will be fixed in Safari, Emscripten or another proposals will be given for implementing a workaround.
Additional information
WebGL2EntryPoints are NOT implemented by experimental WebGL 2.0 context feature in Safari 14.x causing functions like `glUniform4fv()` to fail with `GL_INVALID_OPERATION`.
The first Chrome versions implementing WebGL 2.0 have similar issue, so that Emscripten had even workaround for this in code based on Chrome version check, however this workaround has been removed since Emscripten 1.39.5, so that there is no place for it in up-to-date Emscripten versions:
https://github.com/emscripten-core/emscripten/pull/9919
The first Chrome versions implementing WebGL 2.0 have similar issue, so that Emscripten had even workaround for this in code based on Chrome version check, however this workaround has been removed since Emscripten 1.39.5, so that there is no place for it in up-to-date Emscripten versions:
https://github.com/emscripten-core/emscripten/pull/9919
----------------------------- src/library_webgl.js -----------------------------
index d3051022c..6e53d920c 100644
@@ -807,21 +807,25 @@ var LibraryGL = {
#if USE_PTHREADS
{{{ makeSetValue('handle', 4, '_pthread_self()', 'i32')}}}; // the thread pointer of the thread that owns the control of the context
#endif
+ // workaround Safari bug returning WebGL 1.0 context by canvas.getContext("webgl2") if WebGL context was already created
+ var majVerWebGl = (typeof WebGL2RenderingContext === 'undefined' || !(ctx instanceof WebGL2RenderingContext)) ? 1 : webGLContextAttributes.majorVersion;
var context = {
handle: handle,
attributes: webGLContextAttributes,
- version: webGLContextAttributes.majorVersion,
+ version: majVerWebGl,
GLctx: ctx
};
#if USE_WEBGL2
// BUG: Workaround Chrome WebGL 2 issue: the first shipped versions of WebGL 2 in Chrome did not actually implement the new WebGL 2 functions.
// Those are supported only in Chrome 58 and newer.
+ // The same is for the first experimental WebGL 2.0 implementations in Safari 14.
function getChromeVersion() {
var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
return raw ? parseInt(raw[2], 10) : false;
}
- context.supportsWebGL2EntryPoints = (context.version >= 2) && (getChromeVersion() === false || getChromeVersion() >= 58);
+ context.supportsWebGL2EntryPoints = (context.version >= 2) && (getChromeVersion() === false || getChromeVersion() >= 58)
+ && !navigator.userAgent.includes("AppleWebKit/");
#endif
#if WORKAROUND_OLD_WEBGL_UNIFORM_UPLOAD_IGNORED_OFFSET_BUG
Public activity
2 archived notes
Participants are labeled by their role within this record.
Please close the issue - should be a problem since Safari 15+.
Closed.
Related records
- #0032083 · related to · closedVisualization, TKOpenGl - PBR rendering is unavailable on Apple A12 Bionic (iPad)
- #0032081 · related to · closedVisualization - WebGL sample errors when run in Safari browser with WebGL 1.0
- #0032082 · related to · closedVisualization, TKOpenGl - improve formatting of error messages