Source: core/autoDetectRenderer.js

core/autoDetectRenderer.js

  1. import * as utils from './utils';
  2. import CanvasRenderer from './renderers/canvas/CanvasRenderer';
  3. import WebGLRenderer from './renderers/webgl/WebGLRenderer';
  4. // eslint-disable-next-line valid-jsdoc
  5. /**
  6. * This helper function will automatically detect which renderer you should be using.
  7. * WebGL is the preferred renderer as it is a lot faster. If webGL is not supported by
  8. * the browser then this function will return a canvas renderer
  9. *
  10. * @memberof PIXI
  11. * @function autoDetectRenderer
  12. * @param {object} [options] - The optional renderer parameters
  13. * @param {number} [options.width=800] - the width of the renderers view
  14. * @param {number} [options.height=600] - the height of the renderers view
  15. * @param {HTMLCanvasElement} [options.view] - the canvas to use as a view, optional
  16. * @param {boolean} [options.transparent=false] - If the render view is transparent, default false
  17. * @param {boolean} [options.antialias=false] - sets antialias (only applicable in chrome at the moment)
  18. * @param {boolean} [options.preserveDrawingBuffer=false] - enables drawing buffer preservation, enable this if you
  19. * need to call toDataUrl on the webgl context
  20. * @param {number} [options.backgroundColor=0x000000] - The background color of the rendered area
  21. * (shown if not transparent).
  22. * @param {boolean} [options.clearBeforeRender=true] - This sets if the renderer will clear the canvas or
  23. * not before the new render pass.
  24. * @param {number} [options.resolution=1] - The resolution / device pixel ratio of the renderer, retina would be 2
  25. * @param {boolean} [options.forceCanvas=false] - prevents selection of WebGL renderer, even if such is present
  26. * @param {boolean} [options.roundPixels=false] - If true PixiJS will Math.floor() x/y values when rendering,
  27. * stopping pixel interpolation.
  28. * @param {boolean} [options.forceFXAA=false] - forces FXAA antialiasing to be used over native.
  29. * FXAA is faster, but may not always look as great **webgl only**
  30. * @param {boolean} [options.legacy=false] - `true` to ensure compatibility with older / less advanced devices.
  31. * If you experience unexplained flickering try setting this to true. **webgl only**
  32. * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance"
  33. * for devices with dual graphics card **webgl only**
  34. * @return {PIXI.WebGLRenderer|PIXI.CanvasRenderer} Returns WebGL renderer if available, otherwise CanvasRenderer
  35. */
  36. export function autoDetectRenderer(options, arg1, arg2, arg3)
  37. {
  38. // Backward-compatible support for noWebGL option
  39. let forceCanvas = options && options.forceCanvas;
  40. if (arg3 !== undefined)
  41. {
  42. forceCanvas = arg3;
  43. }
  44. if (!forceCanvas && utils.isWebGLSupported())
  45. {
  46. return new WebGLRenderer(options, arg1, arg2);
  47. }
  48. return new CanvasRenderer(options, arg1, arg2);
  49. }