Source: dependencies/pixi-gl-core/createContext.js

dependencies/pixi-gl-core/createContext.js

  1. /**
  2. * Helper class to create a webGL Context
  3. *
  4. * @class
  5. * @memberof PIXI.glCore
  6. * @param canvas {HTMLCanvasElement} the canvas element that we will get the context from
  7. * @param options {Object} An options object that gets passed in to the canvas element containing the context attributes,
  8. * see https://developer.mozilla.org/en/docs/Web/API/HTMLCanvasElement/getContext for the options available
  9. * @return {WebGLRenderingContext} the WebGL context
  10. */
  11. var createContext = function(canvas, options)
  12. {
  13. var gl = canvas.getContext('webgl', options) ||
  14. canvas.getContext('experimental-webgl', options);
  15. if (!gl)
  16. {
  17. // fail, not able to get a context
  18. throw new Error('This browser does not support webGL. Try using the canvas renderer');
  19. }
  20. return gl;
  21. };
  22. module.exports = createContext;