Skip to content

Remove supportsWebGL2EntryPoints #9919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 39 additions & 30 deletions src/library_webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,18 @@ var LibraryGL = {
webGLContextAttributes['preserveDrawingBuffer'] = true;
#endif

#if USE_WEBGL2 && MIN_CHROME_VERSION <= 57
// BUG: Workaround Chrome WebGL 2 issue: the first shipped versions of WebGL 2 in Chrome 57 did not actually implement
// the new garbage free WebGL 2 entry points that take an offset and a length to an existing heap (instead of having to
// create a completely new heap view). In Chrome the entry points only were added in to Chrome 58 and newer. For
// Chrome 57 (and older), disable WebGL 2 support altogether.
function getChromeVersion() {
var chromeVersion = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
if (chromeVersion) return chromeVersion[2]|0;
// If not chrome, fall through to return undefined. (undefined <= integer will yield false)
}
#endif

#if GL_DEBUG
var errorInfo = '?';
function onContextCreationError(event) {
Expand All @@ -550,7 +562,14 @@ var LibraryGL = {

var ctx =
#if USE_WEBGL2
(webGLContextAttributes.majorVersion > 1) ? canvas.getContext("webgl2", webGLContextAttributes) :
(webGLContextAttributes.majorVersion > 1)
?
#if MIN_CHROME_VERSION <= 57
!(getChromeVersion() <= 57) && canvas.getContext("webgl2", webGLContextAttributes)
#else
canvas.getContext("webgl2", webGLContextAttributes)
#endif
:
#endif
(canvas.getContext("webgl", webGLContextAttributes)
// https://caniuse.com/#feat=webgl
Expand Down Expand Up @@ -873,16 +892,6 @@ var LibraryGL = {
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.
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);
#endif

#if WORKAROUND_OLD_WEBGL_UNIFORM_UPLOAD_IGNORED_OFFSET_BUG
context.cannotHandleOffsetsInUniformArrayViews = (function(g) {
function b(c, t) {
Expand Down Expand Up @@ -1382,7 +1391,7 @@ var LibraryGL = {
glCompressedTexImage2D__sig: 'viiiiiiii',
glCompressedTexImage2D: function(target, level, internalFormat, width, height, border, imageSize, data) {
#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GLctx.currentPixelUnpackBufferBinding) {
GLctx['compressedTexImage2D'](target, level, internalFormat, width, height, border, imageSize, data);
} else {
Expand All @@ -1398,7 +1407,7 @@ var LibraryGL = {
glCompressedTexSubImage2D__sig: 'viiiiiiiii',
glCompressedTexSubImage2D: function(target, level, xoffset, yoffset, width, height, format, imageSize, data) {
#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GLctx.currentPixelUnpackBufferBinding) {
GLctx['compressedTexSubImage2D'](target, level, xoffset, yoffset, width, height, format, imageSize, data);
} else {
Expand Down Expand Up @@ -1495,7 +1504,7 @@ var LibraryGL = {
}
}
#endif
if (GL.currentContext.supportsWebGL2EntryPoints) {
if (GL.currentContext.version >= 2) {
// WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GLctx.currentPixelUnpackBufferBinding) {
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, pixels);
Expand Down Expand Up @@ -1527,7 +1536,7 @@ var LibraryGL = {
if (type == 0x8d61/*GL_HALF_FLOAT_OES*/) type = 0x140B /*GL_HALF_FLOAT*/;
}
#endif
if (GL.currentContext.supportsWebGL2EntryPoints) {
if (GL.currentContext.version >= 2) {
// WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GLctx.currentPixelUnpackBufferBinding) {
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
Expand All @@ -1553,7 +1562,7 @@ var LibraryGL = {
],
glReadPixels: function(x, y, width, height, format, type, pixels) {
#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GLctx.currentPixelPackBufferBinding) {
GLctx.readPixels(x, y, width, height, format, type, pixels);
} else {
Expand Down Expand Up @@ -1731,7 +1740,7 @@ var LibraryGL = {
}
#endif
#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (data) {
GLctx.bufferData(target, HEAPU8, usage, data, size);
} else {
Expand All @@ -1750,7 +1759,7 @@ var LibraryGL = {
glBufferSubData__sig: 'viiii',
glBufferSubData: function(target, offset, size, data) {
#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
GLctx.bufferSubData(target, offset, HEAPU8, data, size);
return;
}
Expand Down Expand Up @@ -2167,7 +2176,7 @@ var LibraryGL = {
#endif

#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
GLctx.uniform1iv(GL.uniforms[location], HEAP32, value>>2, count);
return;
}
Expand All @@ -2184,7 +2193,7 @@ var LibraryGL = {
#endif

#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
GLctx.uniform2iv(GL.uniforms[location], HEAP32, value>>2, count*2);
return;
}
Expand All @@ -2201,7 +2210,7 @@ var LibraryGL = {
#endif

#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
GLctx.uniform3iv(GL.uniforms[location], HEAP32, value>>2, count*3);
return;
}
Expand All @@ -2218,7 +2227,7 @@ var LibraryGL = {
#endif

#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
GLctx.uniform4iv(GL.uniforms[location], HEAP32, value>>2, count*4);
return;
}
Expand All @@ -2235,7 +2244,7 @@ var LibraryGL = {
#endif

#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
GLctx.uniform1fv(GL.uniforms[location], HEAPF32, value>>2, count);
return;
}
Expand Down Expand Up @@ -2267,7 +2276,7 @@ var LibraryGL = {
#endif

#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
GLctx.uniform2fv(GL.uniforms[location], HEAPF32, value>>2, count*2);
return;
}
Expand Down Expand Up @@ -2300,7 +2309,7 @@ var LibraryGL = {
#endif

#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
GLctx.uniform3fv(GL.uniforms[location], HEAPF32, value>>2, count*3);
return;
}
Expand Down Expand Up @@ -2334,7 +2343,7 @@ var LibraryGL = {
#endif

#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
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;
}
Expand Down Expand Up @@ -2369,7 +2378,7 @@ var LibraryGL = {
#endif

#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
GLctx.uniformMatrix2fv(GL.uniforms[location], !!transpose, HEAPF32, value>>2, count*4);
return;
}
Expand Down Expand Up @@ -2404,7 +2413,7 @@ var LibraryGL = {
#endif

#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
GLctx.uniformMatrix3fv(GL.uniforms[location], !!transpose, HEAPF32, value>>2, count*9);
return;
}
Expand Down Expand Up @@ -2444,7 +2453,7 @@ var LibraryGL = {
#endif

#if USE_WEBGL2
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
GLctx.uniformMatrix4fv(GL.uniforms[location], !!transpose, HEAPF32, value>>2, count*16);
return;
}
Expand Down Expand Up @@ -3487,7 +3496,7 @@ var LibraryGL = {
GL.mappedBuffers[buffer] = null;

if (!(mapping.access & 0x10)) /* GL_MAP_FLUSH_EXPLICIT_BIT */
if (GL.currentContext.supportsWebGL2EntryPoints) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
GLctx.bufferSubData(target, mapping.offset, HEAPU8, mapping.mem, mapping.length);
} else {
GLctx.bufferSubData(target, mapping.offset, HEAPU8.subarray(mapping.mem, mapping.mem+mapping.length));
Expand Down
Loading