webgl-extensions.js 996 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Grab the WebGL extensions currently supported and add to the Modernizr.webgl object
  2. // spec: www.khronos.org/registry/webgl/specs/latest/#5.13.14
  3. // based on code from ilmari heikkinen
  4. // code.google.com/p/graphics-detect/source/browse/js/detect.js
  5. (function(){
  6. if (!Modernizr.webgl) return;
  7. var canvas, ctx, exts;
  8. try {
  9. canvas = document.createElement('canvas');
  10. ctx = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
  11. exts = ctx.getSupportedExtensions();
  12. }
  13. catch (e) {
  14. return;
  15. }
  16. if (ctx === undefined) {
  17. Modernizr.webgl = new Boolean(false);
  18. }
  19. else {
  20. Modernizr.webgl = new Boolean(true);
  21. }
  22. for (var i = -1, len = exts.length; ++i < len; ){
  23. Modernizr.webgl[exts[i]] = true;
  24. }
  25. // hack for addressing modernizr testsuite failures. sorry.
  26. if (window.TEST && TEST.audvid){
  27. TEST.audvid.push('webgl');
  28. }
  29. canvas = undefined;
  30. })();