From 290691079dcd71ec490720108ae1fec76e8db175 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 2 Jan 2023 16:53:02 +0000 Subject: VertexArrayObject helper supports binding an entire object, not just fields Invoked by configuring with no attribute member points. --- gfx/gl/vertexArrayObject.hpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'gfx') diff --git a/gfx/gl/vertexArrayObject.hpp b/gfx/gl/vertexArrayObject.hpp index e0c6d76..c0273c0 100644 --- a/gfx/gl/vertexArrayObject.hpp +++ b/gfx/gl/vertexArrayObject.hpp @@ -55,14 +55,21 @@ private: glBufferData(target, static_cast(sizeof(Value) * data.size()), data.data(), GL_STATIC_DRAW); } - template + template static void - set_pointer(GLuint & vertexArrayId) + set_pointer(const GLuint vertexArrayId, const void * ptr) { glEnableVertexAttribArray(vertexArrayId); - using traits = gl_traits().*attrib)>>; - glVertexAttribPointer(vertexArrayId++, traits::size, traits::type, GL_FALSE, sizeof(Vertex), - &(static_cast(nullptr)->*attrib)); + using traits = gl_traits; + glVertexAttribPointer(vertexArrayId, traits::size, traits::type, GL_FALSE, sizeof(Vertex), ptr); + } + + template + static void + set_pointer(const GLuint vertexArrayId) + { + set_pointer().*attrib)>>( + vertexArrayId, &(static_cast(nullptr)->*attrib)); } template @@ -70,7 +77,12 @@ private: configure_attribs(const GLuint arrayBuffer) { glBindBuffer(GL_ARRAY_BUFFER, arrayBuffer); - GLuint vertexArrayId {}; - (set_pointer(vertexArrayId), ...); + if constexpr (sizeof...(attribs) == 0) { + set_pointer(0, nullptr); + } + else { + GLuint vertexArrayId {}; + (set_pointer(vertexArrayId++), ...); + } } }; -- cgit v1.2.3