Skip to content

Commit afc9635

Browse files
committed
PIXI.WebGLGraphics.stencilBufferLimit is a new integer that allows you to define how many points exist in a Graphics object before Pixi swaps to using the Stencil Buffer to render it. The default is now 64 (originally 6). This fixes issues with things like Quadratic curves not rendering as masks in WebGL.
1 parent c3c2dd6 commit afc9635

4 files changed

Lines changed: 34 additions & 12 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ Please note that Phaser uses a custom build of Pixi and always has done. The fol
336336
* TilingSprite would ignore the `renderable` property, and render it regardless. Now it skips render if `renderable` is false (thanks @Green92 #2214)
337337
* We have replaced the PolyK Triangulation calls within Pixi with EarCut 2.0.8. This allows for faster polygon triangulation, and also deals with more complex polygons that PolyK would crash on.
338338
* Graphics.arc has a new argument `segments` that allows you to control how many segments are created when the arc is drawn. The default is 40. Use a higher number for more fidelity, i.e. if you find that reversed arcs are not joining up fully (#2064)
339+
* PIXI.WebGLMaskManager.pushMask and popMask are now more robust in checking that they have been given valid mask data (#2152)
340+
* PIXI.WebGLGraphics.stencilBufferLimit is a new integer that allows you to define how many points exist in a Graphics object before Pixi swaps to using the Stencil Buffer to render it. The default is now 64 (originally 6). This fixes issues with things like Quadratic curves not rendering as masks in WebGL.
339341

340342
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).
341343

src/pixi/primitives/Graphics.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,10 @@ Object.defineProperty(PIXI.Graphics.prototype, "cacheAsBitmap", {
12001200
else
12011201
{
12021202
this.destroyCachedSprite();
1203-
this.dirty = true;
12041203
}
12051204

1205+
this.dirty = true;
1206+
this.webGLDirty = true;
1207+
12061208
}
12071209
});

src/pixi/renderers/webgl/utils/WebGLGraphics.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ PIXI.WebGLGraphics = function()
1313
{
1414
};
1515

16+
/**
17+
* The number of points beyond which Pixi swaps to using the Stencil Buffer to render the Graphics.
18+
*
19+
* @type {number}
20+
*/
21+
PIXI.WebGLGraphics.stencilBufferLimit = 64;
22+
1623
/**
1724
* Renders the graphics object
1825
*
@@ -147,9 +154,9 @@ PIXI.WebGLGraphics.updateGraphics = function(graphics, gl)
147154
// MAKE SURE WE HAVE THE CORRECT TYPE..
148155
if(data.fill)
149156
{
150-
if(data.points.length >= 6)
157+
if(data.points.length >= PIXI.WebGLGraphics.stencilBufferLimit)
151158
{
152-
if(data.points.length < 6 * 2)
159+
if(data.points.length < PIXI.WebGLGraphics.stencilBufferLimit * 2)
153160
{
154161
webGLData = PIXI.WebGLGraphics.switchMode(webGL, 0);
155162

@@ -274,7 +281,7 @@ PIXI.WebGLGraphics.buildRectangle = function(graphicsData, webGLData)
274281
var verts = webGLData.points;
275282
var indices = webGLData.indices;
276283

277-
var vertPos = verts.length/6;
284+
var vertPos = verts.length / 6;
278285

279286
// start
280287
verts.push(x, y);
@@ -290,10 +297,10 @@ PIXI.WebGLGraphics.buildRectangle = function(graphicsData, webGLData)
290297
verts.push(r, g, b, alpha);
291298

292299
// insert 2 dead triangles..
293-
indices.push(vertPos, vertPos, vertPos+1, vertPos+2, vertPos+3, vertPos+3);
300+
indices.push(vertPos, vertPos, vertPos + 1, vertPos + 2, vertPos + 3, vertPos + 3);
294301
}
295302

296-
if(graphicsData.lineWidth)
303+
if (graphicsData.lineWidth)
297304
{
298305
var tempPoints = graphicsData.points;
299306

@@ -347,11 +354,12 @@ PIXI.WebGLGraphics.buildRoundedRectangle = function(graphicsData, webGLData)
347354
var verts = webGLData.points;
348355
var indices = webGLData.indices;
349356

350-
var vecPos = verts.length/6;
357+
var vecPos = verts.length / 6;
351358

352359
var triangles = PIXI.EarCut.Triangulate(recPoints, null, 2);
353360

354361
var i = 0;
362+
355363
for (i = 0; i < triangles.length; i+=3)
356364
{
357365
indices.push(triangles[i] + vecPos);
@@ -478,7 +486,7 @@ PIXI.WebGLGraphics.buildCircle = function(graphicsData, webGLData)
478486
var verts = webGLData.points;
479487
var indices = webGLData.indices;
480488

481-
var vecPos = verts.length/6;
489+
var vecPos = verts.length / 6;
482490

483491
indices.push(vecPos);
484492

@@ -739,7 +747,7 @@ PIXI.WebGLGraphics.buildComplexPoly = function(graphicsData, webGLData)
739747
{
740748
//TODO - no need to copy this as it gets turned into a FLoat32Array anyways..
741749
var points = graphicsData.points.slice();
742-
if(points.length < 6)return;
750+
if(points.length < PIXI.WebGLGraphics.stencilBufferLimit)return;
743751

744752
// get first and last point.. figure out the middle!
745753
var indices = webGLData.indices;
@@ -801,7 +809,7 @@ PIXI.WebGLGraphics.buildPoly = function(graphicsData, webGLData)
801809
{
802810
var points = graphicsData.points;
803811

804-
if(points.length < 6)return;
812+
if(points.length < PIXI.WebGLGraphics.stencilBufferLimit)return;
805813
// get first and last point.. figure out the middle!
806814
var verts = webGLData.points;
807815
var indices = webGLData.indices;

src/pixi/renderers/webgl/utils/WebGLMaskManager.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, renderSession)
3535
{
3636
var gl = renderSession.gl;
3737

38-
if(maskData.dirty)
38+
if (maskData.dirty)
3939
{
4040
PIXI.WebGLGraphics.updateGraphics(maskData, gl);
4141
}
4242

43-
if(!maskData._webGL[gl.id].data.length)return;
43+
if (maskData._webGL[gl.id] === undefined || maskData._webGL[gl.id].data === undefined || maskData._webGL[gl.id].data.length === 0)
44+
{
45+
return;
46+
}
4447

4548
renderSession.stencilManager.pushStencil(maskData, maskData._webGL[gl.id].data[0], renderSession);
4649
};
@@ -55,7 +58,14 @@ PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, renderSession)
5558
PIXI.WebGLMaskManager.prototype.popMask = function(maskData, renderSession)
5659
{
5760
var gl = this.gl;
61+
62+
if (maskData._webGL[gl.id] === undefined || maskData._webGL[gl.id].data === undefined || maskData._webGL[gl.id].data.length === 0)
63+
{
64+
return;
65+
}
66+
5867
renderSession.stencilManager.popStencil(maskData, maskData._webGL[gl.id].data[0], renderSession);
68+
5969
};
6070

6171
/**

0 commit comments

Comments
 (0)