LCOV - code coverage report
Current view: top level - source/renderer - TexturedLineRData.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 4 203 2.0 %
Date: 2026-12-03 01:19:39 Functions: 1 5 20.0 %

          Line data    Source code
       1             : /* Copyright (C) 2026 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #include "precompiled.h"
      19             : 
      20             : #include "TexturedLineRData.h"
      21             : 
      22             : #include "graphics/Color.h"
      23             : #include "graphics/Terrain.h"
      24             : #include "graphics/TextureManager.h"
      25             : #include "lib/debug.h"
      26             : #include "maths/Frustum.h"
      27             : #include "maths/MathUtil.h"
      28             : #include "maths/Quaternion.h"
      29             : #include "ps/CStrIntern.h"
      30             : #include "ps/CStrInternStatic.h"
      31             : #include "renderer/OverlayRenderer.h"
      32             : #include "renderer/Renderer.h"
      33             : #include "renderer/VertexBuffer.h"
      34             : #include "renderer/backend/Format.h"
      35             : #include "renderer/backend/IBuffer.h"
      36             : #include "renderer/backend/IDeviceCommandContext.h"
      37             : #include "renderer/backend/IShaderProgram.h"
      38             : #include "simulation2/components/ICmpWaterManager.h"
      39             : #include "simulation2/system/Component.h"
      40             : #include "simulation2/system/Entity.h"
      41             : 
      42             : #include <array>
      43             : #include <cmath>
      44             : #include <cstddef>
      45             : #include <cstdint>
      46             : #include <numbers>
      47             : 
      48             : /* Note: this implementation uses CVertexBufferManager directly rather than access it through the nicer VertexArray interface,
      49             :  * because it allows you to work with variable amounts of vertices and indices more easily. New code should prefer
      50             :  * to use VertexArray where possible, though. */
      51             : 
      52             : // static
      53          10 : Renderer::Backend::IVertexInputLayout* CTexturedLineRData::GetVertexInputLayout()
      54             : {
      55          10 :     const uint32_t stride = sizeof(CTexturedLineRData::SVertex);
      56          10 :     const std::array<Renderer::Backend::SVertexAttributeFormat, 3> attributes{{
      57             :         {Renderer::Backend::VertexAttributeStream::POSITION,
      58             :             Renderer::Backend::Format::R32G32B32_SFLOAT,
      59             :             offsetof(CTexturedLineRData::SVertex, m_Position), stride,
      60             :             Renderer::Backend::VertexAttributeRate::PER_VERTEX, 0},
      61             :         {Renderer::Backend::VertexAttributeStream::UV0,
      62             :             Renderer::Backend::Format::R32G32_SFLOAT,
      63             :             offsetof(CTexturedLineRData::SVertex, m_UV), stride,
      64             :             Renderer::Backend::VertexAttributeRate::PER_VERTEX, 0},
      65             :         {Renderer::Backend::VertexAttributeStream::UV1,
      66             :             Renderer::Backend::Format::R32G32_SFLOAT,
      67             :             offsetof(CTexturedLineRData::SVertex, m_UV), stride,
      68             :             Renderer::Backend::VertexAttributeRate::PER_VERTEX, 0}
      69             :     }};
      70          10 :     return g_Renderer.GetVertexInputLayout(attributes);
      71             : }
      72             : 
      73           0 : void CTexturedLineRData::Render(
      74             :     Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
      75             :     Renderer::Backend::IVertexInputLayout* vertexInputLayout,
      76             :     const SOverlayTexturedLine& line, Renderer::Backend::IShaderProgram* shader)
      77             : {
      78           0 :     if (!m_VB || !m_VBIndices)
      79             :         return; // might have failed to allocate
      80             : 
      81             :     // -- render main line quad strip ----------------------
      82             : 
      83           0 :     line.m_TextureBase->UploadBackendTextureIfNeeded(deviceCommandContext);
      84           0 :     line.m_TextureMask->UploadBackendTextureIfNeeded(deviceCommandContext);
      85             : 
      86           0 :     ENSURE(!m_VB->m_Owner->GetBuffer()->IsDynamic());
      87           0 :     ENSURE(!m_VBIndices->m_Owner->GetBuffer()->IsDynamic());
      88             : 
      89           0 :     deviceCommandContext->SetTexture(
      90           0 :         shader->GetBindingSlot(str_baseTex), line.m_TextureBase->GetBackendTexture());
      91           0 :     deviceCommandContext->SetTexture(
      92           0 :         shader->GetBindingSlot(str_maskTex), line.m_TextureMask->GetBackendTexture());
      93           0 :     deviceCommandContext->SetUniform(
      94           0 :         shader->GetBindingSlot(str_objectColor), line.m_Color.AsFloatArray());
      95             : 
      96           0 :     deviceCommandContext->SetVertexInputLayout(vertexInputLayout);
      97             : 
      98           0 :     deviceCommandContext->SetVertexBuffer(0, m_VB->m_Owner->GetBuffer(), 0);
      99             : 
     100           0 :     deviceCommandContext->SetIndexBuffer(m_VBIndices->m_Owner->GetBuffer());
     101           0 :     deviceCommandContext->DrawIndexed(m_VBIndices->m_Index, m_VBIndices->m_Count, 0);
     102             : 
     103           0 :     g_Renderer.GetStats().m_DrawCalls++;
     104           0 :     g_Renderer.GetStats().m_OverlayTris += m_VBIndices->m_Count/3;
     105             : }
     106             : 
     107           0 : void CTexturedLineRData::Update(const SOverlayTexturedLine& line)
     108             : {
     109           0 :     m_VBIndices.Reset();
     110           0 :     m_VB.Reset();
     111             : 
     112           0 :     if (!line.m_SimContext)
     113             :     {
     114           0 :         debug_warn(L"[TexturedLineRData] No SimContext set for textured overlay line, cannot render (no terrain data)");
     115           0 :         return;
     116             :     }
     117             : 
     118           0 :     float v = 0.f;
     119           0 :     std::vector<SVertex> vertices;
     120           0 :     std::vector<std::uint16_t> indices;
     121             : 
     122           0 :     const size_t n = line.m_Coords.size(); // number of line points
     123           0 :     bool closed = line.m_Closed;
     124             : 
     125           0 :     ENSURE(n >= 2); // minimum needed to avoid errors (also minimum value to make sense, can't draw a line between 1 point)
     126             : 
     127             :     // In each iteration, p1 is the position of vertex i, p0 is i-1, p2 is i+1.
     128             :     // To avoid slightly expensive terrain computations we cycle these around and
     129             :     // recompute p2 at the end of each iteration.
     130             : 
     131           0 :     CVector3D p0;
     132           0 :     CVector3D p1(line.m_Coords[0].X, 0, line.m_Coords[0].Y);
     133           0 :     CVector3D p2(line.m_Coords[1].X, 0, line.m_Coords[1].Y);
     134             : 
     135           0 :     if (closed)
     136             :         // grab the ending point so as to close the loop
     137           0 :         p0 = CVector3D(line.m_Coords[n - 1].X, 0, line.m_Coords[n - 1].Y);
     138             :     else
     139             :         // we don't want to loop around and use the direction towards the other end of the line, so create an artificial p0 that
     140             :         // extends the p2 -> p1 direction, and use that point instead
     141           0 :         p0 = p1 + (p1 - p2);
     142             : 
     143           0 :     bool p1floating = false;
     144           0 :     bool p2floating = false;
     145             : 
     146             :     // Compute terrain heights, clamped to the water height (and remember whether
     147             :     // each point was floating on water, for normal computation later)
     148             : 
     149             :     // TODO: if we ever support more than one water level per map, recompute this per point
     150           0 :     CmpPtr<ICmpWaterManager> cmpWaterManager(*line.m_SimContext, SYSTEM_ENTITY);
     151           0 :     float w = cmpWaterManager ? cmpWaterManager->GetExactWaterLevel(p0.X, p0.Z) : 0.f;
     152             : 
     153           0 :     const CTerrain& terrain = line.m_SimContext->GetTerrain();
     154             : 
     155           0 :     p0.Y = terrain.GetExactGroundLevel(p0.X, p0.Z);
     156           0 :     if (p0.Y < w)
     157           0 :         p0.Y = w;
     158             : 
     159           0 :     p1.Y = terrain.GetExactGroundLevel(p1.X, p1.Z);
     160           0 :     if (p1.Y < w)
     161             :     {
     162           0 :         p1.Y = w;
     163           0 :         p1floating = true;
     164             :     }
     165             : 
     166           0 :     p2.Y = terrain.GetExactGroundLevel(p2.X, p2.Z);
     167           0 :     if (p2.Y < w)
     168             :     {
     169           0 :         p2.Y = w;
     170           0 :         p2floating = true;
     171             :     }
     172             : 
     173           0 :     for (size_t i = 0; i < n; ++i)
     174             :     {
     175             :         // For vertex i, compute bisector of lines (i-1)..(i) and (i)..(i+1)
     176             :         // perpendicular to terrain normal
     177             : 
     178             :         // Normal is vertical if on water, else computed from terrain
     179           0 :         CVector3D norm;
     180           0 :         if (p1floating)
     181             :             norm = CVector3D(0, 1, 0);
     182             :         else
     183           0 :             norm = terrain.CalcExactNormal(p1.X, p1.Z);
     184             : 
     185           0 :         CVector3D b = ((p1 - p0).Normalized() + (p2 - p1).Normalized()).Cross(norm);
     186             : 
     187             :         // Adjust bisector length to match the line thickness, along the line's width
     188           0 :         float l = b.Dot((p2 - p1).Normalized().Cross(norm));
     189           0 :         if (fabs(l) > 0.000001f) // avoid unlikely divide-by-zero
     190           0 :             b *= line.m_Thickness / l;
     191             : 
     192             :         // Push vertices and indices for each quad in GL_TRIANGLES order. The two triangles of each quad are indexed using
     193             :         // the winding orders (BR, BL, TR) and (TR, BL, TL) (where BR is bottom-right of this iteration's quad, TR top-right etc).
     194           0 :         SVertex vertex1(p1 + b + norm * OverlayRenderer::OVERLAY_VOFFSET, CVector2D(0.f, v));
     195           0 :         SVertex vertex2(p1 - b + norm * OverlayRenderer::OVERLAY_VOFFSET, CVector2D(1.f, v));
     196           0 :         vertices.push_back(vertex1);
     197           0 :         vertices.push_back(vertex2);
     198             : 
     199           0 :         std::uint16_t vertexCount = static_cast<std::uint16_t>(vertices.size());
     200           0 :         std::uint16_t index1 = vertexCount - 2; // index of vertex1 in this iteration (TR of this quad)
     201           0 :         std::uint16_t index2 = vertexCount - 1; // index of the vertex2 in this iteration (TL of this quad)
     202             : 
     203           0 :         if (i == 0)
     204             :         {
     205             :             // initial two vertices to continue building triangles from (n must be >= 2 for this to work)
     206           0 :             indices.push_back(index1);
     207           0 :             indices.push_back(index2);
     208             :         }
     209             :         else
     210             :         {
     211           0 :             std::uint16_t index1Prev = vertexCount - 4; // index of the vertex1 in the previous iteration (BR of this quad)
     212           0 :             std::uint16_t index2Prev = vertexCount - 3; // index of the vertex2 in the previous iteration (BL of this quad)
     213           0 :             ENSURE(index1Prev < vertexCount);
     214           0 :             ENSURE(index2Prev < vertexCount);
     215             :             // Add two corner points from last iteration and join with one of our own corners to create triangle 1
     216             :             // (don't need to do this if i == 1 because i == 0 are the first two ones, they don't need to be copied)
     217           0 :             if (i > 1)
     218             :             {
     219           0 :                 indices.push_back(index1Prev);
     220           0 :                 indices.push_back(index2Prev);
     221             :             }
     222           0 :             indices.push_back(index1); // complete triangle 1
     223             : 
     224             :             // create triangle 2, specifying the adjacent side's vertices in the opposite order from triangle 1
     225           0 :             indices.push_back(index1);
     226           0 :             indices.push_back(index2Prev);
     227           0 :             indices.push_back(index2);
     228             :         }
     229             : 
     230             :         // alternate V coordinate for debugging
     231           0 :         v = 1 - v;
     232             : 
     233             :         // cycle the p's and compute the new p2
     234           0 :         p0 = p1;
     235           0 :         p1 = p2;
     236           0 :         p1floating = p2floating;
     237             : 
     238             :         // if in closed mode, wrap around the coordinate array for p2 -- otherwise, extend linearly
     239           0 :         if (!closed && i == n-2)
     240             :             // next iteration is the last point of the line, so create an artificial p2 that extends the p0 -> p1 direction
     241           0 :             p2 = p1 + (p1 - p0);
     242             :         else
     243           0 :             p2 = CVector3D(line.m_Coords[(i + 2) % n].X, 0, line.m_Coords[(i + 2) % n].Y);
     244             : 
     245           0 :         p2.Y = terrain.GetExactGroundLevel(p2.X, p2.Z);
     246           0 :         if (p2.Y < w)
     247             :         {
     248           0 :             p2.Y = w;
     249           0 :             p2floating = true;
     250             :         }
     251             :         else
     252             :             p2floating = false;
     253             :     }
     254             : 
     255           0 :     if (closed)
     256             :     {
     257             :         // close the path
     258           0 :         if (n % 2 == 0)
     259             :         {
     260           0 :             std::uint16_t vertexCount = static_cast<std::uint16_t>(vertices.size());
     261           0 :             indices.push_back(vertexCount - 2);
     262           0 :             indices.push_back(vertexCount - 1);
     263           0 :             indices.push_back(0);
     264             : 
     265           0 :             indices.push_back(0);
     266           0 :             indices.push_back(vertexCount - 1);
     267           0 :             indices.push_back(1);
     268             :         }
     269             :         else
     270             :         {
     271             :             // add two vertices to have the good UVs for the last quad
     272           0 :             SVertex vertex1(vertices[0].m_Position, CVector2D(0.f, 1.f));
     273           0 :             SVertex vertex2(vertices[1].m_Position, CVector2D(1.f, 1.f));
     274           0 :             vertices.push_back(vertex1);
     275           0 :             vertices.push_back(vertex2);
     276             : 
     277           0 :             std::uint16_t vertexCount = static_cast<std::uint16_t>(vertices.size());
     278           0 :             indices.push_back(vertexCount - 4);
     279           0 :             indices.push_back(vertexCount - 3);
     280           0 :             indices.push_back(vertexCount - 2);
     281             : 
     282           0 :             indices.push_back(vertexCount - 2);
     283           0 :             indices.push_back(vertexCount - 3);
     284           0 :             indices.push_back(vertexCount - 1);
     285             :         }
     286             :     }
     287             :     else
     288             :     {
     289             :         // Create start and end caps. On either end, this is done by taking the centroid between the last and second-to-last pair of
     290             :         // vertices that was generated along the path (i.e. the vertex1's and vertex2's from above), taking a directional vector
     291             :         // between them, and drawing the line cap in the plane given by the two butt-end corner points plus said vector.
     292           0 :         std::vector<std::uint16_t> capIndices;
     293           0 :         std::vector<SVertex> capVertices;
     294             : 
     295             :         // create end cap
     296           0 :         CreateLineCap(
     297             :             line,
     298             :             // the order of these vertices is important here, swapping them produces caps at the wrong side
     299           0 :             vertices[vertices.size()-2].m_Position, // top-right vertex of last quad
     300           0 :             vertices[vertices.size()-1].m_Position, // top-left vertex of last quad
     301             :             // directional vector between centroids of last vertex pair and second-to-last vertex pair
     302           0 :             (Centroid(vertices[vertices.size()-2], vertices[vertices.size()-1]) - Centroid(vertices[vertices.size()-4], vertices[vertices.size()-3])).Normalized(),
     303           0 :             line.m_EndCapType,
     304             :             capVertices,
     305             :             capIndices
     306             :         );
     307             : 
     308           0 :         for (unsigned i = 0; i < capIndices.size(); i++)
     309           0 :             capIndices[i] += static_cast<std::uint16_t>(vertices.size());
     310             : 
     311           0 :         vertices.insert(vertices.end(), capVertices.begin(), capVertices.end());
     312           0 :         indices.insert(indices.end(), capIndices.begin(), capIndices.end());
     313             : 
     314           0 :         capIndices.clear();
     315           0 :         capVertices.clear();
     316             : 
     317             :         // create start cap
     318           0 :         CreateLineCap(
     319             :             line,
     320             :             // the order of these vertices is important here, swapping them produces caps at the wrong side
     321           0 :             vertices[1].m_Position,
     322           0 :             vertices[0].m_Position,
     323             :             // directional vector between centroids of first vertex pair and second vertex pair
     324           0 :             (Centroid(vertices[1], vertices[0]) - Centroid(vertices[3], vertices[2])).Normalized(),
     325           0 :             line.m_StartCapType,
     326             :             capVertices,
     327             :             capIndices
     328             :         );
     329             : 
     330           0 :         for (unsigned i = 0; i < capIndices.size(); i++)
     331           0 :             capIndices[i] += static_cast<std::uint16_t>(vertices.size());
     332             : 
     333           0 :         vertices.insert(vertices.end(), capVertices.begin(), capVertices.end());
     334           0 :         indices.insert(indices.end(), capIndices.begin(), capIndices.end());
     335           0 :     }
     336             : 
     337           0 :     if (vertices.empty() || indices.empty())
     338           0 :         return;
     339             : 
     340             :     // Indices for triangles, so must be multiple of 3.
     341           0 :     ENSURE(indices.size() % 3 == 0);
     342             : 
     343           0 :     m_BoundingBox = CBoundingBoxAligned();
     344           0 :     for (const SVertex& vertex : vertices)
     345           0 :         m_BoundingBox += vertex.m_Position;
     346             : 
     347           0 :     m_VB = g_Renderer.GetVertexBufferManager().AllocateChunk(
     348             :         sizeof(SVertex), vertices.size(), Renderer::Backend::IBuffer::Type::VERTEX,
     349           0 :         Renderer::Backend::IBuffer::Usage::TRANSFER_DST);
     350             :     // Allocation might fail (e.g. due to too many vertices).
     351           0 :     if (m_VB)
     352             :     {
     353             :         // Copy data into backend buffer.
     354           0 :         m_VB->m_Owner->UpdateChunkVertices(m_VB.Get(), &vertices[0]);
     355             : 
     356           0 :         for (size_t k = 0; k < indices.size(); ++k)
     357           0 :             indices[k] += static_cast<std::uint16_t>(m_VB->m_Index);
     358             : 
     359           0 :         m_VBIndices = g_Renderer.GetVertexBufferManager().AllocateChunk(
     360             :             sizeof(std::uint16_t), indices.size(), Renderer::Backend::IBuffer::Type::INDEX,
     361           0 :             Renderer::Backend::IBuffer::Usage::TRANSFER_DST);
     362           0 :         if (m_VBIndices)
     363           0 :             m_VBIndices->m_Owner->UpdateChunkVertices(m_VBIndices.Get(), &indices[0]);
     364             :     }
     365             : 
     366             : }
     367             : 
     368           0 : void CTexturedLineRData::CreateLineCap(const SOverlayTexturedLine& line, const CVector3D& corner1, const CVector3D& corner2,
     369             :     const CVector3D& lineDirectionNormal, SOverlayTexturedLine::LineCapType endCapType, std::vector<SVertex>& verticesOut,
     370             :     std::vector<std::uint16_t>& indicesOut)
     371             : {
     372           0 :     if (endCapType == SOverlayTexturedLine::LINECAP_FLAT)
     373           0 :         return; // no action needed, this is the default
     374             : 
     375             :     // When not in closed mode, we've created artificial points for the start- and endpoints that extend the line in the
     376             :     // direction of the first and the last segment, respectively. Thus, we know both the start and endpoints have perpendicular
     377             :     // butt endings, i.e. the end corner vertices on either side of the line extend perpendicularly from the segment direction.
     378             :     // That is to say, when viewed from the top, we will have something like
     379             :     //                                                 .
     380             :     //  this:                     and not like this:  /|
     381             :     //         ----+                                 / |
     382             :     //             |                                /  .
     383             :     //             |                                  /
     384             :     //         ----+                                 /
     385             :     //
     386             : 
     387           0 :     int roundCapPoints = 8; // amount of points to sample along the semicircle for rounded caps (including corner points)
     388           0 :     float radius = line.m_Thickness;
     389             : 
     390           0 :     CVector3D centerPoint = (corner1 + corner2) * 0.5f;
     391           0 :     SVertex centerVertex(centerPoint, CVector2D(0.5f, 0.5f));
     392           0 :     std::uint16_t indexOffset = static_cast<std::uint16_t>(verticesOut.size()); // index offset in verticesOut from where we start adding our vertices
     393             : 
     394           0 :     switch (endCapType)
     395             :     {
     396           0 :     case SOverlayTexturedLine::LINECAP_SHARP:
     397           0 :         {
     398           0 :             roundCapPoints = 3; // creates only one point directly ahead
     399           0 :             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)
     400           0 :             centerVertex.m_UV.X = 0.480f; // slight visual correction to make the texture match up better at the corner points
     401             :         }
     402           0 :         [[fallthrough]];
     403           0 :     case SOverlayTexturedLine::LINECAP_ROUND:
     404           0 :         {
     405             :             // Draw a rounded line cap in the 3D plane of the line specified by the two corner points and the normal vector of the
     406             :             // line's direction. The terrain normal at the centroid between the two corner points is perpendicular to this plane.
     407             :             // The way this works is by taking a vector from the corner points' centroid to one of the corner points (which is then
     408             :             // of radius length), and rotate it around the terrain normal vector in that centroid. This will rotate the vector in
     409             :             // the line's plane, producing the desired rounded cap.
     410             : 
     411             :             // To please OpenGL's winding order, this angle needs to be negated depending on whether we start rotating from
     412             :             // the (center -> corner1) or (center -> corner2) vector. For the (center -> corner2) vector, we apparently need to use
     413             :             // the negated angle.
     414           0 :             float stepAngle = -std::numbers::pi_v<float> / (roundCapPoints-1);
     415             : 
     416             :             // Push the vertices in triangle fan order (easy to generate GL_TRIANGLES indices for afterwards)
     417             :             // Note that we're manually adding the corner vertices instead of having them be generated by the rotating vector.
     418             :             // This is because we want to support an overly large radius to make the sharp line ending look sharper.
     419           0 :             verticesOut.push_back(centerVertex);
     420           0 :             verticesOut.push_back(SVertex(corner2, CVector2D()));
     421             : 
     422             :             // Get the base vector that we will incrementally rotate in the cap plane to produce the radial sample points.
     423             :             // Normally corner2 - centerPoint would suffice for this since it is of radius length, but we want to support custom
     424             :             // radii to support tuning the 'sharpness' of sharp end caps (see above)
     425           0 :             CVector3D rotationBaseVector = (corner2 - centerPoint).Normalized() * radius;
     426             :             // Calculate the normal vector of the plane in which we're going to be drawing the line cap. This is the vector that
     427             :             // is perpendicular to both baseVector and the 'lineDirectionNormal' vector indicating the direction of the line.
     428             :             // Note that we shouldn't use terrain->CalcExactNormal() here because if the line is being rendered on top of water,
     429             :             // then CalcExactNormal will return the normal vector of the terrain that's underwater (which can be quite funky).
     430           0 :             CVector3D capPlaneNormal = lineDirectionNormal.Cross(rotationBaseVector).Normalized();
     431             : 
     432           0 :             for (int i = 1; i < roundCapPoints - 1; ++i)
     433             :             {
     434             :                 // Rotate the centerPoint -> corner vector by i*stepAngle radians around the cap plane normal at the center point.
     435           0 :                 CQuaternion quatRotation;
     436           0 :                 quatRotation.FromAxisAngle(capPlaneNormal, i * stepAngle);
     437           0 :                 CVector3D worldPos3D = centerPoint + quatRotation.Rotate(rotationBaseVector);
     438             : 
     439             :                 // Let v range from 0 to 1 as we move along the semi-circle, keep u fixed at 0 (i.e. curve the left vertical edge
     440             :                 // of the texture around the edge of the semicircle)
     441           0 :                 float u = 0.f;
     442           0 :                 float v = Clamp((i / static_cast<float>(roundCapPoints - 1)), 0.f, 1.f); // pos, u, v
     443           0 :                 verticesOut.push_back(SVertex(worldPos3D, CVector2D(u, v)));
     444             :             }
     445             : 
     446             :             // connect back to the other butt-end corner point to complete the semicircle
     447           0 :             verticesOut.push_back(SVertex(corner1, CVector2D(0.f, 1.f)));
     448             : 
     449             :             // now push indices in GL_TRIANGLES order; vertices[indexOffset] is the center vertex, vertices[indexOffset + 1] is the
     450             :             // first corner point, then a bunch of radial samples, and then at the end we have the other corner point again. So:
     451           0 :             for (int i=1; i < roundCapPoints; ++i)
     452             :             {
     453           0 :                 indicesOut.push_back(indexOffset); // center vertex
     454           0 :                 indicesOut.push_back(indexOffset + i);
     455           0 :                 indicesOut.push_back(indexOffset + i + 1);
     456             :             }
     457             :         }
     458           0 :         break;
     459             : 
     460           0 :     case SOverlayTexturedLine::LINECAP_SQUARE:
     461           0 :         {
     462             :             // Extend the (corner1 -> corner2) vector along the direction normal and draw a square line ending consisting of
     463             :             // three triangles (sort of like a triangle fan)
     464             :             // NOTE: The order in which the vertices are pushed out determines the visibility, as they
     465             :             // are rendered only one-sided; the wrong order of vertices will make the cap visible only from the bottom.
     466           0 :             verticesOut.push_back(centerVertex);
     467           0 :             verticesOut.push_back(SVertex(corner2, CVector2D()));
     468           0 :             verticesOut.push_back(SVertex(corner2 + (lineDirectionNormal * (line.m_Thickness)), CVector2D(0.f, 0.33333f))); // extend butt corner point 2 along the normal vector
     469           0 :             verticesOut.push_back(SVertex(corner1 + (lineDirectionNormal * (line.m_Thickness)), CVector2D(0.f, 0.66666f))); // extend butt corner point 1 along the normal vector
     470           0 :             verticesOut.push_back(SVertex(corner1, CVector2D(0.f, 1.0f))); // push butt corner point 1
     471             : 
     472           0 :             for (int i=1; i < 4; ++i)
     473             :             {
     474           0 :                 indicesOut.push_back(indexOffset); // center point
     475           0 :                 indicesOut.push_back(indexOffset + i);
     476           0 :                 indicesOut.push_back(indexOffset + i + 1);
     477             :             }
     478             :         }
     479             :         break;
     480             : 
     481             :     default:
     482             :         break;
     483             :     }
     484             : 
     485             : }
     486             : 
     487           0 : bool CTexturedLineRData::IsVisibleInFrustum(const CFrustum& frustum) const
     488             : {
     489           0 :     return frustum.IsBoxVisible(m_BoundingBox);
     490             : }

Generated by: LCOV version 1.16