diff options
| author | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-03-06 14:26:59 +0000 |
|---|---|---|
| committer | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-03-06 14:26:59 +0000 |
| commit | 1db3aead80d9209175aa5547363ad34b881a3660 (patch) | |
| tree | 60591392cda8c55780db55b1eee308b5429e37b2 | |
| parent | Replace use of VertexArrayObject with glVertexArray/glBuffer DSA versions (diff) | |
| download | ilt-1db3aead80d9209175aa5547363ad34b881a3660.tar.bz2 ilt-1db3aead80d9209175aa5547363ad34b881a3660.tar.xz ilt-1db3aead80d9209175aa5547363ad34b881a3660.zip | |
Remove VertexArrayObject and supporting non-DSA gl_traits helpers
| -rw-r--r-- | gfx/gl/vertexArrayObject.h | 125 | ||||
| -rw-r--r-- | lib/gl_traits.h | 34 |
2 files changed, 0 insertions, 159 deletions
diff --git a/gfx/gl/vertexArrayObject.h b/gfx/gl/vertexArrayObject.h deleted file mode 100644 index d008897..0000000 --- a/gfx/gl/vertexArrayObject.h +++ /dev/null @@ -1,125 +0,0 @@ -#pragma once - -#include "collections.h" -#include "gl_traits.h" -#include "special_members.h" -#include <glad/gl.h> - -class VertexArrayObject { -public: - template<typename T> [[nodiscard]] VertexArrayObject(const T & arrayObject) - { - glBindVertexArray(arrayObject); - } - - ~VertexArrayObject() - { - glBindVertexArray(0); - } - - NO_MOVE(VertexArrayObject); - NO_COPY(VertexArrayObject); - - template<typename m, typename T> struct MP { - constexpr MP(m T::* p) : P {p} { } - - constexpr - operator void *() const - { - return &(static_cast<T *>(nullptr)->*P); - } - - m T::* P; - using value_type = m; - }; - - template<typename m, typename T> MP(m T::*) -> MP<m, T>; - - template<typename VertexT, MP... attribs> - VertexArrayObject & - addAttribs(const GLuint arrayBuffer, const SequentialCollection<VertexT> auto & vertices, const GLuint divisor = 0) - { - addAttribs<VertexT, attribs...>(arrayBuffer, divisor); - data(vertices, arrayBuffer, GL_ARRAY_BUFFER); - return *this; - } - - template<typename VertexT, MP... attribs> - VertexArrayObject & - addAttribs(const GLuint arrayBuffer, const GLuint divisor = 0) - { - configure_attribs<VertexT, attribs...>(arrayBuffer, divisor); - return *this; - } - - // Customisation point - template<typename VertexT> VertexArrayObject & addAttribsFor(const GLuint arrayBuffer, const GLuint divisor = 0); - - template<typename Indices> - VertexArrayObject & - addIndices(const GLuint arrayBuffer, const Indices & indices) - { - data(indices, arrayBuffer, GL_ELEMENT_ARRAY_BUFFER); - return *this; - } - - VertexArrayObject & - addIndices(const GLuint arrayBuffer) - { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, arrayBuffer); - return *this; - } - - VertexArrayObject & - data(const GLuint arrayBuffer, GLenum target) - { - glBindBuffer(target, arrayBuffer); - return *this; - } - - template<typename Data> - static void - data(const Data & data, const GLuint arrayBuffer, GLenum target) - { - using Value = typename Data::value_type; - glBindBuffer(target, arrayBuffer); - glBufferData(target, static_cast<GLsizeiptr>(sizeof(Value) * data.size()), data.data(), GL_STATIC_DRAW); - } - -private: - template<typename VertexT, typename T> - static auto - set_pointer(const GLuint vertexArrayId, const void * ptr, const GLuint divisor) - { - using traits = gl_traits<T>; - const auto usedAttribs - = traits::vertexAttribFunc(vertexArrayId, traits::size, traits::type, sizeof(VertexT), ptr); - for (GLuint i {}; i < usedAttribs; i++) { - glEnableVertexAttribArray(vertexArrayId + i); - glVertexAttribDivisor(vertexArrayId + i, divisor); - } - return usedAttribs; - } - - template<typename VertexT, MP attrib> - static auto - set_pointer(const GLuint vertexArrayId, const GLuint divisor) - { - return set_pointer<VertexT, typename decltype(attrib)::value_type>(vertexArrayId, attrib, divisor); - } - - template<typename VertexT, MP... attribs> - void - configure_attribs(const GLuint arrayBuffer, const GLuint divisor) - { - glBindBuffer(GL_ARRAY_BUFFER, arrayBuffer); - if constexpr (sizeof...(attribs) == 0) { - vertexArrayId += set_pointer<VertexT, VertexT>(vertexArrayId, nullptr, divisor); - } - else { - ((vertexArrayId += set_pointer<VertexT, attribs>(vertexArrayId, divisor)), ...); - } - } - - GLuint vertexArrayId {}; -}; diff --git a/lib/gl_traits.h b/lib/gl_traits.h index 97183f0..35ae9e8 100644 --- a/lib/gl_traits.h +++ b/lib/gl_traits.h @@ -14,12 +14,6 @@ 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 { - glVertexAttribPointer(index, size, type, GL_FALSE, stride, pointer); - return 1; - }}; - template<GLenum type, GLint size> static GLuint vertexAttribFormatFunc(GLuint vao, GLuint index, GLuint offset) @@ -30,12 +24,6 @@ struct gl_traits_float : public gl_traits_base { }; struct gl_traits_longfloat : public gl_traits_base { - static constexpr auto vertexAttribFunc { - [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) -> GLuint { - glVertexAttribLPointer(index, size, type, stride, pointer); - return 1; - }}; - template<GLenum type, GLint size> static GLuint vertexAttribFormatFunc(GLuint vao, GLuint index, GLuint offset) @@ -46,12 +34,6 @@ struct gl_traits_longfloat : public gl_traits_base { }; struct gl_traits_integer : public gl_traits_base { - static constexpr auto vertexAttribFunc { - [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) -> GLuint { - glVertexAttribIPointer(index, size, type, stride, pointer); - return 1; - }}; - template<GLenum type, GLint size> static GLuint vertexAttribFormatFunc(GLuint vao, GLuint index, GLuint offset) @@ -115,14 +97,6 @@ template<> struct gl_traits<glm::uint32> : public gl_traits_integer { template<typename T, std::size_t S> struct gl_traits<std::array<T, S>> : public gl_traits<T> { static constexpr GLint size {S * gl_traits<T>::size}; - static constexpr auto vertexAttribFunc { - [](GLuint index, GLint, GLenum type, GLsizei stride, const void * pointer) -> GLuint { - const auto base = static_cast<const T *>(pointer); - for (GLuint e = 0; e < S; e++) { - glVertexAttribPointer(index + e, gl_traits<T>::size, type, GL_FALSE, stride, base + e); - } - return S; - }}; static constexpr auto vertexArrayAttribFormat {[](GLuint vao, GLuint index, GLuint offset) { if constexpr (std::is_pod_v<T>) { return gl_traits<T>::template vertexAttribFormatFunc<gl_traits<T>::type, S>(vao, index, offset); @@ -148,14 +122,6 @@ 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 base = static_cast<const T *>(pointer); - for (GLuint r = 0; r < R; r++) { - glVertexAttribPointer(index + r, C, type, GL_FALSE, stride, base + (r * C)); - } - return R; - }}; static constexpr auto vertexArrayAttribFormat {[](GLuint vao, GLuint index, GLuint offset) { GLuint used = 0; for (GLuint row = 0; row < R; row++) { |
