diff options
Diffstat (limited to 'src/shell.html')
-rw-r--r-- | src/shell.html | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/src/shell.html b/src/shell.html index c096a314..95ab5a6a 100644 --- a/src/shell.html +++ b/src/shell.html @@ -19,12 +19,38 @@ })(), canvas: document.getElementById('canvas') }; - try { - Module.ctx2D = Module.canvas.getContext('2d'); - if (!Module.ctx2D) throw 'Could not create canvas :('; - } catch (e) { - Module.print('(canvas not available)'); - } + // Define the 2D and WebGL contexts lazily, because a canvas can only + // have one context type. + Module.__defineGetter__("ctx2D", function() { + try { + var ctx = Module.canvas.getContext('2d'); + if (!ctx) throw 'Could not create canvas :('; + delete Module["ctxGL"]; + Module.__defineGetter__("ctxGL", function() { + throw 'Could not create a WebGL context for a 2D canvas :('; + }); + delete Module["ctx2D"]; + return Module["ctx2D"] = ctx; + } catch (e) { + Module.print('(canvas not available)'); + return null; + } + }); + Module.__defineGetter__("ctxGL", function() { + try { + var ctx = Module.canvas.getContext('experimental-webgl'); + if (!ctx) throw 'Could not create canvas :('; + delete Module["ctx2D"]; + Module.__defineGetter__("ctx2D", function() { + throw 'Could not create a 2D context for a WebGL canvas :('; + }); + delete Module["ctxGL"]; + return Module["ctxGL"] = ctx; + } catch (e) { + Module.print('(canvas not available)'); + return null; + } + }); // The compiled code {{{ SCRIPT_CODE }}} |