From 5a0b3927a33807cca4c77c40eb873f8a3b51b0b0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 29 Apr 2023 19:07:11 +0100 Subject: Drop .hpp for header only things Half of them acquired a .cpp part anyway --- lib/gl_traits.h | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 lib/gl_traits.h (limited to 'lib/gl_traits.h') diff --git a/lib/gl_traits.h b/lib/gl_traits.h new file mode 100644 index 0000000..6ff8905 --- /dev/null +++ b/lib/gl_traits.h @@ -0,0 +1,77 @@ +#pragma once + +#include +#include +#include +#include + +template struct gl_traits; +struct gl_traits_base { + static constexpr GLint size {1}; +}; +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; + }}; +}; +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; + }}; +}; +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<> struct gl_traits : public gl_traits_float { + static constexpr GLenum type {GL_FLOAT}; +}; +template<> struct gl_traits : public gl_traits_longfloat { + static constexpr GLenum type {GL_DOUBLE}; +}; +template<> struct gl_traits : public gl_traits_integer { + static constexpr GLenum type {GL_BYTE}; +}; +template<> struct gl_traits : public gl_traits_integer { + static constexpr GLenum type {GL_SHORT}; +}; +template<> struct gl_traits : public gl_traits_integer { + static constexpr GLenum type {GL_INT}; +}; +template<> struct gl_traits : public gl_traits_integer { + static constexpr GLenum type {GL_UNSIGNED_BYTE}; +}; +template<> struct gl_traits : public gl_traits_integer { + static constexpr GLenum type {GL_UNSIGNED_SHORT}; +}; +template<> struct gl_traits : public gl_traits_integer { + static constexpr GLenum type {GL_UNSIGNED_INT}; +}; + +template struct gl_traits> : public gl_traits { + static constexpr GLint size {S * gl_traits::size}; +}; + +template struct gl_traits> : public gl_traits { + static constexpr GLint size {L}; +}; + +template +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 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