From 21459ac4c92b82f2a3eeb1d9a6b462726001084c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 18 Apr 2023 00:08:18 +0100 Subject: Specialize vertexAttribFunc for matrices because there's an upper limit of size 4 on attrib pointers --- lib/gl_traits.hpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'lib/gl_traits.hpp') diff --git a/lib/gl_traits.hpp b/lib/gl_traits.hpp index e2e689d..10b42e5 100644 --- a/lib/gl_traits.hpp +++ b/lib/gl_traits.hpp @@ -11,20 +11,23 @@ struct gl_traits_base { }; struct gl_traits_float : public gl_traits_base { static constexpr auto vertexAttribFunc { - [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) { + [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) -> GLuint { glVertexAttribPointer(index, size, type, GL_FALSE, stride, pointer); + return 1; }}; }; struct gl_traits_longfloat : public gl_traits_base { static constexpr auto vertexAttribFunc { - [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) { + [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) -> GLuint { glVertexAttribLPointer(index, size, type, stride, pointer); + return 1; }}; }; struct gl_traits_integer : public gl_traits_base { static constexpr auto vertexAttribFunc { - [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) { + [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) -> GLuint { glVertexAttribIPointer(index, size, type, stride, pointer); + return 1; }}; }; template<> struct gl_traits : public gl_traits_float { @@ -63,4 +66,12 @@ template struct gl_traits struct gl_traits> : public gl_traits { static constexpr GLint size {C * R}; + static constexpr auto vertexAttribFunc { + [](GLuint index, GLint, GLenum type, GLsizei stride, const void * pointer) -> GLuint { + const auto m = static_cast>(pointer); + for (glm::length_t r = 0; r < R; r++) { + glVertexAttribPointer(index, C, type, GL_FALSE, stride, &m[r]); + } + return R; + }}; }; -- cgit v1.2.3 From 4360094ff6e9f4d245f832c58f673ae4d1f75950 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 19 Apr 2023 01:45:47 +0100 Subject: Fixup vertexAttribFunc for matrices --- lib/gl_traits.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/gl_traits.hpp') diff --git a/lib/gl_traits.hpp b/lib/gl_traits.hpp index 10b42e5..6ff8905 100644 --- a/lib/gl_traits.hpp +++ b/lib/gl_traits.hpp @@ -68,9 +68,9 @@ struct gl_traits> : public gl_traits { static constexpr GLint size {C * R}; static constexpr auto vertexAttribFunc { [](GLuint index, GLint, GLenum type, GLsizei stride, const void * pointer) -> GLuint { - const auto m = static_cast>(pointer); - for (glm::length_t r = 0; r < R; r++) { - glVertexAttribPointer(index, C, type, GL_FALSE, stride, &m[r]); + const auto base = static_cast(pointer); + for (GLuint r = 0; r < R; r++) { + glVertexAttribPointer(index + r, C, type, GL_FALSE, stride, base + (r * C)); } return R; }}; -- cgit v1.2.3