summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-01-02 16:53:02 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-01-02 16:53:02 +0000
commit290691079dcd71ec490720108ae1fec76e8db175 (patch)
tree74f74d54a3b4a99f00109ebe8176638467fd631e /gfx
parentShould use value_type, not element_type (diff)
downloadilt-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.
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/vertexArrayObject.hpp26
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++), ...);
+ }
}
};