From 33653a3469ced82b3177653d11e2d8ec9392734d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 9 Aug 2013 17:18:05 +0200 Subject: [PATCH] Math: hardened checks for proper size of primitive types. --- src/Math/instantiation.cpp | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/Math/instantiation.cpp b/src/Math/instantiation.cpp index dcaaaa601..1bf7f918b 100644 --- a/src/Math/instantiation.cpp +++ b/src/Math/instantiation.cpp @@ -105,6 +105,46 @@ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Quate template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Quaternion&); #endif +/* Check proper size of GL types */ +static_assert(sizeof(Vector<2, Float>) == 8, "Improper size of 2-element Float vector"); +static_assert(sizeof(Vector<3, Float>) == 12, "Improper size of 3-element Float vector"); +static_assert(sizeof(Vector<4, Float>) == 16, "Improper size of 4-element Float vector"); +static_assert(sizeof(Vector<2, Int>) == 8, "Improper size of 2-element Int vector"); +static_assert(sizeof(Vector<3, Int>) == 12, "Improper size of 3-element Int vector"); +static_assert(sizeof(Vector<4, Int>) == 16, "Improper size of 4-element Int vector"); +static_assert(sizeof(Vector<2, UnsignedInt>) == 8, "Improper size of 2-element UnsignedInt vector"); +static_assert(sizeof(Vector<3, UnsignedInt>) == 12, "Improper size of 3-element UnsignedInt vector"); +static_assert(sizeof(Vector<4, UnsignedInt>) == 16, "Improper size of 4-element UnsignedInt vector"); +#ifndef MAGNUM_TARGET_GLES +static_assert(sizeof(Vector<2, Double>) == 16, "Improper size of 2-element Double vector"); +static_assert(sizeof(Vector<3, Double>) == 24, "Improper size of 3-element Double vector"); +static_assert(sizeof(Vector<4, Double>) == 32, "Improper size of 4-element Double vector"); +#endif + +static_assert(sizeof(RectangularMatrix<2, 2, Float>) == 16, "Improper size of 2x2 Float matrix"); +static_assert(sizeof(RectangularMatrix<3, 3, Float>) == 36, "Improper size of 3x3 Float matrix"); +static_assert(sizeof(RectangularMatrix<4, 4, Float>) == 64, "Improper size of 4x4 Float matrix"); +#ifndef MAGNUM_TARGET_GLES +static_assert(sizeof(RectangularMatrix<2, 2, Double>) == 32, "Improper size of 2x2 Double matrix"); +static_assert(sizeof(RectangularMatrix<3, 3, Double>) == 72, "Improper size of 3x3 Double matrix"); +static_assert(sizeof(RectangularMatrix<4, 4, Double>) == 128, "Improper size of 4x4 Double matrix"); +#endif + +static_assert(sizeof(RectangularMatrix<2, 3, Float>) == 24, "Improper size of 2x3 Float matrix"); +static_assert(sizeof(RectangularMatrix<3, 2, Float>) == 24, "Improper size of 3x2 Float matrix"); +static_assert(sizeof(RectangularMatrix<2, 4, Float>) == 32, "Improper size of 2x4 Float matrix"); +static_assert(sizeof(RectangularMatrix<4, 2, Float>) == 32, "Improper size of 4x2 Float matrix"); +static_assert(sizeof(RectangularMatrix<3, 4, Float>) == 48, "Improper size of 3x4 Float matrix"); +static_assert(sizeof(RectangularMatrix<4, 3, Float>) == 48, "Improper size of 4x3 Float matrix"); +#ifndef MAGNUM_TARGET_GLES +static_assert(sizeof(RectangularMatrix<2, 3, Double>) == 48, "Improper size of 2x3 Double matrix"); +static_assert(sizeof(RectangularMatrix<3, 2, Double>) == 48, "Improper size of 3x2 Double matrix"); +static_assert(sizeof(RectangularMatrix<2, 4, Double>) == 64, "Improper size of 2x4 Double matrix"); +static_assert(sizeof(RectangularMatrix<4, 2, Double>) == 64, "Improper size of 4x2 Double matrix"); +static_assert(sizeof(RectangularMatrix<3, 4, Double>) == 96, "Improper size of 3x4 Double matrix"); +static_assert(sizeof(RectangularMatrix<4, 3, Double>) == 96, "Improper size of 4x3 Double matrix"); +#endif + template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const RectangularMatrix<2, 2, Float>&); template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const RectangularMatrix<3, 3, Float>&); template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const RectangularMatrix<4, 4, Float>&);