From 63a042d0e392ab9f7ee5d09b44b538dacb899da1 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Mon, 5 Dec 2022 03:30:27 +0000 Subject: [PATCH] dun_render: Simplify non-masked primitives As we recently confirmed, Square and Left/RightTriangle primitives never use masks other than Transparent and Solid. Simplify the code to take advantage of that. --- Source/engine/render/dun_render.cpp | 216 ++++++++++++---------------- 1 file changed, 88 insertions(+), 128 deletions(-) diff --git a/Source/engine/render/dun_render.cpp b/Source/engine/render/dun_render.cpp index 19a5f5b70..f7235f33f 100644 --- a/Source/engine/render/dun_render.cpp +++ b/Source/engine/render/dun_render.cpp @@ -260,14 +260,6 @@ DVL_ALWAYS_INLINE Clip CalculateClip(int_fast16_t x, int_fast16_t y, int_fast16_ return clip; } -template -DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderSquareLowerHalf(uint8_t *DVL_RESTRICT &dst, int dstPitch, const uint8_t *DVL_RESTRICT &src, const uint8_t *DVL_RESTRICT tbl) { - for (auto i = 0; i < LowerHeight; ++i, dst -= dstPitch) { - RenderLineTransparentOrOpaque(dst, src, Width, tbl); - src += Width; - } -} - template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderSquareUpperHalf(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl) { uint_fast8_t prefixWidth = PrefixIncrement < 0 ? 32 : 0; @@ -279,40 +271,32 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderSquareUpperHalf(uint8_t *DVL_REST } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderSquareFull(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl) { - if (PrefixIncrement == 0) { - // Fast path for MaskType::Solid and MaskType::Transparent - for (auto i = 0; i < Height; ++i, dst -= dstPitch) { - RenderLineTransparentOrOpaque(dst, src, Width, tbl); - src += Width; - } - } else { - RenderSquareLowerHalf>(dst, dstPitch, src, tbl); - RenderSquareUpperHalf(dst, dstPitch, src, tbl); + for (auto i = 0; i < Height; ++i, dst -= dstPitch) { + RenderLineTransparentOrOpaque(dst, src, Width, tbl); + src += Width; } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderSquareClipped(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { - int8_t prefix = InitPrefix(clip.bottom); src += clip.bottom * Height + clip.left; for (auto i = 0; i < clip.height; ++i, dst -= dstPitch) { - RenderLine(dst, src, clip.width, tbl, prefix - (clip.left)); + RenderLineTransparentOrOpaque(dst, src, clip.width, tbl); src += Width; - prefix += PrefixIncrement; } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderSquare(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { if (clip.width == Width && clip.height == Height) { - RenderSquareFull(dst, dstPitch, src, tbl); + RenderSquareFull(dst, dstPitch, src, tbl); } else { - RenderSquareClipped(dst, dstPitch, src, tbl, clip); + RenderSquareClipped(dst, dstPitch, src, tbl, clip); } } @@ -419,7 +403,7 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderTransparentSquareClipped(uint8_t } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderTransparentSquare(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { if (clip.width == Width && clip.height == Height) { @@ -479,8 +463,8 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleLower(uint8_t *DVL_RE } } -template -DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleLowerClipVertical(int8_t &prefix, const DiamondClipY &clipY, uint8_t *DVL_RESTRICT &dst, int dstPitch, const uint8_t *DVL_RESTRICT &src, const uint8_t *DVL_RESTRICT tbl) +template +DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleLowerClipVertical(const DiamondClipY &clipY, uint8_t *DVL_RESTRICT &dst, int dstPitch, const uint8_t *DVL_RESTRICT &src, const uint8_t *DVL_RESTRICT tbl) { src += CalculateTriangleSourceSkipLowerBottom(clipY.lowerBottom); dst += XStep * (LowerHeight - clipY.lowerBottom - 1); @@ -488,14 +472,13 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleLowerClipVertical(int for (auto i = 1 + clipY.lowerBottom; i <= lowerMax; ++i, dst -= dstPitch + XStep) { src += 2 * (i % 2); const auto width = XStep * i; - RenderLine(dst, src, width, tbl, prefix); + RenderLineTransparentOrOpaque(dst, src, width, tbl); src += width; - prefix += PrefixIncrement; } } -template -DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleLowerClipLeftAndVertical(int_fast16_t clipLeft, int8_t &prefix, const DiamondClipY &clipY, uint8_t *DVL_RESTRICT &dst, int dstPitch, const uint8_t *DVL_RESTRICT &src, const uint8_t *DVL_RESTRICT tbl) +template +DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleLowerClipLeftAndVertical(int_fast16_t clipLeft, const DiamondClipY &clipY, uint8_t *DVL_RESTRICT &dst, int dstPitch, const uint8_t *DVL_RESTRICT &src, const uint8_t *DVL_RESTRICT tbl) { src += CalculateTriangleSourceSkipLowerBottom(clipY.lowerBottom); dst += XStep * (LowerHeight - clipY.lowerBottom - 1) - clipLeft; @@ -506,14 +489,13 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleLowerClipLeftAndVerti const auto startX = Width - XStep * i; const auto skip = startX < clipLeft ? clipLeft - startX : 0; if (width > skip) - RenderLine(dst + skip, src + skip, width - skip, tbl, prefix - (skip)); + RenderLineTransparentOrOpaque(dst + skip, src + skip, width - skip, tbl); src += width; - prefix += PrefixIncrement; } } -template -DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleLowerClipRightAndVertical(int_fast16_t clipRight, int8_t &prefix, const DiamondClipY &clipY, uint8_t *DVL_RESTRICT &dst, int dstPitch, const uint8_t *DVL_RESTRICT &src, const uint8_t *DVL_RESTRICT tbl) +template +DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleLowerClipRightAndVertical(int_fast16_t clipRight, const DiamondClipY &clipY, uint8_t *DVL_RESTRICT &dst, int dstPitch, const uint8_t *DVL_RESTRICT &src, const uint8_t *DVL_RESTRICT tbl) { src += CalculateTriangleSourceSkipLowerBottom(clipY.lowerBottom); dst += XStep * (LowerHeight - clipY.lowerBottom - 1); @@ -522,52 +504,46 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleLowerClipRightAndVert src += 2 * (i % 2); const auto width = XStep * i; if (width > clipRight) - RenderLine(dst, src, width - clipRight, tbl, prefix); + RenderLineTransparentOrOpaque(dst, src, width - clipRight, tbl); src += width; - prefix += PrefixIncrement; } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleFull(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl) { - RenderLeftTriangleLower>(dst, dstPitch, src, tbl); - int8_t prefix = InitPrefix(LowerHeight); + RenderLeftTriangleLower(dst, dstPitch, src, tbl); dst += 2 * XStep; for (auto i = 1; i <= TriangleUpperHeight; ++i, dst -= dstPitch - XStep) { src += 2 * (i % 2); const auto width = Width - XStep * i; - RenderLine(dst, src, width, tbl, prefix); + RenderLineTransparentOrOpaque(dst, src, width, tbl); src += width; - prefix += PrefixIncrement; } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleClipVertical(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { - int8_t prefix = InitPrefix(clip.bottom); const DiamondClipY clipY = CalculateDiamondClipY(clip); - RenderLeftTriangleLowerClipVertical(prefix, clipY, dst, dstPitch, src, tbl); + RenderLeftTriangleLowerClipVertical(clipY, dst, dstPitch, src, tbl); src += CalculateTriangleSourceSkipUpperBottom(clipY.upperBottom); dst += 2 * XStep + XStep * clipY.upperBottom; const auto upperMax = TriangleUpperHeight - clipY.upperTop; for (auto i = 1 + clipY.upperBottom; i <= upperMax; ++i, dst -= dstPitch - XStep) { src += 2 * (i % 2); const auto width = Width - XStep * i; - RenderLine(dst, src, width, tbl, prefix); + RenderLineTransparentOrOpaque(dst, src, width, tbl); src += width; - prefix += PrefixIncrement; } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleClipLeftAndVertical(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { - int8_t prefix = InitPrefix(clip.bottom); const DiamondClipY clipY = CalculateDiamondClipY(clip); const int_fast16_t clipLeft = clip.left; - RenderLeftTriangleLowerClipLeftAndVertical(clipLeft, prefix, clipY, dst, dstPitch, src, tbl); + RenderLeftTriangleLowerClipLeftAndVertical(clipLeft, clipY, dst, dstPitch, src, tbl); src += CalculateTriangleSourceSkipUpperBottom(clipY.upperBottom); dst += 2 * XStep + XStep * clipY.upperBottom; const auto upperMax = TriangleUpperHeight - clipY.upperTop; @@ -576,20 +552,17 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleClipLeftAndVertical(u const auto width = Width - XStep * i; const auto startX = XStep * i; const auto skip = startX < clipLeft ? clipLeft - startX : 0; - if (width > skip) - RenderLine(dst + skip, src + skip, width - skip, tbl, prefix - (skip)); + RenderLineTransparentOrOpaque(dst + skip, src + skip, width > skip ? width - skip : 0, tbl); src += width; - prefix += PrefixIncrement; } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleClipRightAndVertical(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { - int8_t prefix = InitPrefix(clip.bottom); const DiamondClipY clipY = CalculateDiamondClipY(clip); const int_fast16_t clipRight = clip.right; - RenderLeftTriangleLowerClipRightAndVertical(clipRight, prefix, clipY, dst, dstPitch, src, tbl); + RenderLeftTriangleLowerClipRightAndVertical(clipRight, clipY, dst, dstPitch, src, tbl); src += CalculateTriangleSourceSkipUpperBottom(clipY.upperBottom); dst += 2 * XStep + XStep * clipY.upperBottom; const auto upperMax = TriangleUpperHeight - clipY.upperTop; @@ -598,25 +571,24 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangleClipRightAndVertical( const auto width = Width - XStep * i; if (width <= clipRight) break; - RenderLine(dst, src, width - clipRight, tbl, prefix); + RenderLineTransparentOrOpaque(dst, src, width - clipRight, tbl); src += width; - prefix += PrefixIncrement; } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTriangle(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { if (clip.width == Width) { if (clip.height == TriangleHeight) { - RenderLeftTriangleFull(dst, dstPitch, src, tbl); + RenderLeftTriangleFull(dst, dstPitch, src, tbl); } else { - RenderLeftTriangleClipVertical(dst, dstPitch, src, tbl, clip); + RenderLeftTriangleClipVertical(dst, dstPitch, src, tbl, clip); } } else if (clip.right == 0) { - RenderLeftTriangleClipLeftAndVertical(dst, dstPitch, src, tbl, clip); + RenderLeftTriangleClipLeftAndVertical(dst, dstPitch, src, tbl, clip); } else { - RenderLeftTriangleClipRightAndVertical(dst, dstPitch, src, tbl, clip); + RenderLeftTriangleClipRightAndVertical(dst, dstPitch, src, tbl, clip); } } @@ -630,35 +602,33 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTriangleLower(uint8_t *DVL_R } } -template -DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTriangleLowerClipVertical(int8_t &prefix, const DiamondClipY &clipY, uint8_t *DVL_RESTRICT &dst, int dstPitch, const uint8_t *DVL_RESTRICT &src, const uint8_t *DVL_RESTRICT tbl) +template +DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTriangleLowerClipVertical(const DiamondClipY &clipY, uint8_t *DVL_RESTRICT &dst, int dstPitch, const uint8_t *DVL_RESTRICT &src, const uint8_t *DVL_RESTRICT tbl) { src += CalculateTriangleSourceSkipLowerBottom(clipY.lowerBottom); const auto lowerMax = LowerHeight - clipY.lowerTop; for (auto i = 1 + clipY.lowerBottom; i <= lowerMax; ++i, dst -= dstPitch) { const auto width = XStep * i; - RenderLine(dst, src, width, tbl, prefix); + RenderLineTransparentOrOpaque(dst, src, width, tbl); src += width + 2 * (i % 2); - prefix += PrefixIncrement; } } -template -DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTriangleLowerClipLeftAndVertical(int_fast16_t clipLeft, int8_t &prefix, const DiamondClipY &clipY, uint8_t *DVL_RESTRICT &dst, int dstPitch, const uint8_t *DVL_RESTRICT &src, const uint8_t *DVL_RESTRICT tbl) +template +DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTriangleLowerClipLeftAndVertical(int_fast16_t clipLeft, const DiamondClipY &clipY, uint8_t *DVL_RESTRICT &dst, int dstPitch, const uint8_t *DVL_RESTRICT &src, const uint8_t *DVL_RESTRICT tbl) { src += CalculateTriangleSourceSkipLowerBottom(clipY.lowerBottom); const auto lowerMax = LowerHeight - clipY.lowerTop; for (auto i = 1 + clipY.lowerBottom; i <= lowerMax; ++i, dst -= dstPitch) { const auto width = XStep * i; if (width > clipLeft) - RenderLine(dst, src + clipLeft, width - clipLeft, tbl, prefix - clipLeft); + RenderLineTransparentOrOpaque(dst, src + clipLeft, width - clipLeft, tbl); src += width + 2 * (i % 2); - prefix += PrefixIncrement; } } -template -DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTriangleLowerClipRightAndVertical(int_fast16_t clipRight, int8_t &prefix, const DiamondClipY &clipY, uint8_t *DVL_RESTRICT &dst, int dstPitch, const uint8_t *DVL_RESTRICT &src, const uint8_t *DVL_RESTRICT tbl) +template +DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTriangleLowerClipRightAndVertical(int_fast16_t clipRight, const DiamondClipY &clipY, uint8_t *DVL_RESTRICT &dst, int dstPitch, const uint8_t *DVL_RESTRICT &src, const uint8_t *DVL_RESTRICT tbl) { src += CalculateTriangleSourceSkipLowerBottom(clipY.lowerBottom); const auto lowerMax = LowerHeight - clipY.lowerTop; @@ -666,92 +636,82 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTriangleLowerClipRightAndVer const auto width = XStep * i; const auto skip = Width - width < clipRight ? clipRight - (Width - width) : 0; if (width > skip) - RenderLine(dst, src, width - skip, tbl, prefix); + RenderLineTransparentOrOpaque(dst, src, width - skip, tbl); src += width + 2 * (i % 2); - prefix += PrefixIncrement; } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTriangleFull(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl) { - RenderRightTriangleLower>(dst, dstPitch, src, tbl); - int8_t prefix = InitPrefix(LowerHeight); + RenderRightTriangleLower(dst, dstPitch, src, tbl); for (auto i = 1; i <= TriangleUpperHeight; ++i, dst -= dstPitch) { const auto width = Width - XStep * i; - RenderLine(dst, src, width, tbl, prefix); + RenderLineTransparentOrOpaque(dst, src, width, tbl); src += width + 2 * (i % 2); - prefix += PrefixIncrement; } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTriangleClipVertical(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { - int8_t prefix = InitPrefix(clip.bottom); const DiamondClipY clipY = CalculateDiamondClipY(clip); - RenderRightTriangleLowerClipVertical(prefix, clipY, dst, dstPitch, src, tbl); + RenderRightTriangleLowerClipVertical(clipY, dst, dstPitch, src, tbl); src += CalculateTriangleSourceSkipUpperBottom(clipY.upperBottom); const auto upperMax = TriangleUpperHeight - clipY.upperTop; for (auto i = 1 + clipY.upperBottom; i <= upperMax; ++i, dst -= dstPitch) { const auto width = Width - XStep * i; - RenderLine(dst, src, width, tbl, prefix); + RenderLineTransparentOrOpaque(dst, src, width, tbl); src += width + 2 * (i % 2); - prefix += PrefixIncrement; } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTriangleClipLeftAndVertical(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { - int8_t prefix = InitPrefix(clip.bottom); const DiamondClipY clipY = CalculateDiamondClipY(clip); const int_fast16_t clipLeft = clip.left; - RenderRightTriangleLowerClipLeftAndVertical(clipLeft, prefix, clipY, dst, dstPitch, src, tbl); + RenderRightTriangleLowerClipLeftAndVertical(clipLeft, clipY, dst, dstPitch, src, tbl); src += CalculateTriangleSourceSkipUpperBottom(clipY.upperBottom); const auto upperMax = TriangleUpperHeight - clipY.upperTop; for (auto i = 1 + clipY.upperBottom; i <= upperMax; ++i, dst -= dstPitch) { const auto width = Width - XStep * i; if (width <= clipLeft) break; - RenderLine(dst, src + clipLeft, width - clipLeft, tbl, prefix - clipLeft); + RenderLineTransparentOrOpaque(dst, src + clipLeft, width - clipLeft, tbl); src += width + 2 * (i % 2); - prefix += PrefixIncrement; } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTriangleClipRightAndVertical(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { - int8_t prefix = InitPrefix(clip.bottom); const DiamondClipY clipY = CalculateDiamondClipY(clip); const int_fast16_t clipRight = clip.right; - RenderRightTriangleLowerClipRightAndVertical(clipRight, prefix, clipY, dst, dstPitch, src, tbl); + RenderRightTriangleLowerClipRightAndVertical(clipRight, clipY, dst, dstPitch, src, tbl); src += CalculateTriangleSourceSkipUpperBottom(clipY.upperBottom); const auto upperMax = TriangleUpperHeight - clipY.upperTop; for (auto i = 1 + clipY.upperBottom; i <= upperMax; ++i, dst -= dstPitch) { const auto width = Width - XStep * i; const auto skip = Width - width < clipRight ? clipRight - (Width - width) : 0; - if (width > skip) - RenderLine(dst, src, width - skip, tbl, prefix); + RenderLineTransparentOrOpaque(dst, src, width > skip ? width - skip : 0, tbl); src += width + 2 * (i % 2); - prefix += PrefixIncrement; } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTriangle(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { if (clip.width == Width) { if (clip.height == TriangleHeight) { - RenderRightTriangleFull(dst, dstPitch, src, tbl); + RenderRightTriangleFull(dst, dstPitch, src, tbl); } else { - RenderRightTriangleClipVertical(dst, dstPitch, src, tbl, clip); + RenderRightTriangleClipVertical(dst, dstPitch, src, tbl, clip); } } else if (clip.right == 0) { - RenderRightTriangleClipLeftAndVertical(dst, dstPitch, src, tbl, clip); + RenderRightTriangleClipLeftAndVertical(dst, dstPitch, src, tbl, clip); } else { - RenderRightTriangleClipRightAndVertical(dst, dstPitch, src, tbl, clip); + RenderRightTriangleClipRightAndVertical(dst, dstPitch, src, tbl, clip); } } @@ -766,12 +726,12 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTrapezoidFull(uint8_t *DVL_RE template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTrapezoidClipVertical(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { - int8_t prefix = InitPrefix(clip.bottom); const DiamondClipY clipY = CalculateDiamondClipY(clip); - RenderLeftTriangleLowerClipVertical(prefix, clipY, dst, dstPitch, src, tbl); + RenderLeftTriangleLowerClipVertical>(clipY, dst, dstPitch, src, tbl); src += clipY.upperBottom * Width; dst += XStep; const auto upperMax = TrapezoidUpperHeight - clipY.upperTop; + int8_t prefix = InitPrefix(clip.bottom); for (auto i = 1 + clipY.upperBottom; i <= upperMax; ++i, dst -= dstPitch) { RenderLine(dst, src, Width, tbl, prefix); src += Width; @@ -782,13 +742,13 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTrapezoidClipVertical(uint8_t template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTrapezoidClipLeftAndVertical(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { - int8_t prefix = InitPrefix(clip.bottom); const DiamondClipY clipY = CalculateDiamondClipY(clip); const int_fast16_t clipLeft = clip.left; - RenderLeftTriangleLowerClipLeftAndVertical(clipLeft, prefix, clipY, dst, dstPitch, src, tbl); + RenderLeftTriangleLowerClipLeftAndVertical>(clipLeft, clipY, dst, dstPitch, src, tbl); src += clipY.upperBottom * Width + clipLeft; dst += XStep + clipLeft; const auto upperMax = TrapezoidUpperHeight - clipY.upperTop; + int8_t prefix = InitPrefix(clip.bottom); for (auto i = 1 + clipY.upperBottom; i <= upperMax; ++i, dst -= dstPitch) { RenderLine(dst, src, clip.width, tbl, prefix - clipLeft); src += Width; @@ -799,13 +759,13 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTrapezoidClipLeftAndVertical( template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTrapezoidClipRightAndVertical(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { - int8_t prefix = InitPrefix(clip.bottom); const DiamondClipY clipY = CalculateDiamondClipY(clip); const int_fast16_t clipRight = clip.right; - RenderLeftTriangleLowerClipRightAndVertical(clipRight, prefix, clipY, dst, dstPitch, src, tbl); + RenderLeftTriangleLowerClipRightAndVertical>(clipRight, clipY, dst, dstPitch, src, tbl); src += clipY.upperBottom * Width; dst += XStep; const auto upperMax = TrapezoidUpperHeight - clipY.upperTop; + int8_t prefix = InitPrefix(clip.bottom); for (auto i = 1 + clipY.upperBottom; i <= upperMax; ++i, dst -= dstPitch) { RenderLine(dst, src, clip.width, tbl, prefix); src += Width; @@ -813,7 +773,7 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTrapezoidClipRightAndVertical } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLeftTrapezoid(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { if (clip.width == Width) { @@ -839,11 +799,11 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTrapezoidFull(uint8_t *DVL_R template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTrapezoidClipVertical(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { - int8_t prefix = InitPrefix(clip.bottom); const DiamondClipY clipY = CalculateDiamondClipY(clip); - RenderRightTriangleLowerClipVertical(prefix, clipY, dst, dstPitch, src, tbl); + RenderRightTriangleLowerClipVertical>(clipY, dst, dstPitch, src, tbl); src += clipY.upperBottom * Width; const auto upperMax = TrapezoidUpperHeight - clipY.upperTop; + int8_t prefix = InitPrefix(clip.bottom); for (auto i = 1 + clipY.upperBottom; i <= upperMax; ++i, dst -= dstPitch) { RenderLine(dst, src, Width, tbl, prefix); src += Width; @@ -854,12 +814,12 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTrapezoidClipVertical(uint8_ template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTrapezoidClipLeftAndVertical(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { - int8_t prefix = InitPrefix(clip.bottom); const DiamondClipY clipY = CalculateDiamondClipY(clip); const int_fast16_t clipLeft = clip.left; - RenderRightTriangleLowerClipLeftAndVertical(clipLeft, prefix, clipY, dst, dstPitch, src, tbl); + RenderRightTriangleLowerClipLeftAndVertical>(clipLeft, clipY, dst, dstPitch, src, tbl); src += clipY.upperBottom * Width + clipLeft; const auto upperMax = TrapezoidUpperHeight - clipY.upperTop; + int8_t prefix = InitPrefix(clip.bottom); for (auto i = 1 + clipY.upperBottom; i <= upperMax; ++i, dst -= dstPitch) { RenderLine(dst, src, clip.width, tbl, prefix - clipLeft); src += Width; @@ -873,7 +833,7 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTrapezoidClipRightAndVertica int8_t prefix = InitPrefix(clip.bottom); const DiamondClipY clipY = CalculateDiamondClipY(clip); const int_fast16_t clipRight = clip.right; - RenderRightTriangleLowerClipRightAndVertical(clipRight, prefix, clipY, dst, dstPitch, src, tbl); + RenderRightTriangleLowerClipRightAndVertical>(clipRight, clipY, dst, dstPitch, src, tbl); src += clipY.upperBottom * Width; const auto upperMax = TrapezoidUpperHeight - clipY.upperTop; for (auto i = 1 + clipY.upperBottom; i <= upperMax; ++i, dst -= dstPitch) { @@ -883,7 +843,7 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTrapezoidClipRightAndVertica } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTrapezoid(uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { if (clip.width == Width) { @@ -899,27 +859,27 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTrapezoid(uint8_t *DVL_RESTR } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderTileType(TileType tile, uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { switch (tile) { case TileType::Square: - RenderSquare(dst, dstPitch, src, tbl, clip); + RenderSquare(dst, dstPitch, src, tbl, clip); break; case TileType::TransparentSquare: - RenderTransparentSquare(dst, dstPitch, src, tbl, clip); + RenderTransparentSquare(dst, dstPitch, src, tbl, clip); break; case TileType::LeftTriangle: - RenderLeftTriangle(dst, dstPitch, src, tbl, clip); + RenderLeftTriangle(dst, dstPitch, src, tbl, clip); break; case TileType::RightTriangle: - RenderRightTriangle(dst, dstPitch, src, tbl, clip); + RenderRightTriangle(dst, dstPitch, src, tbl, clip); break; case TileType::LeftTrapezoid: - RenderLeftTrapezoid(dst, dstPitch, src, tbl, clip); + RenderLeftTrapezoid(dst, dstPitch, src, tbl, clip); break; case TileType::RightTrapezoid: - RenderRightTrapezoid(dst, dstPitch, src, tbl, clip); + RenderRightTrapezoid(dst, dstPitch, src, tbl, clip); break; } } @@ -990,15 +950,15 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderRightTrapezoidOrTransparentSquare } } -template +template DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderTileDispatch(uint8_t lightTableIndex, TileType tile, uint8_t *DVL_RESTRICT dst, int dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl, Clip clip) { if (lightTableIndex == LightsMax) { - RenderTileType(tile, dst, dstPitch, src, tbl, clip); + RenderTileType(tile, dst, dstPitch, src, tbl, clip); } else if (lightTableIndex == 0) { - RenderTileType(tile, dst, dstPitch, src, tbl, clip); + RenderTileType(tile, dst, dstPitch, src, tbl, clip); } else { - RenderTileType(tile, dst, dstPitch, src, tbl, clip); + RenderTileType(tile, dst, dstPitch, src, tbl, clip); } } @@ -1160,10 +1120,10 @@ void RenderTile(const Surface &out, Point position, switch (maskType) { case MaskType::Solid: - RenderTileDispatch(lightTableIndex, tile, dst, dstPitch, src, tbl, clip); + RenderTileDispatch(lightTableIndex, tile, dst, dstPitch, src, tbl, clip); break; case MaskType::Transparent: - RenderTileDispatch(lightTableIndex, tile, dst, dstPitch, src, tbl, clip); + RenderTileDispatch(lightTableIndex, tile, dst, dstPitch, src, tbl, clip); break; case MaskType::Left: RenderLeftTrapezoidOrTransparentSquareDispatch(lightTableIndex, tile, dst, dstPitch, src, tbl, clip);