Skip to content
Draft
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
41 changes: 15 additions & 26 deletions flixel/FlxCamera.hx
Original file line number Diff line number Diff line change
Expand Up @@ -573,20 +573,17 @@ class FlxCamera extends FlxBasic
static var renderRect:FlxRect = FlxRect.get();

@:noCompletion
public function startQuadBatch(graphic:FlxGraphic, colored:Bool, hasColorOffsets:Bool = false, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader)
public function startQuadBatch(graphic:FlxGraphic, colored:Bool, ?blend:BlendMode, smooth:Bool = false, ?shader:FlxShader)
{
#if FLX_RENDER_TRIANGLE
return startTrianglesBatch(graphic, smooth, colored, blend);
#else
var itemToReturn = null;
var blendInt:Int = FlxDrawBaseItem.blendToInt(blend);

if (_currentDrawItem != null
&& _currentDrawItem.type == FlxDrawItemType.TILES
&& _headTiles.graphics == graphic
&& _headTiles.colored == colored
&& _headTiles.hasColorOffsets == hasColorOffsets
&& _headTiles.blending == blendInt
&& _headTiles.blend == blend
&& _headTiles.antialiasing == smooth
&& _headTiles.shader == shader)
Expand All @@ -613,8 +610,6 @@ class FlxCamera extends FlxBasic
itemToReturn.graphics = graphic;
itemToReturn.antialiasing = smooth;
itemToReturn.colored = colored;
itemToReturn.hasColorOffsets = hasColorOffsets;
itemToReturn.blending = blendInt;
itemToReturn.blend = blend;
itemToReturn.shader = shader;

Expand All @@ -638,34 +633,32 @@ class FlxCamera extends FlxBasic
}

@:noCompletion
public function startTrianglesBatch(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem
public function startTrianglesBatch(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?shader:FlxShader,
?repeat:Bool = false):FlxDrawTrianglesItem
{
var blendInt:Int = FlxDrawBaseItem.blendToInt(blend);

if (_currentDrawItem != null
&& _currentDrawItem.type == FlxDrawItemType.TRIANGLES
&& _headTriangles.graphics == graphic
&& _headTriangles.antialiasing == smoothing
&& _headTriangles.colored == isColored
&& _headTriangles.blending == blendInt
&& _headTriangles.blend == blend
&& _headTriangles.repeat == repeat
#if !flash
&& _headTriangles.hasColorOffsets == hasColorOffsets
&& _headTriangles.shader == shader
#end
)
{
return _headTriangles;
}

return getNewDrawTrianglesItem(graphic, smoothing, isColored, blend, hasColorOffsets, shader);
return getNewDrawTrianglesItem(graphic, smoothing, isColored, blend, shader, repeat);
}

@:noCompletion
public function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?hasColorOffsets:Bool, ?shader:FlxShader):FlxDrawTrianglesItem
public function getNewDrawTrianglesItem(graphic:FlxGraphic, smoothing:Bool = false, isColored:Bool = false, ?blend:BlendMode, ?shader:FlxShader,
?repeat:Bool = false):FlxDrawTrianglesItem
{
var itemToReturn:FlxDrawTrianglesItem = null;
var blendInt:Int = FlxDrawBaseItem.blendToInt(blend);

if (_storageTrianglesHead != null)
{
Expand All @@ -682,10 +675,9 @@ class FlxCamera extends FlxBasic
itemToReturn.graphics = graphic;
itemToReturn.antialiasing = smoothing;
itemToReturn.colored = isColored;
itemToReturn.blending = blendInt;
itemToReturn.blend = blend;
itemToReturn.repeat = repeat;
#if !flash
itemToReturn.hasColorOffsets = hasColorOffsets;
itemToReturn.shader = shader;
#end

Expand Down Expand Up @@ -773,13 +765,12 @@ class FlxCamera extends FlxBasic
}
else
{
var isColored = (transform != null #if !html5 && transform.hasRGBMultipliers() #end);
var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets());
var isColored = (transform != null #if !html5 && (transform.hasRGBMultipliers() || transform.hasRGBAOffsets()) #end);

#if FLX_RENDER_TRIANGLE
var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend);
#else
var drawItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader);
var drawItem = startQuadBatch(frame.parent, isColored, blend, smoothing, shader);
#end
drawItem.addQuad(frame, matrix, transform);
}
Expand Down Expand Up @@ -817,11 +808,10 @@ class FlxCamera extends FlxBasic
_helperMatrix.identity();
_helperMatrix.translate(destPoint.x + frame.offset.x, destPoint.y + frame.offset.y);

var isColored = (transform != null && transform.hasRGBMultipliers());
var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets());
var isColored = (transform != null #if !html5 && (transform.hasRGBMultipliers() || transform.hasRGBAOffsets()) #end);

#if !FLX_RENDER_TRIANGLE
var drawItem = startQuadBatch(frame.parent, isColored, hasColorOffsets, blend, smoothing, shader);
var drawItem = startQuadBatch(frame.parent, isColored, blend, smoothing, shader);
#else
var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(frame.parent, smoothing, isColored, blend);
#end
Expand Down Expand Up @@ -910,10 +900,9 @@ class FlxCamera extends FlxBasic
var isColored:Bool = (colors != null && colors.length != 0);

#if !flash
var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets());
isColored = isColored || (transform != null && transform.hasRGBMultipliers());
var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(graphic, smoothing, isColored, blend, hasColorOffsets, shader);
drawItem.addTriangles(vertices, indices, uvtData, colors, position, cameraBounds, transform);
isColored = isColored || (transform != null #if !html5 && (transform.hasRGBMultipliers() || transform.hasRGBAOffsets()) #end);
var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(graphic, smoothing, isColored, blend, shader);
drawItem.addTriangles(vertices, indices, uvtData, colors, position, _bounds, transform);
#else
var drawItem:FlxDrawTrianglesItem = startTrianglesBatch(graphic, smoothing, isColored, blend);
drawItem.addTriangles(vertices, indices, uvtData, colors, position, cameraBounds);
Expand Down
2 changes: 1 addition & 1 deletion flixel/FlxStrip.hx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FlxStrip extends FlxSprite

public var colors:DrawData<Int> = new DrawData<Int>();

public var repeat:Bool = false;
public var repeat:Bool = true;
Copy link
Member

Choose a reason for hiding this comment

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

I don't like change the default value of args, even if it is in a major release there's no good way to broadcast this to devs and they end up having either unknown bugs, or hard to track down bugs in their game.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's why I believe this part would be more fit for a major version change, though for this part in particular its mandatory, as the repeat being set to false by default would result in more broken visual behaviour with the repeat wrap mode actually being added as a setting for tile rendering.


override public function destroy():Void
{
Expand Down
7 changes: 0 additions & 7 deletions flixel/graphics/tile/FlxDrawBaseItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,13 @@ class FlxDrawBaseItem<T>
*/
public static var drawCalls:Int = 0;

public static function blendToInt(blend:BlendMode):Int
{
return 0; // no blend mode support in drawQuads()
}

public var nextTyped:T;

public var next:FlxDrawBaseItem<T>;

public var graphics:FlxGraphic;
public var antialiasing:Bool = false;
public var colored:Bool = false;
public var hasColorOffsets:Bool = false;
public var blending:Int = 0;
public var blend:BlendMode;

public var type:FlxDrawItemType;
Expand Down
40 changes: 20 additions & 20 deletions flixel/graphics/tile/FlxDrawQuadsItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem<FlxDrawQuadsItem>
super.reset();
rects.length = 0;
transforms.length = 0;
alphas.splice(0, alphas.length);
alphas.resize(0);
if (colorMultipliers != null)
colorMultipliers.splice(0, colorMultipliers.length);
colorMultipliers.resize(0);
if (colorOffsets != null)
colorOffsets.splice(0, colorOffsets.length);
colorOffsets.resize(0);
}

override public function dispose():Void
Expand Down Expand Up @@ -71,40 +71,36 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem<FlxDrawQuadsItem>
for (i in 0...VERTICES_PER_QUAD)
alphas.push(alphaMultiplier);

if (colored || hasColorOffsets)
if (colored)
{
if (colorMultipliers == null)
colorMultipliers = [];

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

for (i in 0...VERTICES_PER_QUAD)
if (transform != null)
{
if (transform != null)
for (i in 0...VERTICES_PER_QUAD)
{
colorMultipliers.push(transform.redMultiplier);
colorMultipliers.push(transform.greenMultiplier);
colorMultipliers.push(transform.blueMultiplier);
colorMultipliers.push(1);

colorOffsets.push(transform.redOffset);
colorOffsets.push(transform.greenOffset);
colorOffsets.push(transform.blueOffset);
colorOffsets.push(transform.alphaOffset);
}
else
}
else
{
for (i in 0...(VERTICES_PER_QUAD * 4))
{
colorMultipliers.push(1);
colorMultipliers.push(1);
colorMultipliers.push(1);

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

colorMultipliers.push(1);
}
}
}
Expand All @@ -114,24 +110,28 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem<FlxDrawQuadsItem>
{
if (rects.length == 0)
return;

// TODO: catch this error when the dev actually messes up, not in the draw phase
if (shader == null && graphics.isDestroyed)
throw 'Attempted to render an invalid FlxDrawItem, did you destroy a cached sprite?';

final shader = shader != null ? shader : graphics.shader;
shader.bitmap.input = graphics.bitmap;
shader.bitmap.filter = (camera.antialiasing || antialiasing) ? LINEAR : NEAREST;
shader.alpha.value = alphas;

if (colored || hasColorOffsets)
if (colored)
Comment on lines -127 to +123
Copy link
Member

Choose a reason for hiding this comment

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

I wanna say I tried this before and got unexpected issues in some cases. I'll try and find it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please do let me know if it causes any issues, I've tried in many of my projects and its not causing any problems on my part.

{
shader.colorMultiplier.value = colorMultipliers;
shader.colorOffset.value = colorOffsets;
}
else
{
shader.colorMultiplier.value = null;
shader.colorOffset.value = null;
}

setParameterValue(shader.hasTransform, true);
setParameterValue(shader.hasColorTransform, colored || hasColorOffsets);
setParameterValue(shader.hasColorTransform, colored);

camera.canvas.graphics.overrideBlendMode(blend);
camera.canvas.graphics.beginShaderFill(shader);
Expand Down
54 changes: 26 additions & 28 deletions flixel/graphics/tile/FlxDrawTrianglesItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>

#if !flash
public var shader:FlxShader;

var alphas:Array<Float>;
var colorMultipliers:Array<Float>;
var colorOffsets:Array<Float>;
#end

public var repeat:Bool = false;

public var vertices:DrawData<Float> = new DrawData<Float>();
public var indices:DrawData<Int> = new DrawData<Int>();
public var uvtData:DrawData<Float> = new DrawData<Float>();
Expand Down Expand Up @@ -59,13 +62,13 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
return;

#if !flash
var shader = shader != null ? shader : graphics.shader;
final shader = shader != null ? shader : graphics.shader;
shader.bitmap.input = graphics.bitmap;
shader.bitmap.filter = (camera.antialiasing || antialiasing) ? LINEAR : NEAREST;
shader.bitmap.wrap = REPEAT; // in order to prevent breaking tiling behaviour in classes that use drawTriangles
shader.bitmap.wrap = repeat ? REPEAT : CLAMP;
shader.alpha.value = alphas;

if (colored || hasColorOffsets)
if (colored)
{
shader.colorMultiplier.value = colorMultipliers;
shader.colorOffset.value = colorOffsets;
Expand All @@ -76,14 +79,12 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
shader.colorOffset.value = null;
}

setParameterValue(shader.hasTransform, true);
setParameterValue(shader.hasColorTransform, colored || hasColorOffsets);
setParameterValue(shader.hasColorTransform, colored);

camera.canvas.graphics.overrideBlendMode(blend);

camera.canvas.graphics.beginShaderFill(shader);
#else
camera.canvas.graphics.beginBitmapFill(graphics.bitmap, null, true, (camera.antialiasing || antialiasing));
camera.canvas.graphics.beginBitmapFill(graphics.bitmap, null, repeat, (camera.antialiasing || antialiasing));
#end

camera.canvas.graphics.drawTriangles(vertices, indices, uvtData, TriangleCulling.NONE);
Expand Down Expand Up @@ -113,11 +114,11 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
indicesPosition = 0;
colorsPosition = 0;
#if !flash
alphas.splice(0, alphas.length);
alphas.resize(0);
if (colorMultipliers != null)
colorMultipliers.splice(0, colorMultipliers.length);
colorMultipliers.resize(0);
if (colorOffsets != null)
colorOffsets.splice(0, colorOffsets.length);
colorOffsets.resize(0);
#end
}

Expand Down Expand Up @@ -214,45 +215,42 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
cameraBounds.putWeak();

#if !flash
for (_ in 0...indicesLength)
{
alphas.push(transform != null ? transform.alphaMultiplier : 1.0);
}
var alphaMultiplier = transform != null ? transform.alphaMultiplier : 1.0;
for (i in 0...indicesLength)
alphas.push(alphaMultiplier);

if (colored || hasColorOffsets)
if (colored)
{
if (colorMultipliers == null)
colorMultipliers = [];

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

for (_ in 0...indicesLength)
if (transform != null)
{
if(transform != null)
for (i in 0...indicesLength)
{
colorMultipliers.push(transform.redMultiplier);
colorMultipliers.push(transform.greenMultiplier);
colorMultipliers.push(transform.blueMultiplier);
colorMultipliers.push(1);

colorOffsets.push(transform.redOffset);
colorOffsets.push(transform.greenOffset);
colorOffsets.push(transform.blueOffset);
colorOffsets.push(transform.alphaOffset);
}
else
}
else
{
for (i in 0...indicesLength)
{
colorMultipliers.push(1);
colorMultipliers.push(1);
colorMultipliers.push(1);

colorOffsets.push(0);
colorOffsets.push(0);
colorOffsets.push(0);
colorOffsets.push(0);
for (_ in 0...4)
colorMultipliers.push(1);
for (_ in 0...4)
colorOffsets.push(0);
}

colorMultipliers.push(1);
}
}
#end
Expand Down
Loading