summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
Diffstat (limited to 'game')
-rw-r--r--game/terrain.cpp22
-rw-r--r--game/terrain.h9
2 files changed, 24 insertions, 7 deletions
diff --git a/game/terrain.cpp b/game/terrain.cpp
index c19bd0a..3b16e79 100644
--- a/game/terrain.cpp
+++ b/game/terrain.cpp
@@ -15,11 +15,21 @@
#include <utility>
#include <vector>
+static constexpr RGB openSurface {-1};
+
Terrain::Terrain(std::shared_ptr<GeoData> tm) : geoData {std::move(tm)}, grass {std::make_shared<Texture>("grass.png")}
{
generateMeshes();
}
+template<>
+VertexArrayObject &
+VertexArrayObject::addAttribsFor<Terrain::Vertex>(const GLuint arrayBuffer, const GLuint divisor)
+{
+ return addAttribs<Terrain::Vertex, &Terrain::Vertex::pos, &Terrain::Vertex::normal, &Terrain::Vertex::colourBias>(
+ arrayBuffer, divisor);
+}
+
void
Terrain::generateMeshes()
{
@@ -32,13 +42,13 @@ Terrain::generateMeshes()
[this, &vertexIndex, &vertices](const GeoData::VertexHandle v) {
std::for_each(geoData->vf_begin(v), geoData->vf_end(v),
[&vertexIndex, v, this, &vertices](const GeoData::FaceHandle f) {
- if (const auto vertexIndexRef
- = vertexIndex.emplace(std::make_pair(v, geoData->get_surface(f)), 0);
+ const auto surface = geoData->get_surface(f);
+ if (const auto vertexIndexRef = vertexIndex.emplace(std::make_pair(v, surface), 0);
vertexIndexRef.second) {
vertexIndexRef.first->second = vertices.size();
- const auto p = geoData->point(v);
- vertices.emplace_back(p, RelativePosition2D(p) / 10000.F, geoData->normal(v));
+ vertices.emplace_back(geoData->point(v), geoData->normal(v),
+ surface ? surface->colorBias : openSurface);
}
});
});
@@ -49,7 +59,7 @@ Terrain::generateMeshes()
return vertexIndex[std::make_pair(v, geoData->get_surface(f))];
});
});
- meshes.create<Mesh>(vertices, indices);
+ meshes.create<MeshT<Vertex>>(vertices, indices);
}
void
@@ -68,6 +78,6 @@ Terrain::render(const SceneShader & shader) const
void
Terrain::shadows(const ShadowMapper & shadowMapper) const
{
- shadowMapper.fixedPoint.use();
+ shadowMapper.landmess.use();
meshes.apply(&Mesh::Draw);
}
diff --git a/game/terrain.h b/game/terrain.h
index 54593fc..d088f89 100644
--- a/game/terrain.h
+++ b/game/terrain.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,16 @@ public:
void tick(TickDuration) override;
+ struct Vertex {
+ GlobalPosition3D pos;
+ Normal3D normal;
+ RGB colourBias;
+ };
+
private:
void generateMeshes();
std::shared_ptr<GeoData> geoData;
- Collection<Mesh, false> meshes;
+ Collection<MeshT<Vertex>, false> meshes;
std::shared_ptr<Texture> grass;
};