55 */
66
77var GameObject = require ( '../GameObject' ) ;
8+ var Utils = require ( '../../renderer/webgl/Utils' ) ;
89
910/**
1011 * Renders this Game Object with the WebGL Renderer to the given Camera.
@@ -16,19 +17,107 @@ var GameObject = require('../GameObject');
1617 * @private
1718 *
1819 * @param {Phaser.Renderer.WebGL.WebGLRenderer } renderer - A reference to the current active WebGL renderer.
19- * @param {Phaser.GameObjects.Blitter } gameObject - The Game Object being rendered in this call.
20+ * @param {Phaser.GameObjects.Blitter } src - The Game Object being rendered in this call.
2021 * @param {number } interpolationPercentage - Reserved for future use and custom pipelines.
2122 * @param {Phaser.Cameras.Scene2D.Camera } camera - The Camera that is rendering the Game Object.
2223 * @param {Phaser.GameObjects.Components.TransformMatrix } parentMatrix - This transform matrix is defined if the game object is nested
2324 */
24- var BlitterWebGLRenderer = function ( renderer , gameObject , interpolationPercentage , camera , parentMatrix )
25+ var BlitterWebGLRenderer = function ( renderer , src , interpolationPercentage , camera , parentMatrix )
2526{
26- if ( GameObject . RENDER_MASK !== gameObject . renderFlags || ( gameObject . cameraFilter > 0 && ( gameObject . cameraFilter & camera . _id ) ) )
27+ if ( GameObject . RENDER_MASK !== src . renderFlags || ( src . cameraFilter > 0 && ( src . cameraFilter & camera . _id ) ) )
2728 {
2829 return ;
2930 }
3031
31- this . pipeline . drawBlitter ( gameObject , camera , parentMatrix ) ;
32+ var pipeline = this . pipeline ;
33+
34+ renderer . setPipeline ( pipeline ) ;
35+
36+ var cameraScrollX = camera . scrollX * src . scrollFactorX ;
37+ var cameraScrollY = camera . scrollY * src . scrollFactorY ;
38+
39+ var matrix = pipeline . _tempCameraMatrix ;
40+
41+ matrix . copyFrom ( camera . matrix ) ;
42+
43+ if ( parentMatrix )
44+ {
45+ matrix . multiplyWithOffset ( parentMatrix , - cameraScrollX , - cameraScrollY ) ;
46+
47+ cameraScrollX = 0 ;
48+ cameraScrollY = 0 ;
49+ }
50+
51+ var list = src . getRenderList ( ) ;
52+ var blitterX = src . x - cameraScrollX ;
53+ var blitterY = src . y - cameraScrollY ;
54+ var prevTextureSourceIndex = - 1 ;
55+ var tintEffect = false ;
56+ var alpha = camera . alpha * src . alpha ;
57+ var getTint = Utils . getTintAppendFloatAlpha ;
58+ var roundPixels = camera . roundPixels ;
59+
60+ for ( var index = 0 ; index < list . length ; index ++ )
61+ {
62+ var bob = list [ index ] ;
63+ var frame = bob . frame ;
64+ var bobAlpha = bob . alpha * alpha ;
65+
66+ if ( bobAlpha === 0 )
67+ {
68+ continue ;
69+ }
70+
71+ var width = frame . width ;
72+ var height = frame . height ;
73+
74+ var x = blitterX + bob . x + frame . x ;
75+ var y = blitterY + bob . y + frame . y ;
76+
77+ if ( bob . flipX )
78+ {
79+ width *= - 1 ;
80+ x += frame . width ;
81+ }
82+
83+ if ( bob . flipY )
84+ {
85+ height *= - 1 ;
86+ y += frame . height ;
87+ }
88+
89+ var xw = x + width ;
90+ var yh = y + height ;
91+
92+ var tx0 = x * matrix . a + y * matrix . c + matrix . e ;
93+ var ty0 = x * matrix . b + y * matrix . d + matrix . f ;
94+ var tx1 = xw * matrix . a + yh * matrix . c + matrix . e ;
95+ var ty1 = xw * matrix . b + yh * matrix . d + matrix . f ;
96+
97+ var tint = getTint ( 0xffffff , bobAlpha ) ;
98+ var uvs = frame . uvs ;
99+
100+ // Bind texture only if the Texture Source is different from before
101+ if ( frame . sourceIndex !== prevTextureSourceIndex )
102+ {
103+ pipeline . setTexture2D ( frame . glTexture , 0 ) ;
104+
105+ prevTextureSourceIndex = frame . sourceIndex ;
106+ }
107+
108+ if ( roundPixels )
109+ {
110+ tx0 |= 0 ;
111+ ty0 |= 0 ;
112+ tx1 |= 0 ;
113+ ty1 |= 0 ;
114+ }
115+
116+ if ( pipeline . batchVertices ( tx0 , ty0 , tx1 , ty1 , uvs , tint , tint , tint , tint , tintEffect ) )
117+ {
118+ prevTextureSourceIndex = - 1 ;
119+ }
120+ }
32121} ;
33122
34123module . exports = BlitterWebGLRenderer ;
0 commit comments