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