From 9ffb8081f3249c8d9be152b574c74e8642a22c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 14:23:44 +0100 Subject: [PATCH] Got rid of TypeTraits class altogether. --- src/AbstractImage.cpp | 2 - src/AbstractShaderProgram.cpp | 15 ++ src/CMakeLists.txt | 2 - src/MeshTools/Clean.h | 5 +- .../Test/CombineIndexedArraysTest.cpp | 1 + src/MeshTools/Test/SubdivideTest.cpp | 1 + src/TypeTraits.cpp | 36 --- src/TypeTraits.h | 213 ------------------ 8 files changed, 19 insertions(+), 256 deletions(-) delete mode 100644 src/TypeTraits.cpp delete mode 100644 src/TypeTraits.h diff --git a/src/AbstractImage.cpp b/src/AbstractImage.cpp index 97599c3de..19ffdc1f4 100644 --- a/src/AbstractImage.cpp +++ b/src/AbstractImage.cpp @@ -17,8 +17,6 @@ #include -#include "TypeTraits.h" - namespace Magnum { std::size_t AbstractImage::pixelSize(Format format, Type type) { diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index f16b5b31f..854e86fea 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -16,6 +16,7 @@ #include "AbstractShaderProgram.h" #include +#include #include "Math/Matrix.h" #include "Shader.h" @@ -27,6 +28,20 @@ namespace Magnum { +#ifndef DOXYGEN_GENERATING_OUTPUT +static_assert(std::is_same::value, "GLubyte is not the same as std::uint8_t"); +static_assert(std::is_same::value, "GLbyte is not the same as std::int8_t"); +static_assert(std::is_same::value, "GLushort is not the same as std::uint16_t"); +static_assert(std::is_same::value, "GLshort is not the same as std::int16_t"); +static_assert(std::is_same::value, "GLuint is not the same as std::uint32_t"); +static_assert(std::is_same::value, "GLint is not the same as std::int32_t"); +static_assert(std::is_same::value, "GLsizei is not the same as std::int32_t"); +static_assert(std::is_same::value, "GLfloat is not the same as float"); +#ifndef MAGNUM_TARGET_GLES +static_assert(std::is_same::value, "GLdouble is not the same as double"); +#endif +#endif + AbstractShaderProgram::Uniform1fImplementation AbstractShaderProgram::uniform1fImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::Uniform2fvImplementation AbstractShaderProgram::uniform2fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::Uniform3fvImplementation AbstractShaderProgram::uniform3fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a54f7e638..5c74e2888 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,7 +28,6 @@ set(Magnum_SRCS Resource.cpp Shader.cpp Timeline.cpp - TypeTraits.cpp Implementation/BufferState.cpp Implementation/State.cpp @@ -79,7 +78,6 @@ set(Magnum_HEADERS Swizzle.h Texture.h Timeline.h - TypeTraits.h magnumVisibility.h) diff --git a/src/MeshTools/Clean.h b/src/MeshTools/Clean.h index 26583743c..60c940282 100644 --- a/src/MeshTools/Clean.h +++ b/src/MeshTools/Clean.h @@ -24,7 +24,6 @@ #include #include "Math/Vector.h" -#include "TypeTraits.h" namespace Magnum { namespace MeshTools { @@ -35,7 +34,7 @@ template class Clean { public: inline Clean(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} - void operator()(typename Vertex::Type epsilon = TypeTraits::epsilon()) { + void operator()(typename Vertex::Type epsilon = Math::MathTypeTraits::epsilon()) { if(indices.empty()) return; /* Get mesh bounds */ @@ -137,7 +136,7 @@ Removes duplicate vertices from the mesh. @todo Interpolate vertices, not collapse them to first in the cell @todo Ability to specify other attributes for interpolation */ -template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = TypeTraits::epsilon()) { +template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = Math::MathTypeTraits::epsilon()) { Implementation::Clean(indices, vertices)(epsilon); } diff --git a/src/MeshTools/Test/CombineIndexedArraysTest.cpp b/src/MeshTools/Test/CombineIndexedArraysTest.cpp index 1758d5856..ade28f47c 100644 --- a/src/MeshTools/Test/CombineIndexedArraysTest.cpp +++ b/src/MeshTools/Test/CombineIndexedArraysTest.cpp @@ -16,6 +16,7 @@ #include #include +#include "Magnum.h" #include "MeshTools/CombineIndexedArrays.h" namespace Magnum { namespace MeshTools { namespace Test { diff --git a/src/MeshTools/Test/SubdivideTest.cpp b/src/MeshTools/Test/SubdivideTest.cpp index 4bd09edd9..8409f2a59 100644 --- a/src/MeshTools/Test/SubdivideTest.cpp +++ b/src/MeshTools/Test/SubdivideTest.cpp @@ -16,6 +16,7 @@ #include #include +#include "Magnum.h" #include "MeshTools/Clean.h" #include "MeshTools/Subdivide.h" diff --git a/src/TypeTraits.cpp b/src/TypeTraits.cpp deleted file mode 100644 index d8312a764..000000000 --- a/src/TypeTraits.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - 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. -*/ - -#include "TypeTraits.h" - -#include - -namespace Magnum { - -#ifndef DOXYGEN_GENERATING_OUTPUT -static_assert(std::is_same::value, "GLubyte is not the same as std::uint8_t"); -static_assert(std::is_same::value, "GLbyte is not the same as std::int8_t"); -static_assert(std::is_same::value, "GLushort is not the same as std::uint16_t"); -static_assert(std::is_same::value, "GLshort is not the same as std::int16_t"); -static_assert(std::is_same::value, "GLuint is not the same as std::uint32_t"); -static_assert(std::is_same::value, "GLint is not the same as std::int32_t"); -static_assert(std::is_same::value, "GLsizei is not the same as std::int32_t"); -static_assert(std::is_same::value, "GLfloat is not the same as float"); -#ifndef MAGNUM_TARGET_GLES -static_assert(std::is_same::value, "GLdouble is not the same as double"); -#endif -#endif - -} diff --git a/src/TypeTraits.h b/src/TypeTraits.h deleted file mode 100644 index 0770db5dd..000000000 --- a/src/TypeTraits.h +++ /dev/null @@ -1,213 +0,0 @@ -#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