From 0111f824b1111ed6e3b3cd59d862fd4742099fbe Mon Sep 17 00:00:00 2001 From: Joe Williamson Date: Tue, 4 Dec 2018 11:01:09 +0000 Subject: [PATCH 1/5] In FlxDrawQuadsItem if there are colorOffsets, we must also pass the shader valid colorMultipliers --- flixel/graphics/tile/FlxDrawQuadsItem.hx | 37 +++++++++--------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/flixel/graphics/tile/FlxDrawQuadsItem.hx b/flixel/graphics/tile/FlxDrawQuadsItem.hx index 7131b248ce..6b275366ff 100644 --- a/flixel/graphics/tile/FlxDrawQuadsItem.hx +++ b/flixel/graphics/tile/FlxDrawQuadsItem.hx @@ -71,10 +71,13 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem for (i in 0...VERTICES_PER_QUAD) alphas.push(transform != null ? transform.alphaMultiplier : 1.0); - if (colored) + if (colored || hasColorOffsets) { if (colorMultipliers == null) colorMultipliers = []; + + if (colorOffsets == null) + colorOffsets = []; for (i in 0...VERTICES_PER_QUAD) { @@ -83,27 +86,7 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem colorMultipliers.push(transform.redMultiplier); colorMultipliers.push(transform.greenMultiplier); colorMultipliers.push(transform.blueMultiplier); - } - else - { - colorMultipliers.push(1); - colorMultipliers.push(1); - colorMultipliers.push(1); - } - - colorMultipliers.push(1); - } - } - - if (hasColorOffsets) - { - if (colorOffsets == null) - colorOffsets = []; - - for (i in 0...VERTICES_PER_QUAD) - { - if (transform != null) - { + colorOffsets.push(transform.redOffset); colorOffsets.push(transform.greenOffset); colorOffsets.push(transform.blueOffset); @@ -111,11 +94,17 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem } 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); } } } @@ -131,10 +120,10 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem shader.bitmap.filter = (camera.antialiasing || antialiasing) ? LINEAR : NEAREST; shader.alpha.value = alphas; - if (colored) + if (colored || hasColorOffsets) { shader.colorMultiplier.value = colorMultipliers; - if (hasColorOffsets) shader.colorOffset.value = colorOffsets; + } setParameterValue(shader.hasTransform, true); setParameterValue(shader.hasColorTransform, colored || hasColorOffsets); From a54347512fef589a635050c8e9f343a79e8db875 Mon Sep 17 00:00:00 2001 From: Joe Williamson Date: Wed, 5 Dec 2018 03:24:37 +0000 Subject: [PATCH 2/5] Add support for drawQuads blend modes --- flixel/FlxCamera.hx | 1 + flixel/graphics/tile/FlxDrawBaseItem.hx | 1 + flixel/graphics/tile/FlxDrawQuadsItem.hx | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index d5dc54fec5..3293a7b736 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -493,6 +493,7 @@ class FlxCamera extends FlxBasic itemToReturn.colored = colored; itemToReturn.hasColorOffsets = hasColorOffsets; itemToReturn.blending = blendInt; + itemToReturn.blend = blend; itemToReturn.shader = shader; itemToReturn.nextTyped = _headTiles; diff --git a/flixel/graphics/tile/FlxDrawBaseItem.hx b/flixel/graphics/tile/FlxDrawBaseItem.hx index b76123b171..c43b6b2a4c 100644 --- a/flixel/graphics/tile/FlxDrawBaseItem.hx +++ b/flixel/graphics/tile/FlxDrawBaseItem.hx @@ -70,6 +70,7 @@ class FlxDrawBaseItem public var colored:Bool = false; public var hasColorOffsets:Bool = false; public var blending:Int = 0; + public var blend:BlendMode; public var type:FlxDrawItemType; diff --git a/flixel/graphics/tile/FlxDrawQuadsItem.hx b/flixel/graphics/tile/FlxDrawQuadsItem.hx index 6a25dc1fec..facb4dcfe5 100644 --- a/flixel/graphics/tile/FlxDrawQuadsItem.hx +++ b/flixel/graphics/tile/FlxDrawQuadsItem.hx @@ -9,6 +9,8 @@ import flixel.math.FlxMatrix; import openfl.geom.ColorTransform; import openfl.display.ShaderParameter; import openfl.Vector; +import openfl.display.DisplayObject; +import openfl.display.BlendMode; class FlxDrawQuadsItem extends FlxDrawBaseItem { @@ -128,7 +130,8 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem setParameterValue(shader.hasTransform, true); setParameterValue(shader.hasColorTransform, colored || hasColorOffsets); - + + camera.canvas.graphics.beginBlend(blend); camera.canvas.graphics.beginShaderFill(shader); camera.canvas.graphics.drawQuads(rects, null, transforms); super.render(camera); From 9af59f8a8a038640bd0fc80123598a1ed4d7f34c Mon Sep 17 00:00:00 2001 From: Joe Williamson Date: Fri, 7 Dec 2018 11:42:01 +0000 Subject: [PATCH 3/5] Use renamed drawQuads overrideBlendMode command --- flixel/graphics/tile/FlxDrawQuadsItem.hx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/flixel/graphics/tile/FlxDrawQuadsItem.hx b/flixel/graphics/tile/FlxDrawQuadsItem.hx index facb4dcfe5..e4e47ff506 100644 --- a/flixel/graphics/tile/FlxDrawQuadsItem.hx +++ b/flixel/graphics/tile/FlxDrawQuadsItem.hx @@ -9,8 +9,6 @@ import flixel.math.FlxMatrix; import openfl.geom.ColorTransform; import openfl.display.ShaderParameter; import openfl.Vector; -import openfl.display.DisplayObject; -import openfl.display.BlendMode; class FlxDrawQuadsItem extends FlxDrawBaseItem { @@ -131,7 +129,7 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem setParameterValue(shader.hasTransform, true); setParameterValue(shader.hasColorTransform, colored || hasColorOffsets); - camera.canvas.graphics.beginBlend(blend); + camera.canvas.graphics.overrideBlendMode(blend); camera.canvas.graphics.beginShaderFill(shader); camera.canvas.graphics.drawQuads(rects, null, transforms); super.render(camera); From 1adabb94a2db9d0ce6df3aa716ee86421525c3ed Mon Sep 17 00:00:00 2001 From: Joe Williamson Date: Fri, 7 Dec 2018 12:04:00 +0000 Subject: [PATCH 4/5] Check openfl version before tryng to override blend mode --- flixel/graphics/tile/FlxDrawQuadsItem.hx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flixel/graphics/tile/FlxDrawQuadsItem.hx b/flixel/graphics/tile/FlxDrawQuadsItem.hx index e4e47ff506..90a144631b 100644 --- a/flixel/graphics/tile/FlxDrawQuadsItem.hx +++ b/flixel/graphics/tile/FlxDrawQuadsItem.hx @@ -129,7 +129,9 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem setParameterValue(shader.hasTransform, true); setParameterValue(shader.hasColorTransform, colored || hasColorOffsets); + #if (openfl > "8.7.0") camera.canvas.graphics.overrideBlendMode(blend); + #end camera.canvas.graphics.beginShaderFill(shader); camera.canvas.graphics.drawQuads(rects, null, transforms); super.render(camera); From ac3713dba60749b9431356e91a84f2e1ca30c4e5 Mon Sep 17 00:00:00 2001 From: Joe Williamson Date: Fri, 7 Dec 2018 14:45:45 +0000 Subject: [PATCH 5/5] Check blend changed before starting a new FlxDrawQuadsItem --- flixel/FlxCamera.hx | 1 + 1 file changed, 1 insertion(+) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 3293a7b736..bebd718b64 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -470,6 +470,7 @@ class FlxCamera extends FlxBasic && _headTiles.colored == colored && _headTiles.hasColorOffsets == hasColorOffsets && _headTiles.blending == blendInt + && _headTiles.blend == blend && _headTiles.antialiasing == smooth && _headTiles.shader == shader) {