aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-05-13 19:39:16 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-05-13 19:39:16 -0700
commitb915f42db8e2b454b8b07e0eb7f8a176fefdc534 (patch)
treec47876949f44fe7213ea52bddc70ba729600f56c /src
parent17ba5c2b0712b8c871a260f3e1ce00527c5a4d1d (diff)
parent6701e2d57e27e68520b2c1dcd04893336884eccc (diff)
Merge pull request #2348 from juj/context_lost
WebGL context loss handling improvements.
Diffstat (limited to 'src')
-rw-r--r--src/library_browser.js5
-rw-r--r--src/library_html5.js6
-rw-r--r--src/shell.html11
-rw-r--r--src/shell_minimal.html11
4 files changed, 26 insertions, 7 deletions
diff --git a/src/library_browser.js b/src/library_browser.js
index 07d33b32..4ef7c577 100644
--- a/src/library_browser.js
+++ b/src/library_browser.js
@@ -322,11 +322,6 @@ mergeInto(LibraryManager.library, {
#endif
// Set the background of the WebGL canvas to black
canvas.style.backgroundColor = "black";
-
- // Warn on context loss
- canvas.addEventListener('webglcontextlost', function(event) {
- alert('WebGL context lost. You will need to reload the page.');
- }, false);
}
if (setInModule) {
GLctx = Module.ctx = ctx;
diff --git a/src/library_html5.js b/src/library_html5.js
index d9376c2a..d5d0cd66 100644
--- a/src/library_html5.js
+++ b/src/library_html5.js
@@ -1307,6 +1307,12 @@ var LibraryJSEvents = {
JSEvents.registerWebGlEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefine('EMSCRIPTEN_EVENT_WEBGLCONTEXTRESTORED') }}}, "webglcontextrestored");
return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}};
},
+
+ emscripten_is_webgl_context_lost: function(target) {
+ // TODO: In the future if multiple GL contexts are supported, use the 'target' parameter to find the canvas to query.
+ if (!Module['ctx']) return true; // No context ~> lost context.
+ return Module['ctx'].isContextLost();
+ }
};
autoAddDeps(LibraryJSEvents, '$JSEvents');
diff --git a/src/shell.html b/src/shell.html
index 1e213024..d204bfa6 100644
--- a/src/shell.html
+++ b/src/shell.html
@@ -1245,7 +1245,16 @@
console.error(text);
}
},
- canvas: document.getElementById('canvas'),
+ canvas: (function() {
+ var canvas = document.getElementById('canvas');
+
+ // As a default initial behavior, pop up an alert when webgl context is lost. To make your
+ // application robust, you may want to override this behavior before shipping!
+ // See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
+ canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
+
+ return canvas;
+ })(),
setStatus: function(text) {
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
if (text === Module.setStatus.text) return;
diff --git a/src/shell_minimal.html b/src/shell_minimal.html
index 7dd67929..b67c6fdd 100644
--- a/src/shell_minimal.html
+++ b/src/shell_minimal.html
@@ -101,7 +101,16 @@
console.error(text);
}
},
- canvas: document.getElementById('canvas'),
+ canvas: (function() {
+ var canvas = document.getElementById('canvas');
+
+ // As a default initial behavior, pop up an alert when webgl context is lost. To make your
+ // application robust, you may want to override this behavior before shipping!
+ // See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
+ canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
+
+ return canvas;
+ })(),
setStatus: function(text) {
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
if (text === Module.setStatus.text) return;