@@ -122,8 +122,16 @@ PIXI.Tilemap.prototype._renderWebGL = function(renderSession)
122122
123123 renderSession . shaderManager . setShader ( renderSession . shaderManager . tilemapShader ) ;
124124
125- // TODO: switch to the appropriate rendering mode function here (rebuild all, part, edges, none)
126- this . _renderWholeTilemap ( renderSession ) ;
125+ switch ( this . _renderMode )
126+ {
127+ case 0 :
128+ this . _renderVisibleTiles ( renderSession ) ;
129+ break ;
130+
131+ case 1 :
132+ this . _renderWholeTilemap ( renderSession ) ;
133+ break ;
134+ }
127135
128136 renderSession . spriteBatch . start ( ) ;
129137} ;
@@ -184,6 +192,65 @@ PIXI.Tilemap.prototype.makeTransform = function(_x, _y, _angleInRadians, _scaleX
184192};
185193
186194
195+ /**
196+ * render only the visible portion of the tilemap, one layer at a time, one tile at a time
197+ * using a fast webgl tile render
198+ *
199+ * @param {[type] } renderSession [description]
200+ */
201+ PIXI . Tilemap . prototype . _renderVisibleTiles = function ( renderSession )
202+ {
203+ var gl = renderSession . gl ;
204+ var shader = renderSession . shaderManager . tilemapShader ;
205+
206+ renderSession . blendModeManager . setBlendMode ( this . blendMode ) ;
207+
208+ // set the uniforms and texture
209+ gl . uniformMatrix3fv ( shader . uProjectionMatrix , false , this . makeProjection ( gl . drawingBufferWidth , gl . drawingBufferHeight ) ) ;
210+ gl . uniform1i ( shader . uImageSampler , 0 ) ;
211+ gl . activeTexture ( gl . TEXTURE0 ) ;
212+ gl . uniform2f ( shader . uTileSize , this . tileWide , this . tileHigh ) ;
213+
214+ // check if a texture is dirty..
215+ if ( this . texture . baseTexture . _dirty [ gl . id ] )
216+ {
217+ renderSession . renderer . updateTexture ( this . texture . baseTexture ) ;
218+ }
219+ else
220+ {
221+ // bind the current texture
222+ gl . bindTexture ( gl . TEXTURE_2D , this . texture . baseTexture . _glTextures [ gl . id ] ) ;
223+ }
224+
225+ // bind the source buffer
226+ gl . bindBuffer ( gl . ARRAY_BUFFER , this . positionBuffer ) ;
227+
228+ // draw the entire map layer
229+ this . _renderVisibleLayer ( this . layer , renderSession ) ;
230+ } ;
231+
232+
233+ PIXI . Tilemap . prototype . _renderVisibleLayer = function ( _layer , renderSession )
234+ {
235+ var gl = renderSession . gl ;
236+ var shader = renderSession . shaderManager . tilemapShader ;
237+ var firstX = Math . max ( Math . floor ( this . _scrollX / this . tileWide ) , 0 ) ;
238+ var firstY = Math . max ( Math . floor ( this . _scrollY / this . tileHigh ) , 0 ) ;
239+ var lastX = Math . min ( firstX + Math . ceil ( this . game . width / this . tileWide ) + 1 , this . mapWide ) ;
240+ var lastY = Math . min ( firstY + Math . ceil ( this . game . height / this . tileHigh ) + 1 , this . mapHigh ) ;
241+
242+ for ( var y = firstY ; y < lastY ; y ++ )
243+ {
244+ var layerRow = _layer . data [ y ] ;
245+ for ( var x = firstX ; x < lastX ; x ++ )
246+ {
247+ this . _renderTile ( gl , shader , x * this . tileWide , y * this . tileHigh , layerRow [ x ] . index - 1 ) ;
248+ }
249+ }
250+
251+ } ;
252+
253+
187254/**
188255 * render the entire tilemap, one layer at a time, one tile at a time
189256 * using a fast webgl tile render
0 commit comments