From be5c872c8a550eb2340928e63f7c1bfa6a99daf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 18 Mar 2013 12:10:13 +0100 Subject: [PATCH 1/8] Math: fixed two typos in the test. They resulted in fact that the test case didn't actually test anything. Spotted by Clang. --- src/Math/Test/DualComplexTest.cpp | 2 +- src/Math/Test/DualQuaternionTest.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index d0ddce9f5..db1dce3c6 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/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() { diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index d0dc65039..d484dceb5 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/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() { From 127910d5377973e0a09c4c2b6c4126baf285e717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 18 Mar 2013 12:13:22 +0100 Subject: [PATCH 2/8] Shaders: minor tweaks. Non-matching number of opening and closing braces confused editors with code folding feature. --- src/Shaders/DistanceFieldVectorShader.cpp | 10 +++++----- src/Shaders/FlatShader.cpp | 10 +++++----- src/Shaders/PhongShader.cpp | 10 +++++----- src/Shaders/VectorShader.cpp | 10 +++++----- src/Shaders/VertexColorShader.cpp | 10 +++++----- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Shaders/DistanceFieldVectorShader.cpp b/src/Shaders/DistanceFieldVectorShader.cpp index 5d39f356c..e3ec1c106 100644 --- a/src/Shaders/DistanceFieldVectorShader.cpp +++ b/src/Shaders/DistanceFieldVectorShader.cpp @@ -59,10 +59,11 @@ template DistanceFieldVectorShader::Distance #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported() || - 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::Position::Location, "position"); AbstractShaderProgram::bindAttributeLocation(AbstractVectorShader::TextureCoordinates::Location, "textureCoordinates"); } @@ -70,10 +71,9 @@ template DistanceFieldVectorShader::Distance AbstractShaderProgram::link(); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported()) { - #else - { + if(!Context::current()->isExtensionSupported()) #endif + { transformationProjectionMatrixUniform = AbstractShaderProgram::uniformLocation("transformationProjectionMatrix"); colorUniform = AbstractShaderProgram::uniformLocation("color"); outlineColorUniform = AbstractShaderProgram::uniformLocation("outlineColor"); diff --git a/src/Shaders/FlatShader.cpp b/src/Shaders/FlatShader.cpp index 7ee89d254..afbdb8731 100644 --- a/src/Shaders/FlatShader.cpp +++ b/src/Shaders/FlatShader.cpp @@ -58,20 +58,20 @@ template FlatShader::FlatShader(): transform #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported() || - 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()) { - #else - { + if(!Context::current()->isExtensionSupported()) #endif + { transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); colorUniform = uniformLocation("color"); } diff --git a/src/Shaders/PhongShader.cpp b/src/Shaders/PhongShader.cpp index cbba095c0..a953c3d8a 100644 --- a/src/Shaders/PhongShader.cpp +++ b/src/Shaders/PhongShader.cpp @@ -52,10 +52,11 @@ PhongShader::PhongShader(): transformationMatrixUniform(0), projectionMatrixUnif #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported() || - 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()) { - #else - { + if(!Context::current()->isExtensionSupported()) #endif + { transformationMatrixUniform = uniformLocation("transformationMatrix"); projectionMatrixUniform = uniformLocation("projectionMatrix"); normalMatrixUniform = uniformLocation("normalMatrix"); diff --git a/src/Shaders/VectorShader.cpp b/src/Shaders/VectorShader.cpp index af1c7ba2f..11e48d1dc 100644 --- a/src/Shaders/VectorShader.cpp +++ b/src/Shaders/VectorShader.cpp @@ -59,10 +59,11 @@ template VectorShader::VectorShader(): trans #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported() || - 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::Position::Location, "position"); AbstractShaderProgram::bindAttributeLocation(AbstractVectorShader::TextureCoordinates::Location, "textureCoordinates"); } @@ -70,10 +71,9 @@ template VectorShader::VectorShader(): trans AbstractShaderProgram::link(); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported()) { - #else - { + if(!Context::current()->isExtensionSupported()) #endif + { transformationProjectionMatrixUniform = AbstractShaderProgram::uniformLocation("transformationProjectionMatrix"); colorUniform = AbstractShaderProgram::uniformLocation("color"); } diff --git a/src/Shaders/VertexColorShader.cpp b/src/Shaders/VertexColorShader.cpp index 8c6b4699e..82e25231f 100644 --- a/src/Shaders/VertexColorShader.cpp +++ b/src/Shaders/VertexColorShader.cpp @@ -58,10 +58,11 @@ template VertexColorShader::VertexColorShade #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported() || - 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"); } @@ -69,10 +70,9 @@ template VertexColorShader::VertexColorShade link(); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported()) { - #else - { + if(!Context::current()->isExtensionSupported()) #endif + { transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); } } From 14c679070194ebe021cccc686878b1203cccc640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 18 Mar 2013 12:15:00 +0100 Subject: [PATCH 3/8] Shaders: set default values for VertexColorShader uniforms. Default value for matrix uniform would be zero uniform which would cause "black screen of death". --- src/Shaders/VertexColorShader.cpp | 5 +++++ src/Shaders/VertexColorShader.h | 2 ++ src/Shaders/VertexColorShader2D.vert | 6 +++++- src/Shaders/VertexColorShader3D.vert | 6 +++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Shaders/VertexColorShader.cpp b/src/Shaders/VertexColorShader.cpp index 82e25231f..748036744 100644 --- a/src/Shaders/VertexColorShader.cpp +++ b/src/Shaders/VertexColorShader.cpp @@ -75,6 +75,11 @@ template VertexColorShader::VertexColorShade { transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); } + + /* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */ + #ifdef MAGNUM_TARGET_GLES + setTransformationProjectionMatrix(typename DimensionTraits::MatrixType()); + #endif } template class VertexColorShader<2>; diff --git a/src/Shaders/VertexColorShader.h b/src/Shaders/VertexColorShader.h index 87c6a5c88..a68697f90 100644 --- a/src/Shaders/VertexColorShader.h +++ b/src/Shaders/VertexColorShader.h @@ -57,6 +57,8 @@ template class MAGNUM_SHADERS_EXPORT VertexColorShader: /** * @brief Set transformation and projection matrix * @return Pointer to self (for method chaining) + * + * Default is identity matrix. */ inline VertexColorShader* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { setUniform(transformationProjectionMatrixUniform, matrix); diff --git a/src/Shaders/VertexColorShader2D.vert b/src/Shaders/VertexColorShader2D.vert index f7d2c879e..627fe2a64 100644 --- a/src/Shaders/VertexColorShader2D.vert +++ b/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 diff --git a/src/Shaders/VertexColorShader3D.vert b/src/Shaders/VertexColorShader3D.vert index 9cf727389..cbc07d517 100644 --- a/src/Shaders/VertexColorShader3D.vert +++ b/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 From b28261d26921ce651e329ee8ecd9cbcbe8ddd42a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 18 Mar 2013 19:34:04 +0100 Subject: [PATCH 4/8] Math: fix compilation of tests with OpenGL ES. Double precision is not supported there, mention that for skipped test cases. --- src/Math/Algorithms/Svd.h | 2 ++ src/Math/Algorithms/Test/SvdTest.cpp | 34 ++++++++++++++++++++-------- src/Math/Constants.h | 2 ++ src/Math/Test/ConstantsTest.cpp | 14 +++++++++--- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/Math/Algorithms/Svd.h b/src/Math/Algorithms/Svd.h index 9c4200515..51ef991ae 100644 --- a/src/Math/Algorithms/Svd.h +++ b/src/Math/Algorithms/Svd.h @@ -51,7 +51,9 @@ template T pythagoras(T a, T b) { template T smallestDelta(); template<> inline constexpr Float smallestDelta() { return 1.0e-32; } +#ifndef MAGNUM_TARGET_GLES template<> inline constexpr Double smallestDelta() { return 1.0e-64; } +#endif } #endif diff --git a/src/Math/Algorithms/Test/SvdTest.cpp b/src/Math/Algorithms/Test/SvdTest.cpp index ca1a1219b..3397f92f3 100644 --- a/src/Math/Algorithms/Test/SvdTest.cpp +++ b/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); } }}}} diff --git a/src/Math/Constants.h b/src/Math/Constants.h index 9f7402da6..d4c232677 100644 --- a/src/Math/Constants.h +++ b/src/Math/Constants.h @@ -55,6 +55,7 @@ template struct Constants { }; #ifndef DOXYGEN_GENERATING_OUTPUT +#ifndef MAGNUM_TARGET_GLES template<> struct Constants { Constants() = delete; @@ -62,6 +63,7 @@ template<> struct Constants { static inline constexpr Double sqrt2() { return 1.414213562373095; } static inline constexpr Double sqrt3() { return 1.732050807568877; } }; +#endif template<> struct Constants { Constants() = delete; diff --git a/src/Math/Test/ConstantsTest.cpp b/src/Math/Test/ConstantsTest.cpp index eef26316f..9242453b7 100644 --- a/src/Math/Test/ConstantsTest.cpp +++ b/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::sqrt2(); constexpr Float b = Constants::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::sqrt2(); constexpr Double d = Constants::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 } }}} From ba0f56fa519acce3fef5dca0eb5393f4c9dc3608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 18 Mar 2013 19:35:20 +0100 Subject: [PATCH 5/8] No need to use Double type in tests so extensively. Makes porting to OpenGL ES easier. --- src/Math/Test/UnitTest.cpp | 4 ++-- src/Test/SwizzleTest.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Math/Test/UnitTest.cpp b/src/Math/Test/UnitTest.cpp index d1d687a9a..1951fd127 100644 --- a/src/Math/Test/UnitTest.cpp +++ b/src/Math/Test/UnitTest.cpp @@ -55,7 +55,7 @@ UnitTest::UnitTest() { template struct Sec_; typedef Unit Sec; -typedef Unit Secd; +typedef Unit 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)); } diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index e340c3fa8..a7c18d453 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -51,7 +51,7 @@ void SwizzleTest::rgba() { void SwizzleTest::type() { constexpr Vector4i orig; constexpr Color3 origColor3; - constexpr Color4 origColor4; + constexpr Color4 origColor4; constexpr auto a = swizzle<'y', 'a'>(orig); CORRADE_VERIFY((std::is_same::value)); @@ -66,13 +66,13 @@ void SwizzleTest::type() { CORRADE_VERIFY((std::is_same>::value)); constexpr auto e = swizzle<'y', 'z', 'a'>(origColor4); - CORRADE_VERIFY((std::is_same>::value)); + CORRADE_VERIFY((std::is_same>::value)); constexpr auto f = swizzle<'y', 'z', 'y', 'x'>(origColor3); CORRADE_VERIFY((std::is_same>::value)); constexpr auto g = swizzle<'y', 'a', 'y', 'x'>(origColor4); - CORRADE_VERIFY((std::is_same>::value)); + CORRADE_VERIFY((std::is_same>::value)); } void SwizzleTest::defaultType() { From 35eb87630358bfcc428c71fc465d5debde513369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 18 Mar 2013 19:37:15 +0100 Subject: [PATCH 6/8] Various other compilation fixes for OpenGL ES target. --- src/DimensionTraits.h | 4 +++ src/Magnum.h | 8 +++-- src/Math/Angle.h | 6 ++++ src/Math/Test/AngleTest.cpp | 46 ++++++++++++++++++++------ src/Math/Test/FunctionsTest.cpp | 12 +++++++ src/Math/Test/TypeTraitsTest.cpp | 2 ++ src/Math/TypeTraits.h | 10 ++++++ src/Query.cpp | 4 ++- src/Test/AbstractShaderProgramTest.cpp | 27 +++++++++++++++ 9 files changed, 106 insertions(+), 13 deletions(-) diff --git a/src/DimensionTraits.h b/src/DimensionTraits.h index 3ce74b5d7..d729aca74 100644 --- a/src/DimensionTraits.h +++ b/src/DimensionTraits.h @@ -77,12 +77,14 @@ template<> struct DimensionTraits<2, Float> { typedef Math::Vector2 VectorType; typedef Math::Matrix3 MatrixType; }; +#ifndef MAGNUM_TARGET_GLES template<> struct DimensionTraits<2, Double> { DimensionTraits() = delete; typedef Math::Vector2 VectorType; typedef Math::Matrix3 MatrixType; }; +#endif /* Three dimensions - integral */ template struct DimensionTraits<3, T> { @@ -98,6 +100,7 @@ template<> struct DimensionTraits<3, Float> { typedef Math::Vector3 VectorType; typedef Math::Matrix4 MatrixType; }; +#ifndef MAGNUM_TARGET_GLES template<> struct DimensionTraits<3, Double> { DimensionTraits() = delete; @@ -105,6 +108,7 @@ template<> struct DimensionTraits<3, Double> { typedef Math::Matrix4 MatrixType; }; #endif +#endif } diff --git a/src/Magnum.h b/src/Magnum.h index c93a6ce1d..b443cf30a 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -50,9 +50,11 @@ namespace Math { template struct Constants; #ifndef CORRADE_GCC46_COMPATIBILITY + #ifndef MAGNUM_TARGET_GLES constexpr Rad operator "" _rad(long double); - constexpr Rad operator "" _radf(long double); constexpr Deg operator "" _deg(long double); + #endif + constexpr Rad operator "" _radf(long double); constexpr Deg operator "" _degf(long double); #endif } @@ -253,9 +255,11 @@ typedef Math::Geometry::Rectangle 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 diff --git a/src/Math/Angle.h b/src/Math/Angle.h index 8c95d20d4..9b7b66000 100644 --- a/src/Math/Angle.h +++ b/src/Math/Angle.h @@ -147,6 +147,7 @@ template class Deg: public Unit { }; #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 operator "" _deg(long double value) { return Deg(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 operator "" _degf(long double value) { return Deg(value); } #endif @@ -206,6 +210,7 @@ template class Rad: public Unit { }; #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 operator "" _rad(long double value) { return Rad(value); } +#endif /** @relates Rad @brief Single-precision radian value literal diff --git a/src/Math/Test/AngleTest.cpp b/src/Math/Test/AngleTest.cpp index cac78bda1..1feba3aa8 100644 --- a/src/Math/Test/AngleTest.cpp +++ b/src/Math/Test/AngleTest.cpp @@ -43,8 +43,10 @@ class AngleTest: public Corrade::TestSuite::Tester { typedef Math::Deg Deg; typedef Math::Rad Rad; +#ifndef MAGNUM_TARGET_GLES typedef Math::Deg Degd; typedef Math::Rad 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::value)); - CORRADE_VERIFY((std::is_same::value)); CORRADE_COMPARE(Double(a), 25.0); + #endif + constexpr auto b = 25.0_degf; + CORRADE_VERIFY((std::is_same::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::value)); - CORRADE_VERIFY((std::is_same::value)); CORRADE_COMPARE(Double(m), 3.14); + #endif + constexpr auto n = 3.14_radf; + CORRADE_VERIFY((std::is_same::value)); CORRADE_COMPARE(Float(n), 3.14f); #else CORRADE_SKIP("User-defined literals are not available on GCC < 4.7."); diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index 2d178c166..ed32bb73e 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -134,11 +134,13 @@ void FunctionsTest::normalizeUnsigned() { CORRADE_COMPARE((Math::normalize(0)), 0.0f); CORRADE_COMPARE((Math::normalize(255)), 1.0f); + #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE((Math::normalize(0)), 0.0); CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0); CORRADE_COMPARE((Math::normalize(0)), 0.0); CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0); + #endif CORRADE_COMPARE((Math::normalize(0)), 0.0f); CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0f); @@ -158,6 +160,7 @@ void FunctionsTest::normalizeSigned() { CORRADE_COMPARE((Math::normalize(0)), 0.0f); CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0f); + #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE((Math::normalize(std::numeric_limits::min())), -1.0); CORRADE_COMPARE((Math::normalize(0)), 0.0); CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0); @@ -165,6 +168,7 @@ void FunctionsTest::normalizeSigned() { CORRADE_COMPARE((Math::normalize(std::numeric_limits::min())), -1.0); CORRADE_COMPARE((Math::normalize(0)), 0.0); CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0); + #endif CORRADE_COMPARE((Math::normalize(16384)), 0.500015f); CORRADE_COMPARE((Math::normalize(-16384)), -0.500015f); @@ -179,6 +183,7 @@ void FunctionsTest::denormalizeUnsigned() { CORRADE_COMPARE(Math::denormalize(0.0f), 0); CORRADE_COMPARE(Math::denormalize(1.0f), std::numeric_limits::max()); + #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE(Math::denormalize(0.0), 0); CORRADE_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); @@ -188,6 +193,7 @@ void FunctionsTest::denormalizeUnsigned() { CORRADE_VERIFY(false); //CORRADE_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); } + #endif CORRADE_COMPARE(Math::denormalize(0.33f), 21626); CORRADE_COMPARE(Math::denormalize(0.66f), 43253); @@ -204,6 +210,7 @@ void FunctionsTest::denormalizeSigned() { CORRADE_COMPARE(Math::denormalize(0.0f), 0); CORRADE_COMPARE(Math::denormalize(1.0f), std::numeric_limits::max()); + #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE(Math::denormalize(-1.0), std::numeric_limits::min()+1); CORRADE_COMPARE(Math::denormalize(0.0), 0); CORRADE_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); @@ -211,6 +218,7 @@ void FunctionsTest::denormalizeSigned() { CORRADE_COMPARE(Math::denormalize(-1.0l), std::numeric_limits::min()+1); CORRADE_COMPARE(Math::denormalize(0.0l), 0); CORRADE_COMPARE(Math::denormalize(1.0l), std::numeric_limits::max()); + #endif CORRADE_COMPARE(Math::denormalize(-0.33f), -10813); CORRADE_COMPARE(Math::denormalize(0.66f), 21626); @@ -225,11 +233,13 @@ void FunctionsTest::renormalizeUnsinged() { CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); + #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0)), 0.0); CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0)), 1.0); CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0l)), 0.0l); CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0l)), 1.0l); + #endif } void FunctionsTest::renormalizeSinged() { @@ -241,6 +251,7 @@ void FunctionsTest::renormalizeSinged() { CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); + #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE(Math::normalize(Math::denormalize(-1.0)), -1.0); CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0)), 0.0); CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0)), 1.0); @@ -248,6 +259,7 @@ void FunctionsTest::renormalizeSinged() { CORRADE_COMPARE(Math::normalize(Math::denormalize(-1.0l)), -1.0l); CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0l)), 0.0l); CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0l)), 1.0l); + #endif } void FunctionsTest::normalizeTypeDeduction() { diff --git a/src/Math/Test/TypeTraitsTest.cpp b/src/Math/Test/TypeTraitsTest.cpp index 63a6fbace..dd5d0edad 100644 --- a/src/Math/Test/TypeTraitsTest.cpp +++ b/src/Math/Test/TypeTraitsTest.cpp @@ -59,7 +59,9 @@ void TypeTraitsTest::equalsIntegral() { void TypeTraitsTest::equalsFloatingPoint() { _equalsFloatingPoint(); + #ifndef MAGNUM_TARGET_GLES _equalsFloatingPoint(); + #endif } template void TypeTraitsTest::_equalsIntegral() { diff --git a/src/Math/TypeTraits.h b/src/Math/TypeTraits.h index addcb4206..e79c8dca4 100644 --- a/src/Math/TypeTraits.h +++ b/src/Math/TypeTraits.h @@ -136,16 +136,24 @@ template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef Float FloatingPointType; }; template<> struct TypeTraits: Implementation::TypeTraitsIntegral { + #ifndef MAGNUM_TARGET_GLES typedef Double FloatingPointType; + #endif }; template<> struct TypeTraits: Implementation::TypeTraitsIntegral { + #ifndef MAGNUM_TARGET_GLES typedef Double FloatingPointType; + #endif }; template<> struct TypeTraits: Implementation::TypeTraitsIntegral { + #ifndef MAGNUM_TARGET_GLES typedef long double FloatingPointType; + #endif }; template<> struct TypeTraits: Implementation::TypeTraitsIntegral { + #ifndef MAGNUM_TARGET_GLES typedef long double FloatingPointType; + #endif }; /* Floating-point scalar types */ @@ -164,11 +172,13 @@ template<> struct TypeTraits: Implementation::TypeTraitsFloatingPoint struct TypeTraits: Implementation::TypeTraitsFloatingPoint { typedef Double FloatingPointType; inline constexpr static Double epsilon() { return DOUBLE_EQUALITY_PRECISION; } }; +#endif template<> struct TypeTraits: Implementation::TypeTraitsFloatingPoint { typedef long double FloatingPointType; diff --git a/src/Query.cpp b/src/Query.cpp index df80395fa..c53d02fc9 100644 --- a/src/Query.cpp +++ b/src/Query.cpp @@ -93,11 +93,11 @@ template<> Long AbstractQuery::result() { } #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(target), id()); this->target = new Target(target); @@ -135,6 +135,8 @@ void SampleQuery::end() { target = nullptr; } +#ifndef MAGNUM_TARGET_GLES TimeQuery::TimeQuery() = default; +#endif } diff --git a/src/Test/AbstractShaderProgramTest.cpp b/src/Test/AbstractShaderProgramTest.cpp index 4dc11e31b..05838f101 100644 --- a/src/Test/AbstractShaderProgramTest.cpp +++ b/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() { From 83bda8bbe6b6f1fa4c01743f8d3445cccf13f0f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 18 Mar 2013 20:17:39 +0100 Subject: [PATCH 7/8] Math: fixed test for denormalize(). Amazing what single forgotten literal can do. --- src/Math/Functions.h | 1 - src/Math/Test/FunctionsTest.cpp | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Math/Functions.h b/src/Math/Functions.h index d324983a5..9d25668f6 100644 --- a/src/Math/Functions.h +++ b/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 inline Integral denormalize(const FloatingPoint& value); diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index ed32bb73e..6fd0b63d7 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -187,12 +187,8 @@ void FunctionsTest::denormalizeUnsigned() { CORRADE_COMPARE(Math::denormalize(0.0), 0); CORRADE_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); - CORRADE_COMPARE(Math::denormalize(0.0), 0); - { - CORRADE_EXPECT_FAIL("Wrong result with GCC and non-optimized code."); - CORRADE_VERIFY(false); - //CORRADE_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); - } + CORRADE_COMPARE(Math::denormalize(0.0l), 0); + CORRADE_COMPARE(Math::denormalize(1.0l), std::numeric_limits::max()); #endif CORRADE_COMPARE(Math::denormalize(0.33f), 21626); From f490fc81497724ca944e87cb0f03cd808453adfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 18 Mar 2013 20:19:53 +0100 Subject: [PATCH 8/8] DebugTools: no need to prefix the test so much. --- src/DebugTools/Test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DebugTools/Test/CMakeLists.txt b/src/DebugTools/Test/CMakeLists.txt index 68a6ddae3..00f3ccf65 100644 --- a/src/DebugTools/Test/CMakeLists.txt +++ b/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)