summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-01-19 00:23:56 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-01-20 15:08:43 +0000
commitc7af64b7061c59c987958d0830838f1c05caeb29 (patch)
tree8195696b2130eb6a2674c075416b15a352440b61
parentCopy render vital link data to vertex buffer (diff)
downloadilt-c7af64b7061c59c987958d0830838f1c05caeb29.tar.bz2
ilt-c7af64b7061c59c987958d0830838f1c05caeb29.tar.xz
ilt-c7af64b7061c59c987958d0830838f1c05caeb29.zip
Render rail network using new shaders
Non-functional, totally unimplemented at this stage
-rw-r--r--game/network/network.h3
-rw-r--r--game/network/network.impl.h11
-rw-r--r--game/network/rail.cpp22
-rw-r--r--game/network/rail.h1
-rw-r--r--gfx/gl/sceneShader.cpp17
-rw-r--r--gfx/gl/sceneShader.h1
-rw-r--r--gfx/gl/shaders/network.fs6
-rw-r--r--gfx/gl/shaders/networkCurve.gs9
-rw-r--r--gfx/gl/shaders/networkCurve.vs20
-rw-r--r--gfx/gl/shaders/networkStraight.gs15
-rw-r--r--gfx/gl/shaders/networkStraight.vs20
-rw-r--r--test/test-network.cpp5
12 files changed, 110 insertions, 20 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;
diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp
index 1b3b27c..146e642 100644
--- a/gfx/gl/sceneShader.cpp
+++ b/gfx/gl/sceneShader.cpp
@@ -1,14 +1,19 @@
#include "sceneShader.h"
#include <gfx/gl/shaders/fs-landmass.h>
#include <gfx/gl/shaders/fs-material.h>
+#include <gfx/gl/shaders/fs-network.h>
#include <gfx/gl/shaders/fs-pointLight.h>
#include <gfx/gl/shaders/fs-spotLight.h>
#include <gfx/gl/shaders/fs-water.h>
+#include <gfx/gl/shaders/gs-networkCurve.h>
+#include <gfx/gl/shaders/gs-networkStraight.h>
#include <gfx/gl/shaders/gs-pointLight.h>
#include <gfx/gl/shaders/gs-spotLight.h>
#include <gfx/gl/shaders/vs-dynamicPoint.h>
#include <gfx/gl/shaders/vs-dynamicPointInst.h>
#include <gfx/gl/shaders/vs-fixedPoint.h>
+#include <gfx/gl/shaders/vs-networkCurve.h>
+#include <gfx/gl/shaders/vs-networkStraight.h>
#include <gfx/gl/shaders/vs-pointLight.h>
#include <gfx/gl/shaders/vs-spotLight.h>
#include <gfx/gl/shaders/vs-water.h>
@@ -21,15 +26,17 @@
SceneShader::SceneShader() :
basicInst {dynamicPointInst_vs, material_fs}, landmass {fixedPoint_vs, landmass_fs},
absolute {fixedPoint_vs, material_fs}, spotLightInst {spotLight_vs, spotLight_gs, spotLight_fs},
- pointLightInst {pointLight_vs, pointLight_gs, pointLight_fs}
+ pointLightInst {pointLight_vs, pointLight_gs, pointLight_fs},
+ networkStraight {networkStraight_vs, networkStraight_gs, network_fs},
+ networkCurve {networkCurve_vs, networkCurve_gs, network_fs}
{
}
void
SceneShader::setViewProjection(const GlobalPosition3D & viewPoint, const glm::mat4 & viewProjection) const
{
- for (const auto & prog : std::initializer_list<const SceneProgram *> {
- &basic, &basicInst, &water, &landmass, &absolute, &pointLightInst, &spotLightInst}) {
+ for (const auto & prog : std::initializer_list<const SceneProgram *> {&basic, &basicInst, &water, &landmass,
+ &absolute, &pointLightInst, &spotLightInst, &networkStraight, &networkCurve}) {
prog->setViewProjection(viewPoint, viewProjection);
}
}
@@ -37,8 +44,8 @@ SceneShader::setViewProjection(const GlobalPosition3D & viewPoint, const glm::ma
void
SceneShader::setViewPort(const ViewPort & viewPort) const
{
- for (const auto & prog : std::initializer_list<const SceneProgram *> {
- &basic, &basicInst, &water, &landmass, &absolute, &pointLightInst, &spotLightInst}) {
+ for (const auto & prog : std::initializer_list<const SceneProgram *> {&basic, &basicInst, &water, &landmass,
+ &absolute, &pointLightInst, &spotLightInst, &networkStraight, &networkCurve}) {
prog->setViewPort(viewPort);
}
}
diff --git a/gfx/gl/sceneShader.h b/gfx/gl/sceneShader.h
index 813c1bf..c86d157 100644
--- a/gfx/gl/sceneShader.h
+++ b/gfx/gl/sceneShader.h
@@ -57,6 +57,7 @@ public:
BasicProgram basic;
WaterProgram water;
AbsolutePosProgram basicInst, landmass, absolute, spotLightInst, pointLightInst;
+ AbsolutePosProgram networkStraight, networkCurve;
void setViewProjection(const GlobalPosition3D & viewPoint, const glm::mat4 & viewProjection) const;
void setViewPort(const ViewPort & viewPort) const;
diff --git a/gfx/gl/shaders/network.fs b/gfx/gl/shaders/network.fs
new file mode 100644
index 0000000..d427da2
--- /dev/null
+++ b/gfx/gl/shaders/network.fs
@@ -0,0 +1,6 @@
+#version 330 core
+
+void
+main()
+{
+}
diff --git a/gfx/gl/shaders/networkCurve.gs b/gfx/gl/shaders/networkCurve.gs
new file mode 100644
index 0000000..cf70b6e
--- /dev/null
+++ b/gfx/gl/shaders/networkCurve.gs
@@ -0,0 +1,9 @@
+#version 330 core
+
+layout(points) in;
+layout(triangle_strip, max_vertices = 255) out;
+
+void
+main()
+{
+}
diff --git a/gfx/gl/shaders/networkCurve.vs b/gfx/gl/shaders/networkCurve.vs
new file mode 100644
index 0000000..b4324d6
--- /dev/null
+++ b/gfx/gl/shaders/networkCurve.vs
@@ -0,0 +1,20 @@
+#version 330 core
+
+layout(location = 0) in ivec3 v_apos;
+layout(location = 1) in ivec3 v_bpos;
+layout(location = 2) in ivec3 v_centre;
+layout(location = 3) in float v_reps;
+
+uniform mat4 viewProjection;
+
+flat out ivec3 apos;
+flat out ivec3 bpos;
+flat out mat2 rot;
+flat out float reps;
+flat out float dist;
+
+void
+main()
+{
+ dist = viewProjection[0][0];
+}
diff --git a/gfx/gl/shaders/networkStraight.gs b/gfx/gl/shaders/networkStraight.gs
new file mode 100644
index 0000000..c2bfe3f
--- /dev/null
+++ b/gfx/gl/shaders/networkStraight.gs
@@ -0,0 +1,15 @@
+#version 330 core
+
+flat in ivec3 apos[];
+flat in ivec3 bpos[];
+flat in mat2 rot[];
+flat in float reps[];
+flat in float dist[];
+
+layout(points) in;
+layout(triangle_strip, max_vertices = 20) out;
+
+void
+main()
+{
+}
diff --git a/gfx/gl/shaders/networkStraight.vs b/gfx/gl/shaders/networkStraight.vs
new file mode 100644
index 0000000..025ae8f
--- /dev/null
+++ b/gfx/gl/shaders/networkStraight.vs
@@ -0,0 +1,20 @@
+#version 330 core
+
+layout(location = 0) in ivec3 v_apos;
+layout(location = 1) in ivec3 v_bpos;
+layout(location = 2) in mat2 v_rot;
+layout(location = 4) in float v_reps;
+
+uniform mat4 viewProjection;
+
+flat out ivec3 apos;
+flat out ivec3 bpos;
+flat out mat2 rot;
+flat out float reps;
+flat out float dist;
+
+void
+main()
+{
+ dist = viewProjection[0][0];
+}
diff --git a/test/test-network.cpp b/test/test-network.cpp
index dbc184d..df61b94 100644
--- a/test/test-network.cpp
+++ b/test/test-network.cpp
@@ -68,6 +68,11 @@ struct TestNetwork : public NetworkOf<TestLink, TestLinkS> {
addLink<TestLinkS>(p200, p110, 2.F);
addLink<TestLinkS>(p100, p110, 1.F);
}
+
+ void
+ render(const SceneShader &) const override
+ {
+ }
};
const auto VALID_NODES = boost::unit_test::data::make<GlobalPosition3D>({