diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-19 00:23:56 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-20 15:08:43 +0000 |
commit | c7af64b7061c59c987958d0830838f1c05caeb29 (patch) | |
tree | 8195696b2130eb6a2674c075416b15a352440b61 /game | |
parent | Copy render vital link data to vertex buffer (diff) | |
download | ilt-c7af64b7061c59c987958d0830838f1c05caeb29.tar.bz2 ilt-c7af64b7061c59c987958d0830838f1c05caeb29.tar.xz ilt-c7af64b7061c59c987958d0830838f1c05caeb29.zip |
Render rail network using new shaders
Non-functional, totally unimplemented at this stage
Diffstat (limited to 'game')
-rw-r--r-- | game/network/network.h | 3 | ||||
-rw-r--r-- | game/network/network.impl.h | 11 | ||||
-rw-r--r-- | game/network/rail.cpp | 22 | ||||
-rw-r--r-- | game/network/rail.h | 1 |
4 files changed, 22 insertions, 15 deletions
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<typename LinkType> class NetworkLinkHolder { +protected: friend LinkType; mutable InstanceVertices<typename LinkType::Vertex> 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 @@ -4,17 +4,6 @@ template<typename T, typename... Links> void -NetworkOf<T, Links...>::render(const SceneShader & shader) const -{ - if constexpr (std::is_base_of_v<Renderable, T>) { - shader.absolute.use(); - texture->bind(); - links.apply(&Renderable::render, shader); - } -} - -template<typename T, typename... Links> -void NetworkOf<T, Links...>::joinLinks(const Link::Ptr & l) const { for (const auto & ol : links.objects) { 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<RailLinkStraight> & 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<RailLinkCurve> & 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<GLsizei>(count)); + } + }; + if (!links.objects.empty()) { + texture->bind(); + renderType(NetworkLinkHolder<RailLinkStraight>::vertices, shader.networkStraight); + renderType(NetworkLinkHolder<RailLinkCurve>::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<RailLink> addLinksBetween(GlobalPosition3D start, GlobalPosition3D end); + void render(const SceneShader &) const override; private: void tick(TickDuration elapsed) override; |