Skip to content

Commit 577b815

Browse files
committed
New batch system working.
1 parent 7051557 commit 577b815

6 files changed

Lines changed: 335 additions & 294 deletions

File tree

build/config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,14 @@
140140
<script src="$path/src/renderer/webgl/FilterTexture.js"></script>
141141
<script src="$path/src/renderer/webgl/ShaderManager.js"></script>
142142
<script src="$path/src/renderer/webgl/StencilManager.js"></script>
143+
<script src="$path/src/renderer/webgl/batches/BaseBatch.js"></script>
144+
<script src="$path/src/renderer/webgl/batches/ImageBatch.js"></script>
143145
<script src="$path/src/renderer/webgl/shaders/ComplexPrimitiveGraphics.js"></script>
144146
<script src="$path/src/renderer/webgl/shaders/PrimitiveGraphics.js"></script>
145147
<script src="$path/src/renderer/webgl/shaders/Sprite.js"></script>
146148
<script src="$path/src/renderer/webgl/shaders/SpriteBatch.js"></script>
147149
<script src="$path/src/renderer/webgl/shaders/Strip.js"></script>
148150
149-
150151
<script src="$path/src/gameobjects/components/Component.js"></script>
151152
<script src="$path/src/gameobjects/components/Angle.js"></script>
152153
<script src="$path/src/gameobjects/components/Animation.js"></script>

src/gameobjects/image/ImageWebGLRenderer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ Phaser.Renderer.WebGL.GameObjects.Image = {
2424
var tint = src.color._glTint;
2525
var bg = src.color._glBg;
2626

27-
renderer.batch.add(src, verts, uvs, index, alpha, tint, bg);
27+
renderer.batch.add(null, frame.source);
28+
renderer.batch.imageBatch.add(verts, uvs, index, alpha, tint, bg);
2829

2930
/*
3031

src/renderer/webgl/BatchManager.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
3737

3838
init: function ()
3939
{
40+
console.log('BatchManager.init');
41+
4042
this.gl = this.renderer.gl;
4143

4244
this.imageBatch.init();
@@ -57,29 +59,36 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
5759
add: function (batch, source)
5860
{
5961
// Check Batch Size and flush if needed, OR if a different batch then swap
60-
// Also what about blend mode or shader?
61-
if (this.currentBatchSize >= this.maxBatchSize)
62+
// Also what about blend mode or shader swaps?
63+
if (this.currentBatch.size >= this.currentBatch.maxSize)
6264
{
63-
this.flush();
65+
this.currentBatch.flush();
6466
}
6567

66-
source.glLastUsed = this.renderer.startTime;
67-
68-
// Does this Game Objects texture need updating?
69-
if (source.glDirty)
68+
if (source)
7069
{
71-
this.renderer.updateTexture(source);
72-
}
70+
source.glLastUsed = this.renderer.startTime;
7371

74-
// Does the batch need to activate a new texture?
75-
if (this.renderer.textureArray[source.glTextureIndex] !== source)
76-
{
77-
this.setCurrentTexture(source);
72+
// Does this TextureSource need updating?
73+
if (source.glDirty)
74+
{
75+
this.renderer.updateTexture(source);
76+
}
77+
78+
// Does the batch need to activate a new texture?
79+
if (this.renderer.textureArray[source.glTextureIndex] !== source)
80+
{
81+
this.setCurrentTexture(source);
82+
}
7883
}
7984

85+
// Swap Batch check
86+
87+
// At this point the game object should call 'add' on the batch it needs (ImageBatch, FXBatch, etc)
88+
8089
},
8190

82-
flush: function ()
91+
__flush: function ()
8392
{
8493
var gl = this.gl;
8594

src/renderer/webgl/WebGLRenderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,15 +474,15 @@ Phaser.Renderer.WebGL.prototype = {
474474

475475
// console.log('render');
476476

477-
this.batch.begin();
477+
this.batch.start();
478478

479479
// this.filterManager.begin();
480480

481481
// console.log('render stage');
482482

483483
stage.render(this, stage);
484484

485-
this.batch.end();
485+
this.batch.stop();
486486

487487
// debugger;
488488

src/renderer/webgl/batches/BaseBatch.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
/**
88
*
99
*
10-
* @class Phaser.Renderer.WebGL.Batch.Base
10+
* @class Phaser.Renderer.WebGL.Batch
1111
* @constructor
1212
* @param {Phaser.Renderer.WebGL} renderer - The WebGL Renderer.
1313
*/
14-
Phaser.Renderer.WebGL.Batch.Base = function (manager, batchSize, vertSize)
14+
Phaser.Renderer.WebGL.Batch = function (manager, batchSize, vertSize)
1515
{
1616
this.batchManager = manager;
1717

@@ -21,16 +21,16 @@ Phaser.Renderer.WebGL.Batch.Base = function (manager, batchSize, vertSize)
2121

2222
// Total number of objects we'll batch before flushing and rendering
2323
// Integer
24-
this.maxBatchSize = batchSize;
24+
this.maxSize = batchSize;
2525

2626
// Integer
27-
this.halfBatchSize = Math.floor(this.maxBatchSize / 2);
27+
this.halfSize = Math.floor(this.maxSize / 2);
2828

2929
// Integer
3030
this.vertSize = vertSize;
3131

3232
// * 4 because there are 4 verts per batch entry (each corner of the quad)
33-
var numVerts = this.vertSize * this.maxBatchSize * 4;
33+
var numVerts = this.vertSize * this.maxSize * 4;
3434

3535
// ArrayBuffer
3636
// This data is what changes every frame, populated by the game objects
@@ -41,10 +41,13 @@ Phaser.Renderer.WebGL.Batch.Base = function (manager, batchSize, vertSize)
4141
// 6 because there are 2 triangles per quad, and each triangle has 3 indices
4242
// This Typed Array is set in the build method of the extended class, and then
4343
// doesn't change again (it's populated just once)
44-
this.indices = new Uint16Array(this.maxBatchSize * 6);
44+
this.indices = new Uint16Array(this.maxSize * 6);
45+
46+
// Populated by the flush operation when the batch is < 50% of the max size
47+
this.view = null;
4548

4649
// Integer
47-
this.currentBatchSize = 0;
50+
this.size = 0;
4851

4952
// Boolean
5053
this.dirty = true;
@@ -82,17 +85,23 @@ Phaser.Renderer.WebGL.Batch.Base = function (manager, batchSize, vertSize)
8285
this._i = 0;
8386
};
8487

85-
Phaser.Renderer.WebGL.Batch.Base.prototype.constructor = Phaser.Renderer.WebGL.Batch.Base;
88+
Phaser.Renderer.WebGL.Batch.prototype.constructor = Phaser.Renderer.WebGL.Batch;
8689

87-
Phaser.Renderer.WebGL.Batch.Base.prototype = {
90+
Phaser.Renderer.WebGL.Batch.prototype = {
8891

8992
start: function ()
9093
{
9194
this._i = 0;
9295

93-
this.currentBatchSize = 0;
96+
this.size = 0;
97+
98+
// We only need to do this if this batch isn't the current one
9499

95-
this.bindShader();
100+
if (this.dirty)
101+
{
102+
this.bindShader();
103+
this.dirty = false;
104+
}
96105
},
97106

98107
stop: function ()

0 commit comments

Comments
 (0)