Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions flixel/FlxCamera.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import openfl.geom.Rectangle;
import flixel.graphics.FlxGraphic;
import flixel.graphics.frames.FlxFrame;
import flixel.graphics.tile.FlxDrawBaseItem;
import flixel.graphics.tile.FlxDrawQuadsItem;
import flixel.graphics.tile.FlxDrawTrianglesItem;
import flixel.math.FlxMath;
import flixel.math.FlxMatrix;
Expand All @@ -27,8 +28,6 @@ import openfl.filters.BitmapFilter;

using flixel.util.FlxColorTransformUtil;

private typedef FlxDrawItem = flixel.graphics.tile.FlxDrawQuadsItem;

/**
* The camera class is used to display the game's visuals.
* By default one camera is created automatically, that is the same size as window.
Expand Down Expand Up @@ -537,7 +536,7 @@ class FlxCamera extends FlxBasic
/**
* Last draw tiles item
*/
var _headTiles:FlxDrawItem;
var _headTiles:FlxDrawQuadsItem;

/**
* Last draw triangles item
Expand All @@ -547,7 +546,7 @@ class FlxCamera extends FlxBasic
/**
* Draw tiles stack items that can be reused
*/
static var _storageTilesHead:FlxDrawItem;
static var _storageTilesHead:FlxDrawQuadsItem;

/**
* Draw triangles stack items that can be reused
Expand Down Expand Up @@ -601,7 +600,7 @@ class FlxCamera extends FlxBasic
}
else
{
itemToReturn = new FlxDrawItem();
itemToReturn = new FlxDrawQuadsItem();
}

// TODO: catch this error when the dev actually messes up, not in the draw phase
Expand Down Expand Up @@ -765,9 +764,9 @@ class FlxCamera extends FlxBasic
var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets());

#if FLX_RENDER_TRIANGLE
var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend);
final drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader);
#else
var drawItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader);
final drawItem:FlxDrawQuadsItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader);
#end
drawItem.addQuad(frame, matrix, transform);
}
Expand Down Expand Up @@ -808,10 +807,10 @@ class FlxCamera extends FlxBasic
var isColored = (transform != null && transform.hasRGBMultipliers());
var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets());

#if !FLX_RENDER_TRIANGLE
var drawItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader);
#if FLX_RENDER_TRIANGLE
final drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend, hasColorOffsets, shader);
#else
var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend);
final drawItem:FlxDrawQuadsItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader);
#end
drawItem.addQuad(frame, _helperMatrix, transform);
}
Expand Down
147 changes: 65 additions & 82 deletions flixel/graphics/tile/FlxDrawTrianglesItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typedef DrawData<T> = openfl.Vector<T>;
*/
class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
{
static inline final INDICES_PER_QUAD = 6;
static var point:FlxPoint = FlxPoint.get();
static var rect:FlxRect = FlxRect.get();

Expand All @@ -31,10 +32,12 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
public var vertices:DrawData<Float> = new DrawData<Float>();
public var indices:DrawData<Int> = new DrawData<Int>();
public var uvtData:DrawData<Float> = new DrawData<Float>();
@:deprecated("colors is deprecated, use colorMultipliers and colorOffsets")
public var colors:DrawData<Int> = new DrawData<Int>();

public var verticesPosition:Int = 0;
public var indicesPosition:Int = 0;
@:deprecated("colorsPosition is deprecated")
public var colorsPosition:Int = 0;

var bounds:FlxRect = FlxRect.get();
Expand Down Expand Up @@ -100,11 +103,9 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
vertices.length = 0;
indices.length = 0;
uvtData.length = 0;
colors.length = 0;

verticesPosition = 0;
indicesPosition = 0;
colorsPosition = 0;
alphas.splice(0, alphas.length);
if (colorMultipliers != null)
colorMultipliers.splice(0, colorMultipliers.length);
Expand All @@ -119,7 +120,6 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
vertices = null;
indices = null;
uvtData = null;
colors = null;
bounds = null;
alphas = null;
colorMultipliers = null;
Expand All @@ -140,7 +140,6 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
var numberOfVertices:Int = Std.int(verticesLength / 2);
var prevIndicesLength:Int = this.indices.length;
var prevUVTDataLength:Int = this.uvtData.length;
var prevColorsLength:Int = this.colors.length;
var prevNumberOfVertices:Int = this.numVertices;

var tempX:Float, tempY:Float;
Expand Down Expand Up @@ -184,16 +183,6 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
{
this.indices[prevIndicesLength + i] = indices[i] + prevNumberOfVertices;
}

if (colored)
{
for (i in 0...numberOfVertices)
{
this.colors[prevColorsLength + i] = colors[i];
}

colorsPosition += numberOfVertices;
}

final alphaMultiplier = transform != null ? transform.alphaMultiplier : 1.0;
for (_ in 0...indicesLength)
Expand Down Expand Up @@ -280,82 +269,76 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>

override public function addQuad(frame:FlxFrame, matrix:FlxMatrix, ?transform:ColorTransform):Void
{
var prevVerticesPos:Int = verticesPosition;
var prevIndicesPos:Int = indicesPosition;
var prevColorsPos:Int = colorsPosition;
var prevNumberOfVertices:Int = numVertices;

var point = FlxPoint.get();
point.transform(matrix);

vertices[prevVerticesPos] = point.x;
vertices[prevVerticesPos + 1] = point.y;

uvtData[prevVerticesPos] = frame.uv.left;
final prevVerticesPos = verticesPosition;
final prevNumberOfVertices = numVertices;

final w = frame.frame.width;
final h = frame.frame.height;
vertices[prevVerticesPos + 0] = matrix.transformX(0, 0); // left
vertices[prevVerticesPos + 1] = matrix.transformY(0, 0); // top
vertices[prevVerticesPos + 2] = matrix.transformX(w, 0); // right
vertices[prevVerticesPos + 3] = matrix.transformY(w, 0); // top
vertices[prevVerticesPos + 4] = matrix.transformX(0, h); // left
vertices[prevVerticesPos + 5] = matrix.transformY(0, h); // bottom
vertices[prevVerticesPos + 6] = matrix.transformX(w, h); // right
vertices[prevVerticesPos + 7] = matrix.transformY(w, h); // bottom

uvtData[prevVerticesPos + 0] = frame.uv.left;
uvtData[prevVerticesPos + 1] = frame.uv.top;

point.set(frame.frame.width, 0);
point.transform(matrix);

vertices[prevVerticesPos + 2] = point.x;
vertices[prevVerticesPos + 3] = point.y;

uvtData[prevVerticesPos + 2] = frame.uv.right;
uvtData[prevVerticesPos + 3] = frame.uv.top;

point.set(frame.frame.width, frame.frame.height);
point.transform(matrix);

vertices[prevVerticesPos + 4] = point.x;
vertices[prevVerticesPos + 5] = point.y;

uvtData[prevVerticesPos + 4] = frame.uv.right;
uvtData[prevVerticesPos + 4] = frame.uv.left;
uvtData[prevVerticesPos + 5] = frame.uv.bottom;

point.set(0, frame.frame.height);
point.transform(matrix);

vertices[prevVerticesPos + 6] = point.x;
vertices[prevVerticesPos + 7] = point.y;

point.put();

uvtData[prevVerticesPos + 6] = frame.uv.left;
uvtData[prevVerticesPos + 6] = frame.uv.right;
uvtData[prevVerticesPos + 7] = frame.uv.bottom;

indices[prevIndicesPos] = prevNumberOfVertices;
indices[prevIndicesPos + 1] = prevNumberOfVertices + 1;
indices[prevIndicesPos + 2] = prevNumberOfVertices + 2;
indices[prevIndicesPos + 3] = prevNumberOfVertices + 2;
indices[prevIndicesPos + 4] = prevNumberOfVertices + 3;
indices[prevIndicesPos + 5] = prevNumberOfVertices;

if (colored)

final prevIndicesPos = indicesPosition;
indices[prevIndicesPos + 0] = prevNumberOfVertices + 0; // TL
indices[prevIndicesPos + 1] = prevNumberOfVertices + 1; // TR
indices[prevIndicesPos + 2] = prevNumberOfVertices + 2; // BL
indices[prevIndicesPos + 3] = prevNumberOfVertices + 1; // TR
indices[prevIndicesPos + 4] = prevNumberOfVertices + 2; // BL
indices[prevIndicesPos + 5] = prevNumberOfVertices + 3; // BR

final alphaMultiplier = transform != null ? transform.alphaMultiplier : 1.0;
for (i in 0...INDICES_PER_QUAD)
alphas.push(alphaMultiplier);

if (colored || hasColorOffsets)
{
var red = 1.0;
var green = 1.0;
var blue = 1.0;
var alpha = 1.0;

if (transform != null)
if (colorMultipliers == null)
colorMultipliers = [];

if (colorOffsets == null)
colorOffsets = [];

for (i in 0...INDICES_PER_QUAD)
{
red = transform.redMultiplier;
green = transform.greenMultiplier;
blue = transform.blueMultiplier;

#if !neko
alpha = transform.alphaMultiplier;
#end
if (transform != null)
{
colorMultipliers.push(transform.redMultiplier);
colorMultipliers.push(transform.greenMultiplier);
colorMultipliers.push(transform.blueMultiplier);

colorOffsets.push(transform.redOffset);
colorOffsets.push(transform.greenOffset);
colorOffsets.push(transform.blueOffset);
colorOffsets.push(transform.alphaOffset);
}
else
{
colorMultipliers.push(1);
colorMultipliers.push(1);
colorMultipliers.push(1);

colorOffsets.push(0);
colorOffsets.push(0);
colorOffsets.push(0);
colorOffsets.push(0);
}

colorMultipliers.push(1);
}

var color = FlxColor.fromRGBFloat(red, green, blue, alpha);

colors[prevColorsPos] = color;
colors[prevColorsPos + 1] = color;
colors[prevColorsPos + 2] = color;
colors[prevColorsPos + 3] = color;
Comment on lines -353 to -356
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we deprecate colors?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice colors is still used in addTriangles should that be changed as well? why does that seem to work but not this?

Copy link
Contributor Author

@richTrash21 richTrash21 Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we deprecate colors?

Yes, but only in triangle draw item. I think colors as a feature is really nice and should stay, but with different implementation. This would also fix #2263.

I notice colors is still used in addTriangles should that be changed as well? why does that seem to work but not this?

FYI, this is explained this in the description. This was also originally adressed in #3472, where colors were multiplied to transform. I was planning to make this as a sepparate pr, but it might be better to add this change here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think colors as a feature is really nice and should stay, but with different implementation.

Care to make an issue detailing the ideal implementation of colors?


colorsPosition += 4;
}

verticesPosition += 8;
Expand Down