diff options
author | Ehsan Akhgari <ehsan.akhgari@gmail.com> | 2012-01-20 11:18:49 -0500 |
---|---|---|
committer | Ehsan Akhgari <ehsan.akhgari@gmail.com> | 2012-01-20 11:18:49 -0500 |
commit | 51f73defcc6566b34f658443f46f6eaae68179fb (patch) | |
tree | 2c3fb4948b34ede1e879e8eb8172447122acf1c2 /src/shell.html | |
parent | 28273cd235258bbcc930a75aa35ecbdd1b344711 (diff) |
Enable SDL to create a 2D or WebGL context depending on what the caller wants
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 }}} |