_font drawtext transform opt

This commit is contained in:
2023-09-10 11:29:43 +03:00
parent dea5f7aa4e
commit 9d1b65730f

View File

@@ -402,6 +402,13 @@ void WriteRect(const Rectangle& rect, const Color& color, const Float2& uvUpperL
quad[1] = MakeTransformedVertex(rect.GetBottomLeft(), Float2(uvUpperLeft.X, uvBottomRight.Y), color);
quad[2] = MakeTransformedVertex(rect.GetUpperLeft(), uvUpperLeft, color);
quad[3] = MakeTransformedVertex(rect.GetUpperRight(), Float2(uvBottomRight.X, uvUpperLeft.Y), color);
/*RotatedRectangle mask = ClipLayersStack.Peek().Mask;
Float2 customData = { 0.0f, (float)Render2D::Features };
Color colorTint = color * TintLayersStack.Peek();
quad[0] = MakeTransformedVertex(rect.GetBottomRight(), uvBottomRight, colorTint, mask, customData);
quad[1] = MakeTransformedVertex(rect.GetBottomLeft(), Float2(uvUpperLeft.X, uvBottomRight.Y), colorTint, mask, customData);
quad[2] = MakeTransformedVertex(rect.GetUpperLeft(), uvUpperLeft, colorTint, mask, customData);
quad[3] = MakeTransformedVertex(rect.GetUpperRight(), Float2(uvBottomRight.X, uvUpperLeft.Y), colorTint, mask, customData);*/
}
//VB.Write(quad, sizeof(quad));
@@ -1381,12 +1388,23 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
drawCall.Type = DrawCallType::DrawChar;
drawCall.AsChar.Mat = nullptr;
}*/
//Matrix3x3 rotto = TransformCached;
//auto quat = Quaternion::RotationYawPitchRoll(15.0f, 25.0f, 35.0f);
//Matrix3x3 rotto = Matrix3x3::RotationQuaternion(quat);
int32 entryIndex = 0;
int32 actualDrawCallsCount = 0;
for (int32 lineIndex = 0; lineIndex < Lines.Count(); lineIndex++)
{
const FontLineCache& line = Lines[lineIndex];
Float2 pointer = line.Location;
Float2 pointer;
ApplyTransform(line.Location, pointer);
Float2 advanceDirX;
Matrix3x3::Transform2DVector(Float2(1.0f, 0.0f), TransformCached, advanceDirX);
Float2 advanceDirY;
Matrix3x3::Transform2DVector(Float2(0.0f, 1.0f), TransformCached, advanceDirY);
// Render all characters from the line
for (int32 charIndex = line.FirstCharIndex; charIndex < line.LastCharIndex; charIndex++)
@@ -1409,7 +1427,8 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
}
pointer.X += (float)kerning * scale;*/
pointer.X += kerning * scale;
//pointer.X += kerning * scale;
pointer += advanceDirX * (kerning * scale);
previous = entry;
// Omit whitespace characters
@@ -1436,11 +1455,16 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
}
// Calculate character size and atlas coordinates
const float x = pointer.X + entry.OffsetX * scale;
const float y = pointer.Y - entry.OffsetY * scale + fontHeightOffset;
Rectangle charRect(x, y, entry.UVSize.X * scale, entry.UVSize.Y * scale);
charRect.Offset(layout.Bounds.Location);
//const float x = pointer.X + entry.OffsetX * scale;
//const float y = pointer.Y - entry.OffsetY * scale + fontHeightOffset;
// FIXME: skewed, use advanceDirY for rightBottom
Float2 upperLeft(pointer.X + entry.OffsetX * scale, pointer.Y - entry.OffsetY * scale + fontHeightOffset);
Float2 rightBottom(upperLeft.X + (entry.UVSize.X * scale), upperLeft.Y + (entry.UVSize.Y * scale));
upperLeft += layout.Bounds.Location;
rightBottom += layout.Bounds.Location;
//Rectangle charRect(x, y, entry.UVSize.X * scale, entry.UVSize.Y * scale);
//charRect.Offset(layout.Bounds.Location);
Float2 upperLeftUV = entry.UV * invAtlasSize;
Float2 rightBottomUV = (entry.UV + entry.UVSize) * invAtlasSize;
@@ -1459,17 +1483,49 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
drawCall->AsChar.Mat = nullptr;
}
drawCall->AsChar.Tex = fontAtlas ? fontAtlas->GetTexture() : nullptr;
//DrawCalls[drawCallCountBefore + actualDrawCallsCount] = drawCall;
//*drawCalls = drawCall;
drawCall++;
actualDrawCallsCount++;
//DrawCalls.Add(drawCall);
WriteRect(charRect, color, upperLeftUV, rightBottomUV);
//WriteRect(charRect, color, upperLeftUV, rightBottomUV);
{
Render2DVertex* quad = (Render2DVertex*)VB.WriteReserve(sizeof(Render2DVertex) * 4);
//Render2DVertex quad[4];
//if (TransformIsIdentity)
{
RotatedRectangle mask = ClipLayersStack.Peek().Mask;
Float2 customData = { 0.0f, (float)Render2D::Features };
Color colorTint = color * TintLayersStack.Peek();
quad[0] = MakeVertex(rightBottom, rightBottomUV, colorTint, mask, customData);
quad[1] = MakeVertex(Float2(upperLeft.X, rightBottom.Y), Float2(upperLeftUV.X, rightBottomUV.Y), colorTint, mask, customData);
quad[2] = MakeVertex(upperLeft, upperLeftUV, colorTint, mask, customData);
quad[3] = MakeVertex(Float2(rightBottom.X, upperLeft.Y), Float2(rightBottomUV.X, upperLeftUV.Y), colorTint, mask, customData);
}
//VB.Write(quad, sizeof(quad));
//uint32 indices[6];
uint32* indices = (uint32*)IB.WriteReserve(sizeof(uint32) * 6);
indices[0] = VBIndex + 0;
indices[1] = VBIndex + 1;
indices[2] = VBIndex + 2;
indices[3] = VBIndex + 2;
indices[4] = VBIndex + 3;
indices[5] = VBIndex + 0;
//IB.Write(indices, sizeof(indices));
//RENDER2D_WRITE_IB_QUAD(indices);
VBIndex += 4;
IBIndex += 6;
}
}
// Move
pointer.X += entry.AdvanceX * scale;
//pointer.X += entry.AdvanceX * scale;
pointer += advanceDirX * (entry.AdvanceX * scale);
entryIndex++;
}
}