From 5e0233646ef0170e54dfd9c9b991ffdc7674ba84 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 19 Apr 2023 14:48:04 +0100 Subject: Support setting vertex attrib divisor --- gfx/gl/vertexArrayObject.hpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'gfx/gl') diff --git a/gfx/gl/vertexArrayObject.hpp b/gfx/gl/vertexArrayObject.hpp index 92e0325..7ded03e 100644 --- a/gfx/gl/vertexArrayObject.hpp +++ b/gfx/gl/vertexArrayObject.hpp @@ -31,18 +31,18 @@ public: template VertexArrayObject & - addAttribs(const GLuint arrayBuffer, const SequentialCollection auto & vertices) + addAttribs(const GLuint arrayBuffer, const SequentialCollection auto & vertices, const GLuint divisor = 0) { - addAttribs(arrayBuffer); + addAttribs(arrayBuffer, divisor); data(vertices, arrayBuffer, GL_ARRAY_BUFFER); return *this; } template VertexArrayObject & - addAttribs(const GLuint arrayBuffer) + addAttribs(const GLuint arrayBuffer, const GLuint divisor = 0) { - configure_attribs(arrayBuffer); + configure_attribs(arrayBuffer, divisor); return *this; } @@ -73,34 +73,35 @@ public: private: template static auto - set_pointer(const GLuint vertexArrayId, const void * ptr) + set_pointer(const GLuint vertexArrayId, const void * ptr, const GLuint divisor) { using traits = gl_traits; const auto usedAttribs = traits::vertexAttribFunc(vertexArrayId, traits::size, traits::type, sizeof(VertexT), ptr); for (GLuint i {}; i < usedAttribs; i++) { glEnableVertexAttribArray(vertexArrayId + i); + glVertexAttribDivisor(vertexArrayId + i, divisor); } return usedAttribs; } template static auto - set_pointer(const GLuint vertexArrayId) + set_pointer(const GLuint vertexArrayId, const GLuint divisor) { - return set_pointer(vertexArrayId, attrib); + return set_pointer(vertexArrayId, attrib, divisor); } template void - configure_attribs(const GLuint arrayBuffer) + configure_attribs(const GLuint arrayBuffer, const GLuint divisor) { glBindBuffer(GL_ARRAY_BUFFER, arrayBuffer); if constexpr (sizeof...(attribs) == 0) { - vertexArrayId += set_pointer(vertexArrayId, nullptr); + vertexArrayId += set_pointer(vertexArrayId, nullptr, divisor); } else { - ((vertexArrayId += set_pointer(vertexArrayId)), ...); + ((vertexArrayId += set_pointer(vertexArrayId, divisor)), ...); } } -- cgit v1.2.3