Skip to content

Commit f246c27

Browse files
committed
Multi-Texture support has now been built into our version of Pixi. This can offer dramatic performance increases in WebGL games on GPUs that support multiple texture bindings (which is most of them these days).
WebGLRenderer.setTexturePriority is the method used to set the priority of textures when the GPU supports multi-texture batching. Rope has two new properties `textureIndices` and `textureIndex` to handle multi-texture support. Strip has two new properties `textureIndices` and `textureIndex` to handle multi-texture support. The following shaders have all been updated to support multi-textures: `ComplexPrimitiveShader`, `PixiFastShader`, `PixiShader`, `PrimitiveShader`, `StripShader`. WebGLFastSpriteBatch.vertSize was increased from 10 to 11. BaseTexture.textureIndex is a new property that controls the index of the texture within the GPU texture cache. Usually you don't change this yourself, and use `renderer.setTexturePriority` instead, but the property is public and available for more advanced use-cases. CanvasRenderer.setTexturePriority is an empty function, but included to allow you to simply call `game.renderer.setTexturePriority` without first having to wrap that in a WebGL check.
1 parent dfaf0b9 commit f246c27

5 files changed

Lines changed: 31 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ Please note that Phaser uses a custom build of Pixi and always has done. The fol
348348
* Rope has two new properties `textureIndices` and `textureIndex` to handle multi-texture support.
349349
* Strip has two new properties `textureIndices` and `textureIndex` to handle multi-texture support.
350350
* The following shaders have all been updated to support multi-textures: `ComplexPrimitiveShader`, `PixiFastShader`, `PixiShader`, `PrimitiveShader`, `StripShader`.
351+
* WebGLFastSpriteBatch.vertSize was increased from 10 to 11.
351352
* BaseTexture.textureIndex is a new property that controls the index of the texture within the GPU texture cache. Usually you don't change this yourself, and use `renderer.setTexturePriority` instead, but the property is public and available for more advanced use-cases.
353+
* CanvasRenderer.setTexturePriority is an empty function, but included to allow you to simply call `game.renderer.setTexturePriority` without first having to wrap that in a WebGL check.
352354
* This version contains significant fixes for `DisplayObject.getBounds` and `DisplayObjectContainer.getBounds`. The methods can now accept an optional argument `targetCoordinateSpace` which makes it much more flexible, allowing you to check the bounds against any target, not just local and global ones. If the `targetCoordinateSpace` is a valid DisplayObject:
353355

354356
- If it's a parent of the caller at some level it will return the bounds

src/pixi/extras/Rope.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ PIXI.Rope.prototype.updateTransform = function()
177177
*/
178178
PIXI.Rope.prototype.setTexture = function(texture)
179179
{
180-
console.log(texture);
181-
debugger;
182180
// stop current texture
183181
this.texture = texture;
184182
this.textureIndex = texture.baseTexture.textureIndex;

src/pixi/extras/Strip.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
*
1414
*/
1515
PIXI.Strip = function (texture) {
16-
PIXI.DisplayObjectContainer.call(this);
1716

17+
PIXI.DisplayObjectContainer.call(this);
1818

1919
/**
2020
* The texture of the strip
@@ -82,6 +82,7 @@ PIXI.Strip.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
8282
PIXI.Strip.prototype.constructor = PIXI.Strip;
8383

8484
PIXI.Strip.prototype._renderWebGL = function (renderSession) {
85+
8586
// if the sprite is not visible or the alpha is 0 then no need to render this element
8687
if (!this.visible || this.alpha <= 0) return;
8788
// render triangle strip..
@@ -103,6 +104,7 @@ PIXI.Strip.prototype._renderWebGL = function (renderSession) {
103104
};
104105

105106
PIXI.Strip.prototype._initWebGL = function (renderSession) {
107+
106108
// build the strip!
107109
var gl = renderSession.gl;
108110
this.gl = gl;
@@ -132,6 +134,7 @@ PIXI.Strip.prototype._initWebGL = function (renderSession) {
132134
};
133135

134136
PIXI.Strip.prototype._renderStrip = function (renderSession) {
137+
135138
var gl = renderSession.gl;
136139
var projection = renderSession.projection,
137140
offset = renderSession.offset,

src/pixi/renderers/canvas/CanvasRenderer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ PIXI.CanvasRenderer.prototype.render = function (root) {
190190

191191
};
192192

193+
PIXI.CanvasRenderer.prototype.setTexturePriority = function (textureNameCollection) {
194+
195+
// Does nothing on Canvas, but here to allow you to simply set
196+
// `game.renderer.setTexturePriority()` without having to worry about
197+
// running in WebGL or not.
198+
199+
};
200+
193201
/**
194202
* Removes everything from the renderer and optionally removes the Canvas DOM element.
195203
*

src/pixi/renderers/webgl/WebGLRenderer.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,20 +242,32 @@ PIXI.WebGLRenderer.prototype.initContext = function()
242242
this.resize(this.width, this.height);
243243
};
244244

245-
PIXI.WebGLRenderer.prototype.setTexturePriority = function(textureNameCollection) {
245+
PIXI.WebGLRenderer.prototype.setTexturePriority = function (textureNameCollection) {
246+
246247
var maxTextures = this.maxTextures;
247248
var imageCache = this.game.cache._cache.image;
248249
var imageName = null;
250+
249251
// We start from 1 because framebuffer texture uses unit 0.
250-
for (var index = 0; index < textureNameCollection.length; ++index) {
252+
for (var index = 0; index < textureNameCollection.length; ++index)
253+
{
251254
imageName = textureNameCollection[index];
252-
if (!(imageName in imageCache)) continue;
253-
if (index + 1 < maxTextures) {
255+
256+
if (!(imageName in imageCache))
257+
{
258+
continue;
259+
}
260+
261+
if (index + 1 < maxTextures)
262+
{
254263
imageCache[imageName].base.textureIndex = index + 1;
255-
} else {
264+
}
265+
else
266+
{
256267
imageCache[imageName].base.textureIndex = maxTextures - 1;
257268
}
258269
}
270+
259271
};
260272

261273
/**

0 commit comments

Comments
 (0)