Use CVector2D instead of float arrays for TexturedLineRData

Reviewed by: @vladislavbelov
Differential Revision: https://code.wildfiregames.com/D4688
This was SVN commit r26924.
This commit is contained in:
Stan
2022-06-06 21:46:37 +00:00
parent 24140bf620
commit 12dfe2ce55
2 changed files with 17 additions and 17 deletions
+15 -15
View File
@@ -67,12 +67,12 @@ void CTexturedLineRData::Render(
deviceCommandContext->SetVertexAttributeFormat(
Renderer::Backend::VertexAttributeStream::UV0,
Renderer::Backend::Format::R32G32_SFLOAT,
offsetof(CTexturedLineRData::SVertex, m_UVs), stride,
offsetof(CTexturedLineRData::SVertex, m_UV), stride,
Renderer::Backend::VertexAttributeRate::PER_VERTEX, 0);
deviceCommandContext->SetVertexAttributeFormat(
Renderer::Backend::VertexAttributeStream::UV1,
Renderer::Backend::Format::R32G32_SFLOAT,
offsetof(CTexturedLineRData::SVertex, m_UVs), stride,
offsetof(CTexturedLineRData::SVertex, m_UV), stride,
Renderer::Backend::VertexAttributeRate::PER_VERTEX, 0);
deviceCommandContext->SetVertexBuffer(0, m_VB->m_Owner->GetBuffer());
@@ -171,8 +171,8 @@ void CTexturedLineRData::Update(const SOverlayTexturedLine& line)
// Push vertices and indices for each quad in GL_TRIANGLES order. The two triangles of each quad are indexed using
// the winding orders (BR, BL, TR) and (TR, BL, TL) (where BR is bottom-right of this iteration's quad, TR top-right etc).
SVertex vertex1(p1 + b + norm*OverlayRenderer::OVERLAY_VOFFSET, 0.f, v);
SVertex vertex2(p1 - b + norm*OverlayRenderer::OVERLAY_VOFFSET, 1.f, v);
SVertex vertex1(p1 + b + norm * OverlayRenderer::OVERLAY_VOFFSET, CVector2D(0.f, v));
SVertex vertex2(p1 - b + norm * OverlayRenderer::OVERLAY_VOFFSET, CVector2D(1.f, v));
vertices.push_back(vertex1);
vertices.push_back(vertex2);
@@ -249,8 +249,8 @@ void CTexturedLineRData::Update(const SOverlayTexturedLine& line)
else
{
// add two vertices to have the good UVs for the last quad
SVertex vertex1(vertices[0].m_Position, 0.f, 1.f);
SVertex vertex2(vertices[1].m_Position, 1.f, 1.f);
SVertex vertex1(vertices[0].m_Position, CVector2D(0.f, 1.f));
SVertex vertex2(vertices[1].m_Position, CVector2D(1.f, 1.f));
vertices.push_back(vertex1);
vertices.push_back(vertex2);
@@ -366,7 +366,7 @@ void CTexturedLineRData::CreateLineCap(const SOverlayTexturedLine& line, const C
float radius = line.m_Thickness;
CVector3D centerPoint = (corner1 + corner2) * 0.5f;
SVertex centerVertex(centerPoint, 0.5f, 0.5f);
SVertex centerVertex(centerPoint, CVector2D(0.5f, 0.5f));
u16 indexOffset = static_cast<u16>(verticesOut.size()); // index offset in verticesOut from where we start adding our vertices
switch (endCapType)
@@ -375,7 +375,7 @@ void CTexturedLineRData::CreateLineCap(const SOverlayTexturedLine& line, const C
{
roundCapPoints = 3; // creates only one point directly ahead
radius *= 1.5f; // make it a bit sharper (note that we don't use the radius for the butt-end corner points so it should be ok)
centerVertex.m_UVs[0] = 0.480f; // slight visual correction to make the texture match up better at the corner points
centerVertex.m_UV.X = 0.480f; // slight visual correction to make the texture match up better at the corner points
}
FALLTHROUGH;
case SOverlayTexturedLine::LINECAP_ROUND:
@@ -395,7 +395,7 @@ void CTexturedLineRData::CreateLineCap(const SOverlayTexturedLine& line, const C
// Note that we're manually adding the corner vertices instead of having them be generated by the rotating vector.
// This is because we want to support an overly large radius to make the sharp line ending look sharper.
verticesOut.push_back(centerVertex);
verticesOut.push_back(SVertex(corner2, 0.f, 0.f));
verticesOut.push_back(SVertex(corner2, CVector2D()));
// Get the base vector that we will incrementally rotate in the cap plane to produce the radial sample points.
// Normally corner2 - centerPoint would suffice for this since it is of radius length, but we want to support custom
@@ -418,11 +418,11 @@ void CTexturedLineRData::CreateLineCap(const SOverlayTexturedLine& line, const C
// of the texture around the edge of the semicircle)
float u = 0.f;
float v = Clamp((i / static_cast<float>(roundCapPoints - 1)), 0.f, 1.f); // pos, u, v
verticesOut.push_back(SVertex(worldPos3D, u, v));
verticesOut.push_back(SVertex(worldPos3D, CVector2D(u, v)));
}
// connect back to the other butt-end corner point to complete the semicircle
verticesOut.push_back(SVertex(corner1, 0.f, 1.f));
verticesOut.push_back(SVertex(corner1, CVector2D(0.f, 1.f)));
// now push indices in GL_TRIANGLES order; vertices[indexOffset] is the center vertex, vertices[indexOffset + 1] is the
// first corner point, then a bunch of radial samples, and then at the end we have the other corner point again. So:
@@ -442,10 +442,10 @@ void CTexturedLineRData::CreateLineCap(const SOverlayTexturedLine& line, const C
// NOTE: The order in which the vertices are pushed out determines the visibility, as they
// are rendered only one-sided; the wrong order of vertices will make the cap visible only from the bottom.
verticesOut.push_back(centerVertex);
verticesOut.push_back(SVertex(corner2, 0.f, 0.f));
verticesOut.push_back(SVertex(corner2 + (lineDirectionNormal * (line.m_Thickness)), 0.f, 0.33333f)); // extend butt corner point 2 along the normal vector
verticesOut.push_back(SVertex(corner1 + (lineDirectionNormal * (line.m_Thickness)), 0.f, 0.66666f)); // extend butt corner point 1 along the normal vector
verticesOut.push_back(SVertex(corner1, 0.f, 1.0f)); // push butt corner point 1
verticesOut.push_back(SVertex(corner2, CVector2D()));
verticesOut.push_back(SVertex(corner2 + (lineDirectionNormal * (line.m_Thickness)), CVector2D(0.f, 0.33333f))); // extend butt corner point 2 along the normal vector
verticesOut.push_back(SVertex(corner1 + (lineDirectionNormal * (line.m_Thickness)), CVector2D(0.f, 0.66666f))); // extend butt corner point 1 along the normal vector
verticesOut.push_back(SVertex(corner1, CVector2D(0.f, 1.0f))); // push butt corner point 1
for (int i=1; i < 4; ++i)
{