Skip to content

Commit f9fe6a3

Browse files
committed
Fixed canvas SpriteBatch and removed duplicate render functions.
1 parent 5b4280d commit f9fe6a3

5 files changed

Lines changed: 12 additions & 554 deletions

File tree

src/gameobjects/Graphics.js

Lines changed: 0 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -942,187 +942,6 @@ Phaser.Graphics.prototype.generateTexture = function (resolution, scaleMode, pad
942942

943943
};
944944

945-
/**
946-
* Renders the object using the WebGL renderer
947-
*
948-
* @method _renderWebGL
949-
* @param renderSession {RenderSession}
950-
* @private
951-
*/
952-
Phaser.Graphics.prototype._renderWebGL = function (renderSession) {
953-
954-
// if the sprite is not visible or the alpha is 0 then no need to render this element
955-
if (this.visible === false || this.alpha === 0 || this.isMask === true)
956-
{
957-
return;
958-
}
959-
960-
if (this._cacheAsBitmap)
961-
{
962-
if (this.dirty || this.cachedSpriteDirty)
963-
{
964-
this._generateCachedSprite();
965-
966-
// we will also need to update the texture on the gpu too!
967-
this.updateCachedSpriteTexture();
968-
969-
this.cachedSpriteDirty = false;
970-
this.dirty = false;
971-
}
972-
973-
this._cachedSprite.worldAlpha = this.worldAlpha;
974-
975-
PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession);
976-
977-
return;
978-
}
979-
else
980-
{
981-
renderSession.spriteBatch.stop();
982-
renderSession.blendModeManager.setBlendMode(this.blendMode);
983-
984-
if (this._mask)
985-
{
986-
renderSession.maskManager.pushMask(this._mask, renderSession);
987-
}
988-
989-
if (this._filters)
990-
{
991-
renderSession.filterManager.pushFilter(this._filterBlock);
992-
}
993-
994-
// check blend mode
995-
if (this.blendMode !== renderSession.spriteBatch.currentBlendMode)
996-
{
997-
renderSession.spriteBatch.currentBlendMode = this.blendMode;
998-
var blendModeWebGL = PIXI.blendModesWebGL[renderSession.spriteBatch.currentBlendMode];
999-
renderSession.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]);
1000-
}
1001-
1002-
// check if the webgl graphic needs to be updated
1003-
if (this.webGLDirty)
1004-
{
1005-
this.dirty = true;
1006-
this.webGLDirty = false;
1007-
}
1008-
1009-
PIXI.WebGLGraphics.renderGraphics(this, renderSession);
1010-
1011-
// only render if it has children!
1012-
if (this.children.length)
1013-
{
1014-
renderSession.spriteBatch.start();
1015-
1016-
// simple render children!
1017-
for (var i = 0; i < this.children.length; i++)
1018-
{
1019-
this.children[i]._renderWebGL(renderSession);
1020-
}
1021-
1022-
renderSession.spriteBatch.stop();
1023-
}
1024-
1025-
if (this._filters)
1026-
{
1027-
renderSession.filterManager.popFilter();
1028-
}
1029-
1030-
if (this._mask)
1031-
{
1032-
renderSession.maskManager.popMask(this.mask, renderSession);
1033-
}
1034-
1035-
renderSession.drawCount++;
1036-
1037-
renderSession.spriteBatch.start();
1038-
}
1039-
1040-
};
1041-
1042-
/**
1043-
* Renders the object using the Canvas renderer
1044-
*
1045-
* @method _renderCanvas
1046-
* @param renderSession {RenderSession}
1047-
* @private
1048-
*/
1049-
Phaser.Graphics.prototype._renderCanvas = function (renderSession) {
1050-
1051-
// if the sprite is not visible or the alpha is 0 then no need to render this element
1052-
if (this.visible === false || this.alpha === 0 || this.isMask === true)
1053-
{
1054-
return;
1055-
}
1056-
1057-
// if the tint has changed, set the graphics object to dirty.
1058-
if (this._prevTint !== this.tint)
1059-
{
1060-
this.dirty = true;
1061-
this._prevTint = this.tint;
1062-
}
1063-
1064-
if (this._cacheAsBitmap)
1065-
{
1066-
if (this.dirty || this.cachedSpriteDirty)
1067-
{
1068-
this._generateCachedSprite();
1069-
1070-
// we will also need to update the texture
1071-
this.updateCachedSpriteTexture();
1072-
1073-
this.cachedSpriteDirty = false;
1074-
this.dirty = false;
1075-
}
1076-
1077-
this._cachedSprite.alpha = this.alpha;
1078-
1079-
PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession);
1080-
1081-
return;
1082-
}
1083-
else
1084-
{
1085-
var context = renderSession.context;
1086-
var transform = this.worldTransform;
1087-
1088-
if (this.blendMode !== renderSession.currentBlendMode)
1089-
{
1090-
renderSession.currentBlendMode = this.blendMode;
1091-
context.globalCompositeOperation = PIXI.blendModesCanvas[renderSession.currentBlendMode];
1092-
}
1093-
1094-
if (this._mask)
1095-
{
1096-
renderSession.maskManager.pushMask(this._mask, renderSession);
1097-
}
1098-
1099-
var resolution = renderSession.resolution;
1100-
var tx = (transform.tx * renderSession.resolution) + renderSession.shakeX;
1101-
var ty = (transform.ty * renderSession.resolution) + renderSession.shakeY;
1102-
1103-
context.setTransform(transform.a * resolution,
1104-
transform.b * resolution,
1105-
transform.c * resolution,
1106-
transform.d * resolution,
1107-
tx,
1108-
ty);
1109-
1110-
PIXI.CanvasGraphics.renderGraphics(this, context);
1111-
1112-
// simple render children!
1113-
for (var i = 0; i < this.children.length; i++)
1114-
{
1115-
this.children[i]._renderCanvas(renderSession);
1116-
}
1117-
1118-
if (this._mask)
1119-
{
1120-
renderSession.maskManager.popMask(renderSession);
1121-
}
1122-
}
1123-
1124-
};
1125-
1126945
/**
1127946
* Retrieves the bounds of the graphic shape as a rectangle object
1128947
*

src/gameobjects/SpriteBatch.js

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -49,140 +49,3 @@ Phaser.SpriteBatch = function (game, parent, name, addToStage) {
4949
Phaser.SpriteBatch.prototype = Object.create(Phaser.Group.prototype);
5050

5151
Phaser.SpriteBatch.prototype.constructor = Phaser.SpriteBatch;
52-
53-
/**
54-
* Renders the Sprite Batch using the WebGL renderer.
55-
*
56-
* @private
57-
* @method
58-
* @memberof Phaser.SpriteBatch
59-
* @param {RenderSession} renderSession
60-
*/
61-
Phaser.SpriteBatch.prototype._renderWebGL = function (renderSession) {
62-
63-
if (!this.visible || this.alpha <= 0 || !this.children.length)
64-
{
65-
return;
66-
}
67-
68-
if (!this.ready)
69-
{
70-
this.fastSpriteBatch = new PIXI.WebGLFastSpriteBatch(renderSession.gl);
71-
72-
this.ready = true;
73-
}
74-
75-
if (this.fastSpriteBatch.gl !== renderSession.gl)
76-
{
77-
this.fastSpriteBatch.setContext(renderSession.gl);
78-
}
79-
80-
renderSession.spriteBatch.stop();
81-
82-
renderSession.shaderManager.setShader(renderSession.shaderManager.fastShader);
83-
84-
this.fastSpriteBatch.begin(this, renderSession);
85-
this.fastSpriteBatch.render(this);
86-
87-
renderSession.spriteBatch.start();
88-
89-
};
90-
91-
/**
92-
* Renders the Sprite Batch using the Canvas renderer.
93-
*
94-
* @private
95-
* @method
96-
* @memberof Phaser.SpriteBatch
97-
* @param {RenderSession} renderSession
98-
*/
99-
Phaser.SpriteBatch.prototype._renderCanvas = function (renderSession) {
100-
101-
if (!this.visible || this.alpha <= 0 || !this.children.length)
102-
{
103-
return;
104-
}
105-
106-
var context = renderSession.context;
107-
108-
context.globalAlpha = this.worldAlpha;
109-
110-
this.displayObjectUpdateTransform();
111-
112-
var transform = this.worldTransform;
113-
114-
var isRotated = true;
115-
116-
for (var i = 0; i < this.children.length; i++)
117-
{
118-
var child = this.children[i];
119-
120-
if (!child.visible)
121-
{
122-
continue;
123-
}
124-
125-
var texture = child.texture;
126-
var frame = texture.frame;
127-
128-
context.globalAlpha = this.worldAlpha * child.alpha;
129-
130-
if (child.rotation % (Math.PI * 2) === 0)
131-
{
132-
// If rotation === 0 we can avoid setTransform
133-
134-
if (isRotated)
135-
{
136-
context.setTransform(transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty);
137-
isRotated = false;
138-
}
139-
140-
context.drawImage(
141-
texture.baseTexture.source,
142-
frame.x,
143-
frame.y,
144-
frame.width,
145-
frame.height,
146-
((child.anchor.x) * (-frame.width * child.scale.x) + child.position.x + 0.5 + renderSession.shakeX) | 0,
147-
((child.anchor.y) * (-frame.height * child.scale.y) + child.position.y + 0.5 + renderSession.shakeY) | 0,
148-
frame.width * child.scale.x,
149-
frame.height * child.scale.y);
150-
}
151-
else
152-
{
153-
if (!isRotated)
154-
{
155-
isRotated = true;
156-
}
157-
158-
child.displayObjectUpdateTransform();
159-
160-
var childTransform = child.worldTransform;
161-
var tx = (childTransform.tx * renderSession.resolution) + renderSession.shakeX;
162-
var ty = (childTransform.ty * renderSession.resolution) + renderSession.shakeY;
163-
164-
// allow for trimming
165-
166-
if (renderSession.roundPixels)
167-
{
168-
context.setTransform(childTransform.a, childTransform.b, childTransform.c, childTransform.d, tx | 0, ty | 0);
169-
}
170-
else
171-
{
172-
context.setTransform(childTransform.a, childTransform.b, childTransform.c, childTransform.d, tx, ty);
173-
}
174-
175-
context.drawImage(
176-
texture.baseTexture.source,
177-
frame.x,
178-
frame.y,
179-
frame.width,
180-
frame.height,
181-
((child.anchor.x) * (-frame.width) + 0.5) | 0,
182-
((child.anchor.y) * (-frame.height) + 0.5) | 0,
183-
frame.width,
184-
frame.height);
185-
}
186-
}
187-
188-
};

src/gameobjects/Text.js

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,44 +1479,6 @@ Phaser.Text.prototype.updateTexture = function () {
14791479

14801480
};
14811481

1482-
/**
1483-
* Renders the object using the WebGL renderer
1484-
*
1485-
* @method Phaser.Text#_renderWebGL
1486-
* @private
1487-
* @param {RenderSession} renderSession - The Render Session to render the Text on.
1488-
*/
1489-
Phaser.Text.prototype._renderWebGL = function (renderSession) {
1490-
1491-
if (this.dirty)
1492-
{
1493-
this.updateText();
1494-
this.dirty = false;
1495-
}
1496-
1497-
PIXI.Sprite.prototype._renderWebGL.call(this, renderSession);
1498-
1499-
};
1500-
1501-
/**
1502-
* Renders the object using the Canvas renderer.
1503-
*
1504-
* @method Phaser.Text#_renderCanvas
1505-
* @private
1506-
* @param {RenderSession} renderSession - The Render Session to render the Text on.
1507-
*/
1508-
Phaser.Text.prototype._renderCanvas = function (renderSession) {
1509-
1510-
if (this.dirty)
1511-
{
1512-
this.updateText();
1513-
this.dirty = false;
1514-
}
1515-
1516-
PIXI.Sprite.prototype._renderCanvas.call(this, renderSession);
1517-
1518-
};
1519-
15201482
/**
15211483
* Calculates the ascent, descent and fontSize of a given font style.
15221484
*

0 commit comments

Comments
 (0)