From a6052168340f9831c766f76a3ec7b94da38da78a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 4 Mar 2026 16:53:58 +0000 Subject: Replace basic glVertexArray with a specific class ready for helpers --- gfx/models/mesh.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gfx/models/mesh.h') diff --git a/gfx/models/mesh.h b/gfx/models/mesh.h index 8791aed..d6ac171 100644 --- a/gfx/models/mesh.h +++ b/gfx/models/mesh.h @@ -2,7 +2,7 @@ #include "config/types.h" #include "gfx/gl/vertexArrayObject.h" -#include +#include #include #include #include -- cgit v1.3 From 182f823116458ad357823f4cc56638980aafa0f6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 6 Mar 2026 14:11:38 +0000 Subject: Replace generic glBuffer type alias with a full implementation Adds wrappers for DSA storage and data uploads. --- gfx/gl/glBuffer.h | 27 +++++++++++++++++++++++++++ gfx/models/mesh.h | 1 + lib/glArrays.cpp | 14 -------------- lib/glArrays.h | 2 -- lib/glContainer.h | 2 +- 5 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 gfx/gl/glBuffer.h delete mode 100644 lib/glArrays.cpp (limited to 'gfx/models/mesh.h') diff --git a/gfx/gl/glBuffer.h b/gfx/gl/glBuffer.h new file mode 100644 index 0000000..f43c223 --- /dev/null +++ b/gfx/gl/glBuffer.h @@ -0,0 +1,27 @@ +#pragma once + +#include "glArrays.h" + +namespace Impl { + // NOLINTNEXTLINE(readability-identifier-naming) + struct glBuffer : Detail::glNamed { + void + storage(const std::ranges::contiguous_range auto & data, GLenum flags) + { + glNamedBufferStorage( + name, static_cast(data.size() * sizeof(decltype(*data.data()))), data.data(), flags); + } + + void + data(const std::ranges::contiguous_range auto & data, GLenum flags) + { + glNamedBufferData( + name, static_cast(data.size() * sizeof(decltype(*data.data()))), data.data(), flags); + } + }; +} + +// NOLINTBEGIN(readability-identifier-naming) +template using glBuffers = glManagedArray; +using glBuffer = glManagedSingle; +// NOLINTEND(readability-identifier-naming) diff --git a/gfx/models/mesh.h b/gfx/models/mesh.h index d6ac171..4135a30 100644 --- a/gfx/models/mesh.h +++ b/gfx/models/mesh.h @@ -1,6 +1,7 @@ #pragma once #include "config/types.h" +#include "gfx/gl/glBuffer.h" #include "gfx/gl/vertexArrayObject.h" #include #include diff --git a/lib/glArrays.cpp b/lib/glArrays.cpp deleted file mode 100644 index cb12f91..0000000 --- a/lib/glArrays.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "glArrays.h" -#include - -// Specialisations (glBuffer is an example of the typedef) -static_assert(std::is_nothrow_default_constructible_v); -static_assert(!std::is_trivially_default_constructible_v); -static_assert(std::is_nothrow_destructible_v); -static_assert(!std::is_trivially_destructible_v); -static_assert(std::is_default_constructible_v); -static_assert(!std::is_copy_constructible_v); -static_assert(!std::is_copy_assignable_v); -static_assert(std::is_nothrow_move_constructible_v); -static_assert(std::is_nothrow_move_assignable_v); -static_assert(sizeof(glBuffer) == sizeof(GLuint)); diff --git a/lib/glArrays.h b/lib/glArrays.h index e949ccd..1cf2fbf 100644 --- a/lib/glArrays.h +++ b/lib/glArrays.h @@ -119,8 +119,6 @@ struct glManagedArray : public std::array { }; // NOLINTBEGIN(readability-identifier-naming) -template using glBuffers = glManagedArray; -using glBuffer = glManagedSingle; template using glFrameBuffers = glManagedArray; using glFrameBuffer = glManagedSingle; template diff --git a/lib/glContainer.h b/lib/glContainer.h index 4119ef5..45f1030 100644 --- a/lib/glContainer.h +++ b/lib/glContainer.h @@ -1,6 +1,6 @@ #pragma once -#include "glArrays.h" +#include "gfx/gl/glBuffer.h" #include #include #include -- cgit v1.3 From cf0ecc35ed114c6bf54fce9c6228d60dbba1a3b5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 6 Mar 2026 14:22:28 +0000 Subject: Replace use of VertexArrayObject with glVertexArray/glBuffer DSA versions --- game/network/rail.cpp | 9 ++++----- game/scenary/foliage.cpp | 9 ++++----- game/scenary/illuminator.cpp | 17 ++++++++--------- game/terrain.cpp | 18 ++++++++---------- game/vehicles/railVehicleClass.cpp | 13 ++++++------- game/water.cpp | 6 +++--- gfx/gl/sceneRenderer.cpp | 3 +-- gfx/gl/sceneShader.cpp | 2 +- gfx/models/mesh.h | 13 ++++++------- gfx/models/vertex.cpp | 8 ++++---- 10 files changed, 45 insertions(+), 53 deletions(-) (limited to 'gfx/models/mesh.h') diff --git a/game/network/rail.cpp b/game/network/rail.cpp index f265d6b..8d85f35 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -3,7 +3,6 @@ #include "network.h" #include // IWYU pragma: keep #include -#include #include template class NetworkOf; @@ -139,18 +138,18 @@ RailLink::vehiclePositionOffset() const template<> NetworkLinkHolder::NetworkLinkHolder() { - VertexArrayObject {vao} + vao.configure() .addAttribs( - vertices.bufferName()); + 0, vertices.bufferName()); } template<> NetworkLinkHolder::NetworkLinkHolder() { - VertexArrayObject {vao} + vao.configure() .addAttribs(vertices.bufferName()); + &RailLinkCurve::Vertex::bangle, &RailLinkCurve::Vertex::radius>(0, vertices.bufferName()); } namespace { diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp index 0981ffc..49a4831 100644 --- a/game/scenary/foliage.cpp +++ b/game/scenary/foliage.cpp @@ -4,7 +4,6 @@ #include "gfx/gl/sceneShader.h" #include "gfx/gl/shadowMapper.h" #include "gfx/gl/shadowStenciller.h" -#include "gfx/gl/vertexArrayObject.h" #include static_assert(std::is_constructible_v); @@ -38,11 +37,11 @@ void Foliage::postLoad() { texture = getTexture(); - bodyMesh->configureVAO(instanceVAO) + bodyMesh->configureVAO(instanceVAO, 0) .addAttribs( - instances.bufferName(), 1); - VertexArrayObject {instancePointVAO}.addAttribs( - instances.bufferName()); + 1, instances.bufferName()); + instancePointVAO.configure().addAttribs( + 0, instances.bufferName()); const auto & size = bodyMesh->getDimensions().size; billboardSize = billboardTextureSizeForObject(size); diff --git a/game/scenary/illuminator.cpp b/game/scenary/illuminator.cpp index d8e4c4e..590062e 100644 --- a/game/scenary/illuminator.cpp +++ b/game/scenary/illuminator.cpp @@ -1,6 +1,5 @@ #include "illuminator.h" #include "gfx/gl/sceneShader.h" -#include "gfx/gl/vertexArrayObject.h" #include "gfx/models/texture.h" // IWYU pragma: keep #include @@ -41,15 +40,15 @@ Illuminator::postLoad() throw std::logic_error {"Illuminator has no lights"}; } texture = getTexture(); - bodyMesh->configureVAO(instanceVAO) - .addAttribs(instances.bufferName(), 1); + bodyMesh->configureVAO(instanceVAO, 0) + .addAttribs(1, instances.bufferName()); if (!spotLight.empty()) { instancesSpotLightVAO.emplace(); - VertexArrayObject {*instancesSpotLightVAO} + instancesSpotLightVAO->configure() .addAttribs( - instancesSpotLight.bufferName(), 0) - .addAttribs(instances.bufferName(), 1); + 0, instancesSpotLight.bufferName()) + .addAttribs(1, instances.bufferName()); std::transform( spotLight.begin(), spotLight.end(), std::back_inserter(spotLightInstances), [this](const auto & s) { return instancesSpotLight.acquire(*s); @@ -57,10 +56,10 @@ Illuminator::postLoad() } if (!pointLight.empty()) { instancesPointLightVAO.emplace(); - VertexArrayObject {*instancesPointLightVAO} + instancesPointLightVAO->configure() .addAttribs(instancesPointLight.bufferName(), 0) - .addAttribs(instances.bufferName(), 1); + &PointLightVertex::kq>(0, instancesPointLight.bufferName()) + .addAttribs(1, instances.bufferName()); std::transform( pointLight.begin(), pointLight.end(), std::back_inserter(pointLightInstances), [this](const auto & s) { return instancesPointLight.acquire(*s); diff --git a/game/terrain.cpp b/game/terrain.cpp index 187d035..25ecca9 100644 --- a/game/terrain.cpp +++ b/game/terrain.cpp @@ -17,10 +17,10 @@ static constexpr RGB OPEN_SURFACE {-1}; static constexpr GlobalDistance TILE_SIZE = 1024 * 1024; // ~1km, power of 2, fast divide template<> -VertexArrayObject & -VertexArrayObject::addAttribsFor(const GLuint arrayBuffer, const GLuint divisor) +Impl::VertexArrayConfigurator & +Impl::VertexArrayConfigurator::addAttribsFor(const GLuint divisor, const glBuffer & buffer) { - return addAttribs(arrayBuffer, divisor); + return addAttribs(divisor, buffer); } bool @@ -78,16 +78,14 @@ Terrain::copyIndicesToBuffers(const SurfaceIndices & surfaceIndices) auto meshItr = meshes.find(surfaceKey); if (meshItr == meshes.end()) { meshItr = meshes.emplace(surfaceKey, SurfaceArrayBuffer {}).first; - VertexArrayObject {meshItr->second.vertexArray} - .addAttribsFor(verticesBuffer) - .addIndices(meshItr->second.indicesBuffer, indices) - .data(verticesBuffer, GL_ARRAY_BUFFER); + meshItr->second.vertexArray.configure() + .addAttribsFor(0, verticesBuffer) + .addIndices(meshItr->second.indicesBuffer); } else { - VertexArrayObject {meshItr->second.vertexArray} - .addIndices(meshItr->second.indicesBuffer, indices) - .data(verticesBuffer, GL_ARRAY_BUFFER); + meshItr->second.vertexArray.configure().addIndices(meshItr->second.indicesBuffer); } + meshItr->second.indicesBuffer.data(indices, GL_DYNAMIC_DRAW); meshItr->second.count = static_cast(indices.size()); meshItr->second.aabb = AxisAlignedBoundingBox::fromPoints( indices | std::views::transform([this](const auto vertex) { diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index 21f01c8..a11b435 100644 --- a/game/vehicles/railVehicleClass.cpp +++ b/game/vehicles/railVehicleClass.cpp @@ -1,7 +1,6 @@ #include "railVehicleClass.h" #include "gfx/gl/sceneShader.h" #include "gfx/gl/shadowMapper.h" -#include "gfx/gl/vertexArrayObject.h" #include #include #include @@ -34,14 +33,14 @@ void RailVehicleClass::postLoad() { texture = getTexture(); - bodyMesh->configureVAO(instanceVAO) - .addAttribs(instances.bufferName(), 1); + bodyMesh->configureVAO(instanceVAO, 0) + .addAttribs(1, instances.bufferName()); bogies.front() - ->configureVAO(instancesBogiesVAO.front()) - .addAttribs(instances.bufferName(), 1); + ->configureVAO(instancesBogiesVAO.front(), 0) + .addAttribs(1, instances.bufferName()); bogies.back() - ->configureVAO(instancesBogiesVAO.back()) - .addAttribs(instances.bufferName(), 1); + ->configureVAO(instancesBogiesVAO.back(), 0) + .addAttribs(1, instances.bufferName()); static_assert(sizeof(LocationVertex) == 144UL); } diff --git a/game/water.cpp b/game/water.cpp index 527e85a..0657214 100644 --- a/game/water.cpp +++ b/game/water.cpp @@ -24,10 +24,10 @@ namespace glm { } template<> -VertexArrayObject & -VertexArrayObject::addAttribsFor(const GLuint arrayBuffer, const GLuint divisor) +Impl::VertexArrayConfigurator & +Impl::VertexArrayConfigurator::addAttribsFor(const GLuint divisor, const glBuffer & buffer) { - return addAttribs(arrayBuffer, divisor); + return addAttribs(divisor, buffer); } Water::Water(std::shared_ptr tm) : geoData {std::move(tm)}, water {std::make_shared("water.png")} diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index 15dde1b..e67711b 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -1,6 +1,5 @@ #include "sceneRenderer.h" #include "maths.h" -#include "vertexArrayObject.h" #include #include #include @@ -22,7 +21,7 @@ SceneRenderer::SceneRenderer(ScreenAbsCoord s, GLuint o, glDebugScope) : lighting {lighting_vert, lighting_frag}, shadowMapper {{2048, 2048}} { shader.setViewPort({0, 0, size.x, size.y}); - VertexArrayObject {displayVAO}.addAttribs(displayVBO, displayVAOdata); + displayVAO.configure().addAttribs(0, displayVBO, displayVAOdata); const auto configuregdata = [this](const auto & data, const std::initializer_list iformats, const GLenum format, const GLenum attachment) { diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index 43e54a5..302edda 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/gfx/models/mesh.h b/gfx/models/mesh.h index 4135a30..e78d27e 100644 --- a/gfx/models/mesh.h +++ b/gfx/models/mesh.h @@ -2,7 +2,6 @@ #include "config/types.h" #include "gfx/gl/glBuffer.h" -#include "gfx/gl/vertexArrayObject.h" #include #include #include @@ -54,15 +53,15 @@ public: return static_cast(v.pos); }))} { - VertexArrayObject::data(vertices, m_vertexArrayBuffers[0], GL_ARRAY_BUFFER); - VertexArrayObject::data(indices, m_vertexArrayBuffers[1], GL_ARRAY_BUFFER); - configureVAO(m_vertexArrayObject); + m_vertexArrayBuffers[0].storage(vertices, 0); + m_vertexArrayBuffers[1].storage(indices, 0); + configureVAO(m_vertexArrayObject, 0); } - VertexArrayObject & - configureVAO(VertexArrayObject && vao) const + auto + configureVAO(glVertexArray & vao, GLuint divisor) const { - return vao.addAttribsFor(m_vertexArrayBuffers[0]).addIndices(m_vertexArrayBuffers[1]); + return vao.configure().addAttribsFor(divisor, m_vertexArrayBuffers[0]).addIndices(m_vertexArrayBuffers[1]); } }; diff --git a/gfx/models/vertex.cpp b/gfx/models/vertex.cpp index c144db3..dc32f72 100644 --- a/gfx/models/vertex.cpp +++ b/gfx/models/vertex.cpp @@ -1,10 +1,10 @@ #include "vertex.h" -#include "gfx/gl/vertexArrayObject.h" +#include "gfx/gl/glVertexArray.h" template<> -VertexArrayObject & -VertexArrayObject::addAttribsFor(const GLuint arrayBuffer, const GLuint divisor) +Impl::VertexArrayConfigurator & +Impl::VertexArrayConfigurator::addAttribsFor(const GLuint divisor, const glBuffer & buffer) { return addAttribs( - arrayBuffer, divisor); + divisor, buffer); } -- cgit v1.3