diff options
author | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2023-04-19 14:48:04 +0100 |
---|---|---|
committer | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2023-04-19 14:48:04 +0100 |
commit | 5e0233646ef0170e54dfd9c9b991ffdc7674ba84 (patch) | |
tree | a2cfc830c662099dec017a98687825e93594ae9d /gfx/gl/vertexArrayObject.hpp | |
parent | Enable all vertex array attribs configured by vertexAttribFunc (diff) | |
download | ilt-5e0233646ef0170e54dfd9c9b991ffdc7674ba84.tar.bz2 ilt-5e0233646ef0170e54dfd9c9b991ffdc7674ba84.tar.xz ilt-5e0233646ef0170e54dfd9c9b991ffdc7674ba84.zip |
Support setting vertex attrib divisor
Diffstat (limited to 'gfx/gl/vertexArrayObject.hpp')
-rw-r--r-- | gfx/gl/vertexArrayObject.hpp | 21 |
1 files changed, 11 insertions, 10 deletions
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<typename VertexT, MP... attribs> VertexArrayObject & - addAttribs(const GLuint arrayBuffer, const SequentialCollection<VertexT> auto & vertices) + addAttribs(const GLuint arrayBuffer, const SequentialCollection<VertexT> auto & vertices, const GLuint divisor = 0) { - addAttribs<VertexT, attribs...>(arrayBuffer); + addAttribs<VertexT, attribs...>(arrayBuffer, divisor); data(vertices, arrayBuffer, GL_ARRAY_BUFFER); return *this; } template<typename VertexT, MP... attribs> VertexArrayObject & - addAttribs(const GLuint arrayBuffer) + addAttribs(const GLuint arrayBuffer, const GLuint divisor = 0) { - configure_attribs<VertexT, attribs...>(arrayBuffer); + configure_attribs<VertexT, attribs...>(arrayBuffer, divisor); return *this; } @@ -73,34 +73,35 @@ public: private: template<typename VertexT, typename T> 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<T>; 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<typename VertexT, MP attrib> static auto - set_pointer(const GLuint vertexArrayId) + set_pointer(const GLuint vertexArrayId, const GLuint divisor) { - return set_pointer<VertexT, typename decltype(attrib)::value_type>(vertexArrayId, attrib); + return set_pointer<VertexT, typename decltype(attrib)::value_type>(vertexArrayId, attrib, divisor); } template<typename VertexT, MP... attribs> 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<VertexT, VertexT>(vertexArrayId, nullptr); + vertexArrayId += set_pointer<VertexT, VertexT>(vertexArrayId, nullptr, divisor); } else { - ((vertexArrayId += set_pointer<VertexT, attribs>(vertexArrayId)), ...); + ((vertexArrayId += set_pointer<VertexT, attribs>(vertexArrayId, divisor)), ...); } } |