diff options
Diffstat (limited to 'game/network')
-rw-r--r-- | game/network/network.h | 5 | ||||
-rw-r--r-- | game/network/rail.cpp | 37 | ||||
-rw-r--r-- | game/network/rail.h | 3 |
3 files changed, 36 insertions, 9 deletions
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<typename LinkType> class NetworkLinkHolder { -protected: +public: + // Implemented per LinkType to configure vao + NetworkLinkHolder(); friend LinkType; + glVertexArray vao; mutable InstanceVertices<typename LinkType::Vertex> 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<RailLinkStraight>::NetworkLinkHolder() +{ + VertexArrayObject {vao} + .addAttribs<RailLinkStraight::Vertex, &RailLinkStraight::Vertex::a, &RailLinkStraight::Vertex::b, + &RailLinkStraight::Vertex::rotation, &RailLinkStraight::Vertex::textureRepeats>( + vertices.bufferName()); +} + +template<> NetworkLinkHolder<RailLinkCurve>::NetworkLinkHolder() { - auto renderType = [](auto & v, auto & s) { - if (auto count = v.size()) { + VertexArrayObject {vao} + .addAttribs<RailLinkCurve::Vertex, &RailLinkCurve::Vertex::a, &RailLinkCurve::Vertex::b, + &RailLinkCurve::Vertex::c, &RailLinkCurve::Vertex::textureRepeats>(vertices.bufferName()); +} + +namespace { + template<typename LinkType> + void + renderType(const NetworkLinkHolder<LinkType> & 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<GLsizei>(count)); } }; +} + +void +RailLinks::render(const SceneShader & shader) const +{ if (!links.objects.empty()) { texture->bind(); - renderType(NetworkLinkHolder<RailLinkStraight>::vertices, shader.networkStraight); - renderType(NetworkLinkHolder<RailLinkCurve>::vertices, shader.networkCurve); - glBindBuffer(GL_VERTEX_ARRAY, 0); + renderType<RailLinkStraight>(*this, shader.networkStraight); + renderType<RailLinkCurve>(*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<Vertex>::InstanceProxy instance; }; +template<> NetworkLinkHolder<RailLinkStraight>::NetworkLinkHolder(); +template<> NetworkLinkHolder<RailLinkCurve>::NetworkLinkHolder(); + class RailLinks : public NetworkOf<RailLink, RailLinkStraight, RailLinkCurve>, public WorldObject { public: RailLinks(); |