summaryrefslogtreecommitdiff
path: root/game/terrain.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-05-27 13:44:08 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-05-27 13:44:08 +0100
commitad85d0843dc80d195120dd53dd4a8deee004af4b (patch)
tree420723815ac6753441f14fe51836555de5551a19 /game/terrain.cpp
parentMerge branch 'separate-water' (diff)
parentSurface asset test doesn't need render dump (diff)
downloadilt-ad85d0843dc80d195120dd53dd4a8deee004af4b.tar.bz2
ilt-ad85d0843dc80d195120dd53dd4a8deee004af4b.tar.xz
ilt-ad85d0843dc80d195120dd53dd4a8deee004af4b.zip
Merge remote-tracking branch 'origin/terrain-surfaces'
Diffstat (limited to 'game/terrain.cpp')
-rw-r--r--game/terrain.cpp38
1 files changed, 28 insertions, 10 deletions
diff --git a/game/terrain.cpp b/game/terrain.cpp
index 201c732..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()
{
@@ -27,21 +37,29 @@ Terrain::generateMeshes()
indices.reserve(geoData->n_faces() * 3);
std::vector<Vertex> vertices;
vertices.reserve(geoData->n_vertices());
- std::map<GeoData::VertexHandle, size_t> vertexIndex;
- std::transform(geoData->vertices_sbegin(), geoData->vertices_end(), std::back_inserter(vertices),
- [this, &vertexIndex](const GeoData::VertexHandle v) {
- vertexIndex.emplace(v, vertexIndex.size());
- const auto p = geoData->point(v);
- return Vertex {p, RelativePosition2D(p) / 10000.F, geoData->normal(v)};
+ std::map<std::pair<GeoData::VertexHandle, const Surface *>, size_t> vertexIndex;
+ std::for_each(geoData->vertices_sbegin(), geoData->vertices_end(),
+ [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) {
+ 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();
+
+ vertices.emplace_back(geoData->point(v), geoData->normal(v),
+ surface ? surface->colorBias : openSurface);
+ }
+ });
});
std::for_each(
geoData->faces_sbegin(), geoData->faces_end(), [this, &vertexIndex, &indices](const GeoData::FaceHandle f) {
std::transform(geoData->fv_begin(f), geoData->fv_end(f), std::back_inserter(indices),
- [&vertexIndex](const GeoData::VertexHandle v) {
- return vertexIndex[v];
+ [&vertexIndex, f, this](const GeoData::VertexHandle v) {
+ return vertexIndex[std::make_pair(v, geoData->get_surface(f))];
});
});
- meshes.create<Mesh>(vertices, indices);
+ meshes.create<MeshT<Vertex>>(vertices, indices);
}
void
@@ -60,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);
}