import { isWebGLSupported } from '@pixi/utils'; import { Renderer } from '@pixi/core'; import CanvasRenderer from './CanvasRenderer'; // eslint-disable-next-line valid-jsdoc /** * This helper function will automatically detect which renderer you should be using. * WebGL is the preferred renderer as it is a lot faster. If webGL is not supported by * the browser then this function will return a canvas renderer * * @memberof PIXI * @function autoDetectRenderer * @param {object} [options] - The optional renderer parameters * @param {number} [options.width=800] - the width of the renderers view * @param {number} [options.height=600] - the height of the renderers view * @param {HTMLCanvasElement} [options.view] - the canvas to use as a view, optional * @param {boolean} [options.transparent=false] - If the render view is transparent, default false * @param {boolean} [options.antialias=false] - sets antialias (only applicable in chrome at the moment) * @param {boolean} [options.preserveDrawingBuffer=false] - enables drawing buffer preservation, enable this if you * need to call toDataUrl on the webgl context * @param {number} [options.backgroundColor=0x000000] - The background color of the rendered area * (shown if not transparent). * @param {boolean} [options.clearBeforeRender=true] - This sets if the renderer will clear the canvas or * not before the new render pass. * @param {number} [options.resolution=1] - The resolution / device pixel ratio of the renderer, retina would be 2 * @param {boolean} [options.forceCanvas=false] - prevents selection of WebGL renderer, even if such is present * @param {boolean} [options.roundPixels=false] - If true PixiJS will Math.floor() x/y values when rendering, * stopping pixel interpolation. * @param {boolean} [options.forceFXAA=false] - forces FXAA antialiasing to be used over native. * FXAA is faster, but may not always look as great **webgl only** * @param {boolean} [options.legacy=false] - `true` to ensure compatibility with older / less advanced devices. * If you experience unexplained flickering try setting this to true. **webgl only** * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance" * for devices with dual graphics card **webgl only** * @return {PIXI.Renderer|PIXI.CanvasRenderer} Returns WebGL renderer if available, otherwise CanvasRenderer */ export function autoDetectRenderer(options, arg1, arg2, arg3) { // Backward-compatible support for noWebGL option let forceCanvas = options && options.forceCanvas; if (arg3 !== undefined) { forceCanvas = arg3; } if (!forceCanvas && isWebGLSupported()) { return new Renderer(options, arg1, arg2); } return new CanvasRenderer(options, arg1, arg2); }