Skip to content

Commit c40e94f

Browse files
committed
Manager is now in charge of swapping texture if needed
1 parent ba4b4b9 commit c40e94f

4 files changed

Lines changed: 26 additions & 48 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '791c9de0-df38-11e6-a5ba-6db6a9dcaab8'
2+
build: 'ffd962c0-df3b-11e6-9dea-914dbb3db0ce'
33
};
44
module.exports = CHECKSUM;

v3/src/renderer/webgl/WebGLRenderer.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,25 @@ WebGLRenderer.prototype = {
150150

151151
setTexture2D: function (texture2D)
152152
{
153-
this.currentTexture = texture2D;
154-
this.batch.dirty = true;
153+
if (this.currentTexture2D != texture2D)
154+
{
155+
this.flush();
156+
gl.activeTexture(gl.TEXTURE0);
157+
gl.bindTexture(gl.TEXTURE_2D, texture2D);
158+
this.currentTexture2D = texture2D;
159+
}
155160
},
156161

157-
setBatch: function (batch)
162+
setBatch: function (batch, texture2D)
158163
{
164+
this.setTexture2D(texture2D);
159165
if (this.batch != batch)
160166
{
161167
if (this.batch)
162168
{
163169
this.batch.flush();
164170
}
165171
batch.bind();
166-
batch.setTexture2D(this.currentTexture2D, true);
167172
this.batch = batch;
168173
}
169174
},

v3/src/renderer/webgl/batches/blitter/BlitterBatch.js

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ BlitterBatch.prototype = {
109109

110110
// Populate the index buffer only once
111111
for (var indexA = 0, indexB = 0; indexA < max; indexA += CONST.PARTICLE_INDEX_COUNT, indexB += CONST.PARTICLE_VERTEX_COUNT)
112-
{
112+
{
113113
indexBuffer[indexA + 0] = indexB + 0;
114114
indexBuffer[indexA + 1] = indexB + 1;
115115
indexBuffer[indexA + 2] = indexB + 2;
@@ -131,54 +131,42 @@ BlitterBatch.prototype = {
131131
return (this.vertexDataBuffer.getByteLength() >= this.vertexDataBuffer.getByteCapacity());
132132
},
133133

134-
add: function (x, y, width, height, umin, vmin, umax, vmax)
134+
add: function (x, y, frame)
135135
{
136-
this.manager.setBatch(this);
136+
this.manager.setBatch(this, frame.texture.source[0].glTexture);
137137

138138
// The user must check if the buffers are full before flushing
139139
// this is to give freedom of when should the renderer flush. var vertexDataBuffer = this.vertexDataBuffer;
140140
var vertexDataBuffer = this.vertexDataBuffer;
141141
var vertexBuffer = vertexDataBuffer.floatView;
142142
var vertexOffset = vertexDataBuffer.allocate(CONST.PARTICLE_VERTEX_COMPONENT_COUNT * CONST.PARTICLE_VERTEX_COUNT);
143+
var uvs = frame.uvs;
144+
var width = frame.width;
145+
var height = frame.height;
143146

144147
vertexBuffer[vertexOffset++] = x;
145148
vertexBuffer[vertexOffset++] = y;
146-
vertexBuffer[vertexOffset++] = umin;
147-
vertexBuffer[vertexOffset++] = vmin;
149+
vertexBuffer[vertexOffset++] = uvs.x0;
150+
vertexBuffer[vertexOffset++] = uvs.y0;
148151

149152
vertexBuffer[vertexOffset++] = x;
150153
vertexBuffer[vertexOffset++] = y + height;
151-
vertexBuffer[vertexOffset++] = umin;
152-
vertexBuffer[vertexOffset++] = vmax;
154+
vertexBuffer[vertexOffset++] = uvs.x1;
155+
vertexBuffer[vertexOffset++] = uvs.y1;
153156

154157
vertexBuffer[vertexOffset++] = x + width;
155158
vertexBuffer[vertexOffset++] = y + height;
156-
vertexBuffer[vertexOffset++] = umax;
157-
vertexBuffer[vertexOffset++] = vmax;
159+
vertexBuffer[vertexOffset++] = uvs.x2;
160+
vertexBuffer[vertexOffset++] = uvs.y2;
158161

159162
vertexBuffer[vertexOffset++] = x + width;
160163
vertexBuffer[vertexOffset++] = y;
161-
vertexBuffer[vertexOffset++] = umax;
162-
vertexBuffer[vertexOffset++] = vmin;
164+
vertexBuffer[vertexOffset++] = uvs.x3;
165+
vertexBuffer[vertexOffset++] = uvs.y3;
163166

164167
this.elementCount += CONST.PARTICLE_INDEX_COUNT;
165168
},
166169

167-
setTexture2D: function (texture2D, force)
168-
{
169-
var gl = this.glContext;
170-
171-
if (this.currentTexture2D !== texture2D || force)
172-
{
173-
this.flush();
174-
175-
gl.activeTexture(gl.TEXTURE0);
176-
gl.bindTexture(gl.TEXTURE_2D, texture2D);
177-
178-
this.currentTexture2D = texture2D;
179-
}
180-
},
181-
182170
bind: function ()
183171
{
184172
var gl = this.glContext;

v3/src/renderer/webgl/batches/sprite/SpriteBatch.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ SpriteBatch.prototype = {
110110

111111
// Populate the index buffer only once
112112
for (var indexA = 0, indexB = 0; indexA < max; indexA += CONST.SPRITE_INDEX_COUNT, indexB += CONST.SPRITE_VERTEX_COUNT)
113-
{
113+
{
114114
indexBuffer[indexA + 0] = indexB + 0;
115115
indexBuffer[indexA + 1] = indexB + 1;
116116
indexBuffer[indexA + 2] = indexB + 2;
@@ -134,7 +134,7 @@ SpriteBatch.prototype = {
134134

135135
add: function (frame, pivotX, pivotY, translateX, translateY, scaleX, scaleY, rotation)
136136
{
137-
this.manager.setBatch(this);
137+
this.manager.setBatch(this, frame.texture.source[0].glTexture);
138138

139139
// The user must check if the buffers are full before flushing
140140
// this is to give freedom of when should the renderer flush. var vertexDataBuffer = this.vertexDataBuffer;
@@ -190,21 +190,6 @@ SpriteBatch.prototype = {
190190
this.elementCount += CONST.SPRITE_INDEX_COUNT;
191191
},
192192

193-
setTexture2D: function (texture2D, force)
194-
{
195-
var gl = this.glContext;
196-
197-
if (this.currentTexture2D !== texture2D || force)
198-
{
199-
this.flush();
200-
201-
gl.activeTexture(gl.TEXTURE0);
202-
gl.bindTexture(gl.TEXTURE_2D, texture2D);
203-
204-
this.currentTexture2D = texture2D;
205-
}
206-
},
207-
208193
bind: function ()
209194
{
210195
var gl = this.glContext;

0 commit comments

Comments
 (0)