diff --git a/src/BufferedImage.h b/src/BufferedImage.h index 22ec4db6c..fa6fa6505 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -83,7 +83,7 @@ template class BufferedImage: public AbstractImage { * in constructor. */ template void setData(const T* data) { - if(TypeTraits::TextureType>::glType() != _type) { + if(TypeTraits::imageType() != _type) { Corrade::Utility::Error() << "BufferedImage: Passed data have wrong type"; return; } diff --git a/src/Image.h b/src/Image.h index 172c854bb..cbc1694d3 100644 --- a/src/Image.h +++ b/src/Image.h @@ -45,7 +45,7 @@ template class Image: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - template inline Image(ColorFormat colorFormat, const Math::Vector& dimensions, T* data): AbstractImage(colorFormat, TypeTraits::TextureType>::glType()), _dimensions(dimensions), _data(data) {} + template inline Image(ColorFormat colorFormat, const Math::Vector& dimensions, T* data): AbstractImage(colorFormat, TypeTraits::imageType()), _dimensions(dimensions), _data(data) {} /** * @brief Constructor @@ -88,7 +88,7 @@ template class Image: public AbstractImage { * constructor. */ template void setData(const T* data) { - if(TypeTraits::TextureType>::glType() != _type) { + if(TypeTraits::imageType() != _type) { Corrade::Utility::Error() << "Image: Passed data have wrong type"; return; } diff --git a/src/Mesh.h b/src/Mesh.h index 0cf15b870..b762c5ebe 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -172,7 +172,7 @@ class MAGNUM_EXPORT Mesh { * function does nothing. */ template inline void bindAttribute(Buffer* buffer) { - bindAttribute(buffer, Attribute::Location, TypeTraits::count(), TypeTraits::glType()); + bindAttribute(buffer, Attribute::Location, TypeTraits::count(), TypeTraits::type()); } /** diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index 793192c8c..e05dab678 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -94,7 +94,7 @@ class CompressIndices { memcpy(buffer+i*sizeof(IndexType), reinterpret_cast(&index), sizeof(IndexType)); } - return Result{indices.size(), TypeTraits::glType(), buffer}; + return Result{indices.size(), TypeTraits::indexType(), buffer}; } }; diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index 2f32a9a50..ad9ac4c55 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -43,7 +43,7 @@ template class ImageData: public AbstractImage { * @attention Note that the image data are not copied on construction, * but they are deleted on class destruction. */ - template inline ImageData(ColorFormat colorFormat, const Math::Vector& dimensions, const T* data): AbstractImage(colorFormat, TypeTraits::TextureType>::glType()), _dimensions(dimensions), _data(reinterpret_cast(data)) {} + template inline ImageData(ColorFormat colorFormat, const Math::Vector& dimensions, const T* data): AbstractImage(colorFormat, TypeTraits::imageType()), _dimensions(dimensions), _data(reinterpret_cast(data)) {} /** @brief Destructor */ inline virtual ~ImageData() { delete[] _data; } diff --git a/src/TypeTraits.h b/src/TypeTraits.h index 85b5a11bf..d9859f91f 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -34,29 +34,29 @@ traits. #ifdef DOXYGEN_GENERATING_OUTPUT template struct TypeTraits: public Math::TypeTraits { /** - * @brief Type which can be used for indices + * @brief OpenGL plain type ID * - * Implemented only in types which can be used for vertex indices (all - * unsigned types). This typedef is not present for types unusable for - * vertex indices, like GLfloat or GLint. + * Returns e.g. Type::UnsignedInt for GLuint. */ - typedef T IndexType; + constexpr inline static Type type(); /** - * @brief Type which can be used in textures + * @brief OpenGL type ID for indices * - * Implemented only in types which can be used for texture data, like - * GLubyte. This typedef is not present for types unusable for texture data, - * like GLdouble and Matrix3. + * Implemented only in types which can be used for vertex indices (all + * unsigned types). This function is not present for types unusable for + * vertex indices, like GLfloat or GLint. */ - typedef T TextureType; + constexpr inline static Type indexType(); /** - * @brief OpenGL plain type ID + * @brief OpenGL type ID for images * - * Returns e.g. Type::UnsignedInt for GLuint. + * Implemented only in types which can be used for image data, like + * GLubyte. This function is not present for types unusable for image data, + * like GLdouble and Matrix3. */ - constexpr inline static Type glType(); + constexpr inline static Type imageType(); /** * @brief Size of plain OpenGL type @@ -96,8 +96,8 @@ When you want to use TypeTraits on type specified only as enum value, you can use this class to convert it into type, for example these two statements are equivalent: @code -TypeTraits::Type>::TextureType data; -TypeTraits::TextureType data; +type = TypeTraits::Type>::imageType(); +type = TypeTraits::imageType(); @endcode */ template class TypeOf { @@ -147,82 +147,73 @@ template<> struct TypeOf { typedef GLfloat Type; }; template<> struct TypeOf { typedef GLdouble Type; }; template<> struct TypeTraits: public Math::TypeTraits { - typedef GLubyte IndexType; - typedef GLubyte TextureType; - - inline constexpr static Type glType() { return Type::UnsignedByte; } + inline constexpr static Type type() { return Type::UnsignedByte; } + inline constexpr static Type indexType() { return Type::UnsignedByte; } + inline constexpr static Type imageType() { return Type::UnsignedByte; } inline constexpr static size_t size() { return sizeof(GLubyte); } inline constexpr static size_t count() { return 1; } }; template<> struct TypeTraits: public Math::TypeTraits { + inline constexpr static Type type() { return Type::Byte; } /* Can not be used for indices */ - typedef GLbyte TextureType; - - inline constexpr static Type glType() { return Type::Byte; } + inline constexpr static Type imageType() { return Type::Byte; } inline constexpr static size_t size() { return sizeof(GLbyte); } inline constexpr static size_t count() { return 1; } }; template<> struct TypeTraits: public Math::TypeTraits { - typedef GLushort IndexType; - typedef GLushort TextureType; - - inline constexpr static Type glType() { return Type::UnsignedShort; } + inline constexpr static Type type() { return Type::UnsignedShort; } + inline constexpr static Type indexType() { return Type::UnsignedShort; } + inline constexpr static Type imageType() { return Type::UnsignedShort; } inline constexpr static size_t size() { return sizeof(GLushort); } inline constexpr static size_t count() { return 1; } }; template<> struct TypeTraits: public Math::TypeTraits { + inline constexpr static Type type() { return Type::Short; } /* Can not be used for indices */ - typedef GLshort TextureType; - - inline constexpr static Type glType() { return Type::Short; } + inline constexpr static Type imageType() { return Type::Short; } inline constexpr static size_t size() { return sizeof(GLshort); } inline constexpr static size_t count() { return 1; } }; template<> struct TypeTraits: public Math::TypeTraits { - typedef GLuint IndexType; - typedef GLuint TextureType; - - inline constexpr static Type glType() { return Type::UnsignedInt; } + inline constexpr static Type type() { return Type::UnsignedInt; } + inline constexpr static Type indexType() { return Type::UnsignedInt; } + inline constexpr static Type imageType() { return Type::UnsignedInt; } inline constexpr static size_t size() { return sizeof(GLuint); } inline constexpr static size_t count() { return 1; } }; template<> struct TypeTraits: public Math::TypeTraits { + inline constexpr static Type type() { return Type::Int; } /* Can not be used for indices */ - typedef GLint TextureType; - - inline constexpr static Type glType() { return Type::Int; } + inline constexpr static Type imageType() { return Type::Int; } inline constexpr static size_t size() { return sizeof(GLint); } inline constexpr static size_t count() { return 1; } }; template<> struct TypeTraits: public Math::TypeTraits { + inline constexpr static Type type() { return Type::Float; } /* Can not be used for indices */ - typedef GLfloat TextureType; - - inline constexpr static Type glType() { return Type::Float; } + inline constexpr static Type imageType() { return Type::Float; } inline constexpr static size_t size() { return sizeof(GLfloat); } inline constexpr static size_t count() { return 1; } }; template<> struct TypeTraits: public Math::TypeTraits { + inline constexpr static Type type() { return Type::Double; } /* Can not be used for indices */ - /* Can not be used for textures */ - - inline constexpr static Type glType() { return Type::Double; } + /* Can not be used for images */ inline constexpr static size_t size() { return sizeof(GLdouble); } inline constexpr static size_t count() { return 1; } }; template struct TypeTraits> { + inline constexpr static Type type() { return TypeTraits::type(); } /* Can not be used for indices */ - /* Can not be used for textures */ - - inline constexpr static Type glType() { return TypeTraits::glType(); } + /* Can not be used for images */ inline constexpr static size_t size() { return sizeof(T); } inline constexpr static size_t count() { return vectorSize; } }; @@ -232,10 +223,9 @@ template struct TypeTraits>: public TypeTraits struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits> { + inline constexpr static Type type() { return TypeTraits::type(); } /* Can not be used for indices */ - /* Can not be used for textures, obviously */ - - inline constexpr static Type glType() { return TypeTraits::glType(); } + /* Can not be used for images */ inline constexpr static size_t size() { return sizeof(T); } inline constexpr static size_t count() { return matrixSize*matrixSize; } };