Browse Source

Merge branch 'master' into compatibility

Conflicts:
	src/Test/SwizzleTest.cpp
Vladimír Vondruš 13 years ago
parent
commit
476418d5eb
  1. 2
      src/DebugTools/Test/CMakeLists.txt
  2. 4
      src/DimensionTraits.h
  3. 8
      src/Magnum.h
  4. 2
      src/Math/Algorithms/Svd.h
  5. 34
      src/Math/Algorithms/Test/SvdTest.cpp
  6. 6
      src/Math/Angle.h
  7. 2
      src/Math/Constants.h
  8. 1
      src/Math/Functions.h
  9. 46
      src/Math/Test/AngleTest.cpp
  10. 14
      src/Math/Test/ConstantsTest.cpp
  11. 2
      src/Math/Test/DualComplexTest.cpp
  12. 2
      src/Math/Test/DualQuaternionTest.cpp
  13. 20
      src/Math/Test/FunctionsTest.cpp
  14. 2
      src/Math/Test/TypeTraitsTest.cpp
  15. 4
      src/Math/Test/UnitTest.cpp
  16. 10
      src/Math/TypeTraits.h
  17. 4
      src/Query.cpp
  18. 10
      src/Shaders/DistanceFieldVectorShader.cpp
  19. 10
      src/Shaders/FlatShader.cpp
  20. 10
      src/Shaders/PhongShader.cpp
  21. 10
      src/Shaders/VectorShader.cpp
  22. 15
      src/Shaders/VertexColorShader.cpp
  23. 2
      src/Shaders/VertexColorShader.h
  24. 6
      src/Shaders/VertexColorShader2D.vert
  25. 6
      src/Shaders/VertexColorShader3D.vert
  26. 27
      src/Test/AbstractShaderProgramTest.cpp
  27. 6
      src/Test/SwizzleTest.cpp

2
src/DebugTools/Test/CMakeLists.txt

@ -22,4 +22,4 @@
# DEALINGS IN THE SOFTWARE.
#
corrade_add_test(MagnumDebugToolsForceRendererTest ForceRendererTest.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(DebugToolsForceRendererTest ForceRendererTest.cpp LIBRARIES MagnumMathTestLib)

4
src/DimensionTraits.h

@ -77,12 +77,14 @@ template<> struct DimensionTraits<2, Float> {
typedef Math::Vector2<Float> VectorType;
typedef Math::Matrix3<Float> MatrixType;
};
#ifndef MAGNUM_TARGET_GLES
template<> struct DimensionTraits<2, Double> {
DimensionTraits() = delete;
typedef Math::Vector2<Double> VectorType;
typedef Math::Matrix3<Double> MatrixType;
};
#endif
/* Three dimensions - integral */
template<class T> struct DimensionTraits<3, T> {
@ -98,6 +100,7 @@ template<> struct DimensionTraits<3, Float> {
typedef Math::Vector3<Float> VectorType;
typedef Math::Matrix4<Float> MatrixType;
};
#ifndef MAGNUM_TARGET_GLES
template<> struct DimensionTraits<3, Double> {
DimensionTraits() = delete;
@ -105,6 +108,7 @@ template<> struct DimensionTraits<3, Double> {
typedef Math::Matrix4<Double> MatrixType;
};
#endif
#endif
}

8
src/Magnum.h

@ -50,9 +50,11 @@ namespace Math {
template<class T> struct Constants;
#ifndef CORRADE_GCC46_COMPATIBILITY
#ifndef MAGNUM_TARGET_GLES
constexpr Rad<Double> operator "" _rad(long double);
constexpr Rad<Float> operator "" _radf(long double);
constexpr Deg<Double> operator "" _deg(long double);
#endif
constexpr Rad<Float> operator "" _radf(long double);
constexpr Deg<Float> operator "" _degf(long double);
#endif
}
@ -253,9 +255,11 @@ typedef Math::Geometry::Rectangle<Double> Rectangled;
#ifndef CORRADE_GCC46_COMPATIBILITY
/* Using angle literals from Math namespace */
#ifndef MAGNUM_TARGET_GLES
using Math::operator "" _deg;
using Math::operator "" _degf;
using Math::operator "" _rad;
#endif
using Math::operator "" _degf;
using Math::operator "" _radf;
#endif

2
src/Math/Algorithms/Svd.h

@ -51,7 +51,9 @@ template<class T> T pythagoras(T a, T b) {
template<class T> T smallestDelta();
template<> inline constexpr Float smallestDelta<Float>() { return 1.0e-32; }
#ifndef MAGNUM_TARGET_GLES
template<> inline constexpr Double smallestDelta<Double>() { return 1.0e-64; }
#endif
}
#endif

34
src/Math/Algorithms/Test/SvdTest.cpp

@ -36,11 +36,13 @@ class SvdTest: public Corrade::TestSuite::Tester {
void testFloat();
};
#ifndef MAGNUM_TARGET_GLES
typedef RectangularMatrix<5, 8, Double> Matrix5x8d;
typedef Matrix<8, Double> Matrix8d;
typedef Matrix<5, Double> Matrix5d;
typedef Vector<8, Double> Vector8d;
typedef Vector<5, Double> Vector5d;
#endif
typedef RectangularMatrix<5, 8, Float> Matrix5x8f;
typedef Matrix<8, Float> Matrix8f;
@ -48,15 +50,25 @@ typedef Matrix<5, Float> Matrix5f;
typedef Vector<8, Float> Vector8f;
typedef Vector<5, Float> Vector5f;
constexpr static Matrix5x8d a(
#ifndef MAGNUM_TARGET_GLES
constexpr static Matrix5x8d ad(
Vector8d(22.0, 14.0, -1.0, -3.0, 9.0, 9.0, 2.0, 4.0),
Vector8d(10.0, 7.0, 13.0, -2.0, 8.0, 1.0, -6.0, 5.0),
Vector8d( 2.0, 10.0, -1.0, 13.0, 1.0, -7.0, 6.0, 0.0),
Vector8d( 3.0, 0.0, -11.0, -2.0, -2.0, 5.0, 5.0, -2.0),
Vector8d( 7.0, 8.0, 3.0, 4.0, 4.0, -1.0, 1.0, 2.0)
);
static const Vector5d expected(std::sqrt(1248.0), 0.0, 20.0, std::sqrt(384.0), 0.0);
static const Vector5d expectedd(std::sqrt(1248.0), 0.0, 20.0, std::sqrt(384.0), 0.0);
#endif
constexpr static Matrix5x8f af(
Vector8f(22.0f, 14.0f, -1.0f, -3.0f, 9.0f, 9.0f, 2.0f, 4.0f),
Vector8f(10.0f, 7.0f, 13.0f, -2.0f, 8.0f, 1.0f, -6.0f, 5.0f),
Vector8f( 2.0f, 10.0f, -1.0f, 13.0f, 1.0f, -7.0f, 6.0f, 0.0f),
Vector8f( 3.0f, 0.0f, -11.0f, -2.0f, -2.0f, 5.0f, 5.0f, -2.0f),
Vector8f( 7.0f, 8.0f, 3.0f, 4.0f, 4.0f, -1.0f, 1.0f, 2.0f)
);
static const Vector5f expectedf(std::sqrt(1248.0f), 0.0f, 20.0f, std::sqrt(384.0f), 0.0f);
SvdTest::SvdTest() {
addTests({&SvdTest::testDouble,
@ -64,41 +76,45 @@ SvdTest::SvdTest() {
}
void SvdTest::testDouble() {
#ifndef MAGNUM_TARGET_GLES
Matrix5x8d u;
Vector5d w;
Matrix5d v;
std::tie(u, w, v) = Algorithms::svd(a);
std::tie(u, w, v) = Algorithms::svd(ad);
/* Test composition */
Matrix8d u2(u[0], u[1], u[2], u[3], u[4], Vector8d(), Vector8d(), Vector8d());
Matrix5x8d w2 = Matrix5x8d::fromDiagonal(w);
CORRADE_COMPARE(u2*w2*v.transposed(), a);
CORRADE_COMPARE(u2*w2*v.transposed(), ad);
/* Test that V is unitary */
CORRADE_COMPARE(v*v.transposed(), Matrix5d(Matrix5d::Identity));
CORRADE_COMPARE(v.transposed()*v, Matrix5d(Matrix5d::Identity));
/* Test W */
CORRADE_COMPARE(w, expected);
CORRADE_COMPARE(w, expectedd);
#else
CORRADE_SKIP("Double precision is not supported when targeting OpenGL ES.");
#endif
}
void SvdTest::testFloat() {
Matrix5x8f u;
Vector5f w;
Matrix5f v;
std::tie(u, w, v) = Algorithms::svd(Matrix5x8f(a));
std::tie(u, w, v) = Algorithms::svd(af);
/* Test composition (single precision is not enough, test for similarity) */
Matrix8f u2(u[0], u[1], u[2], u[3], u[4], Vector8f(), Vector8f(), Vector8f());
Matrix5x8f w2 = Matrix5x8f::fromDiagonal(w);
CORRADE_VERIFY((u2*w2*v.transposed()-Matrix5x8f(a)).maxAbs() < 1.0e-5f);
CORRADE_VERIFY((u2*w2*v.transposed()-af).maxAbs() < 1.0e-5f);
/* Test that V is unitary */
CORRADE_COMPARE(v*v.transposed(), Matrix5f(Matrix5f::Identity));
CORRADE_COMPARE(v.transposed()*v, Matrix5f(Matrix5f::Identity));
/* Test W (single precision is not enough, test for similarity) */
CORRADE_VERIFY((w-Vector5f(expected)).maxAbs() < 1.0e-5f);
CORRADE_VERIFY((w-expectedf).maxAbs() < 1.0e-5f);
}
}}}}

6
src/Math/Angle.h

@ -147,6 +147,7 @@ template<class T> class Deg: public Unit<Deg, T> {
};
#ifndef CORRADE_GCC46_COMPATIBILITY
#ifndef MAGNUM_TARGET_GLES
/** @relates Deg
@brief Double-precision degree value literal
@ -157,8 +158,10 @@ Double cosine = Math::cos(1.047_rad); // cosine = 0.5
@endcode
@see Magnum::operator""_deg(), operator""_degf(), operator""_rad()
@note Not available on GCC < 4.7. Use Deg::Deg(T) instead.
@requires_gl Only single-precision types are available in OpenGL ES.
*/
inline constexpr Deg<Double> operator "" _deg(long double value) { return Deg<Double>(value); }
#endif
/** @relates Deg
@brief Single-precision degree value literal
@ -170,6 +173,7 @@ Float tangent = Math::tan(1.047_radf); // tangent = 1.732f
@endcode
@see Magnum::operator""_degf(), operator""_deg(), operator""_radf()
@note Not available on GCC < 4.7. Use Deg::Deg(T) instead.
@requires_gl Only single-precision types are available in OpenGL ES.
*/
inline constexpr Deg<Float> operator "" _degf(long double value) { return Deg<Float>(value); }
#endif
@ -206,6 +210,7 @@ template<class T> class Rad: public Unit<Rad, T> {
};
#ifndef CORRADE_GCC46_COMPATIBILITY
#ifndef MAGNUM_TARGET_GLES
/** @relates Rad
@brief Double-precision radian value literal
@ -214,6 +219,7 @@ See operator""_rad() for more information.
@note Not available on GCC < 4.7. Use Rad::Rad(T) instead.
*/
inline constexpr Rad<Double> operator "" _rad(long double value) { return Rad<Double>(value); }
#endif
/** @relates Rad
@brief Single-precision radian value literal

2
src/Math/Constants.h

@ -55,6 +55,7 @@ template<class T> struct Constants {
};
#ifndef DOXYGEN_GENERATING_OUTPUT
#ifndef MAGNUM_TARGET_GLES
template<> struct Constants<Double> {
Constants() = delete;
@ -62,6 +63,7 @@ template<> struct Constants<Double> {
static inline constexpr Double sqrt2() { return 1.414213562373095; }
static inline constexpr Double sqrt3() { return 1.732050807568877; }
};
#endif
template<> struct Constants<Float> {
Constants() = delete;

1
src/Math/Functions.h

@ -289,7 +289,6 @@ integral type.
range is undefined.
@see normalize()
@todo Fix test for UnsignedLong
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
template<class Integral, class FloatingPoint> inline Integral denormalize(const FloatingPoint& value);

46
src/Math/Test/AngleTest.cpp

@ -43,8 +43,10 @@ class AngleTest: public Corrade::TestSuite::Tester {
typedef Math::Deg<Float> Deg;
typedef Math::Rad<Float> Rad;
#ifndef MAGNUM_TARGET_GLES
typedef Math::Deg<Double> Degd;
typedef Math::Rad<Double> Radd;
#endif
AngleTest::AngleTest() {
addTests({&AngleTest::construct,
@ -57,44 +59,68 @@ AngleTest::AngleTest() {
void AngleTest::construct() {
/* Default constructor */
constexpr Degd a;
constexpr Deg m;
CORRADE_COMPARE(Double(a), 0.0f);
CORRADE_COMPARE(Float(m), 0.0f);
#ifndef MAGNUM_TARGET_GLES
constexpr Degd a;
CORRADE_COMPARE(Double(a), 0.0);
#else
constexpr Deg a;
CORRADE_COMPARE(Float(a), 0.0f);
#endif
/* Value constructor */
constexpr Deg b(25.0);
CORRADE_COMPARE(Float(b), 25.0f);
#ifndef MAGNUM_TARGET_GLES
constexpr Radd n(3.14);
CORRADE_COMPARE(Float(b), 25.0);
CORRADE_COMPARE(Double(n), 3.14);
#else
constexpr Rad n(3.14);
CORRADE_COMPARE(Float(n), 3.14f);
#endif
/* Copy constructor */
constexpr Deg c(b);
constexpr Radd o(n);
CORRADE_COMPARE(c, b);
#ifndef MAGNUM_TARGET_GLES
constexpr Radd o(n);
CORRADE_COMPARE(o, n);
#else
constexpr Rad o(n);
CORRADE_COMPARE(o, n);
#endif
/* Conversion operator */
constexpr Degd d(b);
constexpr Rad p(n);
CORRADE_COMPARE(Double(d), 25.0);
CORRADE_COMPARE(Float(p), 3.14f);
#ifndef MAGNUM_TARGET_GLES
constexpr Degd d(b);
CORRADE_COMPARE(Double(d), 25.0);
#else
constexpr Deg d(b);
CORRADE_COMPARE(Float(d), 25.0f);
#endif
}
void AngleTest::literals() {
#ifndef CORRADE_GCC46_COMPATIBILITY
#ifndef MAGNUM_TARGET_GLES
constexpr auto a = 25.0_deg;
constexpr auto b = 25.0_degf;
CORRADE_VERIFY((std::is_same<decltype(a), const Degd>::value));
CORRADE_VERIFY((std::is_same<decltype(b), const Deg>::value));
CORRADE_COMPARE(Double(a), 25.0);
#endif
constexpr auto b = 25.0_degf;
CORRADE_VERIFY((std::is_same<decltype(b), const Deg>::value));
CORRADE_COMPARE(Float(b), 25.0f);
#ifndef MAGNUM_TARGET_GLES
constexpr auto m = 3.14_rad;
constexpr auto n = 3.14_radf;
CORRADE_VERIFY((std::is_same<decltype(m), const Radd>::value));
CORRADE_VERIFY((std::is_same<decltype(n), const Rad>::value));
CORRADE_COMPARE(Double(m), 3.14);
#endif
constexpr auto n = 3.14_radf;
CORRADE_VERIFY((std::is_same<decltype(n), const Rad>::value));
CORRADE_COMPARE(Float(n), 3.14f);
#else
CORRADE_SKIP("User-defined literals are not available on GCC < 4.7.");

14
src/Math/Test/ConstantsTest.cpp

@ -33,23 +33,31 @@ class ConstantsTest: public Corrade::TestSuite::Tester {
public:
ConstantsTest();
void constants();
void constantsFloat();
void constantsDouble();
};
ConstantsTest::ConstantsTest() {
addTests({&ConstantsTest::constants});
addTests({&ConstantsTest::constantsFloat,
&ConstantsTest::constantsDouble});
}
void ConstantsTest::constants() {
void ConstantsTest::constantsFloat() {
constexpr Float a = Constants<Float>::sqrt2();
constexpr Float b = Constants<Float>::sqrt3();
CORRADE_COMPARE(Math::pow<2>(a), 2.0f);
CORRADE_COMPARE(Math::pow<2>(b), 3.0f);
}
void ConstantsTest::constantsDouble() {
#ifndef MAGNUM_TARGET_GLES
constexpr Double c = Constants<Double>::sqrt2();
constexpr Double d = Constants<Double>::sqrt3();
CORRADE_COMPARE(Math::pow<2>(c), 2.0);
CORRADE_COMPARE(Math::pow<2>(d), 3.0);
#else
CORRADE_SKIP("Double precision is not supported when targeting OpenGL ES.");
#endif
}
}}}

2
src/Math/Test/DualComplexTest.cpp

@ -126,7 +126,7 @@ void DualComplexTest::constructFromVector() {
void DualComplexTest::constructCopy() {
constexpr DualComplex a({-1.0f, 2.5f}, {3.0f, -7.5f});
constexpr DualComplex b(a);
CORRADE_COMPARE(a, DualComplex({-1.0f, 2.5f}, {3.0f, -7.5f}));
CORRADE_COMPARE(b, DualComplex({-1.0f, 2.5f}, {3.0f, -7.5f}));
}
void DualComplexTest::isNormalized() {

2
src/Math/Test/DualQuaternionTest.cpp

@ -124,7 +124,7 @@ void DualQuaternionTest::constructFromVector() {
void DualQuaternionTest::constructCopy() {
constexpr DualQuaternion a({{1.0f, 2.0f, -3.0f}, -3.5f}, {{4.5f, -7.0f, 2.0f}, 1.0f});
constexpr DualQuaternion b(a);
CORRADE_COMPARE(a, DualQuaternion({{1.0f, 2.0f, -3.0f}, -3.5f}, {{4.5f, -7.0f, 2.0f}, 1.0f}));
CORRADE_COMPARE(b, DualQuaternion({{1.0f, 2.0f, -3.0f}, -3.5f}, {{4.5f, -7.0f, 2.0f}, 1.0f}));
}
void DualQuaternionTest::isNormalized() {

20
src/Math/Test/FunctionsTest.cpp

@ -134,11 +134,13 @@ void FunctionsTest::normalizeUnsigned() {
CORRADE_COMPARE((Math::normalize<Float, UnsignedByte>(0)), 0.0f);
CORRADE_COMPARE((Math::normalize<Float, UnsignedByte>(255)), 1.0f);
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE((Math::normalize<Double, UnsignedInt>(0)), 0.0);
CORRADE_COMPARE((Math::normalize<Double, UnsignedInt>(std::numeric_limits<UnsignedInt>::max())), 1.0);
CORRADE_COMPARE((Math::normalize<long double, UnsignedLong>(0)), 0.0);
CORRADE_COMPARE((Math::normalize<long double, UnsignedLong>(std::numeric_limits<UnsignedLong>::max())), 1.0);
#endif
CORRADE_COMPARE((Math::normalize<Float, UnsignedShort>(0)), 0.0f);
CORRADE_COMPARE((Math::normalize<Float, UnsignedShort>(std::numeric_limits<UnsignedShort>::max())), 1.0f);
@ -158,6 +160,7 @@ void FunctionsTest::normalizeSigned() {
CORRADE_COMPARE((Math::normalize<Float, Short>(0)), 0.0f);
CORRADE_COMPARE((Math::normalize<Float, Short>(std::numeric_limits<Short>::max())), 1.0f);
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE((Math::normalize<Double, Int>(std::numeric_limits<Int>::min())), -1.0);
CORRADE_COMPARE((Math::normalize<Double, Int>(0)), 0.0);
CORRADE_COMPARE((Math::normalize<Double, Int>(std::numeric_limits<Int>::max())), 1.0);
@ -165,6 +168,7 @@ void FunctionsTest::normalizeSigned() {
CORRADE_COMPARE((Math::normalize<long double, Long>(std::numeric_limits<Long>::min())), -1.0);
CORRADE_COMPARE((Math::normalize<long double, Long>(0)), 0.0);
CORRADE_COMPARE((Math::normalize<long double, Long>(std::numeric_limits<Long>::max())), 1.0);
#endif
CORRADE_COMPARE((Math::normalize<Float, Short>(16384)), 0.500015f);
CORRADE_COMPARE((Math::normalize<Float, Short>(-16384)), -0.500015f);
@ -179,15 +183,13 @@ void FunctionsTest::denormalizeUnsigned() {
CORRADE_COMPARE(Math::denormalize<UnsignedShort>(0.0f), 0);
CORRADE_COMPARE(Math::denormalize<UnsignedShort>(1.0f), std::numeric_limits<UnsignedShort>::max());
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(Math::denormalize<UnsignedInt>(0.0), 0);
CORRADE_COMPARE(Math::denormalize<UnsignedInt>(1.0), std::numeric_limits<UnsignedInt>::max());
CORRADE_COMPARE(Math::denormalize<UnsignedLong>(0.0), 0);
{
CORRADE_EXPECT_FAIL("Wrong result with GCC and non-optimized code.");
CORRADE_VERIFY(false);
//CORRADE_COMPARE(Math::denormalize<UnsignedLong>(1.0), std::numeric_limits<UnsignedLong>::max());
}
CORRADE_COMPARE(Math::denormalize<UnsignedLong>(0.0l), 0);
CORRADE_COMPARE(Math::denormalize<UnsignedLong>(1.0l), std::numeric_limits<UnsignedLong>::max());
#endif
CORRADE_COMPARE(Math::denormalize<UnsignedShort>(0.33f), 21626);
CORRADE_COMPARE(Math::denormalize<UnsignedShort>(0.66f), 43253);
@ -204,6 +206,7 @@ void FunctionsTest::denormalizeSigned() {
CORRADE_COMPARE(Math::denormalize<Short>(0.0f), 0);
CORRADE_COMPARE(Math::denormalize<Short>(1.0f), std::numeric_limits<Short>::max());
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(Math::denormalize<Int>(-1.0), std::numeric_limits<Int>::min()+1);
CORRADE_COMPARE(Math::denormalize<Int>(0.0), 0);
CORRADE_COMPARE(Math::denormalize<Int>(1.0), std::numeric_limits<Int>::max());
@ -211,6 +214,7 @@ void FunctionsTest::denormalizeSigned() {
CORRADE_COMPARE(Math::denormalize<Long>(-1.0l), std::numeric_limits<Long>::min()+1);
CORRADE_COMPARE(Math::denormalize<Long>(0.0l), 0);
CORRADE_COMPARE(Math::denormalize<Long>(1.0l), std::numeric_limits<Long>::max());
#endif
CORRADE_COMPARE(Math::denormalize<Short>(-0.33f), -10813);
CORRADE_COMPARE(Math::denormalize<Short>(0.66f), 21626);
@ -225,11 +229,13 @@ void FunctionsTest::renormalizeUnsinged() {
CORRADE_COMPARE(Math::normalize<Float>(Math::denormalize<UnsignedShort>(0.0f)), 0.0f);
CORRADE_COMPARE(Math::normalize<Float>(Math::denormalize<UnsignedShort>(1.0f)), 1.0f);
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(Math::normalize<Double>(Math::denormalize<UnsignedInt>(0.0)), 0.0);
CORRADE_COMPARE(Math::normalize<Double>(Math::denormalize<UnsignedInt>(1.0)), 1.0);
CORRADE_COMPARE(Math::normalize<long double>(Math::denormalize<UnsignedLong>(0.0l)), 0.0l);
CORRADE_COMPARE(Math::normalize<long double>(Math::denormalize<UnsignedLong>(1.0l)), 1.0l);
#endif
}
void FunctionsTest::renormalizeSinged() {
@ -241,6 +247,7 @@ void FunctionsTest::renormalizeSinged() {
CORRADE_COMPARE(Math::normalize<Float>(Math::denormalize<Short>(0.0f)), 0.0f);
CORRADE_COMPARE(Math::normalize<Float>(Math::denormalize<Short>(1.0f)), 1.0f);
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(Math::normalize<Double>(Math::denormalize<Int>(-1.0)), -1.0);
CORRADE_COMPARE(Math::normalize<Double>(Math::denormalize<Int>(0.0)), 0.0);
CORRADE_COMPARE(Math::normalize<Double>(Math::denormalize<Int>(1.0)), 1.0);
@ -248,6 +255,7 @@ void FunctionsTest::renormalizeSinged() {
CORRADE_COMPARE(Math::normalize<long double>(Math::denormalize<Long>(-1.0l)), -1.0l);
CORRADE_COMPARE(Math::normalize<long double>(Math::denormalize<Long>(0.0l)), 0.0l);
CORRADE_COMPARE(Math::normalize<long double>(Math::denormalize<Long>(1.0l)), 1.0l);
#endif
}
void FunctionsTest::normalizeTypeDeduction() {

2
src/Math/Test/TypeTraitsTest.cpp

@ -59,7 +59,9 @@ void TypeTraitsTest::equalsIntegral() {
void TypeTraitsTest::equalsFloatingPoint() {
_equalsFloatingPoint<Float>();
#ifndef MAGNUM_TARGET_GLES
_equalsFloatingPoint<Double>();
#endif
}
template<class T> void TypeTraitsTest::_equalsIntegral() {

4
src/Math/Test/UnitTest.cpp

@ -55,7 +55,7 @@ UnitTest::UnitTest() {
template<class> struct Sec_;
typedef Unit<Sec_, Float> Sec;
typedef Unit<Sec_, Double> Secd;
typedef Unit<Sec_, Int> Seci;
inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, Sec value) {
return debug << Float(value);
@ -72,7 +72,7 @@ void UnitTest::constructDefault() {
}
void UnitTest::constructConversion() {
constexpr Secd a(25.0);
constexpr Seci a(25.0);
constexpr Sec b(a);
CORRADE_COMPARE(b, Sec(25.0f));
}

10
src/Math/TypeTraits.h

@ -137,16 +137,24 @@ template<> struct TypeTraits<Short>: Implementation::TypeTraitsIntegral<Short> {
typedef Float FloatingPointType;
};
template<> struct TypeTraits<UnsignedInt>: Implementation::TypeTraitsIntegral<UnsignedInt> {
#ifndef MAGNUM_TARGET_GLES
typedef Double FloatingPointType;
#endif
};
template<> struct TypeTraits<Int>: Implementation::TypeTraitsIntegral<Int> {
#ifndef MAGNUM_TARGET_GLES
typedef Double FloatingPointType;
#endif
};
template<> struct TypeTraits<UnsignedLong>: Implementation::TypeTraitsIntegral<UnsignedLong> {
#ifndef MAGNUM_TARGET_GLES
typedef long double FloatingPointType;
#endif
};
template<> struct TypeTraits<Long>: Implementation::TypeTraitsIntegral<Long> {
#ifndef MAGNUM_TARGET_GLES
typedef long double FloatingPointType;
#endif
};
/* Floating-point scalar types */
@ -165,11 +173,13 @@ template<> struct TypeTraits<Float>: Implementation::TypeTraitsFloatingPoint<Flo
inline constexpr static Float epsilon() { return FLOAT_EQUALITY_PRECISION; }
};
#ifndef MAGNUM_TARGET_GLES
template<> struct TypeTraits<Double>: Implementation::TypeTraitsFloatingPoint<Double> {
typedef Double FloatingPointType;
inline constexpr static Double epsilon() { return DOUBLE_EQUALITY_PRECISION; }
};
#endif
template<> struct TypeTraits<long double>: Implementation::TypeTraitsFloatingPoint<long double> {
typedef long double FloatingPointType;

4
src/Query.cpp

@ -93,11 +93,11 @@ template<> Long AbstractQuery::result<Long>() {
}
#endif
#ifndef MAGNUM_TARGET_GLES2
Query::Query(): target(nullptr) {}
Query::~Query() { delete target; }
#ifndef MAGNUM_TARGET_GLES2
void Query::begin(Query::Target target) {
glBeginQuery(static_cast<GLenum>(target), id());
this->target = new Target(target);
@ -135,6 +135,8 @@ void SampleQuery::end() {
target = nullptr;
}
#ifndef MAGNUM_TARGET_GLES
TimeQuery::TimeQuery() = default;
#endif
}

10
src/Shaders/DistanceFieldVectorShader.cpp

@ -62,10 +62,11 @@ template<UnsignedInt dimensions> DistanceFieldVectorShader<dimensions>::Distance
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_attrib_location>() ||
Context::current()->version() == Version::GL210) {
Context::current()->version() == Version::GL210)
#else
if(!Context::current()->isVersionSupported(Version::GLES300)) {
if(!Context::current()->isVersionSupported(Version::GLES300))
#endif
{
AbstractShaderProgram::bindAttributeLocation(AbstractVectorShader<dimensions>::Position::Location, "position");
AbstractShaderProgram::bindAttributeLocation(AbstractVectorShader<dimensions>::TextureCoordinates::Location, "textureCoordinates");
}
@ -73,10 +74,9 @@ template<UnsignedInt dimensions> DistanceFieldVectorShader<dimensions>::Distance
AbstractShaderProgram::link();
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>()) {
#else
{
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>())
#endif
{
transformationProjectionMatrixUniform = AbstractShaderProgram::uniformLocation("transformationProjectionMatrix");
colorUniform = AbstractShaderProgram::uniformLocation("color");
outlineColorUniform = AbstractShaderProgram::uniformLocation("outlineColor");

10
src/Shaders/FlatShader.cpp

@ -61,20 +61,20 @@ template<UnsignedInt dimensions> FlatShader<dimensions>::FlatShader(): transform
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_attrib_location>() ||
Context::current()->version() == Version::GL210) {
Context::current()->version() == Version::GL210)
#else
if(!Context::current()->isVersionSupported(Version::GLES300)) {
if(!Context::current()->isVersionSupported(Version::GLES300))
#endif
{
bindAttributeLocation(Position::Location, "position");
}
link();
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>()) {
#else
{
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>())
#endif
{
transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix");
colorUniform = uniformLocation("color");
}

10
src/Shaders/PhongShader.cpp

@ -52,10 +52,11 @@ PhongShader::PhongShader(): transformationMatrixUniform(0), projectionMatrixUnif
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_attrib_location>() ||
Context::current()->version() == Version::GL210) {
Context::current()->version() == Version::GL210)
#else
if(!Context::current()->isVersionSupported(Version::GLES300)) {
if(!Context::current()->isVersionSupported(Version::GLES300))
#endif
{
bindAttributeLocation(Position::Location, "position");
bindAttributeLocation(Normal::Location, "normal");
}
@ -63,10 +64,9 @@ PhongShader::PhongShader(): transformationMatrixUniform(0), projectionMatrixUnif
link();
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>()) {
#else
{
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>())
#endif
{
transformationMatrixUniform = uniformLocation("transformationMatrix");
projectionMatrixUniform = uniformLocation("projectionMatrix");
normalMatrixUniform = uniformLocation("normalMatrix");

10
src/Shaders/VectorShader.cpp

@ -62,10 +62,11 @@ template<UnsignedInt dimensions> VectorShader<dimensions>::VectorShader(): trans
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_attrib_location>() ||
Context::current()->version() == Version::GL210) {
Context::current()->version() == Version::GL210)
#else
if(!Context::current()->isVersionSupported(Version::GLES300)) {
if(!Context::current()->isVersionSupported(Version::GLES300))
#endif
{
AbstractShaderProgram::bindAttributeLocation(AbstractVectorShader<dimensions>::Position::Location, "position");
AbstractShaderProgram::bindAttributeLocation(AbstractVectorShader<dimensions>::TextureCoordinates::Location, "textureCoordinates");
}
@ -73,10 +74,9 @@ template<UnsignedInt dimensions> VectorShader<dimensions>::VectorShader(): trans
AbstractShaderProgram::link();
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>()) {
#else
{
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>())
#endif
{
transformationProjectionMatrixUniform = AbstractShaderProgram::uniformLocation("transformationProjectionMatrix");
colorUniform = AbstractShaderProgram::uniformLocation("color");
}

15
src/Shaders/VertexColorShader.cpp

@ -69,10 +69,11 @@ template<UnsignedInt dimensions> VertexColorShader<dimensions>::VertexColorShade
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_attrib_location>() ||
Context::current()->version() == Version::GL210) {
Context::current()->version() == Version::GL210)
#else
if(!Context::current()->isVersionSupported(Version::GLES300)) {
if(!Context::current()->isVersionSupported(Version::GLES300))
#endif
{
bindAttributeLocation(Position::Location, "position");
bindAttributeLocation(Color::Location, "color");
}
@ -80,12 +81,16 @@ template<UnsignedInt dimensions> VertexColorShader<dimensions>::VertexColorShade
link();
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>()) {
#else
{
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>())
#endif
{
transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix");
}
/* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */
#ifdef MAGNUM_TARGET_GLES
setTransformationProjectionMatrix(typename DimensionTraits<dimensions>::MatrixType());
#endif
}
template class VertexColorShader<2>;

2
src/Shaders/VertexColorShader.h

@ -57,6 +57,8 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT VertexColorShader:
/**
* @brief Set transformation and projection matrix
* @return Pointer to self (for method chaining)
*
* Default is identity matrix.
*/
inline VertexColorShader<dimensions>* setTransformationProjectionMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) {
setUniform(transformationProjectionMatrixUniform, matrix);

6
src/Shaders/VertexColorShader2D.vert

@ -27,8 +27,12 @@
#define out varying
#endif
#ifndef GL_ES
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0) uniform mat3 transformationProjectionMatrix;
layout(location = 0) uniform mat3 transformationProjectionMatrix = mat3(1.0);
#else
uniform mat3 transformationProjectionMatrix = mat3(1.0);
#endif
#else
uniform highp mat3 transformationProjectionMatrix;
#endif

6
src/Shaders/VertexColorShader3D.vert

@ -27,8 +27,12 @@
#define out varying
#endif
#ifndef GL_ES
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0) uniform mat4 transformationProjectionMatrix;
layout(location = 0) uniform mat4 transformationProjectionMatrix = mat4(1.0);
#else
uniform mat4 transformationProjectionMatrix = mat4(1.0);
#endif
#else
uniform highp mat4 transformationProjectionMatrix;
#endif

27
src/Test/AbstractShaderProgramTest.cpp

@ -83,6 +83,7 @@ void AbstractShaderProgramTest::attributeScalar() {
}
void AbstractShaderProgramTest::attributeScalarInt() {
#ifndef MAGNUM_TARGET_GLES2
typedef AbstractShaderProgram::Attribute<3, Int> Attribute;
/* Default constructor */
@ -92,9 +93,13 @@ void AbstractShaderProgramTest::attributeScalarInt() {
/* Options */
Attribute b(Attribute::DataType::Short);
CORRADE_COMPARE(b.dataSize(), 2);
#else
CORRADE_SKIP("Integer attributes are not available in OpenGL ES 2.");
#endif
}
void AbstractShaderProgramTest::attributeScalarUnsignedInt() {
#ifndef MAGNUM_TARGET_GLES2
typedef AbstractShaderProgram::Attribute<3, UnsignedInt> Attribute;
/* Default constructor */
@ -104,6 +109,9 @@ void AbstractShaderProgramTest::attributeScalarUnsignedInt() {
/* Options */
Attribute b(Attribute::DataType::UnsignedByte);
CORRADE_COMPARE(b.dataSize(), 1);
#else
CORRADE_SKIP("Integer attributes are not available in OpenGL ES 2.");
#endif
}
void AbstractShaderProgramTest::attributeScalarDouble() {
@ -128,12 +136,19 @@ void AbstractShaderProgramTest::attributeVector() {
CORRADE_COMPARE(a.dataType(), Attribute::DataType::Float);
/* Options */
#ifndef MAGNUM_TARGET_GLES
Attribute b(Attribute::Components::Two, Attribute::DataType::Double);
CORRADE_COMPARE(b.components(), Attribute::Components::Two);
CORRADE_COMPARE(b.dataSize(), 2*8);
#else
Attribute b(Attribute::Components::Two, Attribute::DataType::Float);
CORRADE_COMPARE(b.components(), Attribute::Components::Two);
CORRADE_COMPARE(b.dataSize(), 2*4);
#endif
}
void AbstractShaderProgramTest::attributeVectorInt() {
#ifndef MAGNUM_TARGET_GLES2
typedef AbstractShaderProgram::Attribute<3, Vector2i> Attribute;
/* Default constructor */
@ -145,9 +160,13 @@ void AbstractShaderProgramTest::attributeVectorInt() {
/* Options */
Attribute b(Attribute::Components::One, Attribute::DataType::Int);
CORRADE_COMPARE(b.dataSize(), 4);
#else
CORRADE_SKIP("Integer attributes are not available in OpenGL ES 2.");
#endif
}
void AbstractShaderProgramTest::attributeVectorUnsignedInt() {
#ifndef MAGNUM_TARGET_GLES2
typedef AbstractShaderProgram::Attribute<3, Vector4ui> Attribute;
/* Default constructor */
@ -159,6 +178,9 @@ void AbstractShaderProgramTest::attributeVectorUnsignedInt() {
/* Options */
Attribute b(Attribute::Components::Three, Attribute::DataType::UnsignedShort);
CORRADE_COMPARE(b.dataSize(), 3*2);
#else
CORRADE_SKIP("Integer attributes are not available in OpenGL ES 2.");
#endif
}
void AbstractShaderProgramTest::attributeVectorDouble() {
@ -183,8 +205,13 @@ void AbstractShaderProgramTest::attributeVector4() {
typedef AbstractShaderProgram::Attribute<3, Vector4> Attribute;
/* Custom type */
#ifndef MAGNUM_TARGET_GLES
Attribute a(Attribute::DataType::UnsignedInt2101010Rev);
CORRADE_COMPARE(a.dataSize(), 4);
#else
Attribute a(Attribute::DataType::HalfFloat);
CORRADE_COMPARE(a.dataSize(), 8);
#endif
}
void AbstractShaderProgramTest::attributeVectorBGRA() {

6
src/Test/SwizzleTest.cpp

@ -51,7 +51,7 @@ void SwizzleTest::rgba() {
void SwizzleTest::type() {
constexpr Vector4i orig;
constexpr Color3<Float> origColor3;
constexpr Color4<Double> origColor4;
constexpr Color4<UnsignedByte> origColor4;
/* decltype(a) is not const because a is not constexpr under GCC <= 4.5 */
#ifdef CORRADE_GCC45_COMPATIBILITY
@ -71,13 +71,13 @@ void SwizzleTest::type() {
CORRADE_VERIFY((std::is_same<decltype(d), const Color3<Float>>::value));
constexpr auto e = swizzle<'y', 'z', 'a'>(origColor4);
CORRADE_VERIFY((std::is_same<decltype(e), const Color3<Double>>::value));
CORRADE_VERIFY((std::is_same<decltype(e), const Color3<UnsignedByte>>::value));
constexpr auto f = swizzle<'y', 'z', 'y', 'x'>(origColor3);
CORRADE_VERIFY((std::is_same<decltype(f), const Color4<Float>>::value));
constexpr auto g = swizzle<'y', 'a', 'y', 'x'>(origColor4);
CORRADE_VERIFY((std::is_same<decltype(g), const Color4<Double>>::value));
CORRADE_VERIFY((std::is_same<decltype(g), const Color4<UnsignedByte>>::value));
#ifdef CORRADE_GCC45_COMPATIBILITY
#undef const

Loading…
Cancel
Save