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/network') 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