Skip to content

Commit 18b12df

Browse files
committed
Huge amount of work getting the WebGL renderer sorted out, tidied up and merged with the latest Texture and Transform components.
1 parent c39c97f commit 18b12df

12 files changed

Lines changed: 663 additions & 296 deletions

File tree

src/core/Filter.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
* @param {object} [uniforms] - Uniform mappings object. The uniforms are added on the default uniforms, or replace them if the keys are the same.
3333
* @param {Array|string} [fragmentSrc] - The fragment shader code. Either an array, one element per line of code, or a string.
3434
*/
35-
Phaser.Filter = function (game, uniforms, fragmentSrc) {
36-
35+
Phaser.Filter = function (game, uniforms, fragmentSrc)
36+
{
3737
/**
3838
* @property {Phaser.Game} game - A reference to the currently running game.
3939
*/
@@ -90,7 +90,7 @@ Phaser.Filter = function (game, uniforms, fragmentSrc) {
9090
resolution: { type: '2f', value: { x: 256, y: 256 }},
9191
time: { type: '1f', value: 0 },
9292
mouse: { type: '2f', value: { x: 0.0, y: 0.0 } },
93-
date: { type: '4fv', value: [ d.getFullYear(), d.getMonth(), d.getDate(), d.getHours() *60 * 60 + d.getMinutes() * 60 + d.getSeconds() ] },
93+
date: { type: '4fv', value: [ d.getFullYear(), d.getMonth(), d.getDate(), d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds() ] },
9494
sampleRate: { type: '1f', value: 44100.0 },
9595
iChannel0: { type: 'sampler2D', value: null, textureData: { repeat: true } },
9696
iChannel1: { type: 'sampler2D', value: null, textureData: { repeat: true } },
@@ -125,10 +125,11 @@ Phaser.Filter.prototype = {
125125

126126
/**
127127
* This should be over-ridden. Will receive a variable number of arguments.
128-
*
128+
*
129129
* @method Phaser.Filter#init
130130
*/
131-
init: function () {
131+
init: function ()
132+
{
132133

133134
// This should be over-ridden. Will receive a variable number of arguments.
134135

@@ -141,21 +142,20 @@ Phaser.Filter.prototype = {
141142
* @param {number} width - The width of the display.
142143
* @param {number} height - The height of the display.
143144
*/
144-
setResolution: function (width, height) {
145-
145+
setResolution: function (width, height)
146+
{
146147
this.uniforms.resolution.value.x = width;
147148
this.uniforms.resolution.value.y = height;
148-
149149
},
150150

151151
/**
152152
* Updates the filter.
153-
*
153+
*
154154
* @method Phaser.Filter#update
155155
* @param {Phaser.Pointer} [pointer] - A Pointer object to use for the filter. The coordinates are mapped to the mouse uniform.
156156
*/
157-
update: function (pointer) {
158-
157+
update: function (pointer)
158+
{
159159
if (pointer)
160160
{
161161
var x = pointer.x / this.game.width;
@@ -170,11 +170,10 @@ Phaser.Filter.prototype = {
170170
}
171171

172172
this.uniforms.time.value = this.game.time.totalElapsedSeconds();
173-
174173
},
175174

176175
/**
177-
* Creates a new Phaser.Image object using a blank texture and assigns
176+
* Creates a new Phaser.Image object using a blank texture and assigns
178177
* this Filter to it. The image is then added to the world.
179178
*
180179
* If you don't provide width and height values then Filter.width and Filter.height are used.
@@ -191,8 +190,8 @@ Phaser.Filter.prototype = {
191190
* @param {number} [anchorY=0] - Set the y anchor point of the Image. A value between 0 and 1, where 0 is the top-left and 1 is bottom-right.
192191
* @return {Phaser.Image} The newly added Image object.
193192
*/
194-
addToWorld: function (x, y, width, height, anchorX, anchorY) {
195-
193+
addToWorld: function (x, y, width, height, anchorX, anchorY)
194+
{
196195
if (anchorX === undefined) { anchorX = 0; }
197196
if (anchorY === undefined) { anchorY = 0; }
198197

@@ -232,30 +231,28 @@ Phaser.Filter.prototype = {
232231
*
233232
* @method Phaser.Filter#syncUniforms
234233
*/
235-
syncUniforms: function () {
236-
234+
syncUniforms: function ()
235+
{
237236
for (var i = 0; i < this.shaders.length; i++)
238237
{
239238
this.shaders[i].dirty = true;
240239
}
241-
242240
},
243241

244242
/**
245243
* Clear down this Filter and null out references to game.
246-
*
244+
*
247245
* @method Phaser.Filter#destroy
248246
*/
249-
destroy: function () {
250-
247+
destroy: function ()
248+
{
251249
this.passes.length = 0;
252250
this.shaders.length = 0;
253251
this.fragmentSrc.length = 0;
254252

255253
this.game = null;
256254
this.uniforms = null;
257255
this.prevPoint = null;
258-
259256
}
260257

261258
};

src/gameobjects/image/ImageWebGLRenderer.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ Phaser.Renderer.WebGL.GameObjects.Image = {
66

77
render: function (renderer, src)
88
{
9-
// If the sprite is not visible or the alpha is 0 then no need to render this element
10-
if (!src.visible || src.alpha === 0 || !src.renderable)
9+
var frame = src.frame;
10+
11+
// Skip rendering?
12+
13+
if (src.skipRender || !src.visible || src.worldAlpha <= 0 || !frame.cutWidth || !frame.cutHeight)
1114
{
1215
return;
1316
}
1417

15-
// Add back in: || src.texture.crop.width <= 0 || src.texture.crop.height <= 0
16-
1718
renderer.spriteBatch.render(src);
1819
}
1920

src/gameobjects/stage/StageWebGLRenderer.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@ Phaser.Renderer.WebGL.GameObjects.Stage = {
1111

1212
render: function (renderer, src)
1313
{
14-
if (src.visible === false || src.alpha === 0 || src.children.length === 0)
14+
if (!src.visible || src.alpha === 0 || src.children.list.length === 0)
1515
{
1616
return;
1717
}
1818

19+
for (var i = 0; i < src.children.list.length; i++)
20+
{
21+
var child = src.children.list[i];
22+
23+
child.render(renderer, child);
24+
}
25+
26+
/*
1927
var i;
2028
2129
if (src._mask || src._filters)
@@ -64,6 +72,7 @@ Phaser.Renderer.WebGL.GameObjects.Stage = {
6472
child.render(renderer, child);
6573
}
6674
}
75+
*/
6776

6877
}
6978

src/loader/Cache.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ Phaser.Cache.prototype = {
329329

330330
img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABVJREFUeF7NwIEAAAAAgKD9qdeocAMAoAABm3DkcAAAAABJRU5ErkJggg==';
331331

332-
this.game.textures.addImage('__DEFAULT', img);
332+
// this.game.textures.addImage('__DEFAULT', img);
333333
},
334334

335335
/**
@@ -347,7 +347,7 @@ Phaser.Cache.prototype = {
347347

348348
img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJ9JREFUeNq01ssOwyAMRFG46v//Mt1ESmgh+DFmE2GPOBARKb2NVjo+17PXLD8a1+pl5+A+wSgFygymWYHBb0FtsKhJDdZlncG2IzJ4ayoMDv20wTmSMzClEgbWYNTAkQ0Z+OJ+A/eWnAaR9+oxCF4Os0H8htsMUp+pwcgBBiMNnAwF8GqIgL2hAzaGFFgZauDPKABmowZ4GL369/0rwACp2yA/ttmvsQAAAABJRU5ErkJggg==';
349349

350-
this.game.textures.addImage('__MISSING', img);
350+
// this.game.textures.addImage('__MISSING', img);
351351
},
352352

353353
/**

0 commit comments

Comments
 (0)