summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game/network/network.h5
-rw-r--r--game/network/rail.cpp37
-rw-r--r--game/network/rail.h3
-rw-r--r--test/test-network.cpp2
4 files changed, 38 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();
diff --git a/test/test-network.cpp b/test/test-network.cpp
index df61b94..174e2a5 100644
--- a/test/test-network.cpp
+++ b/test/test-network.cpp
@@ -52,6 +52,8 @@ struct TestLinkS : public TestLink, public LinkStraight {
constexpr GlobalPosition3D p000 {0, 0, 0}, p100 {10000, 0, 0}, p200 {20000, 0, 0}, p300 {30000, 0, 0};
constexpr GlobalPosition3D p110 {10000, 10000, 0};
+template<> NetworkLinkHolder<TestLinkS>::NetworkLinkHolder() = default;
+
struct TestNetwork : public NetworkOf<TestLink, TestLinkS> {
TestNetwork() : NetworkOf<TestLink, TestLinkS> {RESDIR "rails.jpg"}
{