Browse Source

Using fixed-size integer types also everywhere else.

It solves issues with int/long int/long long int ambiguity, which is
good.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
c1cf94fb46
  1. 4
      src/Color.h
  2. 7
      src/Math/Math.h
  3. 52
      src/Math/MathTypeTraits.h
  4. 2
      src/Math/RectangularMatrix.h
  5. 2
      src/Math/Test/ConstantsTest.cpp
  6. 54
      src/Math/Test/MathTest.cpp
  7. 20
      src/Math/Test/MathTypeTraitsTest.cpp
  8. 4
      src/Math/Test/MatrixTest.cpp
  9. 14
      src/Math/Test/RectangularMatrixTest.cpp
  10. 10
      src/MeshTools/Test/CleanTest.h
  11. 20
      src/MeshTools/Test/InterleaveTest.cpp
  12. 10
      src/MeshTools/Test/SubdivideTest.h
  13. 8
      src/MeshTools/Test/TipsifyTest.cpp
  14. 30
      src/Primitives/Capsule.cpp
  15. 12
      src/Primitives/Capsule.h
  16. 2
      src/Primitives/Cube.cpp
  17. 4
      src/Primitives/Cylinder.cpp
  18. 2
      src/Primitives/Cylinder.h
  19. 2
      src/Primitives/UVSphere.cpp
  20. 2
      src/Primitives/UVSphere.h
  21. 2
      src/Profiler.h
  22. 4
      src/Swizzle.h
  23. 4
      src/Test/ColorTest.cpp
  24. 14
      src/Test/ResourceManagerTest.cpp
  25. 2
      src/Test/ResourceManagerTest.h
  26. 14
      src/Test/SwizzleTest.cpp
  27. 2
      src/Timeline.cpp
  28. 20
      src/TypeTraits.cpp
  29. 12
      src/TypeTraits.h

4
src/Color.h

@ -160,7 +160,7 @@ template<class T> class Color3: public Math::Vector3<T> {
* @brief Create integral color from floating-point color
*
* E.g. `{0.294118, 0.45098, 0.878431}` is converted to
* `{75, 115, 224}`, if resulting type is `unsigned char`.
* `{75, 115, 224}`, if resulting type is `uint8_t`.
*
* @note This function is enabled only if source type is floating-point
* and destination type is integral.
@ -175,7 +175,7 @@ template<class T> class Color3: public Math::Vector3<T> {
* @brief Create floating-point color from integral color
*
* E.g. `{75, 115, 224}` is converted to
* `{0.294118, 0.45098, 0.878431}`, if source type is `unsigned char`.
* `{0.294118, 0.45098, 0.878431}`, if source type is `uint8_t`.
*
* @note This function is enabled only if source type is integral
* and destination type is floating-point.

7
src/Math/Math.h

@ -74,11 +74,11 @@ type to value in range @f$ [0, 1] @f$.
literals, this function should be called with both template parameters
explicit, e.g.:
@code
// Even if this is char literal, integral type is `int`, thus a = 0.1f
// Even if this is character literal, integral type is 32bit, thus a != 1.0f
float a = normalize<float>('\127');
// b = 1.0f
float b = normalize<float, char>('\127');
float b = normalize<float, int8_t>('\127');
@endcode
@todo Signed normalization to [-1.0, 1.0] like in OpenGL?
@ -95,7 +95,8 @@ Converts floating-point value in range @f$ [0, 1] @f$ to full range of given
integral type.
@note For best precision, `FloatingPoint` type should be always larger that
resulting `Integral` type (e.g. `double` to `int`, `long double` to `long long`).
resulting `Integral` type (e.g. `double` to `std::int32_t`, `long double` to
`std::int64_t`).
@todo Signed normalization to [-1.0, 1.0] like in OpenGL?
@todo Stable behavior (working/broken) for long double and long long

52
src/Math/MathTypeTraits.h

@ -19,7 +19,7 @@
* @brief Class Magnum::Math::MathTypeTraits
*/
#include <cstddef>
#include <cstdint>
#include <cmath>
/** @brief Precision when testing floats for equality */
@ -53,7 +53,7 @@ support given feature, thus forcing the compilation stop with an error.
template<class T> struct MathTypeTraits {
#ifdef DOXYGEN_GENERATING_OUTPUT
/**
* @brief Corresponding numeric type large at least as `int`
* @brief Corresponding numeric type large at least as 32bit integer
*
* Usable e.g. to prevent conversion of `char` to characters when printing
* numeric types to output.
@ -114,58 +114,54 @@ template<class T> struct MathTypeTraitsFloatingPoint {
template<std::size_t> struct MathTypeTraitsLong {};
template<> struct MathTypeTraitsLong<sizeof(int)> {
typedef unsigned int UnsignedType;
typedef int Type;
template<> struct MathTypeTraitsLong<4> {
typedef std::uint32_t UnsignedType;
typedef std::int32_t Type;
};
template<> struct MathTypeTraitsLong<sizeof(long long)> {
typedef unsigned long long UnsignedType;
typedef long long Type;
template<> struct MathTypeTraitsLong<8> {
typedef std::uint64_t UnsignedType;
typedef std::int64_t Type;
};
}
template<> struct MathTypeTraits<unsigned char>: public Implementation::MathTypeTraitsIntegral<unsigned char> {
typedef unsigned int NumericType;
template<> struct MathTypeTraits<std::uint8_t>: public Implementation::MathTypeTraitsIntegral<std::uint8_t> {
typedef std::uint32_t NumericType;
typedef float FloatingPointType;
};
template<> struct MathTypeTraits<char>: public Implementation::MathTypeTraitsIntegral<char> {
typedef int NumericType;
template<> struct MathTypeTraits<std::int8_t>: public Implementation::MathTypeTraitsIntegral<std::int8_t> {
typedef std::int32_t NumericType;
typedef float FloatingPointType;
};
template<> struct MathTypeTraits<unsigned short>: public Implementation::MathTypeTraitsIntegral<unsigned short> {
typedef unsigned int NumericType;
template<> struct MathTypeTraits<std::uint16_t>: public Implementation::MathTypeTraitsIntegral<std::uint16_t> {
typedef std::uint32_t NumericType;
typedef float FloatingPointType;
};
template<> struct MathTypeTraits<short>: public Implementation::MathTypeTraitsIntegral<short> {
typedef int NumericType;
template<> struct MathTypeTraits<std::int16_t>: public Implementation::MathTypeTraitsIntegral<std::int16_t> {
typedef std::int32_t NumericType;
typedef float FloatingPointType;
};
template<> struct MathTypeTraits<unsigned int>: public Implementation::MathTypeTraitsIntegral<unsigned int> {
typedef unsigned int NumericType;
template<> struct MathTypeTraits<std::uint32_t>: public Implementation::MathTypeTraitsIntegral<std::uint32_t> {
typedef std::uint32_t NumericType;
typedef double FloatingPointType;
};
template<> struct MathTypeTraits<int>: public Implementation::MathTypeTraitsIntegral<int> {
typedef int NumericType;
template<> struct MathTypeTraits<std::int32_t>: public Implementation::MathTypeTraitsIntegral<std::int32_t> {
typedef std::int32_t NumericType;
typedef double FloatingPointType;
};
template<> struct MathTypeTraits<unsigned long long>: public Implementation::MathTypeTraitsIntegral<unsigned long long> {
typedef unsigned long long NumericType;
template<> struct MathTypeTraits<std::uint64_t>: public Implementation::MathTypeTraitsIntegral<std::uint64_t> {
typedef std::uint64_t NumericType;
typedef long double FloatingPointType;
};
template<> struct MathTypeTraits<long long>: public Implementation::MathTypeTraitsIntegral<long long> {
typedef long long NumericType;
template<> struct MathTypeTraits<std::int64_t>: public Implementation::MathTypeTraitsIntegral<std::int64_t> {
typedef std::int64_t NumericType;
typedef long double FloatingPointType;
};
/* long is 32 bits somewhere and 64 bits elsewhere */
template<> struct MathTypeTraits<long unsigned int>: public Implementation::MathTypeTraitsIntegral<typename Implementation::MathTypeTraitsLong<sizeof(long unsigned int)>::Type> {};
template<> struct MathTypeTraits<long int>: public Implementation::MathTypeTraitsIntegral<typename Implementation::MathTypeTraitsLong<sizeof(long int)>::Type> {};
template<> struct MathTypeTraits<float>: public Implementation::MathTypeTraitsFloatingPoint<float> {
typedef float NumericType;
typedef float FloatingPointType;

2
src/Math/RectangularMatrix.h

@ -101,7 +101,7 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
* anything else. Example usage:
* @code
* RectangularMatrix<4, 1, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f);
* RectangularMatrix<4, 1, int> integral(RectangularMatrix<4, 1, int>::from(floatingPoint));
* RectangularMatrix<4, 1, std::int8_t> integral(RectangularMatrix<4, 1, std::int8_t>::from(floatingPoint));
* // integral == {1, 2, -15, 7}
* @endcode
*/

2
src/Math/Test/ConstantsTest.cpp

@ -18,8 +18,6 @@
#include "Constants.h"
#include "Math.h"
using namespace std;
CORRADE_TEST_MAIN(Magnum::Math::Test::ConstantsTest)
namespace Magnum { namespace Math { namespace Test {

54
src/Math/Test/MathTest.cpp

@ -33,46 +33,46 @@ MathTest::MathTest() {
void MathTest::normalize() {
/* Range for signed and unsigned */
CORRADE_COMPARE((Math::normalize<float, char>(-128)), 0.0f);
CORRADE_COMPARE((Math::normalize<float, char>(127)), 1.0f);
CORRADE_COMPARE((Math::normalize<float, unsigned char>(0)), 0.0f);
CORRADE_COMPARE((Math::normalize<float, unsigned char>(255)), 1.0f);
CORRADE_COMPARE((Math::normalize<float, int8_t>(-128)), 0.0f);
CORRADE_COMPARE((Math::normalize<float, int8_t>(127)), 1.0f);
CORRADE_COMPARE((Math::normalize<float, uint8_t>(0)), 0.0f);
CORRADE_COMPARE((Math::normalize<float, uint8_t>(255)), 1.0f);
/* Between */
CORRADE_COMPARE((Math::normalize<float, short>(16384)), 0.750011f);
CORRADE_COMPARE((Math::normalize<float, short>(-16384)), 0.250004f);
CORRADE_COMPARE((Math::normalize<float, int16_t>(16384)), 0.750011f);
CORRADE_COMPARE((Math::normalize<float, int16_t>(-16384)), 0.250004f);
/* Test overflow for large types */
CORRADE_COMPARE((Math::normalize<float, int>(numeric_limits<int>::min())), 0.0f);
CORRADE_COMPARE((Math::normalize<float, int>(numeric_limits<int>::max())), 1.0f);
CORRADE_COMPARE((Math::normalize<float, unsigned int>(0)), 0.0f);
CORRADE_COMPARE((Math::normalize<float, unsigned int>(numeric_limits<unsigned int>::max())), 1.0f);
CORRADE_COMPARE((Math::normalize<double, long long>(numeric_limits<long long>::min())), 0.0);
CORRADE_COMPARE((Math::normalize<double, long long>(numeric_limits<long long>::max())), 1.0);
CORRADE_COMPARE((Math::normalize<double, unsigned long long>(0)), 0.0);
CORRADE_COMPARE((Math::normalize<double, unsigned long long>(numeric_limits<unsigned long long>::max())), 1.0);
CORRADE_COMPARE((Math::normalize<float, int32_t>(numeric_limits<int32_t>::min())), 0.0f);
CORRADE_COMPARE((Math::normalize<float, int32_t>(numeric_limits<int32_t>::max())), 1.0f);
CORRADE_COMPARE((Math::normalize<float, uint32_t>(0)), 0.0f);
CORRADE_COMPARE((Math::normalize<float, uint32_t>(numeric_limits<uint32_t>::max())), 1.0f);
CORRADE_COMPARE((Math::normalize<double, int64_t>(numeric_limits<int64_t>::min())), 0.0);
CORRADE_COMPARE((Math::normalize<double, int64_t>(numeric_limits<int64_t>::max())), 1.0);
CORRADE_COMPARE((Math::normalize<double, uint64_t>(0)), 0.0);
CORRADE_COMPARE((Math::normalize<double, uint64_t>(numeric_limits<uint64_t>::max())), 1.0);
}
void MathTest::denormalize() {
/* Range for signed and unsigned */
CORRADE_COMPARE(Math::denormalize<char>(0.0f), -128);
CORRADE_COMPARE(Math::denormalize<char>(1.0f), 127);
CORRADE_COMPARE(Math::denormalize<unsigned char>(0.0f), 0);
CORRADE_COMPARE(Math::denormalize<unsigned char>(1.0f), 255);
CORRADE_COMPARE(Math::denormalize<int8_t>(0.0f), -128);
CORRADE_COMPARE(Math::denormalize<int8_t>(1.0f), 127);
CORRADE_COMPARE(Math::denormalize<uint8_t>(0.0f), 0);
CORRADE_COMPARE(Math::denormalize<uint8_t>(1.0f), 255);
/* Between */
CORRADE_COMPARE(Math::denormalize<short>(0.33f), -11141);
CORRADE_COMPARE(Math::denormalize<short>(0.66f), 10485);
CORRADE_COMPARE(Math::denormalize<int16_t>(0.33f), -11141);
CORRADE_COMPARE(Math::denormalize<int16_t>(0.66f), 10485);
/* Test overflow for large types */
CORRADE_COMPARE(Math::denormalize<int>(0.0f), numeric_limits<int>::min());
CORRADE_COMPARE(Math::denormalize<unsigned int>(0.0f), 0);
CORRADE_COMPARE(Math::denormalize<long long>(0.0), numeric_limits<long long>::min());
CORRADE_COMPARE(Math::denormalize<unsigned long long>(0.0), 0);
CORRADE_COMPARE(Math::denormalize<int32_t>(0.0f), numeric_limits<int32_t>::min());
CORRADE_COMPARE(Math::denormalize<uint32_t>(0.0f), 0);
CORRADE_COMPARE(Math::denormalize<int64_t>(0.0), numeric_limits<int64_t>::min());
CORRADE_COMPARE(Math::denormalize<uint64_t>(0.0), 0);
CORRADE_COMPARE(Math::denormalize<int>(1.0), numeric_limits<int>::max());
CORRADE_COMPARE(Math::denormalize<unsigned int>(1.0), numeric_limits<unsigned int>::max());
CORRADE_COMPARE(Math::denormalize<int32_t>(1.0), numeric_limits<int32_t>::max());
CORRADE_COMPARE(Math::denormalize<uint32_t>(1.0), numeric_limits<uint32_t>::max());
// {
// CORRADE_EXPECT_FAIL("Denormalize doesn't work for large types well");

20
src/Math/Test/MathTypeTraitsTest.cpp

@ -21,6 +21,8 @@
CORRADE_TEST_MAIN(Magnum::Math::Test::MathTypeTraitsTest)
using namespace std;
namespace Magnum { namespace Math { namespace Test {
MathTypeTraitsTest::MathTypeTraitsTest() {
@ -29,16 +31,14 @@ MathTypeTraitsTest::MathTypeTraitsTest() {
}
void MathTypeTraitsTest::equalsIntegral() {
_equalsIntegral<unsigned char>();
_equalsIntegral<char>();
_equalsIntegral<unsigned short>();
_equalsIntegral<short>();
_equalsIntegral<unsigned int>();
_equalsIntegral<int>();
_equalsIntegral<unsigned long int>();
_equalsIntegral<long int>();
_equalsIntegral<unsigned long long>();
_equalsIntegral<long long>();
_equalsIntegral<uint8_t>();
_equalsIntegral<int8_t>();
_equalsIntegral<uint16_t>();
_equalsIntegral<int16_t>();
_equalsIntegral<uint32_t>();
_equalsIntegral<int32_t>();
_equalsIntegral<uint64_t>();
_equalsIntegral<int64_t>();
}
void MathTypeTraitsTest::equalsFloatingPoint() {

4
src/Math/Test/MatrixTest.cpp

@ -98,7 +98,7 @@ void MatrixTest::constructZero() {
}
void MatrixTest::trace() {
Matrix<5, int> m(
Matrix<5, int32_t> m(
1, 2, 3, 0, 0,
2, 3, 2, 1, -2,
1, 1, -20, 1, 0,
@ -127,7 +127,7 @@ void MatrixTest::ij() {
}
void MatrixTest::determinant() {
Matrix<5, int> m(
Matrix<5, int32_t> m(
1, 2, 2, 1, 0,
2, 3, 2, 1, -2,
1, 1, 1, 1, 0,

14
src/Math/Test/RectangularMatrixTest.cpp

@ -29,7 +29,7 @@ namespace Magnum { namespace Math { namespace Test {
typedef RectangularMatrix<4, 3, float> Matrix4x3;
typedef RectangularMatrix<3, 4, float> Matrix3x4;
typedef RectangularMatrix<2, 2, float> Matrix2;
typedef RectangularMatrix<2, 2, int> Matrix2i;
typedef RectangularMatrix<2, 2, int32_t> Matrix2i;
typedef Vector<4, float> Vector4;
RectangularMatrixTest::RectangularMatrixTest() {
@ -154,8 +154,8 @@ void RectangularMatrixTest::multiplyDivide() {
CORRADE_COMPARE(-1.5f*vec, multiplied);
CORRADE_COMPARE(multiplied/-1.5f, vec);
Math::RectangularMatrix<1, 1, char> vecChar(32);
Math::RectangularMatrix<1, 1, char> multipliedChar(-48);
Math::RectangularMatrix<1, 1, int8_t> vecChar(32);
Math::RectangularMatrix<1, 1, int8_t> multipliedChar(-48);
CORRADE_COMPARE(vecChar*-1.5f, multipliedChar);
CORRADE_COMPARE(multipliedChar/-1.5f, vecChar);
CORRADE_COMPARE(-1.5f*vecChar, multipliedChar);
@ -168,14 +168,14 @@ void RectangularMatrixTest::multiplyDivide() {
}
void RectangularMatrixTest::multiply() {
RectangularMatrix<4, 6, int> left(
RectangularMatrix<4, 6, int32_t> left(
-5, 27, 10, 33, 0, -15,
7, 56, 66, 1, 0, -24,
4, 41, 4, 0, 1, -4,
9, -100, 19, -49, 1, 9
);
RectangularMatrix<5, 4, int> right(
RectangularMatrix<5, 4, int32_t> right(
1, -7, 0, 158,
2, 24, -3, 40,
3, -15, -2, -50,
@ -183,7 +183,7 @@ void RectangularMatrixTest::multiply() {
5, 30, 4, 18
);
RectangularMatrix<5, 6, int> expected(
RectangularMatrix<5, 6, int32_t> expected(
1368, -16165, 2550, -7716, 158, 1575,
506, -2725, 2352, -1870, 37, -234,
-578, 4159, -1918, 2534, -52, -127,
@ -226,7 +226,7 @@ void RectangularMatrixTest::debug() {
" 4, 3, 0)\n");
o.str("");
Debug(&o) << "a" << Matrix3x4() << "b" << RectangularMatrix<4, 3, char>();
Debug(&o) << "a" << Matrix3x4() << "b" << RectangularMatrix<4, 3, int8_t>();
CORRADE_COMPARE(o.str(), "a Matrix(0, 0, 0,\n"
" 0, 0, 0,\n"
" 0, 0, 0,\n"

10
src/MeshTools/Test/CleanTest.h

@ -29,17 +29,17 @@ class CleanTest: public Corrade::TestSuite::Tester<CleanTest> {
class Vector1 {
public:
static const std::size_t Size = 1;
typedef int Type;
typedef std::int32_t Type;
Vector1(): data(0) {}
Vector1(int i): data(i) {}
int operator[](std::size_t) const { return data; }
int& operator[](std::size_t) { return data; }
Vector1(Type i): data(i) {}
Type operator[](std::size_t) const { return data; }
Type& operator[](std::size_t) { return data; }
bool operator==(Vector1 i) const { return i.data == data; }
Vector1 operator-(Vector1 i) const { return data-i.data; }
private:
int data;
Type data;
};
};

20
src/MeshTools/Test/InterleaveTest.cpp

@ -37,18 +37,18 @@ InterleaveTest::InterleaveTest() {
void InterleaveTest::attributeCount() {
stringstream ss;
Error::setOutput(&ss);
CORRADE_COMPARE((Implementation::Interleave::attributeCount(vector<char>{0, 1, 2},
vector<char>{0, 1, 2, 3, 4, 5})), size_t(0));
CORRADE_COMPARE((Implementation::Interleave::attributeCount(vector<int8_t>{0, 1, 2},
vector<int8_t>{0, 1, 2, 3, 4, 5})), size_t(0));
CORRADE_COMPARE(ss.str(), "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.\n");
CORRADE_COMPARE((Implementation::Interleave::attributeCount(vector<char>{0, 1, 2},
vector<char>{3, 4, 5})), size_t(3));
CORRADE_COMPARE((Implementation::Interleave::attributeCount(vector<int8_t>{0, 1, 2},
vector<int8_t>{3, 4, 5})), size_t(3));
}
void InterleaveTest::stride() {
CORRADE_COMPARE(Implementation::Interleave::stride(vector<char>()), size_t(1));
CORRADE_COMPARE(Implementation::Interleave::stride(vector<int>()), size_t(4));
CORRADE_COMPARE((Implementation::Interleave::stride(vector<char>(), vector<int>())), size_t(5));
CORRADE_COMPARE(Implementation::Interleave::stride(vector<int8_t>()), size_t(1));
CORRADE_COMPARE(Implementation::Interleave::stride(vector<int32_t>()), size_t(4));
CORRADE_COMPARE((Implementation::Interleave::stride(vector<int8_t>(), vector<int32_t>())), size_t(5));
}
void InterleaveTest::write() {
@ -56,9 +56,9 @@ void InterleaveTest::write() {
size_t stride;
char* data;
tie(attributeCount, stride, data) = MeshTools::interleave(
vector<char>{0, 1, 2},
vector<int>{3, 4, 5},
vector<short>{6, 7, 8});
vector<int8_t>{0, 1, 2},
vector<int32_t>{3, 4, 5},
vector<int16_t>{6, 7, 8});
CORRADE_COMPARE(attributeCount, size_t(3));
CORRADE_COMPARE(stride, size_t(7));

10
src/MeshTools/Test/SubdivideTest.h

@ -30,17 +30,17 @@ class SubdivideTest: public Corrade::TestSuite::Tester<SubdivideTest> {
class Vector1 {
public:
static const std::size_t Size = 1;
typedef int Type;
typedef std::int32_t Type;
Vector1(): data(0) {}
Vector1(int i): data(i) {}
int operator[](std::size_t) const { return data; }
int& operator[](std::size_t) { return data; }
Vector1(Type i): data(i) {}
Type operator[](std::size_t) const { return data; }
Type& operator[](std::size_t) { return data; }
bool operator==(Vector1 i) const { return i.data == data; }
Vector1 operator-(Vector1 i) const { return data-i.data; }
private:
int data;
Type data;
};
inline static Vector1 interpolator(Vector1 a, Vector1 b) { return (a[0]+b[0])/2; }

8
src/MeshTools/Test/TipsifyTest.cpp

@ -67,10 +67,10 @@ TipsifyTest::TipsifyTest(): indices{
}
void TipsifyTest::buildAdjacency() {
vector<unsigned int> liveTriangleCount, neighborOffset, neighbors;
vector<uint32_t> liveTriangleCount, neighborOffset, neighbors;
Implementation::Tipsify(indices, vertexCount).buildAdjacency(liveTriangleCount, neighborOffset, neighbors);
CORRADE_COMPARE(liveTriangleCount, (vector<unsigned int>{
CORRADE_COMPARE(liveTriangleCount, (vector<uint32_t>{
1, 3, 3, 2,
4, 6, 6, 2,
2, 6, 6, 4,
@ -78,7 +78,7 @@ void TipsifyTest::buildAdjacency() {
1, 1, 1
}));
CORRADE_COMPARE(neighborOffset, (vector<unsigned int>{
CORRADE_COMPARE(neighborOffset, (vector<uint32_t>{
0, 1, 4, 7,
9, 13, 19, 25,
27, 29, 35, 41,
@ -86,7 +86,7 @@ void TipsifyTest::buildAdjacency() {
54, 55, 56, 57
}));
CORRADE_COMPARE(neighbors, (vector<unsigned int>{
CORRADE_COMPARE(neighbors, (vector<uint32_t>{
0,
0, 7, 11,
2, 7, 13,

30
src/Primitives/Capsule.cpp

@ -22,7 +22,7 @@ using namespace std;
namespace Magnum { namespace Primitives {
Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new vector<uint32_t>, {new vector<Point3D>()}, {new vector<Vector3>()}, textureCoords == TextureCoords::Generate ? vector<vector<Vector2>*>{new vector<Vector2>()} : vector<vector<Vector2>*>()), segments(segments), textureCoords(textureCoords) {
Capsule::Capsule(uint32_t hemisphereRings, uint32_t cylinderRings, uint32_t segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new vector<uint32_t>, {new vector<Point3D>()}, {new vector<Vector3>()}, textureCoords == TextureCoords::Generate ? vector<vector<Vector2>*>{new vector<Vector2>()} : vector<vector<Vector2>*>()), segments(segments), textureCoords(textureCoords) {
CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 3, "Capsule must have at least one hemisphere ring, one cylinder ring and three segments", );
GLfloat height = 2.0f+length;
@ -50,7 +50,7 @@ Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsig
topFaceRing();
}
Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector<std::uint32_t>, {new std::vector<Point3D>()}, {new std::vector<Vector3>()}, textureCoords == TextureCoords::Generate ? std::vector<std::vector<Vector2>*>{new std::vector<Vector2>()} : std::vector<std::vector<Vector2>*>()), segments(segments), textureCoords(textureCoords) {}
Capsule::Capsule(uint32_t segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector<uint32_t>, {new std::vector<Point3D>()}, {new std::vector<Vector3>()}, textureCoords == TextureCoords::Generate ? std::vector<std::vector<Vector2>*>{new std::vector<Vector2>()} : std::vector<std::vector<Vector2>*>()), segments(segments), textureCoords(textureCoords) {}
void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) {
positions(0)->push_back({0.0f, y, 0.0f});
@ -60,15 +60,15 @@ void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) {
textureCoords2D(0)->push_back({0.5, textureCoordsV});
}
void Capsule::hemisphereVertexRings(unsigned int count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) {
void Capsule::hemisphereVertexRings(uint32_t count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) {
GLfloat segmentAngleIncrement = 2*Math::Constants<GLfloat>::pi()/segments;
GLfloat x, y, z;
for(unsigned int i = 0; i != count; ++i) {
for(uint32_t i = 0; i != count; ++i) {
GLfloat ringAngle = startRingAngle + i*ringAngleIncrement;
x = z = cos(ringAngle);
y = sin(ringAngle);
for(unsigned int j = 0; j != segments; ++j) {
for(uint32_t j = 0; j != segments; ++j) {
GLfloat segmentAngle = j*segmentAngleIncrement;
positions(0)->push_back({x*sin(segmentAngle), centerY+y, z*cos(segmentAngle)});
normals(0)->push_back({x*sin(segmentAngle), y, z*cos(segmentAngle)});
@ -86,10 +86,10 @@ void Capsule::hemisphereVertexRings(unsigned int count, GLfloat centerY, GLfloat
}
}
void Capsule::cylinderVertexRings(unsigned int count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) {
void Capsule::cylinderVertexRings(uint32_t count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) {
GLfloat segmentAngleIncrement = 2*Math::Constants<GLfloat>::pi()/segments;
for(unsigned int i = 0; i != count; ++i) {
for(unsigned int j = 0; j != segments; ++j) {
for(uint32_t i = 0; i != count; ++i) {
for(uint32_t j = 0; j != segments; ++j) {
GLfloat segmentAngle = j*segmentAngleIncrement;
positions(0)->push_back({sin(segmentAngle), startY, cos(segmentAngle)});
normals(0)->push_back({sin(segmentAngle), 0.0f, cos(segmentAngle)});
@ -110,7 +110,7 @@ void Capsule::cylinderVertexRings(unsigned int count, GLfloat startY, GLfloat yI
}
void Capsule::bottomFaceRing() {
for(unsigned int j = 0; j != segments; ++j) {
for(uint32_t j = 0; j != segments; ++j) {
/* Bottom vertex */
indices()->push_back(0);
@ -123,11 +123,11 @@ void Capsule::bottomFaceRing() {
}
}
void Capsule::faceRings(unsigned int count, unsigned int offset) {
unsigned int vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0);
void Capsule::faceRings(uint32_t count, uint32_t offset) {
uint32_t vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0);
for(unsigned int i = 0; i != count; ++i) {
for(unsigned int j = 0; j != segments; ++j) {
for(uint32_t i = 0; i != count; ++i) {
for(uint32_t j = 0; j != segments; ++j) {
uint32_t bottomLeft = i*vertexSegments+j+offset;
uint32_t bottomRight = ((j != segments-1 || textureCoords == TextureCoords::Generate) ?
i*vertexSegments+j+1+offset : i*segments+offset);
@ -145,9 +145,9 @@ void Capsule::faceRings(unsigned int count, unsigned int offset) {
}
void Capsule::topFaceRing() {
unsigned int vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0);
uint32_t vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0);
for(unsigned int j = 0; j != segments; ++j) {
for(uint32_t j = 0; j != segments; ++j) {
/* Bottom left vertex */
indices()->push_back(normals(0)->size()-vertexSegments+j-1);

12
src/Primitives/Capsule.h

@ -53,19 +53,19 @@ class Capsule: public Trade::MeshData3D {
* If texture coordinates are generated, vertices of one segment are
* duplicated for texture wrapping.
*/
Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords = TextureCoords::DontGenerate);
Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords = TextureCoords::DontGenerate);
private:
Capsule(unsigned int segments, TextureCoords textureCoords);
Capsule(std::uint32_t segments, TextureCoords textureCoords);
void capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV);
void hemisphereVertexRings(unsigned int count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement);
void cylinderVertexRings(unsigned int count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement);
void hemisphereVertexRings(std::uint32_t count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement);
void cylinderVertexRings(std::uint32_t count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement);
void bottomFaceRing();
void faceRings(unsigned int count, unsigned int offset = 1);
void faceRings(std::uint32_t count, std::uint32_t offset = 1);
void topFaceRing();
unsigned int segments;
std::uint32_t segments;
TextureCoords textureCoords;
};

2
src/Primitives/Cube.cpp

@ -21,7 +21,7 @@ using namespace std;
namespace Magnum { namespace Primitives {
Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new vector<std::uint32_t>{
Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new vector<uint32_t>{
0, 2, 1,
2, 3, 1,
1, 3, 5,

4
src/Primitives/Cylinder.cpp

@ -21,7 +21,7 @@ using namespace std;
namespace Magnum { namespace Primitives {
Cylinder::Cylinder(unsigned int rings, unsigned int segments, GLfloat length, Flags flags): Capsule(segments, flags & Flag::GenerateTextureCoords ? TextureCoords::Generate : TextureCoords::DontGenerate) {
Cylinder::Cylinder(uint32_t rings, uint32_t segments, GLfloat length, Flags flags): Capsule(segments, flags & Flag::GenerateTextureCoords ? TextureCoords::Generate : TextureCoords::DontGenerate) {
CORRADE_ASSERT(rings >= 1 && segments >= 3, "Cylinder must have at least one ring and three segments", );
GLfloat y = length*0.5f;
@ -51,7 +51,7 @@ Cylinder::Cylinder(unsigned int rings, unsigned int segments, GLfloat length, Fl
void Cylinder::capVertexRing(GLfloat y, GLfloat textureCoordsV, const Vector3& normal) {
GLfloat segmentAngleIncrement = 2*Math::Constants<GLfloat>::pi()/segments;
for(unsigned int i = 0; i != segments; ++i) {
for(uint32_t i = 0; i != segments; ++i) {
GLfloat segmentAngle = i*segmentAngleIncrement;
positions(0)->push_back({sin(segmentAngle), y, cos(segmentAngle)});
normals(0)->push_back(normal);

2
src/Primitives/Cylinder.h

@ -58,7 +58,7 @@ class Cylinder: public Capsule {
* If texture coordinates are generated, vertices of one segment are
* duplicated for texture wrapping.
*/
Cylinder(unsigned int rings, unsigned int segments, GLfloat length, Flags flags = Flags());
Cylinder(std::uint32_t rings, std::uint32_t segments, GLfloat length, Flags flags = Flags());
private:
void capVertexRing(GLfloat y, GLfloat textureCoordsV, const Vector3& normal);

2
src/Primitives/UVSphere.cpp

@ -23,7 +23,7 @@ using namespace std;
namespace Magnum { namespace Primitives {
UVSphere::UVSphere(unsigned int rings, unsigned int segments, TextureCoords textureCoords): Capsule(segments, textureCoords) {
UVSphere::UVSphere(uint32_t rings, uint32_t segments, TextureCoords textureCoords): Capsule(segments, textureCoords) {
CORRADE_ASSERT(rings >= 2 && segments >= 3, "UVSphere must have at least two rings and three segments", );
GLfloat textureCoordsVIncrement = 1.0f/rings;

2
src/Primitives/UVSphere.h

@ -39,7 +39,7 @@ class UVSphere: public Capsule {
* If texture coordinates are generated, vertices of one segment are
* duplicated for texture wrapping.
*/
UVSphere(unsigned int rings, unsigned int segments, TextureCoords textureCoords = TextureCoords::DontGenerate);
UVSphere(std::uint32_t rings, std::uint32_t segments, TextureCoords textureCoords = TextureCoords::DontGenerate);
};
}}

2
src/Profiler.h

@ -95,7 +95,7 @@ class MAGNUM_EXPORT Profiler {
*
* @see otherSection, addSection(), start(Section)
*/
typedef unsigned int Section;
typedef std::uint32_t Section;
/**
* @brief Default section

4
src/Swizzle.h

@ -90,7 +90,7 @@ namespace Implementation {
Creates new vector from given components. Example:
@code
Vector4<int> original(-1, 2, 3, 4);
Vector4<std::int32_t> original(-1, 2, 3, 4);
auto vec = swizzle<'a', '1', '0', 'r', 'g', 'b'>(original);
// vec == { 4, 1, 0, -1, 2, 3 }
@ -118,7 +118,7 @@ template<char ...components, class T> inline constexpr typename Implementation::
Creates new vector from given components. Example:
@code
Vector4<int> original(-1, 2, 3, 4);
Vector4<std::int32_t> original(-1, 2, 3, 4);
auto vec = swizzle(original, "a10rgb");
// vec == { 4, 1, 0, -1, 2, 3 }

4
src/Test/ColorTest.cpp

@ -25,8 +25,8 @@ using namespace Corrade::Utility;
namespace Magnum { namespace Test {
typedef Magnum::Color3<unsigned char> Color3;
typedef Magnum::Color4<unsigned char> Color4;
typedef Magnum::Color3<uint8_t> Color3;
typedef Magnum::Color4<uint8_t> Color4;
typedef Magnum::Color3<float> Color3f;
typedef Magnum::Color4<float> Color4f;

14
src/Test/ResourceManagerTest.cpp

@ -39,29 +39,29 @@ ResourceManagerTest::ResourceManagerTest() {
void ResourceManagerTest::state() {
ResourceKey questionKey("the-question");
rm->set(questionKey, new int(10), ResourceDataState::Mutable, ResourcePolicy::Resident);
Resource<int> theQuestion = rm->get<int>(questionKey);
rm->set(questionKey, new int32_t(10), ResourceDataState::Mutable, ResourcePolicy::Resident);
Resource<int32_t> theQuestion = rm->get<int32_t>(questionKey);
CORRADE_VERIFY(theQuestion.state() == ResourceState::Mutable);
CORRADE_COMPARE(*theQuestion, 10);
/* Check that hash function is working properly */
ResourceKey answerKey("the-answer");
rm->set(answerKey, new int(42), ResourceDataState::Final, ResourcePolicy::Resident);
Resource<int> theAnswer = rm->get<int>(answerKey);
rm->set(answerKey, new int32_t(42), ResourceDataState::Final, ResourcePolicy::Resident);
Resource<int32_t> theAnswer = rm->get<int32_t>(answerKey);
CORRADE_VERIFY(theAnswer.state() == ResourceState::Final);
CORRADE_COMPARE(*theAnswer, 42);
CORRADE_COMPARE(rm->count<int>(), 2);
CORRADE_COMPARE(rm->count<int32_t>(), 2);
/* Cannot change already final resource */
stringstream out;
Error::setOutput(&out);
rm->set(answerKey, new int(43), ResourceDataState::Mutable, ResourcePolicy::Resident);
rm->set(answerKey, new int32_t(43), ResourceDataState::Mutable, ResourcePolicy::Resident);
CORRADE_COMPARE(*theAnswer, 42);
CORRADE_COMPARE(out.str(), "ResourceManager: cannot change already final resource\n");
/* Check non-final resource changes */
rm->set(questionKey, new int(20), ResourceDataState::Final, ResourcePolicy::Resident);
rm->set(questionKey, new int32_t(20), ResourceDataState::Final, ResourcePolicy::Resident);
CORRADE_VERIFY(theQuestion.state() == ResourceState::Final);
CORRADE_COMPARE(*theQuestion, 20);
}

2
src/Test/ResourceManagerTest.h

@ -31,7 +31,7 @@ class Data {
inline ~Data() { --count; }
};
typedef Magnum::ResourceManager<int, Data> ResourceManager;
typedef Magnum::ResourceManager<int32_t, Data> ResourceManager;
class ResourceManagerTest: public Corrade::TestSuite::Tester<ResourceManagerTest> {
public:

14
src/Test/SwizzleTest.cpp

@ -23,9 +23,9 @@ CORRADE_TEST_MAIN(Magnum::Test::SwizzleTest)
namespace Magnum { namespace Test {
typedef Math::Vector2<int> Vector2;
typedef Math::Vector3<int> Vector3;
typedef Math::Vector4<int> Vector4;
typedef Math::Vector2<int32_t> Vector2;
typedef Math::Vector3<int32_t> Vector3;
typedef Math::Vector4<int32_t> Vector4;
SwizzleTest::SwizzleTest() {
addTests(&SwizzleTest::xyzw,
@ -88,10 +88,10 @@ void SwizzleTest::type() {
void SwizzleTest::defaultType() {
Vector4 orig(1, 2, 3, 4);
CORRADE_COMPARE(swizzle<'b'>(orig), (Math::Vector<1, int>(3)));
CORRADE_COMPARE(swizzle(orig, "b"), (Math::Vector<1, int>(3)));
CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g', 'z', 'y', 'x'>(orig)), (Math::Vector<7, int>(3, 1, 4, 2, 3, 2, 1)));
CORRADE_COMPARE(swizzle(orig, "bragzyx"), (Math::Vector<7, int>(3, 1, 4, 2, 3, 2, 1)));
CORRADE_COMPARE(swizzle<'b'>(orig), (Math::Vector<1, int32_t>(3)));
CORRADE_COMPARE(swizzle(orig, "b"), (Math::Vector<1, int32_t>(3)));
CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g', 'z', 'y', 'x'>(orig)), (Math::Vector<7, int32_t>(3, 1, 4, 2, 3, 2, 1)));
CORRADE_COMPARE(swizzle(orig, "bragzyx"), (Math::Vector<7, int32_t>(3, 1, 4, 2, 3, 2, 1)));
}
}}

2
src/Timeline.cpp

@ -37,7 +37,7 @@ void Timeline::nextFrame() {
if(!running) return;
auto now = high_resolution_clock::now();
unsigned int duration = duration_cast<microseconds>(now-previousFrameTime).count();
std::uint32_t duration = duration_cast<microseconds>(now-previousFrameTime).count();
_previousFrameDuration = duration/1e6f;
if(_previousFrameDuration < _minimalFrameTime) {

20
src/TypeTraits.cpp

@ -15,18 +15,22 @@
#include "TypeTraits.h"
#include <type_traits>
using namespace std;
namespace Magnum {
#ifndef DOXYGEN_GENERATING_OUTPUT
static_assert(sizeof(GLubyte) == sizeof(unsigned char), "GLubyte is not the same as unsigned char");
static_assert(sizeof(GLbyte) == sizeof(char), "GLbyte is not the same as char");
static_assert(sizeof(GLushort) == sizeof(unsigned short), "GLushort is not the same as unsigned short");
static_assert(sizeof(GLshort) == sizeof(short), "GLshort is not the same as short");
static_assert(sizeof(GLuint) == sizeof(unsigned int), "GLuint is not the same as unsigned int");
static_assert(sizeof(GLint) == sizeof(int), "GLint is not the same as int");
static_assert(sizeof(GLfloat) == sizeof(float), "GLfloat is not the same as float");
static_assert(is_same<GLubyte, uint8_t>::value, "GLubyte is not the same as uint8_t");
static_assert(is_same<GLbyte, int8_t>::value, "GLbyte is not the same as int8_t");
static_assert(is_same<GLushort, uint16_t>::value, "GLushort is not the same as uint16_t");
static_assert(is_same<GLshort, int16_t>::value, "GLshort is not the same as int16_t");
static_assert(is_same<GLuint, uint32_t>::value, "GLuint is not the same as uint32_t");
static_assert(is_same<GLint, int32_t>::value, "GLint is not the same as int32_t");
static_assert(is_same<GLfloat, float>::value, "GLfloat is not the same as float");
#ifndef MAGNUM_TARGET_GLES
static_assert(sizeof(GLdouble) == sizeof(double), "GLdouble is not the same as double");
static_assert(is_same<GLdouble, double>::value, "GLdouble is not the same as double");
#endif
#endif

12
src/TypeTraits.h

@ -165,7 +165,7 @@ template<> struct TypeOf<Type::Float> { typedef GLfloat Type; };
template<> struct TypeOf<Type::Double> { typedef GLdouble Type; };
#endif
template<> struct TypeTraits<GLubyte>: public Math::MathTypeTraits<unsigned char> {
template<> struct TypeTraits<GLubyte>: public Math::MathTypeTraits<std::uint8_t> {
inline constexpr static Type type() { return Type::UnsignedByte; }
inline constexpr static Type indexType() { return Type::UnsignedByte; }
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedByte; }
@ -173,7 +173,7 @@ template<> struct TypeTraits<GLubyte>: public Math::MathTypeTraits<unsigned char
inline constexpr static std::size_t count() { return 1; }
};
template<> struct TypeTraits<GLbyte>: public Math::MathTypeTraits<char> {
template<> struct TypeTraits<GLbyte>: public Math::MathTypeTraits<std::int8_t> {
inline constexpr static Type type() { return Type::Byte; }
/* Can not be used for indices */
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Byte; }
@ -181,7 +181,7 @@ template<> struct TypeTraits<GLbyte>: public Math::MathTypeTraits<char> {
inline constexpr static std::size_t count() { return 1; }
};
template<> struct TypeTraits<GLushort>: public Math::MathTypeTraits<unsigned short> {
template<> struct TypeTraits<GLushort>: public Math::MathTypeTraits<std::uint16_t> {
inline constexpr static Type type() { return Type::UnsignedShort; }
inline constexpr static Type indexType() { return Type::UnsignedShort; }
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedShort; }
@ -189,7 +189,7 @@ template<> struct TypeTraits<GLushort>: public Math::MathTypeTraits<unsigned sho
inline constexpr static std::size_t count() { return 1; }
};
template<> struct TypeTraits<GLshort>: public Math::MathTypeTraits<short> {
template<> struct TypeTraits<GLshort>: public Math::MathTypeTraits<std::int16_t> {
inline constexpr static Type type() { return Type::Short; }
/* Can not be used for indices */
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Short; }
@ -197,7 +197,7 @@ template<> struct TypeTraits<GLshort>: public Math::MathTypeTraits<short> {
inline constexpr static std::size_t count() { return 1; }
};
template<> struct TypeTraits<GLuint>: public Math::MathTypeTraits<unsigned int> {
template<> struct TypeTraits<GLuint>: public Math::MathTypeTraits<std::uint16_t> {
inline constexpr static Type type() { return Type::UnsignedInt; }
inline constexpr static Type indexType() { return Type::UnsignedInt; }
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedInt; }
@ -205,7 +205,7 @@ template<> struct TypeTraits<GLuint>: public Math::MathTypeTraits<unsigned int>
inline constexpr static std::size_t count() { return 1; }
};
template<> struct TypeTraits<GLint>: public Math::MathTypeTraits<int> {
template<> struct TypeTraits<GLint>: public Math::MathTypeTraits<std::int16_t> {
inline constexpr static Type type() { return Type::Int; }
/* Can not be used for indices */
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Int; }

Loading…
Cancel
Save