@@ -2398,6 +2398,15 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession)
23982398
23992399 renderSession . context . globalAlpha = this . worldAlpha ;
24002400
2401+ // If smoothingEnabled is supported and we need to change the smoothing property for this texture
2402+ if ( renderSession . smoothProperty && renderSession . scaleMode !== this . texture . baseTexture . scaleMode )
2403+ {
2404+ renderSession . scaleMode = this . texture . baseTexture . scaleMode ;
2405+ renderSession . context [ renderSession . smoothProperty ] = ( renderSession . scaleMode === PIXI . scaleModes . LINEAR ) ;
2406+ }
2407+ // If the texture is trimmed we offset by the trim x/y, otherwise we use the frame dimensions
2408+ var dx = ( this . texture . trim ) ? this . texture . trim . x - this . anchor . x * this . texture . trim . width : this . anchor . x * - this . texture . frame . width ;
2409+ var dy = ( this . texture . trim ) ? this . texture . trim . y - this . anchor . y * this . texture . trim . height : this . anchor . y * - this . texture . frame . height ;
24012410 // Allow for pixel rounding
24022411 if ( renderSession . roundPixels )
24032412 {
@@ -2408,6 +2417,8 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession)
24082417 this . worldTransform . d ,
24092418 ( this . worldTransform . tx * renderSession . resolution ) | 0 ,
24102419 ( this . worldTransform . ty * renderSession . resolution ) | 0 ) ;
2420+ dx = dx | 0 ;
2421+ dy = dy | 0 ;
24112422 }
24122423 else
24132424 {
@@ -2420,17 +2431,6 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession)
24202431 this . worldTransform . ty * renderSession . resolution ) ;
24212432 }
24222433
2423- // If smoothingEnabled is supported and we need to change the smoothing property for this texture
2424- if ( renderSession . smoothProperty && renderSession . scaleMode !== this . texture . baseTexture . scaleMode )
2425- {
2426- renderSession . scaleMode = this . texture . baseTexture . scaleMode ;
2427- renderSession . context [ renderSession . smoothProperty ] = ( renderSession . scaleMode === PIXI . scaleModes . LINEAR ) ;
2428- }
2429-
2430- // If the texture is trimmed we offset by the trim x/y, otherwise we use the frame dimensions
2431- var dx = ( this . texture . trim ) ? this . texture . trim . x - this . anchor . x * this . texture . trim . width : this . anchor . x * - this . texture . frame . width ;
2432- var dy = ( this . texture . trim ) ? this . texture . trim . y - this . anchor . y * this . texture . trim . height : this . anchor . y * - this . texture . frame . height ;
2433-
24342434 if ( this . tint !== 0xFFFFFF )
24352435 {
24362436 if ( this . cachedTint !== this . tint )
@@ -3810,6 +3810,10 @@ PIXI.getNextPowerOfTwo = function(number)
38103810 return result ;
38113811 }
38123812} ;
3813+ PIXI . isPowerOfTwo = function ( width , height )
3814+ {
3815+ return ( width > 0 && ( width & ( width - 1 ) ) === 0 && height > 0 && ( height & ( height - 1 ) ) === 0 ) ;
3816+ } ;
38133817
38143818/**
38153819 * @author Mat Groves http://matgroves.com/ @Doormat23
@@ -6118,7 +6122,6 @@ PIXI.WebGLGraphicsData = function(gl)
61186122 this . color = [ 0 , 0 , 0 ] ; // color split!
61196123 this . points = [ ] ;
61206124 this . indices = [ ] ;
6121- this . lastIndex = 0 ;
61226125 this . buffer = gl . createBuffer ( ) ;
61236126 this . indexBuffer = gl . createBuffer ( ) ;
61246127 this . mode = 1 ;
@@ -6133,7 +6136,6 @@ PIXI.WebGLGraphicsData.prototype.reset = function()
61336136{
61346137 this . points = [ ] ;
61356138 this . indices = [ ] ;
6136- this . lastIndex = 0 ;
61376139} ;
61386140
61396141/**
@@ -6580,7 +6582,17 @@ PIXI.WebGLRenderer.prototype.updateTexture = function(texture)
65806582 gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , gl . RGBA , gl . UNSIGNED_BYTE , texture . source ) ;
65816583
65826584 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , texture . scaleMode === PIXI . scaleModes . LINEAR ? gl . LINEAR : gl . NEAREST ) ;
6583- gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , texture . scaleMode === PIXI . scaleModes . LINEAR ? gl . LINEAR : gl . NEAREST ) ;
6585+
6586+
6587+ if ( texture . mipmap && PIXI . isPowerOfTwo ( texture . width , texture . height ) )
6588+ {
6589+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , texture . scaleMode === PIXI . scaleModes . LINEAR ? gl . LINEAR_MIPMAP_LINEAR : gl . NEAREST_MIPMAP_NEAREST ) ;
6590+ gl . generateMipmap ( gl . TEXTURE_2D ) ;
6591+ }
6592+ else
6593+ {
6594+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , texture . scaleMode === PIXI . scaleModes . LINEAR ? gl . LINEAR : gl . NEAREST ) ;
6595+ }
65846596
65856597 // reguler...
65866598 if ( ! texture . _powerOf2 )
@@ -7531,50 +7543,71 @@ PIXI.WebGLSpriteBatch.prototype.render = function(sprite)
75317543 var tx = worldTransform . tx ;
75327544 var ty = worldTransform . ty ;
75337545
7546+ if ( this . renderSession . roundPixels )
7547+ {
7548+ //xy
7549+ verticies [ index ] = a * w1 + c * h1 + tx | 0 ;
7550+ verticies [ index + 1 ] = d * h1 + b * w1 + ty | 0 ;
75347551
7535- // xy
7536- verticies [ index ++ ] = a * w1 + c * h1 + tx ;
7537- verticies [ index ++ ] = d * h1 + b * w1 + ty ;
7538- // uv
7539- verticies [ index ++ ] = uvs . x0 ;
7540- verticies [ index ++ ] = uvs . y0 ;
7541- // color
7542- verticies [ index ++ ] = alpha ;
7543- verticies [ index ++ ] = tint ;
7552+ // xy
7553+ verticies [ index + 6 ] = a * w0 + c * h1 + tx | 0 ;
7554+ verticies [ index + 7 ] = d * h1 + b * w0 + ty | 0 ;
75447555
7545- // xy
7546- verticies [ index ++ ] = a * w0 + c * h1 + tx ;
7547- verticies [ index ++ ] = d * h1 + b * w0 + ty ;
7556+ // xy
7557+ verticies [ index + 12 ] = a * w0 + c * h0 + tx | 0 ;
7558+ verticies [ index + 13 ] = d * h0 + b * w0 + ty | 0 ;
7559+
7560+ // xy
7561+ verticies [ index + 18 ] = a * w1 + c * h0 + tx | 0 ;
7562+ verticies [ index + 19 ] = d * h0 + b * w1 + ty | 0 ;
7563+ }
7564+ else
7565+ {
7566+ //xy
7567+ verticies [ index ] = a * w1 + c * h1 + tx ;
7568+ verticies [ index + 1 ] = d * h1 + b * w1 + ty ;
7569+
7570+ // xy
7571+ verticies [ index + 6 ] = a * w0 + c * h1 + tx ;
7572+ verticies [ index + 7 ] = d * h1 + b * w0 + ty ;
7573+
7574+ // xy
7575+ verticies [ index + 12 ] = a * w0 + c * h0 + tx ;
7576+ verticies [ index + 13 ] = d * h0 + b * w0 + ty ;
7577+
7578+ // xy
7579+ verticies [ index + 18 ] = a * w1 + c * h0 + tx ;
7580+ verticies [ index + 19 ] = d * h0 + b * w1 + ty ;
7581+ }
7582+
75487583 // uv
7549- verticies [ index ++ ] = uvs . x1 ;
7550- verticies [ index ++ ] = uvs . y1 ;
7551- // color
7552- verticies [ index ++ ] = alpha ;
7553- verticies [ index ++ ] = tint ;
7584+ verticies [ index + 2 ] = uvs . x0 ;
7585+ verticies [ index + 3 ] = uvs . y0 ;
75547586
7555- // xy
7556- verticies [ index ++ ] = a * w0 + c * h0 + tx ;
7557- verticies [ index ++ ] = d * h0 + b * w0 + ty ;
75587587 // uv
7559- verticies [ index ++ ] = uvs . x2 ;
7560- verticies [ index ++ ] = uvs . y2 ;
7561- // color
7562- verticies [ index ++ ] = alpha ;
7563- verticies [ index ++ ] = tint ;
7588+ verticies [ index + 8 ] = uvs . x1 ;
7589+ verticies [ index + 9 ] = uvs . y1 ;
7590+
7591+ // uv
7592+ verticies [ index + 14 ] = uvs . x2 ;
7593+ verticies [ index + 15 ] = uvs . y2 ;
75647594
7565- // xy
7566- verticies [ index ++ ] = a * w1 + c * h0 + tx ;
7567- verticies [ index ++ ] = d * h0 + b * w1 + ty ;
75687595 // uv
7569- verticies [ index ++ ] = uvs . x3 ;
7570- verticies [ index ++ ] = uvs . y3 ;
7596+ verticies [ index + 20 ] = uvs . x3 ;
7597+ verticies [ index + 21 ] = uvs . y3 ;
7598+
75717599 // color
7572- verticies [ index ++ ] = alpha ;
7573- verticies [ index ++ ] = tint ;
7600+ verticies [ index + 4 ] = verticies [ index + 10 ] = verticies [ index + 16 ] = verticies [ index + 22 ] = alpha ;
7601+
7602+ // alpha
7603+ verticies [ index + 5 ] = verticies [ index + 11 ] = verticies [ index + 17 ] = verticies [ index + 23 ] = tint ;
7604+
75747605
7606+
75757607 // increment the batchsize
75767608 this . sprites [ this . currentBatchSize ++ ] = sprite ;
75777609
7610+
75787611} ;
75797612
75807613/**
@@ -11165,6 +11198,15 @@ PIXI.BaseTexture = function(source, scaleMode)
1116511198 */
1116611199 this . _glTextures = [ ] ;
1116711200
11201+ /**
11202+ *
11203+ * Set this to true if a mipmap of this texture needs to be generated. This value needs to be set before the texture is used
11204+ * Also the texture must be a power of two size to work
11205+ *
11206+ * @property mipmap
11207+ * @type {Boolean }
11208+ */
11209+ this . mipmap = false ;
1116811210 // used for webGL texture updating...
1116911211 // TODO - this needs to be addressed
1117011212
0 commit comments