summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-18 00:08:18 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-18 00:08:18 +0100
commit21459ac4c92b82f2a3eeb1d9a6b462726001084c (patch)
tree17ef14ecfb67b9f247685c8eba36210023beff06
parentSeparate storing of mesh vertex/index data from configuring VAO (diff)
downloadilt-21459ac4c92b82f2a3eeb1d9a6b462726001084c.tar.bz2
ilt-21459ac4c92b82f2a3eeb1d9a6b462726001084c.tar.xz
ilt-21459ac4c92b82f2a3eeb1d9a6b462726001084c.zip
Specialize vertexAttribFunc for matrices because there's an upper limit of size 4 on attrib pointers
-rw-r--r--gfx/gl/vertexArrayObject.hpp10
-rw-r--r--lib/gl_traits.hpp17
2 files changed, 19 insertions, 8 deletions
diff --git a/gfx/gl/vertexArrayObject.hpp b/gfx/gl/vertexArrayObject.hpp
index 8c828c8..fdc43e9 100644
--- a/gfx/gl/vertexArrayObject.hpp
+++ b/gfx/gl/vertexArrayObject.hpp
@@ -72,19 +72,19 @@ public:
private:
template<typename VertexT, typename T>
- static void
+ static auto
set_pointer(const GLuint vertexArrayId, const void * ptr)
{
glEnableVertexAttribArray(vertexArrayId);
using traits = gl_traits<T>;
- traits::vertexAttribFunc(vertexArrayId, traits::size, traits::type, sizeof(VertexT), ptr);
+ return traits::vertexAttribFunc(vertexArrayId, traits::size, traits::type, sizeof(VertexT), ptr);
}
template<typename VertexT, MP attrib>
- static void
+ static auto
set_pointer(const GLuint vertexArrayId)
{
- set_pointer<VertexT, typename decltype(attrib)::value_type>(vertexArrayId, attrib);
+ return set_pointer<VertexT, typename decltype(attrib)::value_type>(vertexArrayId, attrib);
}
template<typename VertexT, MP... attribs>
@@ -97,7 +97,7 @@ private:
}
else {
GLuint vertexArrayId {};
- (set_pointer<VertexT, attribs>(vertexArrayId++), ...);
+ ((vertexArrayId += set_pointer<VertexT, attribs>(vertexArrayId)), ...);
}
}
};
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<glm::f32> : public gl_traits_float {
@@ -63,4 +66,12 @@ template<glm::length_t L, typename T, glm::qualifier Q> struct gl_traits<glm::ve
template<glm::length_t C, glm::length_t R, typename T, glm::qualifier Q>
struct gl_traits<glm::mat<C, R, T, Q>> : public gl_traits<T> {
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<glm::mat<C, R, T, Q>>(pointer);
+ for (glm::length_t r = 0; r < R; r++) {
+ glVertexAttribPointer(index, C, type, GL_FALSE, stride, &m[r]);
+ }
+ return R;
+ }};
};