Skip to content

Commit 5499761

Browse files
committed
Only return 2d context
1 parent 529cded commit 5499761

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

src/display/canvas/CanvasPool.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ var pool = [];
1414
var _disableContextSmoothing = false;
1515

1616
/**
17-
* The CanvasPool is a global static object, that allows Phaser to recycle and pool Canvas DOM elements.
17+
* The CanvasPool is a global static object, that allows Phaser to recycle and pool 2D Context Canvas DOM elements.
18+
* It does not pool WebGL Contexts, because once the context options are set they cannot be modified again,
19+
* which is useless for some of the Phaser pipelines / renderer.
1820
*
19-
* This singleton is instantiated as soon as Phaser loads,
20-
* before a Phaser.Game instance has even been created.
21-
* Which means all instances of Phaser Games on the same page
22-
* can share the one single pool
21+
* This singleton is instantiated as soon as Phaser loads, before a Phaser.Game instance has even been created.
22+
* Which means all instances of Phaser Games on the same page can share the one single pool.
2323
*
2424
* @namespace Phaser.Display.Canvas.CanvasPool
2525
* @since 3.0.0
@@ -56,7 +56,10 @@ var CanvasPool = function ()
5656
type: canvasType
5757
};
5858

59-
pool.push(container);
59+
if (canvasType === CONST.CANVAS)
60+
{
61+
pool.push(container);
62+
}
6063

6164
canvas = container.canvas;
6265
}
@@ -126,6 +129,11 @@ var CanvasPool = function ()
126129
{
127130
if (canvasType === undefined) { canvasType = CONST.CANVAS; }
128131

132+
if (canvasType === CONST.WEBGL)
133+
{
134+
return null;
135+
}
136+
129137
for (var i = 0; i < pool.length; i++)
130138
{
131139
var container = pool[i];
@@ -157,7 +165,6 @@ var CanvasPool = function ()
157165
{
158166
if ((isCanvas && container.canvas === parent) || (!isCanvas && container.parent === parent))
159167
{
160-
// console.log('CanvasPool.remove found and removed');
161168
container.parent = null;
162169
container.canvas.width = 1;
163170
container.canvas.height = 1;

0 commit comments

Comments
 (0)