summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2026-03-07 12:32:55 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2026-03-07 14:17:44 +0000
commit4420f20a901ed1f96d9fb8f4df0148bc0bc3666d (patch)
treeb6484d3a75acb1c9461707d2c7168fa5b652b15c
parentDon't create and then replace shadow and billboard textures (diff)
downloadilt-4420f20a901ed1f96d9fb8f4df0148bc0bc3666d.tar.bz2
ilt-4420f20a901ed1f96d9fb8f4df0148bc0bc3666d.tar.xz
ilt-4420f20a901ed1f96d9fb8f4df0148bc0bc3666d.zip
Add glVertexArray useBuffer
Wraps glVertexArrayVertexBuffer automatically getting the buffer name from the argument and deriving the stride from the container's value_type.
-rw-r--r--game/network/rail.cpp3
-rw-r--r--game/scenary/foliage.cpp8
-rw-r--r--game/scenary/illuminator.cpp12
-rw-r--r--game/vehicles/railVehicleClass.cpp7
-rw-r--r--gfx/gl/glVertexArray.h11
-rw-r--r--gfx/gl/instanceVertices.h2
6 files changed, 26 insertions, 17 deletions
diff --git a/game/network/rail.cpp b/game/network/rail.cpp
index 545620d..d0a8bdd 100644
--- a/game/network/rail.cpp
+++ b/game/network/rail.cpp
@@ -159,8 +159,7 @@ namespace {
if (auto count = networkLinks.vertices.size()) {
shader.use(RAIL_CROSS_SECTION, RAIL_TEXTURE_POS);
glBindVertexArray(networkLinks.vao);
- glVertexArrayVertexBuffer(
- networkLinks.vao, 0, networkLinks.vertices.bufferName(), 0, sizeof(typename LinkType::Vertex));
+ networkLinks.vao.useBuffer(0, networkLinks.vertices);
glDrawArrays(mode, 0, static_cast<GLsizei>(count));
}
};
diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp
index 4e10ed9..edfb0e9 100644
--- a/game/scenary/foliage.cpp
+++ b/game/scenary/foliage.cpp
@@ -102,7 +102,7 @@ Foliage::render(const SceneShader & shader, const Frustum &) const
billboard[1].bind(GL_TEXTURE_2D_ARRAY, GL_TEXTURE1);
billboard[2].bind(GL_TEXTURE_2D_ARRAY, GL_TEXTURE2);
glBindVertexArray(instancePointVAO);
- glVertexArrayVertexBuffer(instancePointVAO, 0, instances.bufferName(), 0, sizeof(LocationVertex));
+ instancePointVAO.useBuffer(0, instances);
glDrawArrays(GL_POINTS, static_cast<GLint>(instancePartitions.second.first), static_cast<GLsizei>(count));
glBindVertexArray(0);
}
@@ -112,7 +112,7 @@ Foliage::render(const SceneShader & shader, const Frustum &) const
if (texture) {
texture->bind();
}
- glVertexArrayVertexBuffer(instanceVAO, 1, instances.bufferName(), 0, sizeof(LocationVertex));
+ instanceVAO.useBuffer(1, instances);
bodyMesh->DrawInstanced(instanceVAO, static_cast<GLsizei>(count));
}
}
@@ -129,7 +129,7 @@ Foliage::shadows(const ShadowMapper & mapper, const Frustum &) const
mapper.stencilShadowProgram.use(dimensions.centre, dimensions.size);
shadowStencil.bind(GL_TEXTURE_2D_ARRAY, GL_TEXTURE0);
glBindVertexArray(instancePointVAO);
- glVertexArrayVertexBuffer(instancePointVAO, 0, instances.bufferName(), 0, sizeof(LocationVertex));
+ instancePointVAO.useBuffer(0, instances);
glDrawArrays(GL_POINTS, static_cast<GLint>(instancePartitions.second.first), static_cast<GLsizei>(count));
glBindVertexArray(0);
}
@@ -141,7 +141,7 @@ Foliage::shadows(const ShadowMapper & mapper, const Frustum &) const
else {
mapper.dynamicPointInst.use();
}
- glVertexArrayVertexBuffer(instanceVAO, 1, instances.bufferName(), 0, sizeof(LocationVertex));
+ instanceVAO.useBuffer(1, instances);
bodyMesh->DrawInstanced(instanceVAO, static_cast<GLsizei>(count));
}
}
diff --git a/game/scenary/illuminator.cpp b/game/scenary/illuminator.cpp
index 7ab17fe..1dd0644 100644
--- a/game/scenary/illuminator.cpp
+++ b/game/scenary/illuminator.cpp
@@ -74,7 +74,7 @@ Illuminator::render(const SceneShader & shader, const Frustum &) const
if (texture) {
texture->bind();
}
- glVertexArrayVertexBuffer(instanceVAO, 1, instances.bufferName(), 0, sizeof(LocationVertex));
+ instanceVAO.useBuffer(1, instances);
bodyMesh->DrawInstanced(instanceVAO, static_cast<GLsizei>(count));
}
}
@@ -86,17 +86,15 @@ Illuminator::lights(const SceneShader & shader) const
if (const auto scount = instancesSpotLight.size()) {
shader.spotLightInst.use();
glBindVertexArray(*instancesSpotLightVAO);
- glVertexArrayVertexBuffer(
- *instancesSpotLightVAO, 0, instancesSpotLight.bufferName(), 0, sizeof(SpotLightVertex));
- glVertexArrayVertexBuffer(*instancesSpotLightVAO, 1, instances.bufferName(), 0, sizeof(LocationVertex));
+ instancesSpotLightVAO->useBuffer(0, instancesSpotLight);
+ instancesSpotLightVAO->useBuffer(1, instances);
glDrawArraysInstanced(GL_POINTS, 0, static_cast<GLsizei>(scount), static_cast<GLsizei>(count));
}
if (const auto pcount = instancesPointLight.size()) {
shader.pointLightInst.use();
glBindVertexArray(*instancesPointLightVAO);
- glVertexArrayVertexBuffer(
- *instancesPointLightVAO, 0, instancesPointLight.bufferName(), 0, sizeof(PointLightVertex));
- glVertexArrayVertexBuffer(*instancesPointLightVAO, 1, instances.bufferName(), 0, sizeof(LocationVertex));
+ instancesPointLightVAO->useBuffer(0, instancesPointLight);
+ instancesPointLightVAO->useBuffer(1, instances);
glDrawArraysInstanced(GL_POINTS, 0, static_cast<GLsizei>(pcount), static_cast<GLsizei>(count));
}
diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp
index 100073d..2bdd7c4 100644
--- a/game/vehicles/railVehicleClass.cpp
+++ b/game/vehicles/railVehicleClass.cpp
@@ -52,10 +52,9 @@ RailVehicleClass::render(const SceneShader & shader, const Frustum &) const
texture->bind();
}
shader.basicInst.use();
- const auto instancesBuffer = instances.bufferName();
- glVertexArrayVertexBuffer(instanceVAO, 1, instancesBuffer, 0, sizeof(LocationVertex));
- glVertexArrayVertexBuffer(instancesBogiesVAO.front(), 1, instancesBuffer, 0, sizeof(LocationVertex));
- glVertexArrayVertexBuffer(instancesBogiesVAO.back(), 1, instancesBuffer, 0, sizeof(LocationVertex));
+ instanceVAO.useBuffer(1, instances);
+ instancesBogiesVAO.front().useBuffer(1, instances);
+ instancesBogiesVAO.back().useBuffer(1, instances);
bodyMesh->DrawInstanced(instanceVAO, count);
bogies.front()->DrawInstanced(instancesBogiesVAO.front(), count);
bogies.back()->DrawInstanced(instancesBogiesVAO.back(), count);
diff --git a/gfx/gl/glVertexArray.h b/gfx/gl/glVertexArray.h
index 3594cbf..3790863 100644
--- a/gfx/gl/glVertexArray.h
+++ b/gfx/gl/glVertexArray.h
@@ -115,6 +115,17 @@ namespace Impl {
{
return VertexArrayConfigurator {name};
}
+
+ template<typename GlAllocated>
+ void
+ useBuffer(GLuint binding, const GlAllocated & buffer) const
+ requires requires {
+ { buffer.bufferName() } -> std::same_as<GLuint>;
+ }
+ {
+ using T = typename GlAllocated::value_type;
+ glVertexArrayVertexBuffer(name, binding, buffer.bufferName(), 0, sizeof(T));
+ }
};
}
diff --git a/gfx/gl/instanceVertices.h b/gfx/gl/instanceVertices.h
index f24eaa3..2643e68 100644
--- a/gfx/gl/instanceVertices.h
+++ b/gfx/gl/instanceVertices.h
@@ -126,6 +126,8 @@ public:
return base::get_allocator().getNameFor(static_cast<const base &>(*this));
}
+ using base::value_type;
+
using base::at;
using base::begin;
using base::cbegin;