From 5596a040e02e2693ed72450a56a9c487609e50ae Mon Sep 17 00:00:00 2001 From: Stan Date: Mon, 6 Jun 2022 21:46:37 +0000 Subject: [PATCH] Use CVector2D instead of float arrays for `TexturedLineRData` Reviewed by: @vladislavbelov Differential Revision: https://code.wildfiregames.com/D4688 git-svn-id: https://svn.wildfiregames.com/public/ps/trunk@26924 3db68df2-c116-0410-a063-a993310a9797 --- source/renderer/TexturedLineRData.cpp | 30 +++++++++++++++--------------- source/renderer/TexturedLineRData.h | 4 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/source/renderer/TexturedLineRData.cpp b/source/renderer/TexturedLineRData.cpp index 3821e9c24c..dab688c4dc 100644 --- a/source/renderer/TexturedLineRData.cpp +++ b/source/renderer/TexturedLineRData.cpp @@ -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(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(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) { diff --git a/source/renderer/TexturedLineRData.h b/source/renderer/TexturedLineRData.h index 358ca30741..a8b59e4bfe 100644 --- a/source/renderer/TexturedLineRData.h +++ b/source/renderer/TexturedLineRData.h @@ -61,9 +61,9 @@ protected: struct SVertex { - SVertex(CVector3D pos, float u, float v) : m_Position(pos) { m_UVs[0] = u; m_UVs[1] = v; } + SVertex(const CVector3D& pos, const CVector2D& uv) : m_Position(pos), m_UV(uv) { } CVector3D m_Position; - float m_UVs[2]; + CVector2D m_UV; float padding[3]; // get a pow2 struct size }; cassert(sizeof(SVertex) == 32); -- 2.11.4.GIT