2016-11-29 11:26:30 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
var CONST = require('../const');
|
|
|
|
var CanvasPool = require('../dom/CanvasPool');
|
|
|
|
var Features = require('../device/Features');
|
2016-12-07 02:28:22 +00:00
|
|
|
var WebGLRenderer = require('../renderer/webgl/WebGLRenderer');
|
2016-11-29 11:26:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the device is capable of using the requested renderer and sets it up or an alternative if not.
|
|
|
|
*
|
|
|
|
* @method Phaser.Game#setUpRenderer
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
var CreateRenderer = function (game)
|
|
|
|
{
|
|
|
|
var config = game.config;
|
|
|
|
|
|
|
|
// Game either requested Canvas,
|
|
|
|
// or requested AUTO or WEBGL but the browser doesn't support it, so fall back to Canvas
|
|
|
|
if (config.renderType === CONST.CANVAS || (config.renderType !== CONST.CANVAS && !Features.webGL))
|
|
|
|
{
|
|
|
|
if (Features.canvas)
|
|
|
|
{
|
|
|
|
// They requested Canvas and their browser supports it
|
|
|
|
config.renderType = CONST.CANVAS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new Error('Cannot create Canvas or WebGL context, aborting.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Game requested WebGL and browser says it supports it
|
|
|
|
config.renderType = CONST.WEBGL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Does the game config provide its own canvas element to use?
|
|
|
|
if (config.canvas)
|
|
|
|
{
|
|
|
|
game.canvas = config.canvas;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
game.canvas = CanvasPool.create(game, config.width, config.height, config.renderType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Does the game config provide some canvas css styles to use?
|
|
|
|
if (config.canvasStyle)
|
|
|
|
{
|
|
|
|
game.canvas.style = config.canvasStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the renderer
|
|
|
|
if (config.renderType === CONST.WEBGL)
|
|
|
|
{
|
|
|
|
console.log('Creating WEBGL Renderer');
|
2016-12-07 02:28:22 +00:00
|
|
|
game.renderer = new WebGLRenderer(game);
|
|
|
|
game.context = null;
|
2016-11-29 11:26:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.log('Creating Canvas Renderer');
|
|
|
|
// game.renderer = new Phaser.Renderer.Canvas(this);
|
|
|
|
// game.context = this.renderer.context;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config.renderType !== Phaser.HEADLESS)
|
|
|
|
{
|
|
|
|
// Phaser.Canvas.addToDOM(this.canvas, this.parent, false);
|
|
|
|
// Phaser.Canvas.setTouchAction(this.canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = CreateRenderer;
|