diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-04-07 19:38:18 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-04-07 19:38:18 +0100 |
commit | 97d4db588bfc4254e09e4305fb0525a04748f84e (patch) | |
tree | 049049622e338b3ad72d9b1639a51b65250caeba /game | |
parent | Create water squares/polygons only where required (diff) | |
download | ilt-97d4db588bfc4254e09e4305fb0525a04748f84e.tar.bz2 ilt-97d4db588bfc4254e09e4305fb0525a04748f84e.tar.xz ilt-97d4db588bfc4254e09e4305fb0525a04748f84e.zip |
Stripped down water vertex and simplified shaders
Diffstat (limited to 'game')
-rw-r--r-- | game/water.cpp | 15 | ||||
-rw-r--r-- | game/water.h | 7 |
2 files changed, 16 insertions, 6 deletions
diff --git a/game/water.cpp b/game/water.cpp index 3dc1916..f720e3e 100644 --- a/game/water.cpp +++ b/game/water.cpp @@ -9,7 +9,6 @@ #include <gfx/models/mesh.h> #include <gfx/models/vertex.h> #include <glm/glm.hpp> -#include <iterator> #include <location.h> #include <maths.h> #include <set> @@ -24,6 +23,13 @@ namespace glm { } } +template<> +VertexArrayObject & +VertexArrayObject::addAttribsFor<Water::Vertex>(const GLuint arrayBuffer, const GLuint divisor) +{ + return addAttribs<Water::Vertex, &Water::Vertex::pos>(arrayBuffer, divisor); +} + Water::Water(std::shared_ptr<GeoData> tm) : geoData {std::move(tm)}, water {std::make_shared<Texture>("water.png")} { generateMeshes(); @@ -77,8 +83,7 @@ Water::generateMeshes() const auto v = vertexIndex.emplace(pos, vertices.size()); if (v.second) { const auto cpos = glm::clamp(pos, std::get<0>(extents).xy(), std::get<1>(extents).xy()); - vertices.emplace_back(RelativePosition3D {geoData->positionAt(cpos)}, - TextureRelCoord(pos / TILE_SIZE), up); + vertices.emplace_back(geoData->positionAt(cpos)); } *out++ = static_cast<unsigned int>(v.first->second); } @@ -87,7 +92,7 @@ Water::generateMeshes() indices.push_back(currentIndices[i]); } }); - meshes.create<Mesh>(vertices, indices); + meshes.create<MeshT<Vertex>>(vertices, indices); } void @@ -101,5 +106,5 @@ Water::render(const SceneShader & shader) const { shader.water.use(waveCycle); water->bind(); - meshes.apply(&Mesh::Draw); + meshes.apply(&MeshT<GlobalPosition3D>::Draw); } diff --git a/game/water.h b/game/water.h index 20796d7..ceb7bd2 100644 --- a/game/water.h +++ b/game/water.h @@ -2,6 +2,7 @@ #include "chronology.h" #include "collection.h" +#include "config/types.h" #include "game/worldobject.h" #include <gfx/models/mesh.h> #include <gfx/renderable.h> @@ -20,10 +21,14 @@ public: void tick(TickDuration) override; float waveCycle {0.F}; + struct Vertex { + GlobalPosition3D pos; + }; + private: void generateMeshes(); std::shared_ptr<GeoData> geoData; - Collection<Mesh, false> meshes; + Collection<MeshT<Vertex>, false> meshes; std::shared_ptr<Texture> water; }; |