From a6e28fe377b41500d6ce3e0a9a4d6e6288d97f61 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 17 Jan 2024 01:08:54 +0000 Subject: Copy render vital link data to vertex buffer --- game/network/network.h | 13 ++++++++++--- game/network/network.impl.h | 40 ++++++++++++++++++++-------------------- game/network/rail.cpp | 31 ++++++++++++++++++++----------- game/network/rail.h | 26 +++++++++++++++++++++----- 4 files changed, 71 insertions(+), 39 deletions(-) (limited to 'game') diff --git a/game/network/network.h b/game/network/network.h index fa311ac..12c006c 100644 --- a/game/network/network.h +++ b/game/network/network.h @@ -1,5 +1,6 @@ #pragma once +#include "gfx/gl/instanceVertices.h" #include "link.h" #include #include @@ -58,7 +59,13 @@ protected: std::shared_ptr texture; }; -template class NetworkOf : public Network, public Renderable { +template class NetworkLinkHolder { + friend LinkType; + mutable InstanceVertices vertices; +}; + +template +class NetworkOf : public Network, public Renderable, public NetworkLinkHolder... { protected: using Network::Network; @@ -75,7 +82,7 @@ public: requires std::is_base_of_v { const auto node1 = candidateNodeAt(a).first, node2 = candidateNodeAt(b).first; - return std::make_shared(node1, node2, std::forward(params)...); + return std::make_shared(*this, node1, node2, std::forward(params)...); } template @@ -84,7 +91,7 @@ public: requires std::is_base_of_v { const auto node1 = nodeAt(a), node2 = nodeAt(b); - auto l {links.template create(node1, node2, std::forward(params)...)}; + auto l {links.template create(*this, node1, node2, std::forward(params)...)}; joinLinks(l); return l; } diff --git a/game/network/network.impl.h b/game/network/network.impl.h index f9595ed..c1f079d 100644 --- a/game/network/network.impl.h +++ b/game/network/network.impl.h @@ -2,9 +2,9 @@ #include #include -template +template void -NetworkOf::render(const SceneShader & shader) const +NetworkOf::render(const SceneShader & shader) const { if constexpr (std::is_base_of_v) { shader.absolute.use(); @@ -13,18 +13,18 @@ NetworkOf::render(const SceneShader & shader) const } } -template +template void -NetworkOf::joinLinks(const Link::Ptr & l) const +NetworkOf::joinLinks(const Link::Ptr & l) const { for (const auto & ol : links.objects) { Network::joinLinks(l, ol); } } -template +template Link::Ptr -NetworkOf::intersectRayLinks(const Ray & ray) const +NetworkOf::intersectRayLinks(const Ray & ray) const { // Click link if (const auto link = std::find_if(links.objects.begin(), links.objects.end(), @@ -37,9 +37,9 @@ NetworkOf::intersectRayLinks(const Ray & ray) const return {}; } -template +template float -NetworkOf::findNodeDirection(Node::AnyCPtr n) const +NetworkOf::findNodeDirection(Node::AnyCPtr n) const { for (const auto & l : links.objects) { for (const auto & e : l->ends) { @@ -52,16 +52,16 @@ NetworkOf::findNodeDirection(Node::AnyCPtr n) const throw std::runtime_error("Node exists but couldn't find it"); } -template +template Link::CCollection -NetworkOf::candidateStraight(GlobalPosition3D n1, GlobalPosition3D n2) +NetworkOf::candidateStraight(GlobalPosition3D n1, GlobalPosition3D n2) { return {candidateLink(n1, n2)}; } -template +template Link::CCollection -NetworkOf::candidateJoins(GlobalPosition3D start, GlobalPosition3D end) +NetworkOf::candidateJoins(GlobalPosition3D start, GlobalPosition3D end) { if (glm::length(RelativePosition3D(start - end)) < 2000.F) { return {}; @@ -73,24 +73,24 @@ NetworkOf::candidateJoins(GlobalPosition3D start, GlobalPosition3D end) return {candidateLink(c1s, c1e, c1c), candidateLink(c2s, c2e, c2c)}; } -template +template Link::CCollection -NetworkOf::candidateExtend(GlobalPosition3D start, GlobalPosition3D end) +NetworkOf::candidateExtend(GlobalPosition3D start, GlobalPosition3D end) { const auto [cstart, cend, centre] = genCurveDef(start, end, findNodeDirection(candidateNodeAt(start).first)); return {candidateLink(cstart, cend, centre)}; } -template +template Link::CCollection -NetworkOf::addStraight(GlobalPosition3D n1, GlobalPosition3D n2) +NetworkOf::addStraight(GlobalPosition3D n1, GlobalPosition3D n2) { return {addLink(n1, n2)}; } -template +template Link::CCollection -NetworkOf::addJoins(GlobalPosition3D start, GlobalPosition3D end) +NetworkOf::addJoins(GlobalPosition3D start, GlobalPosition3D end) { if (glm::length(RelativePosition3D(start - end)) < 2000.F) { return {}; @@ -101,9 +101,9 @@ NetworkOf::addJoins(GlobalPosition3D start, GlobalPosition3D end) return {addLink(c1s, c1e, c1c), addLink(c2s, c2e, c2c)}; } -template +template Link::CCollection -NetworkOf::addExtend(GlobalPosition3D start, GlobalPosition3D end) +NetworkOf::addExtend(GlobalPosition3D start, GlobalPosition3D end) { const auto [cstart, cend, centre] = genCurveDef(start, end, findNodeDirection(nodeAt(start))); return {addLink(cstart, cend, centre)}; diff --git a/game/network/rail.cpp b/game/network/rail.cpp index 79aaf97..3d29ea5 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -13,12 +13,12 @@ #include #include -template class NetworkOf; +template class NetworkOf; constexpr auto RAIL_CROSSSECTION_VERTICES {5U}; constexpr Size3D RAIL_HEIGHT {0, 0, 250.F}; -RailLinks::RailLinks() : NetworkOf {"rails.jpg"} { } +RailLinks::RailLinks() : NetworkOf {"rails.jpg"} { } void RailLinks::tick(TickDuration) @@ -117,15 +117,20 @@ round_sleepers(const float v) return round_frac(v, sleepers); } -RailLinkStraight::RailLinkStraight(const Node::Ptr & a, const Node::Ptr & b) : RailLinkStraight(a, b, b->pos - a->pos) +RailLinkStraight::RailLinkStraight( + NetworkLinkHolder & instances, const Node::Ptr & a, const Node::Ptr & b) : + RailLinkStraight(instances, a, b, b->pos - a->pos) { } -RailLinkStraight::RailLinkStraight(Node::Ptr a, Node::Ptr b, const RelativePosition3D & diff) : - Link({std::move(a), vector_yaw(diff)}, {std::move(b), vector_yaw(-diff)}, glm::length(diff)) +RailLinkStraight::RailLinkStraight( + NetworkLinkHolder & instances, Node::Ptr a, Node::Ptr b, const RelativePosition3D & diff) : + Link({std::move(a), vector_yaw(diff)}, {std::move(b), vector_yaw(-diff)}, glm::length(diff)), + instance {instances.vertices.acquire( + ends[0].node->pos, ends[1].node->pos, flat_orientation(diff), round_sleepers(length / 2.F))} { if (glGenVertexArrays) { - std::vector vertices; + std::vector<::Vertex> vertices; vertices.reserve(2 * railCrossSection.size()); const auto len = round_sleepers(length / 2000.F); const glm::mat3 trans {flat_orientation(diff)}; @@ -139,15 +144,19 @@ RailLinkStraight::RailLinkStraight(Node::Ptr a, Node::Ptr b, const RelativePosit } } -RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, GlobalPosition2D c) : - RailLinkCurve(a, b, c || a->pos.z, {c || 0, a->pos, b->pos}) +RailLinkCurve::RailLinkCurve( + NetworkLinkHolder & instances, const Node::Ptr & a, const Node::Ptr & b, GlobalPosition2D c) : + RailLinkCurve(instances, a, b, c || a->pos.z, {c || 0, a->pos, b->pos}) { } -RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, GlobalPosition3D c, const Arc arc) : +RailLinkCurve::RailLinkCurve(NetworkLinkHolder & instances, const Node::Ptr & a, const Node::Ptr & b, + GlobalPosition3D c, const Arc arc) : Link({a, normalize(arc.first + half_pi)}, {b, normalize(arc.second - half_pi)}, glm::length(RelativePosition3D(a->pos - c)) * arc_length(arc)), - LinkCurve {c, glm::length(RelativePosition3D(ends[0].node->pos - c)), arc} + LinkCurve {c, glm::length(RelativePosition3D(ends[0].node->pos - c)), arc}, + instance {instances.vertices.acquire(ends[0].node->pos, ends[1].node->pos, c, round_sleepers(length / 2.F))} + { if (glGenVertexArrays) { const auto & e0p {ends[0].node->pos}; @@ -157,7 +166,7 @@ RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, GlobalPos const auto step {RelativePosition3D {arc_length(arc), e1p.z - e0p.z, slength / 1000.F} / segs}; auto segCount = static_cast(std::lround(segs)) + 1; - std::vector vertices; + std::vector<::Vertex> vertices; vertices.reserve(segCount * railCrossSection.size()); for (RelativePosition3D swing = {arc.first, centreBase.z - e0p.z, 0.F}; segCount; swing += step, --segCount) { const auto t { diff --git a/game/network/rail.h b/game/network/rail.h index 986b0aa..e06568f 100644 --- a/game/network/rail.h +++ b/game/network/rail.h @@ -40,23 +40,39 @@ protected: RailLink::~RailLink() = default; +class RailLinks; + class RailLinkStraight : public RailLink, public LinkStraight { public: - RailLinkStraight(const Node::Ptr &, const Node::Ptr &); + RailLinkStraight(NetworkLinkHolder &, const Node::Ptr &, const Node::Ptr &); + + struct Vertex { + GlobalPosition3D a, b; + glm::mat2 rotation; + float textureRepeats; + }; private: - RailLinkStraight(Node::Ptr, Node::Ptr, const RelativePosition3D & diff); + RailLinkStraight(NetworkLinkHolder &, Node::Ptr, Node::Ptr, const RelativePosition3D & diff); + InstanceVertices::InstanceProxy instance; }; class RailLinkCurve : public RailLink, public LinkCurve { public: - RailLinkCurve(const Node::Ptr &, const Node::Ptr &, GlobalPosition2D); + RailLinkCurve(NetworkLinkHolder &, const Node::Ptr &, const Node::Ptr &, GlobalPosition2D); + + struct Vertex { + GlobalPosition3D a, b, c; + float textureRepeats; + }; private: - RailLinkCurve(const Node::Ptr &, const Node::Ptr &, GlobalPosition3D, const Arc); + RailLinkCurve( + NetworkLinkHolder &, const Node::Ptr &, const Node::Ptr &, GlobalPosition3D, const Arc); + InstanceVertices::InstanceProxy instance; }; -class RailLinks : public NetworkOf, public WorldObject { +class RailLinks : public NetworkOf, public WorldObject { public: RailLinks(); -- cgit v1.2.3 From c7af64b7061c59c987958d0830838f1c05caeb29 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 19 Jan 2024 00:23:56 +0000 Subject: Render rail network using new shaders Non-functional, totally unimplemented at this stage --- game/network/network.h | 3 +-- game/network/network.impl.h | 11 ----------- game/network/rail.cpp | 22 ++++++++++++++++++++-- game/network/rail.h | 1 + 4 files changed, 22 insertions(+), 15 deletions(-) (limited to 'game') diff --git a/game/network/network.h b/game/network/network.h index 12c006c..49322f9 100644 --- a/game/network/network.h +++ b/game/network/network.h @@ -60,6 +60,7 @@ protected: }; template class NetworkLinkHolder { +protected: friend LinkType; mutable InstanceVertices vertices; }; @@ -105,8 +106,6 @@ public: [[nodiscard]] float findNodeDirection(Node::AnyCPtr) const override; - void render(const SceneShader &) const override; - protected: Link::CCollection addJoins(); }; diff --git a/game/network/network.impl.h b/game/network/network.impl.h index c1f079d..ff29088 100644 --- a/game/network/network.impl.h +++ b/game/network/network.impl.h @@ -2,17 +2,6 @@ #include #include -template -void -NetworkOf::render(const SceneShader & shader) const -{ - if constexpr (std::is_base_of_v) { - shader.absolute.use(); - texture->bind(); - links.apply(&Renderable::render, shader); - } -} - template void NetworkOf::joinLinks(const Link::Ptr & l) const diff --git a/game/network/rail.cpp b/game/network/rail.cpp index 3d29ea5..9766851 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -127,7 +127,7 @@ RailLinkStraight::RailLinkStraight( NetworkLinkHolder & instances, Node::Ptr a, Node::Ptr b, const RelativePosition3D & diff) : Link({std::move(a), vector_yaw(diff)}, {std::move(b), vector_yaw(-diff)}, glm::length(diff)), instance {instances.vertices.acquire( - ends[0].node->pos, ends[1].node->pos, flat_orientation(diff), round_sleepers(length / 2.F))} + ends[0].node->pos, ends[1].node->pos, flat_orientation(diff), round_sleepers(length / 2000.F))} { if (glGenVertexArrays) { std::vector<::Vertex> vertices; @@ -155,7 +155,7 @@ RailLinkCurve::RailLinkCurve(NetworkLinkHolder & instances, const Link({a, normalize(arc.first + half_pi)}, {b, normalize(arc.second - half_pi)}, glm::length(RelativePosition3D(a->pos - c)) * arc_length(arc)), LinkCurve {c, glm::length(RelativePosition3D(ends[0].node->pos - c)), arc}, - instance {instances.vertices.acquire(ends[0].node->pos, ends[1].node->pos, c, round_sleepers(length / 2.F))} + instance {instances.vertices.acquire(ends[0].node->pos, ends[1].node->pos, c, round_sleepers(length / 2000.F))} { if (glGenVertexArrays) { @@ -185,3 +185,21 @@ RailLink::vehiclePositionOffset() const { return RAIL_HEIGHT; } + +void +RailLinks::render(const SceneShader & shader) const +{ + auto renderType = [](auto & v, auto & s) { + if (auto count = v.size()) { + s.use(); + glBindBuffer(GL_VERTEX_ARRAY, v.bufferName()); + glDrawArrays(GL_POINTS, 0, static_cast(count)); + } + }; + if (!links.objects.empty()) { + texture->bind(); + renderType(NetworkLinkHolder::vertices, shader.networkStraight); + renderType(NetworkLinkHolder::vertices, shader.networkCurve); + glBindBuffer(GL_VERTEX_ARRAY, 0); + } +} diff --git a/game/network/rail.h b/game/network/rail.h index e06568f..5191b90 100644 --- a/game/network/rail.h +++ b/game/network/rail.h @@ -77,6 +77,7 @@ public: RailLinks(); std::shared_ptr addLinksBetween(GlobalPosition3D start, GlobalPosition3D end); + void render(const SceneShader &) const override; private: void tick(TickDuration elapsed) override; -- cgit v1.2.3 From 538af692b66e67dfa4f347cc9ddd784a36f9a991 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Jan 2024 01:23:53 +0000 Subject: Update network with vertex array --- game/network/network.h | 5 ++++- game/network/rail.cpp | 37 +++++++++++++++++++++++++++++-------- game/network/rail.h | 3 +++ 3 files changed, 36 insertions(+), 9 deletions(-) (limited to 'game') diff --git a/game/network/network.h b/game/network/network.h index 49322f9..5725360 100644 --- a/game/network/network.h +++ b/game/network/network.h @@ -60,8 +60,11 @@ protected: }; template class NetworkLinkHolder { -protected: +public: + // Implemented per LinkType to configure vao + NetworkLinkHolder(); friend LinkType; + glVertexArray vao; mutable InstanceVertices vertices; }; diff --git a/game/network/rail.cpp b/game/network/rail.cpp index 9766851..efe4e2d 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -186,20 +186,41 @@ RailLink::vehiclePositionOffset() const return RAIL_HEIGHT; } -void -RailLinks::render(const SceneShader & shader) const +template<> NetworkLinkHolder::NetworkLinkHolder() +{ + VertexArrayObject {vao} + .addAttribs( + vertices.bufferName()); +} + +template<> NetworkLinkHolder::NetworkLinkHolder() { - auto renderType = [](auto & v, auto & s) { - if (auto count = v.size()) { + VertexArrayObject {vao} + .addAttribs(vertices.bufferName()); +} + +namespace { + template + void + renderType(const NetworkLinkHolder & n, auto & s) + { + if (auto count = n.vertices.size()) { s.use(); - glBindBuffer(GL_VERTEX_ARRAY, v.bufferName()); + glBindVertexArray(n.vao); glDrawArrays(GL_POINTS, 0, static_cast(count)); } }; +} + +void +RailLinks::render(const SceneShader & shader) const +{ if (!links.objects.empty()) { texture->bind(); - renderType(NetworkLinkHolder::vertices, shader.networkStraight); - renderType(NetworkLinkHolder::vertices, shader.networkCurve); - glBindBuffer(GL_VERTEX_ARRAY, 0); + renderType(*this, shader.networkStraight); + renderType(*this, shader.networkCurve); + glBindVertexArray(0); } } diff --git a/game/network/rail.h b/game/network/rail.h index 5191b90..b6a9ebe 100644 --- a/game/network/rail.h +++ b/game/network/rail.h @@ -72,6 +72,9 @@ private: InstanceVertices::InstanceProxy instance; }; +template<> NetworkLinkHolder::NetworkLinkHolder(); +template<> NetworkLinkHolder::NetworkLinkHolder(); + class RailLinks : public NetworkOf, public WorldObject { public: RailLinks(); -- cgit v1.2.3 From a19011b730ac6d770e3b42cde3a10961495a417d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Jan 2024 20:10:12 +0000 Subject: Implement basic network curve part shader --- game/network/rail.cpp | 7 ++++--- game/network/rail.h | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'game') diff --git a/game/network/rail.cpp b/game/network/rail.cpp index efe4e2d..46c129b 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -155,8 +155,8 @@ RailLinkCurve::RailLinkCurve(NetworkLinkHolder & instances, const Link({a, normalize(arc.first + half_pi)}, {b, normalize(arc.second - half_pi)}, glm::length(RelativePosition3D(a->pos - c)) * arc_length(arc)), LinkCurve {c, glm::length(RelativePosition3D(ends[0].node->pos - c)), arc}, - instance {instances.vertices.acquire(ends[0].node->pos, ends[1].node->pos, c, round_sleepers(length / 2000.F))} - + instance {instances.vertices.acquire(ends[0].node->pos, ends[1].node->pos, c, round_sleepers(length / 2000.F), + half_pi - arc.first, half_pi - arc.second)} { if (glGenVertexArrays) { const auto & e0p {ends[0].node->pos}; @@ -198,7 +198,8 @@ template<> NetworkLinkHolder::NetworkLinkHolder() { VertexArrayObject {vao} .addAttribs(vertices.bufferName()); + &RailLinkCurve::Vertex::c, &RailLinkCurve::Vertex::textureRepeats, &RailLinkCurve::Vertex::aangle, + &RailLinkCurve::Vertex::bangle>(vertices.bufferName()); } namespace { diff --git a/game/network/rail.h b/game/network/rail.h index b6a9ebe..39dfdc9 100644 --- a/game/network/rail.h +++ b/game/network/rail.h @@ -64,6 +64,7 @@ public: struct Vertex { GlobalPosition3D a, b, c; float textureRepeats; + float aangle, bangle; }; private: -- cgit v1.2.3 From 35a9f035963458156c719dc16f4073b8244d66eb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Jan 2024 23:27:01 +0000 Subject: Pass curve link radius, no recalculate, its constant --- game/network/rail.cpp | 4 ++-- game/network/rail.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'game') diff --git a/game/network/rail.cpp b/game/network/rail.cpp index 46c129b..b500006 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -156,7 +156,7 @@ RailLinkCurve::RailLinkCurve(NetworkLinkHolder & instances, const glm::length(RelativePosition3D(a->pos - c)) * arc_length(arc)), LinkCurve {c, glm::length(RelativePosition3D(ends[0].node->pos - c)), arc}, instance {instances.vertices.acquire(ends[0].node->pos, ends[1].node->pos, c, round_sleepers(length / 2000.F), - half_pi - arc.first, half_pi - arc.second)} + half_pi - arc.first, half_pi - arc.second, radius)} { if (glGenVertexArrays) { const auto & e0p {ends[0].node->pos}; @@ -199,7 +199,7 @@ template<> NetworkLinkHolder::NetworkLinkHolder() VertexArrayObject {vao} .addAttribs(vertices.bufferName()); + &RailLinkCurve::Vertex::bangle, &RailLinkCurve::Vertex::radius>(vertices.bufferName()); } namespace { diff --git a/game/network/rail.h b/game/network/rail.h index 39dfdc9..a95ba04 100644 --- a/game/network/rail.h +++ b/game/network/rail.h @@ -64,7 +64,7 @@ public: struct Vertex { GlobalPosition3D a, b, c; float textureRepeats; - float aangle, bangle; + float aangle, bangle, radius; }; private: -- cgit v1.2.3 From 80ff7597e0d6b083d1ad4c7c7b758379de69786d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 21 Jan 2024 03:36:03 +0000 Subject: Remove the old custom mesh per network link rendering --- game/network/rail.cpp | 65 +++------------------------------------------------ game/network/rail.h | 8 +------ 2 files changed, 4 insertions(+), 69 deletions(-) (limited to 'game') diff --git a/game/network/rail.cpp b/game/network/rail.cpp index b500006..216ec1c 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -1,17 +1,9 @@ #include "rail.h" #include "network.h" -#include -#include -#include -#include -#include #include // IWYU pragma: keep -#include -#include -#include -#include -#include -#include +#include +#include +#include template class NetworkOf; @@ -81,24 +73,6 @@ RailLinks::addLinksBetween(GlobalPosition3D start, GlobalPosition3D end) return addLink(start, end, centre.first); } -Mesh::Ptr -RailLink::defaultMesh(const std::span vertices) -{ - std::vector indices; - for (auto n = RAIL_CROSSSECTION_VERTICES; n < vertices.size(); n += 1) { - indices.push_back(n - RAIL_CROSSSECTION_VERTICES); - indices.push_back(n); - } - - return std::make_unique(vertices, indices, GL_TRIANGLE_STRIP); -} - -void -RailLink::render(const SceneShader &) const -{ - mesh->Draw(); -} - constexpr const std::array, RAIL_CROSSSECTION_VERTICES> railCrossSection {{ // ___________ // _/ \_ @@ -129,19 +103,6 @@ RailLinkStraight::RailLinkStraight( instance {instances.vertices.acquire( ends[0].node->pos, ends[1].node->pos, flat_orientation(diff), round_sleepers(length / 2000.F))} { - if (glGenVertexArrays) { - std::vector<::Vertex> vertices; - vertices.reserve(2 * railCrossSection.size()); - const auto len = round_sleepers(length / 2000.F); - const glm::mat3 trans {flat_orientation(diff)}; - for (auto ei : {1U, 0U}) { - for (const auto & rcs : railCrossSection) { - const auto m {ends[ei].node->pos + GlobalPosition3D(trans * rcs.first)}; - vertices.emplace_back(m, TextureRelCoord {rcs.second, len * static_cast(ei)}, up); - } - } - mesh = defaultMesh(vertices); - } } RailLinkCurve::RailLinkCurve( @@ -158,26 +119,6 @@ RailLinkCurve::RailLinkCurve(NetworkLinkHolder & instances, const instance {instances.vertices.acquire(ends[0].node->pos, ends[1].node->pos, c, round_sleepers(length / 2000.F), half_pi - arc.first, half_pi - arc.second, radius)} { - if (glGenVertexArrays) { - const auto & e0p {ends[0].node->pos}; - const auto & e1p {ends[1].node->pos}; - const auto slength = round_sleepers(length / 2.F); - const auto segs = std::round(slength / std::pow(radius, 0.7F)); - const auto step {RelativePosition3D {arc_length(arc), e1p.z - e0p.z, slength / 1000.F} / segs}; - - auto segCount = static_cast(std::lround(segs)) + 1; - std::vector<::Vertex> vertices; - vertices.reserve(segCount * railCrossSection.size()); - for (RelativePosition3D swing = {arc.first, centreBase.z - e0p.z, 0.F}; segCount; swing += step, --segCount) { - const auto t { - glm::rotate(half_pi - swing.x, up) * glm::translate(RelativePosition3D {radius, 0.F, swing.y})}; - for (const auto & rcs : railCrossSection) { - const auto m {centreBase + GlobalPosition3D(t * (rcs.first || 1.F))}; - vertices.emplace_back(m, TextureRelCoord {rcs.second, swing.z}, up); - } - } - mesh = defaultMesh(vertices); - } } RelativePosition3D diff --git a/game/network/rail.h b/game/network/rail.h index a95ba04..c8effef 100644 --- a/game/network/rail.h +++ b/game/network/rail.h @@ -2,13 +2,11 @@ #include "chronology.h" #include "game/worldobject.h" -#include "gfx/models/mesh.h" #include "gfx/renderable.h" #include "link.h" #include "network.h" #include #include -#include #include class SceneShader; @@ -19,7 +17,7 @@ struct Arc; class RailLinkStraight; class RailLinkCurve; -class RailLink : public virtual Link, public Renderable { +class RailLink : public virtual Link { public: RailLink() = default; inline ~RailLink() override = 0; @@ -27,15 +25,11 @@ public: using StraightLink = RailLinkStraight; using CurveLink = RailLinkCurve; - void render(const SceneShader &) const override; NO_COPY(RailLink); NO_MOVE(RailLink); protected: [[nodiscard]] RelativePosition3D vehiclePositionOffset() const override; - [[nodiscard]] static Mesh::Ptr defaultMesh(const std::span vertices); - - Mesh::Ptr mesh; }; RailLink::~RailLink() = default; -- cgit v1.2.3 From 961f69d8cda0364c04ec98efc70a6f21e0a091e6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 22 Jan 2024 02:25:47 +0000 Subject: Bind the network profile in as uniforms Makes the network shaders generic to network type --- game/network/rail.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'game') diff --git a/game/network/rail.cpp b/game/network/rail.cpp index 216ec1c..176a704 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -73,16 +73,20 @@ RailLinks::addLinksBetween(GlobalPosition3D start, GlobalPosition3D end) return addLink(start, end, centre.first); } -constexpr const std::array, RAIL_CROSSSECTION_VERTICES> railCrossSection {{ - // ___________ - // _/ \_ - // left to right - {{-1900.F, 0.F, 0.F}, 0.F}, - {{-608.F, 0.F, RAIL_HEIGHT.z}, .34F}, - {{0, 0.F, RAIL_HEIGHT.z * .7F}, .5F}, - {{608.F, 0.F, RAIL_HEIGHT.z}, .66F}, - {{1900.F, 0.F, 0.F}, 1.F}, +constexpr const std::array railCrossSection {{ + {-1900.F, 0.F, 0.F}, + {-608.F, 0.F, RAIL_HEIGHT.z}, + {0, 0.F, RAIL_HEIGHT.z * .7F}, + {608.F, 0.F, RAIL_HEIGHT.z}, + {1900.F, 0.F, 0.F}, }}; +constexpr const std::array railTexturePos { + 0.F, + .34F, + .5F, + .66F, + 1.F, +}; constexpr auto sleepers {5.F}; // There are 5 repetitions of sleepers in the texture inline auto @@ -149,7 +153,7 @@ namespace { renderType(const NetworkLinkHolder & n, auto & s) { if (auto count = n.vertices.size()) { - s.use(); + s.use(railCrossSection, railTexturePos); glBindVertexArray(n.vao); glDrawArrays(GL_POINTS, 0, static_cast(count)); } -- cgit v1.2.3