Skip to content

Commit ddde59e

Browse files
authored
FlxCamera: Honor color transformation in drawTriangles on FlxG.renderBlit (#3503)
* fix strip color transform on blit render * remove unnecessary `#if !flash` conditionals
1 parent 08e7225 commit ddde59e

File tree

3 files changed

+47
-74
lines changed

3 files changed

+47
-74
lines changed

flixel/FlxCamera.hx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,8 @@ class FlxCamera extends FlxBasic
643643
&& _headTriangles.antialiasing == smoothing
644644
&& _headTriangles.colored == isColored
645645
&& _headTriangles.blend == blend
646-
#if !flash
647646
&& _headTriangles.hasColorOffsets == hasColorOffsets
648647
&& _headTriangles.shader == shader
649-
#end
650648
)
651649
{
652650
return _headTriangles;
@@ -676,10 +674,8 @@ class FlxCamera extends FlxBasic
676674
itemToReturn.antialiasing = smoothing;
677675
itemToReturn.colored = isColored;
678676
itemToReturn.blend = blend;
679-
#if !flash
680677
itemToReturn.hasColorOffsets = hasColorOffsets;
681678
itemToReturn.shader = shader;
682-
#end
683679

684680
itemToReturn.nextTyped = _headTriangles;
685681
_headTriangles = itemToReturn;
@@ -881,7 +877,8 @@ class FlxCamera extends FlxBasic
881877
_helperMatrix.translate(-viewMarginLeft, -viewMarginTop);
882878
}
883879

884-
buffer.draw(trianglesSprite, _helperMatrix);
880+
buffer.draw(trianglesSprite, _helperMatrix, transform);
881+
885882
#if FLX_DEBUG
886883
if (FlxG.debugger.drawDebug)
887884
{
@@ -899,17 +896,11 @@ class FlxCamera extends FlxBasic
899896
}
900897
else
901898
{
902-
var isColored:Bool = (colors != null && colors.length != 0);
899+
final isColored = (colors != null && colors.length != 0) || (transform != null && transform.hasRGBMultipliers());
900+
final hasColorOffsets = (transform != null && transform.hasRGBAOffsets());
903901

904-
#if !flash
905-
var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets());
906-
isColored = isColored || (transform != null && transform.hasRGBMultipliers());
907-
var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader);
902+
final drawItem = startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader);
908903
drawItem.addTriangles(vertices, indices, uvtData, colors, position, cameraBounds, transform);
909-
#else
910-
var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(graphic, smoothing, isColored, blend);
911-
drawItem.addTriangles(vertices, indices, uvtData, colors, position, cameraBounds);
912-
#end
913904
}
914905
}
915906

flixel/FlxStrip.hx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ class FlxStrip extends FlxSprite
5757
continue;
5858

5959
getScreenPosition(_point, camera).subtractPoint(offset);
60-
#if !flash
6160
camera.drawTriangles(graphic, vertices, indices, uvtData, colors, _point, blend, repeat, antialiasing, colorTransform, shader);
62-
#else
63-
camera.drawTriangles(graphic, vertices, indices, uvtData, colors, _point, blend, repeat, antialiasing);
64-
#end
6561
}
6662
}
6763
}

flixel/graphics/tile/FlxDrawTrianglesItem.hx

Lines changed: 42 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
2323
static var point:FlxPoint = FlxPoint.get();
2424
static var rect:FlxRect = FlxRect.get();
2525

26-
#if !flash
2726
public var shader:FlxShader;
2827
var alphas:Array<Float>;
2928
var colorMultipliers:Array<Float>;
3029
var colorOffsets:Array<Float>;
31-
#end
3230

3331
public var vertices:DrawData<Float> = new DrawData<Float>();
3432
public var indices:DrawData<Int> = new DrawData<Int>();
@@ -45,16 +43,11 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
4543
{
4644
super();
4745
type = FlxDrawItemType.TRIANGLES;
48-
#if !flash
4946
alphas = [];
50-
#end
5147
}
5248

5349
override public function render(camera:FlxCamera):Void
5450
{
55-
if (!FlxG.renderTile)
56-
return;
57-
5851
if (numTriangles <= 0)
5952
return;
6053

@@ -112,13 +105,11 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
112105
verticesPosition = 0;
113106
indicesPosition = 0;
114107
colorsPosition = 0;
115-
#if !flash
116108
alphas.splice(0, alphas.length);
117109
if (colorMultipliers != null)
118110
colorMultipliers.splice(0, colorMultipliers.length);
119111
if (colorOffsets != null)
120112
colorOffsets.splice(0, colorOffsets.length);
121-
#end
122113
}
123114

124115
override public function dispose():Void
@@ -130,15 +121,13 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
130121
uvtData = null;
131122
colors = null;
132123
bounds = null;
133-
#if !flash
134124
alphas = null;
135125
colorMultipliers = null;
136126
colorOffsets = null;
137-
#end
138127
}
139128

140129
public function addTriangles(vertices:DrawData<Float>, indices:DrawData<Int>, uvtData:DrawData<Float>, ?colors:DrawData<Int>, ?position:FlxPoint,
141-
?cameraBounds:FlxRect #if !flash , ?transform:ColorTransform #end):Void
130+
?cameraBounds:FlxRect, ?transform:ColorTransform):Void
142131
{
143132
if (position == null)
144133
position = point.set();
@@ -205,57 +194,54 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
205194

206195
colorsPosition += numberOfVertices;
207196
}
208-
209-
verticesPosition += verticesLength;
210-
indicesPosition += indicesLength;
211-
}
212-
213-
position.putWeak();
214-
cameraBounds.putWeak();
215-
216-
#if !flash
217-
for (_ in 0...indicesLength)
218-
{
219-
alphas.push(transform != null ? transform.alphaMultiplier : 1.0);
220-
}
221-
222-
if (colored || hasColorOffsets)
223-
{
224-
if (colorMultipliers == null)
225-
colorMultipliers = [];
226-
227-
if (colorOffsets == null)
228-
colorOffsets = [];
229-
197+
198+
final alphaMultiplier = transform != null ? transform.alphaMultiplier : 1.0;
230199
for (_ in 0...indicesLength)
200+
alphas.push(alphaMultiplier);
201+
202+
if (colored || hasColorOffsets)
231203
{
232-
if(transform != null)
233-
{
234-
colorMultipliers.push(transform.redMultiplier);
235-
colorMultipliers.push(transform.greenMultiplier);
236-
colorMultipliers.push(transform.blueMultiplier);
237-
238-
colorOffsets.push(transform.redOffset);
239-
colorOffsets.push(transform.greenOffset);
240-
colorOffsets.push(transform.blueOffset);
241-
colorOffsets.push(transform.alphaOffset);
242-
}
243-
else
204+
if (colorMultipliers == null)
205+
colorMultipliers = [];
206+
207+
if (colorOffsets == null)
208+
colorOffsets = [];
209+
210+
for (_ in 0...indicesLength)
244211
{
212+
if (transform != null)
213+
{
214+
colorMultipliers.push(transform.redMultiplier);
215+
colorMultipliers.push(transform.greenMultiplier);
216+
colorMultipliers.push(transform.blueMultiplier);
217+
218+
colorOffsets.push(transform.redOffset);
219+
colorOffsets.push(transform.greenOffset);
220+
colorOffsets.push(transform.blueOffset);
221+
colorOffsets.push(transform.alphaOffset);
222+
}
223+
else
224+
{
225+
colorMultipliers.push(1);
226+
colorMultipliers.push(1);
227+
colorMultipliers.push(1);
228+
229+
colorOffsets.push(0);
230+
colorOffsets.push(0);
231+
colorOffsets.push(0);
232+
colorOffsets.push(0);
233+
}
234+
245235
colorMultipliers.push(1);
246-
colorMultipliers.push(1);
247-
colorMultipliers.push(1);
248-
249-
colorOffsets.push(0);
250-
colorOffsets.push(0);
251-
colorOffsets.push(0);
252-
colorOffsets.push(0);
253236
}
254-
255-
colorMultipliers.push(1);
256237
}
238+
239+
verticesPosition += verticesLength;
240+
indicesPosition += indicesLength;
257241
}
258-
#end
242+
243+
position.putWeak();
244+
cameraBounds.putWeak();
259245
}
260246

261247
inline function setParameterValue(parameter:ShaderParameter<Bool>, value:Bool):Void

0 commit comments

Comments
 (0)