Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. function isWebGLSupported()
  2. {
  3. const contextOptions = { stencil: true, failIfMajorPerformanceCaveat: true };
  4.  
  5. try
  6. {
  7. if (!window.WebGLRenderingContext)
  8. {
  9. console.log('No window.WebGLRenderingContext');
  10. return false;
  11. }
  12.  
  13. const canvas = document.createElement('canvas');
  14. let gl = canvas.getContext('webgl', contextOptions) || canvas.getContext('experimental-webgl', contextOptions);
  15.  
  16. if (!gl) {
  17. console.log('no webgl context');
  18. }
  19.  
  20. if (!gl.getContextAttributes().stencil) {
  21. console.log('no stencil');
  22. }
  23.  
  24. const success = !!(gl && gl.getContextAttributes().stencil);
  25.  
  26. if (gl)
  27. {
  28. const loseContext = gl.getExtension('WEBGL_lose_context');
  29. if (loseContext)
  30. {
  31. loseContext.loseContext();
  32. }
  33. }
  34.  
  35. gl = null;
  36.  
  37. return success;
  38. }
  39. catch (e)
  40. {
  41. console.log('catched error', e);
  42. return false;
  43. }
  44. }
  45.  
  46. isWebGLSupported();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement