#ifndef Magnum_TypeTraits_h #define Magnum_TypeTraits_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš This file is part of Magnum. Magnum is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3 only, as published by the Free Software Foundation. Magnum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License version 3 for more details. */ /** @file /TypeTraits.h * @brief Class Magnum::TypeTraits */ #include #include "Math/MathTypeTraits.h" #include "Magnum.h" #include "magnumVisibility.h" namespace Magnum { /** @brief Traits class for plain OpenGL types @copydetails Math::MathTypeTraits Where it makes sense, this class extends Math::MathTypeTraits with OpenGL-specific traits. */ #ifdef DOXYGEN_GENERATING_OUTPUT template struct TypeTraits: Math::MathTypeTraits { /** * @brief Corresponding type for vertex attributes * * Implemented only in types which can be used for vertex attributes. This * function is not present for types unusable for vertex attributes, like * five-component vectors or GLdouble in OpenGL ES. See also * @ref AbstractShaderProgram-types. */ typedef U AttributeType; /** * @brief Size of plain OpenGL type * * Returns sizeof(GLfloat) for GLfloat, but also sizeof(GLfloat) for * Vector3. See count(). */ inline constexpr static std::size_t size(); /** * @brief Count of plain elements in this type * * Returns 1 for plain OpenGL types like GLint, but e.g. 3 for Vector3. */ inline constexpr static std::size_t count(); }; #else template struct TypeTraits { TypeTraits() = delete; }; #endif #ifndef DOXYGEN_GENERATING_OUTPUT template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static std::size_t size() { return sizeof(GLubyte); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static std::size_t size() { return sizeof(GLbyte); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static std::size_t size() { return sizeof(GLushort); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static std::size_t size() { return sizeof(GLshort); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { typedef GLuint AttributeType; inline constexpr static std::size_t size() { return sizeof(GLuint); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { typedef GLint AttributeType; inline constexpr static std::size_t size() { return sizeof(GLint); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { typedef GLfloat AttributeType; inline constexpr static std::size_t size() { return sizeof(GLfloat); } inline constexpr static std::size_t count() { return 1; } }; #ifndef MAGNUM_TARGET_GLES template<> struct TypeTraits: Math::MathTypeTraits { typedef GLdouble AttributeType; inline constexpr static std::size_t size() { return sizeof(GLdouble); } inline constexpr static std::size_t count() { return 1; } }; #endif namespace Implementation { template struct VectorTypeTraits { VectorTypeTraits() = delete; /* Might be used for attributes, see below */ inline constexpr static std::size_t size() { return sizeof(T); } inline constexpr static std::size_t count() { return vectorSize; } }; template struct VectorAttributeType {}; template<> struct VectorAttributeType { typedef GLuint AttributeType; }; template<> struct VectorAttributeType { typedef GLint AttributeType; }; template<> struct VectorAttributeType { typedef GLfloat AttributeType; }; #ifndef MAGNUM_TARGET_GLES template<> struct VectorAttributeType { typedef GLdouble AttributeType; }; #endif } template struct TypeTraits>: Implementation::VectorTypeTraits {}; /* Only some vectors can be used as attributes */ template struct TypeTraits>: Implementation::VectorTypeTraits<1, T>, Implementation::VectorAttributeType {}; template struct TypeTraits>: Implementation::VectorTypeTraits<2, T>, Implementation::VectorAttributeType {}; template struct TypeTraits>: Implementation::VectorTypeTraits<3, T>, Implementation::VectorAttributeType {}; template struct TypeTraits>: Implementation::VectorTypeTraits<4, T>, Implementation::VectorAttributeType {}; template struct TypeTraits>: TypeTraits> {}; template struct TypeTraits>: TypeTraits> {}; template struct TypeTraits>: TypeTraits> {}; template struct TypeTraits>: TypeTraits> {}; template struct TypeTraits>: TypeTraits> {}; template struct TypeTraits>: TypeTraits> {}; template struct TypeTraits>: TypeTraits> {}; namespace Implementation { template struct MatrixTypeTraits { MatrixTypeTraits() = delete; /* Might be used for attributes, see below */ inline constexpr static std::size_t size() { return sizeof(T); } inline constexpr static std::size_t count() { return rows; } inline constexpr static std::size_t vectors() { return cols; } }; template struct MatrixAttributeType {}; template<> struct MatrixAttributeType { typedef GLfloat AttributeType; }; #ifndef MAGNUM_TARGET_GLES template<> struct MatrixAttributeType { typedef GLdouble AttributeType; }; #endif } template struct TypeTraits>: Implementation::MatrixTypeTraits {}; /* Only some floating-point matrices can be used as attributes */ template struct TypeTraits>: Implementation::MatrixTypeTraits<2, 2, T>, Implementation::MatrixAttributeType {}; template struct TypeTraits>: Implementation::MatrixTypeTraits<3, 3, T>, Implementation::MatrixAttributeType {}; template struct TypeTraits>: Implementation::MatrixTypeTraits<4, 4, T>, Implementation::MatrixAttributeType {}; template struct TypeTraits>: Implementation::MatrixTypeTraits<2, 3, T>, Implementation::MatrixAttributeType {}; template struct TypeTraits>: Implementation::MatrixTypeTraits<3, 2, T>, Implementation::MatrixAttributeType {}; template struct TypeTraits>: Implementation::MatrixTypeTraits<2, 4, T>, Implementation::MatrixAttributeType {}; template struct TypeTraits>: Implementation::MatrixTypeTraits<4, 2, T>, Implementation::MatrixAttributeType {}; template struct TypeTraits>: Implementation::MatrixTypeTraits<3, 4, T>, Implementation::MatrixAttributeType {}; template struct TypeTraits>: Implementation::MatrixTypeTraits<4, 3, T>, Implementation::MatrixAttributeType {}; template struct TypeTraits>: TypeTraits> {}; template struct TypeTraits>: TypeTraits> {}; template struct TypeTraits>: TypeTraits> {}; #endif } #endif