_line render small opt

This commit is contained in:
2023-09-10 14:11:32 +03:00
parent a2edead792
commit f29a014aec
3 changed files with 82 additions and 28 deletions

View File

@@ -10,9 +10,23 @@ static_assert(sizeof(Half2) == 4, "Invalid Half2 type size.");
static_assert(sizeof(Half3) == 6, "Invalid Half3 type size.");
static_assert(sizeof(Half4) == 8, "Invalid Half4 type size.");
Half2 Half2::Zero(0.0f, 0.0f);
Half3 Half3::Zero(0.0f, 0.0f, 0.0f);
Half4 Half4::Zero(0.0f, 0.0f, 0.0f, 0.0f);
const Half2 Half2::Zero(0.0f, 0.0f);
const Half2 Half2::One(1.0f, 1.0f);
const Half2 Half2::UnitX(1.0f, 0.0f);
const Half2 Half2::UnitY(0.0f, 1.0f);
const Half3 Half3::Zero(0.0f, 0.0f, 0.0f);
const Half3 Half3::One(1.0f, 1.0f, 1.0f);
const Half3 Half3::UnitX(1.0f, 0.0f, 0.0f);
const Half3 Half3::UnitY(0.0f, 1.0f, 0.0f);
const Half3 Half3::UnitZ(0.0f, 0.0f, 1.0f);
const Half4 Half4::Zero(0.0f, 0.0f, 0.0f, 0.0f);
const Half4 Half4::One(1.0f, 1.0f, 1.0f, 1.0f);
const Half4 Half4::UnitX(1.0f, 0.0f, 0.0f, 0.0f);
const Half4 Half4::UnitY(0.0f, 1.0f, 0.0f, 0.0f);
const Half4 Half4::UnitZ(0.0f, 0.0f, 1.0f, 0.0f);
const Half4 Half4::UnitW(0.0f, 0.0f, 0.0f, 1.0f);
#if !USE_SSE_HALF_CONVERSION

View File

@@ -82,10 +82,17 @@ public:
struct FLAXENGINE_API Half2
{
public:
/// <summary>
/// Zero vector
/// </summary>
static Half2 Zero;
// Vector with all components equal 0
static const Half2 Zero;
// Vector with all components equal 1
static const Half2 One;
// Vector X=1, Y=0
static const Half2 UnitX;
// Vector X=0, Y=1
static const Half2 UnitY;
public:
/// <summary>
@@ -146,10 +153,20 @@ public:
struct FLAXENGINE_API Half3
{
public:
/// <summary>
/// Zero vector
/// </summary>
static Half3 Zero;
// Vector with all components equal 0
static const Half3 Zero;
// Vector with all components equal 1
static const Half3 One;
// Vector X=1, Y=0, Z=0
static const Half3 UnitX;
// Vector X=0, Y=1, Z=0
static const Half3 UnitY;
// Vector X=0, Y=0, Z=1
static const Half3 UnitZ;
public:
/// <summary>
@@ -201,10 +218,23 @@ public:
struct FLAXENGINE_API Half4
{
public:
/// <summary>
/// Zero vector
/// </summary>
static Half4 Zero;
// Vector with all components equal 0
static const Half4 Zero;
// Vector with all components equal 1
static const Half4 One;
// Vector X=1, Y=0, Z=0, W=0
static const Half4 UnitX;
// Vector X=0, Y=1, Z=0, W=0
static const Half4 UnitY;
// Vector X=0, Y=0, Z=1, W=0
static const Half4 UnitZ;
// Vector X=0, Y=0, Z=0, W=1
static const Half4 UnitW;
public:
/// <summary>

View File

@@ -255,6 +255,18 @@ void ApplyTransform(const Rectangle& value, RotatedRectangle& result)
}
}
FORCE_INLINE Render2DVertex MakeVertex(const Float2& point, const Half2& uv, const Color& color, const RotatedRectangle& mask, const Float2& customData)
{
return
{
point,
uv,
color,
customData,
mask,
};
}
FORCE_INLINE Render2DVertex MakeVertex(const Float2& point, const Float2& uv, const Color& color, const RotatedRectangle& mask, const Float2& customData)
{
return
@@ -1834,14 +1846,15 @@ void Render2D::DrawCustom(GPUTexture* t, const Rectangle& rect, GPUPipelineState
void DrawLineCap(const Float2& capOrigin, const Float2& capDirection, const Float2& up, const Color& color, float thickness)
{
const auto& mask = ClipLayersStack.Peek().Mask;
const Half2 halfPointFiveX(Float2(0.5f, 0.0f));
//Render2DVertex v[5];
Render2DVertex* v = (Render2DVertex*)VB.WriteReserve(sizeof(Render2DVertex) * 5);
v[0] = MakeVertex(capOrigin, Float2(0.5f, 0.0f), color, mask, { thickness, (float)Render2D::Features });
v[1] = MakeVertex(capOrigin + capDirection + up, Float2::Zero, color, mask, { thickness, (float)Render2D::Features });
v[2] = MakeVertex(capOrigin + capDirection - up, Float2::Zero, color, mask, { thickness, (float)Render2D::Features });
v[3] = MakeVertex(capOrigin + up, Float2::Zero, color, mask, { thickness, (float)Render2D::Features });
v[4] = MakeVertex(capOrigin - up, Float2::Zero, color, mask, { thickness, (float)Render2D::Features });
v[0] = MakeVertex(capOrigin, halfPointFiveX, color, mask, { thickness, (float)Render2D::Features });
v[1] = MakeVertex(capOrigin + capDirection + up, Half2::Zero, color, mask, { thickness, (float)Render2D::Features });
v[2] = MakeVertex(capOrigin + capDirection - up, Half2::Zero, color, mask, { thickness, (float)Render2D::Features });
v[3] = MakeVertex(capOrigin + up, Half2::Zero, color, mask, { thickness, (float)Render2D::Features });
v[4] = MakeVertex(capOrigin - up, Half2::Zero, color, mask, { thickness, (float)Render2D::Features });
//VB.Write(v, sizeof(v));
//uint32 indices[9];
@@ -1868,10 +1881,7 @@ void DrawLines(const Float2* points, int32 pointsCount, const Color& color1, con
ASSERT(points && pointsCount >= 2);
const auto& mask = ClipLayersStack.Peek().Mask;
if (TransformIsIdentity)
thickness *= (TransformCached.M11 + TransformCached.M22 + TransformCached.M33) * 0.3333333f;
else
thickness *= (TransformCached.M11 + TransformCached.M22 + TransformCached.M33) * 0.3333333f;
thickness *= (TransformCached.M11 + TransformCached.M22 + TransformCached.M33) * 0.3333333f;
Render2DDrawCall& drawCall = DrawCalls.AddOne();
drawCall.StartIB = IBIndex;
@@ -1914,10 +1924,10 @@ void DrawLines(const Float2* points, int32 pointsCount, const Color& color1, con
normal = Float2::Normalize(Float2(-line.Y, line.X));
up = normal * thicknessHalf;
v[0] = MakeVertex(p2t + up, Float2::UnitX, color2, mask, { thickness, (float)Render2D::Features });
v[1] = MakeVertex(p1t + up, Float2::UnitX, color1, mask, { thickness, (float)Render2D::Features });
v[2] = MakeVertex(p1t - up, Float2::Zero, color1, mask, { thickness, (float)Render2D::Features });
v[3] = MakeVertex(p2t - up, Float2::Zero, color2, mask, { thickness, (float)Render2D::Features });
v[0] = MakeVertex(p2t + up, Half2::UnitX, color2, mask, { thickness, (float)Render2D::Features });
v[1] = MakeVertex(p1t + up, Half2::UnitX, color1, mask, { thickness, (float)Render2D::Features });
v[2] = MakeVertex(p1t - up, Half2::Zero, color1, mask, { thickness, (float)Render2D::Features });
v[3] = MakeVertex(p2t - up, Half2::Zero, color2, mask, { thickness, (float)Render2D::Features });
VB.Write(v, sizeof(Render2DVertex) * 4);
indices[0] = VBIndex + 0;