diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-01-02 16:53:02 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-01-02 16:53:02 +0000 |
commit | 290691079dcd71ec490720108ae1fec76e8db175 (patch) | |
tree | 74f74d54a3b4a99f00109ebe8176638467fd631e | |
parent | Should use value_type, not element_type (diff) | |
download | ilt-290691079dcd71ec490720108ae1fec76e8db175.tar.bz2 ilt-290691079dcd71ec490720108ae1fec76e8db175.tar.xz ilt-290691079dcd71ec490720108ae1fec76e8db175.zip |
VertexArrayObject helper supports binding an entire object, not just fields
Invoked by configuring with no attribute member points.
-rw-r--r-- | gfx/gl/vertexArrayObject.hpp | 26 |
1 files changed, 19 insertions, 7 deletions
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<GLsizeiptr>(sizeof(Value) * data.size()), data.data(), GL_STATIC_DRAW); } - template<auto Vertex::*attrib> + template<typename T> static void - set_pointer(GLuint & vertexArrayId) + set_pointer(const GLuint vertexArrayId, const void * ptr) { glEnableVertexAttribArray(vertexArrayId); - using traits = gl_traits<std::decay_t<decltype(std::declval<Vertex>().*attrib)>>; - glVertexAttribPointer(vertexArrayId++, traits::size, traits::type, GL_FALSE, sizeof(Vertex), - &(static_cast<const Vertex *>(nullptr)->*attrib)); + using traits = gl_traits<T>; + glVertexAttribPointer(vertexArrayId, traits::size, traits::type, GL_FALSE, sizeof(Vertex), ptr); + } + + template<auto Vertex::*attrib> + static void + set_pointer(const GLuint vertexArrayId) + { + set_pointer<std::decay_t<decltype(std::declval<Vertex>().*attrib)>>( + vertexArrayId, &(static_cast<const Vertex *>(nullptr)->*attrib)); } template<auto Vertex::*... attribs> @@ -70,7 +77,12 @@ private: configure_attribs(const GLuint arrayBuffer) { glBindBuffer(GL_ARRAY_BUFFER, arrayBuffer); - GLuint vertexArrayId {}; - (set_pointer<attribs>(vertexArrayId), ...); + if constexpr (sizeof...(attribs) == 0) { + set_pointer<Vertex>(0, nullptr); + } + else { + GLuint vertexArrayId {}; + (set_pointer<attribs>(vertexArrayId++), ...); + } } }; |