@@ -158,7 +158,11 @@ var TextureTintPipeline = new Class({
158158
159159 flush : function ( )
160160 {
161+ if ( this . flushLocked ) return this ;
162+ this . flushLocked = true ;
163+
161164 var gl = this . gl ;
165+ var renderer = this . renderer ;
162166 var vertexCount = this . vertexCount ;
163167 var vertexBuffer = this . vertexBuffer ;
164168 var vertexData = this . vertexData ;
@@ -170,8 +174,11 @@ var TextureTintPipeline = new Class({
170174 var batch = null ;
171175 var nextBatch = null ;
172176
173- if ( batchCount === 0 || vertexCount === 0 ) return ;
174-
177+ if ( batchCount === 0 || vertexCount === 0 )
178+ {
179+ this . flushLocked = false ;
180+ return this ;
181+ }
175182 gl . bufferSubData ( gl . ARRAY_BUFFER , 0 , this . bytes . subarray ( 0 , vertexCount * vertexSize ) ) ;
176183
177184 for ( var index = 0 ; index < batches . length - 1 ; ++ index )
@@ -186,8 +193,7 @@ var TextureTintPipeline = new Class({
186193 var nTexture = batch . textures [ textureIndex ] ;
187194 if ( nTexture )
188195 {
189- gl . activeTexture ( gl . TEXTURE0 + 1 + textureIndex ) ;
190- gl . bindTexture ( gl . TEXTURE_2D , nTexture ) ;
196+ renderer . setTexture2D ( nTexture , 1 + textureIndex ) ;
191197 }
192198 }
193199 gl . activeTexture ( gl . TEXTURE0 ) ;
@@ -197,7 +203,7 @@ var TextureTintPipeline = new Class({
197203
198204 if ( batch . texture === null || batchVertexCount <= 0 ) continue ;
199205
200- gl . bindTexture ( gl . TEXTURE_2D , batch . texture ) ;
206+ renderer . setTexture2D ( batch . texture , 0 ) ;
201207 gl . drawArrays ( topology , batch . first , batchVertexCount ) ;
202208 }
203209
@@ -211,8 +217,7 @@ var TextureTintPipeline = new Class({
211217 var nTexture = batch . textures [ textureIndex ] ;
212218 if ( nTexture )
213219 {
214- gl . activeTexture ( gl . TEXTURE0 + 1 + textureIndex ) ;
215- gl . bindTexture ( gl . TEXTURE_2D , nTexture ) ;
220+ renderer . setTexture2D ( nTexture , 1 + textureIndex ) ;
216221 }
217222 }
218223 gl . activeTexture ( gl . TEXTURE0 ) ;
@@ -222,12 +227,13 @@ var TextureTintPipeline = new Class({
222227
223228 if ( batch . texture && batchVertexCount > 0 )
224229 {
225- gl . bindTexture ( gl . TEXTURE_2D , batch . texture ) ;
230+ renderer . setTexture2D ( batch . texture , 0 ) ;
226231 gl . drawArrays ( topology , batch . first , batchVertexCount ) ;
227232 }
228233
229234 this . vertexCount = 0 ;
230235 batches . length = 0 ;
236+ this . flushLocked = false ;
231237
232238 return this ;
233239 } ,
0 commit comments