@@ -20,6 +20,7 @@ typedef DrawData<T> = openfl.Vector<T>;
2020 */
2121class FlxDrawTrianglesItem extends FlxDrawBaseItem <FlxDrawTrianglesItem >
2222{
23+ static inline final INDICES_PER_QUAD = 6 ;
2324 static var point : FlxPoint = FlxPoint .get ();
2425 static var rect : FlxRect = FlxRect .get ();
2526
@@ -31,10 +32,12 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
3132 public var vertices : DrawData <Float > = new DrawData <Float >();
3233 public var indices : DrawData <Int > = new DrawData <Int >();
3334 public var uvtData : DrawData <Float > = new DrawData <Float >();
35+ @:deprecated (" colors is deprecated, use colorMultipliers and colorOffsets" )
3436 public var colors : DrawData <Int > = new DrawData <Int >();
3537
3638 public var verticesPosition : Int = 0 ;
3739 public var indicesPosition : Int = 0 ;
40+ @:deprecated (" colorsPosition is deprecated" )
3841 public var colorsPosition : Int = 0 ;
3942
4043 var bounds : FlxRect = FlxRect .get ();
@@ -100,11 +103,9 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
100103 vertices .length = 0 ;
101104 indices .length = 0 ;
102105 uvtData .length = 0 ;
103- colors .length = 0 ;
104106
105107 verticesPosition = 0 ;
106108 indicesPosition = 0 ;
107- colorsPosition = 0 ;
108109 alphas .splice (0 , alphas .length );
109110 if (colorMultipliers != null )
110111 colorMultipliers .splice (0 , colorMultipliers .length );
@@ -119,7 +120,6 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
119120 vertices = null ;
120121 indices = null ;
121122 uvtData = null ;
122- colors = null ;
123123 bounds = null ;
124124 alphas = null ;
125125 colorMultipliers = null ;
@@ -140,7 +140,6 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
140140 var numberOfVertices : Int = Std .int (verticesLength / 2 );
141141 var prevIndicesLength : Int = this .indices .length ;
142142 var prevUVTDataLength : Int = this .uvtData .length ;
143- var prevColorsLength : Int = this .colors .length ;
144143 var prevNumberOfVertices : Int = this .numVertices ;
145144
146145 var tempX : Float , tempY : Float ;
@@ -184,16 +183,6 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
184183 {
185184 this .indices [prevIndicesLength + i ] = indices [i ] + prevNumberOfVertices ;
186185 }
187-
188- if (colored )
189- {
190- for (i in 0 ... numberOfVertices )
191- {
192- this .colors [prevColorsLength + i ] = colors [i ];
193- }
194-
195- colorsPosition + = numberOfVertices ;
196- }
197186
198187 final alphaMultiplier = transform != null ? transform .alphaMultiplier : 1.0 ;
199188 for (_ in 0 ... indicesLength )
@@ -280,82 +269,76 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
280269
281270 override public function addQuad (frame : FlxFrame , matrix : FlxMatrix , ? transform : ColorTransform ): Void
282271 {
283- var prevVerticesPos : Int = verticesPosition ;
284- var prevIndicesPos : Int = indicesPosition ;
285- var prevColorsPos : Int = colorsPosition ;
286- var prevNumberOfVertices : Int = numVertices ;
287-
288- var point = FlxPoint .get ();
289- point .transform (matrix );
290-
291- vertices [prevVerticesPos ] = point .x ;
292- vertices [prevVerticesPos + 1 ] = point .y ;
293-
294- uvtData [prevVerticesPos ] = frame .uv .left ;
272+ final prevVerticesPos = verticesPosition ;
273+ final prevNumberOfVertices = numVertices ;
274+
275+ final w = frame .frame .width ;
276+ final h = frame .frame .height ;
277+ vertices [prevVerticesPos + 0 ] = matrix .transformX (0 , 0 ); // left
278+ vertices [prevVerticesPos + 1 ] = matrix .transformY (0 , 0 ); // top
279+ vertices [prevVerticesPos + 2 ] = matrix .transformX (w , 0 ); // right
280+ vertices [prevVerticesPos + 3 ] = matrix .transformY (w , 0 ); // top
281+ vertices [prevVerticesPos + 4 ] = matrix .transformX (0 , h ); // left
282+ vertices [prevVerticesPos + 5 ] = matrix .transformY (0 , h ); // bottom
283+ vertices [prevVerticesPos + 6 ] = matrix .transformX (w , h ); // right
284+ vertices [prevVerticesPos + 7 ] = matrix .transformY (w , h ); // bottom
285+
286+ uvtData [prevVerticesPos + 0 ] = frame .uv .left ;
295287 uvtData [prevVerticesPos + 1 ] = frame .uv .top ;
296-
297- point .set (frame .frame .width , 0 );
298- point .transform (matrix );
299-
300- vertices [prevVerticesPos + 2 ] = point .x ;
301- vertices [prevVerticesPos + 3 ] = point .y ;
302-
303288 uvtData [prevVerticesPos + 2 ] = frame .uv .right ;
304289 uvtData [prevVerticesPos + 3 ] = frame .uv .top ;
305-
306- point .set (frame .frame .width , frame .frame .height );
307- point .transform (matrix );
308-
309- vertices [prevVerticesPos + 4 ] = point .x ;
310- vertices [prevVerticesPos + 5 ] = point .y ;
311-
312- uvtData [prevVerticesPos + 4 ] = frame .uv .right ;
290+ uvtData [prevVerticesPos + 4 ] = frame .uv .left ;
313291 uvtData [prevVerticesPos + 5 ] = frame .uv .bottom ;
314-
315- point .set (0 , frame .frame .height );
316- point .transform (matrix );
317-
318- vertices [prevVerticesPos + 6 ] = point .x ;
319- vertices [prevVerticesPos + 7 ] = point .y ;
320-
321- point .put ();
322-
323- uvtData [prevVerticesPos + 6 ] = frame .uv .left ;
292+ uvtData [prevVerticesPos + 6 ] = frame .uv .right ;
324293 uvtData [prevVerticesPos + 7 ] = frame .uv .bottom ;
325-
326- indices [prevIndicesPos ] = prevNumberOfVertices ;
327- indices [prevIndicesPos + 1 ] = prevNumberOfVertices + 1 ;
328- indices [prevIndicesPos + 2 ] = prevNumberOfVertices + 2 ;
329- indices [prevIndicesPos + 3 ] = prevNumberOfVertices + 2 ;
330- indices [prevIndicesPos + 4 ] = prevNumberOfVertices + 3 ;
331- indices [prevIndicesPos + 5 ] = prevNumberOfVertices ;
332-
333- if (colored )
294+
295+ final prevIndicesPos = indicesPosition ;
296+ indices [prevIndicesPos + 0 ] = prevNumberOfVertices + 0 ; // TL
297+ indices [prevIndicesPos + 1 ] = prevNumberOfVertices + 1 ; // TR
298+ indices [prevIndicesPos + 2 ] = prevNumberOfVertices + 2 ; // BL
299+ indices [prevIndicesPos + 3 ] = prevNumberOfVertices + 1 ; // TR
300+ indices [prevIndicesPos + 4 ] = prevNumberOfVertices + 2 ; // BL
301+ indices [prevIndicesPos + 5 ] = prevNumberOfVertices + 3 ; // BR
302+
303+ final alphaMultiplier = transform != null ? transform .alphaMultiplier : 1.0 ;
304+ for (i in 0 ... INDICES_PER_QUAD )
305+ alphas .push (alphaMultiplier );
306+
307+ if (colored || hasColorOffsets )
334308 {
335- var red = 1.0 ;
336- var green = 1.0 ;
337- var blue = 1.0 ;
338- var alpha = 1.0 ;
339-
340- if (transform != null )
309+ if (colorMultipliers == null )
310+ colorMultipliers = [];
311+
312+ if (colorOffsets == null )
313+ colorOffsets = [];
314+
315+ for (i in 0 ... INDICES_PER_QUAD )
341316 {
342- red = transform .redMultiplier ;
343- green = transform .greenMultiplier ;
344- blue = transform .blueMultiplier ;
345-
346- #if !neko
347- alpha = transform .alphaMultiplier ;
348- #end
317+ if (transform != null )
318+ {
319+ colorMultipliers .push (transform .redMultiplier );
320+ colorMultipliers .push (transform .greenMultiplier );
321+ colorMultipliers .push (transform .blueMultiplier );
322+
323+ colorOffsets .push (transform .redOffset );
324+ colorOffsets .push (transform .greenOffset );
325+ colorOffsets .push (transform .blueOffset );
326+ colorOffsets .push (transform .alphaOffset );
327+ }
328+ else
329+ {
330+ colorMultipliers .push (1 );
331+ colorMultipliers .push (1 );
332+ colorMultipliers .push (1 );
333+
334+ colorOffsets .push (0 );
335+ colorOffsets .push (0 );
336+ colorOffsets .push (0 );
337+ colorOffsets .push (0 );
338+ }
339+
340+ colorMultipliers .push (1 );
349341 }
350-
351- var color = FlxColor .fromRGBFloat (red , green , blue , alpha );
352-
353- colors [prevColorsPos ] = color ;
354- colors [prevColorsPos + 1 ] = color ;
355- colors [prevColorsPos + 2 ] = color ;
356- colors [prevColorsPos + 3 ] = color ;
357-
358- colorsPosition + = 4 ;
359342 }
360343
361344 verticesPosition + = 8 ;
0 commit comments