Skip to content

Commit 3924371

Browse files
committed
New property for batched textures.
1 parent b0ce81b commit 3924371

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

src/pixi/renderers/webgl/WebGLRenderer.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ PIXI.WebGLRenderer = function(game) {
178178
*/
179179
this.renderSession = {};
180180

181+
/**
182+
* @property currentBatchedTextures
183+
* @type Array
184+
*/
185+
this.currentBatchedTextures = [];
181186

182187
// Needed?
183188
this.renderSession.game = this.game;
@@ -250,13 +255,22 @@ PIXI.WebGLRenderer.prototype.initContext = function()
250255
*
251256
* The number of textures that can be batched is dependent on hardware. If you provide more textures
252257
* than can be batched by the GPU, then only those at the start of the array will be used. Generally
253-
* you shouldn't provide more than 16 textures to this method. You can check the hardware limit
254-
* via the `maxTextures` property.
258+
* you shouldn't provide more than 16 textures to this method. You can check the hardware limit via the
259+
* `maxTextures` property.
260+
*
261+
* You can also check the property `currentBatchedTextures` at any time, to see which textures are currently
262+
* being batched.
263+
*
264+
* To stop all textures from being batched, call this method again with an empty array.
265+
*
266+
* To change the textures being batched, call this method with a new array of image keys. The old ones
267+
* will all be purged out and no-longer batched, and the new ones enabled.
255268
*
256269
* Note: Throws a warning if you haven't enabled Multiple Texture batching support in the Phaser Game config.
257270
*
258271
* @method setTexturePriority
259272
* @param textureNameCollection {Array} An Array of Texture Cache keys to use for multi-texture batching.
273+
* @return {Array} An array containing the texture keys that were enabled for batching.
260274
*/
261275
PIXI.WebGLRenderer.prototype.setTexturePriority = function (textureNameCollection) {
262276

@@ -271,6 +285,23 @@ PIXI.WebGLRenderer.prototype.setTexturePriority = function (textureNameCollectio
271285
var imageName = null;
272286
var gl = this.gl;
273287

288+
// Clear out all previously batched textures and reset their flags.
289+
// If the array has been modified, then the developer will have to
290+
// deal with that in their own way.
291+
for (var i = 0; i < this.currentBatchedTextures.length; i++)
292+
{
293+
imageName = textureNameCollection[index];
294+
295+
if (!(imageName in imageCache))
296+
{
297+
continue;
298+
}
299+
300+
imageCache[imageName].base.textureIndex = 0;
301+
}
302+
303+
this.currentBatchedTextures.length = 0;
304+
274305
// We start from 1 because framebuffer texture uses unit 0.
275306
for (var index = 0; index < textureNameCollection.length; ++index)
276307
{
@@ -284,13 +315,17 @@ PIXI.WebGLRenderer.prototype.setTexturePriority = function (textureNameCollectio
284315
if (index + 1 < maxTextures)
285316
{
286317
imageCache[imageName].base.textureIndex = index + 1;
318+
319+
this.currentBatchedTextures.push(imageName);
287320
}
288321
else
289322
{
290323
imageCache[imageName].base.textureIndex = maxTextures - 1;
291324
}
292325
}
293326

327+
return this.currentBatchedTextures;
328+
294329
};
295330

296331
/**

0 commit comments

Comments
 (0)