@@ -139,16 +139,22 @@ PIXI.WebGLSpriteBatch = function () {
139139 * @type AbstractFilter
140140 */
141141 this . defaultShader = null ;
142+
143+ /**
144+ * @property textureArray
145+ * @type Array
146+ */
147+ this . textureArray = [ ] ;
142148} ;
143149
144150/**
145151 * @method setContext
146152 * @param gl {WebGLContext} the current WebGL drawing context
147153 */
148154PIXI . WebGLSpriteBatch . prototype . setContext = function ( gl ) {
149- var MAX_TEXTURES = gl . getParameter ( gl . MAX_TEXTURE_IMAGE_UNITS ) ;
155+ this . MAX_TEXTURES = gl . getParameter ( gl . MAX_TEXTURE_IMAGE_UNITS ) ;
150156 var dynamicIfs = '\tif (vTextureIndex == 0.0) gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;\n'
151- for ( var index = 1 ; index < MAX_TEXTURES ; ++ index ) {
157+ for ( var index = 1 ; index < this . MAX_TEXTURES ; ++ index ) {
152158 dynamicIfs += '\telse if (vTextureIndex == ' +
153159 index + '.0) gl_FragColor = texture2D(uSamplerArray[' +
154160 index + '], vTextureCoord) * vColor;\n'
@@ -160,7 +166,7 @@ PIXI.WebGLSpriteBatch.prototype.setContext = function (gl) {
160166 'varying vec2 vTextureCoord;' ,
161167 'varying vec4 vColor;' ,
162168 'varying float vTextureIndex;' ,
163- 'uniform sampler2D uSamplerArray[' + MAX_TEXTURES + '];' ,
169+ 'uniform sampler2D uSamplerArray[' + this . MAX_TEXTURES + '];' ,
164170 'void main(void) {' ,
165171 dynamicIfs ,
166172 '\telse gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;' ,
@@ -216,6 +222,14 @@ PIXI.WebGLSpriteBatch.prototype.end = function () {
216222 */
217223PIXI . WebGLSpriteBatch . prototype . render = function ( sprite , matrix ) {
218224 var texture = sprite . texture ;
225+ var baseTexture = texture . baseTexture ;
226+ var gl = this . gl ;
227+ if ( this . textureArray [ baseTexture . textureIndex ] != baseTexture ) {
228+ gl . activeTexture ( gl . TEXTURE0 + baseTexture . textureIndex ) ;
229+ gl . bindTexture ( gl . TEXTURE_2D , baseTexture . _glTextures [ gl . id ] ) ;
230+ this . textureArray [ baseTexture . textureIndex ] = baseTexture ;
231+ this . flush ( ) ;
232+ }
219233
220234 // They provided an alternative rendering matrix, so use it
221235 var wt = sprite . worldTransform ;
@@ -260,7 +274,7 @@ PIXI.WebGLSpriteBatch.prototype.render = function (sprite, matrix) {
260274 h1 = texture . frame . height * - aY ;
261275 }
262276
263- var i = this . currentBatchSize * this . vertexSize ; //4 * this.vertSize;
277+ var i = this . currentBatchSize * this . vertexSize ; //4 * this.vertSize;
264278 var tiOffset = this . currentBatchSize * 4 ;
265279 var resolution = texture . baseTexture . resolution ;
266280 var textureIndex = texture . baseTexture . textureIndex ;
@@ -347,6 +361,7 @@ PIXI.WebGLSpriteBatch.prototype.render = function (sprite, matrix) {
347361PIXI . WebGLSpriteBatch . prototype . renderTilingSprite = function ( sprite ) {
348362 var texture = sprite . tilingTexture ;
349363
364+
350365 // check texture..
351366 if ( this . currentBatchSize >= this . size ) {
352367 this . flush ( ) ;
@@ -409,7 +424,7 @@ PIXI.WebGLSpriteBatch.prototype.renderTilingSprite = function (sprite) {
409424 var h0 = height * ( 1 - aY ) ;
410425 var h1 = height * - aY ;
411426
412- var i = this . currentBatchSize * this . vertexSize ; //4 * this.vertSize;
427+ var i = this . currentBatchSize * this . vertexSize ; //4 * this.vertSize;
413428
414429 var resolution = texture . baseTexture . resolution ;
415430
@@ -538,6 +553,7 @@ PIXI.WebGLSpriteBatch.prototype.flush = function () {
538553 } else {
539554 nextTexture = sprite . texture . baseTexture ;
540555 }
556+
541557 nextBlendMode = sprite . blendMode ;
542558 nextShader = sprite . shader || this . defaultShader ;
543559
@@ -549,8 +565,10 @@ PIXI.WebGLSpriteBatch.prototype.flush = function () {
549565 if ( skip && sprite . children . length > 0 ) {
550566 skip = false ;
551567 }
552-
553- if ( ( currentBaseTexture !== nextTexture && ! skip ) || blendSwap || shaderSwap ) {
568+ //
569+ if ( /*(currentBaseTexture != nextTexture && !skip) ||*/
570+ blendSwap ||
571+ shaderSwap ) {
554572 this . renderBatch ( currentBaseTexture , batchSize , start ) ;
555573
556574 start = i ;
@@ -627,13 +645,9 @@ PIXI.WebGLSpriteBatch.prototype.renderBatch = function (texture, size, startInde
627645 }
628646 } else {
629647 gl . activeTexture ( gl . TEXTURE0 + texture . textureIndex ) ;
630- // bind the current texture
631648 gl . bindTexture ( gl . TEXTURE_2D , texture . _glTextures [ gl . id ] ) ;
632649 }
633-
634- // now draw those suckas!
635650 gl . drawElements ( gl . TRIANGLES , size * 6 , gl . UNSIGNED_SHORT , startIndex * 6 * 2 ) ;
636-
637651 // increment the draw count
638652 this . renderSession . drawCount ++ ;
639653} ;
0 commit comments